Skip to content
This repository was archived by the owner on May 9, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ You can also review our [Local Setup Guide](https://github.com/ChainSafe/chainbr

 

### Tracing
Jaeger traces observer will be available at [http://localhost:16686/](http://localhost:16686/)

## Contributing

Chainbridge-core is a open project and welcomes contributions of all kinds: code, docs, and more. If you wish to submit more complex changes,
Expand Down
14 changes: 13 additions & 1 deletion chains/evm/calls/contracts/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bridge

import (
"bytes"
"context"
"math/big"
"strconv"
"strings"
Expand Down Expand Up @@ -41,6 +42,7 @@ func (c *BridgeContract) AddRelayer(
) (*common.Hash, error) {
log.Debug().Msgf("Adding new relayer %s", relayerAddr.String())
return c.ExecuteTransaction(
context.Background(),
"adminAddRelayer",
opts,
relayerAddr,
Expand All @@ -58,6 +60,7 @@ func (c *BridgeContract) AdminSetGenericResource(
) (*common.Hash, error) {
log.Debug().Msgf("Setting generic resource %s", hexutil.Encode(rID[:]))
return c.ExecuteTransaction(
context.Background(),
"adminSetGenericResource",
opts,
handler, rID, addr, depositFunctionSig, depositerOffset, executeFunctionSig,
Expand All @@ -72,6 +75,7 @@ func (c *BridgeContract) AdminSetResource(
) (*common.Hash, error) {
log.Debug().Msgf("Setting resource %s", hexutil.Encode(rID[:]))
return c.ExecuteTransaction(
context.Background(),
"adminSetResource",
opts,
handlerAddr, rID, targetContractAddr,
Expand All @@ -85,6 +89,7 @@ func (c *BridgeContract) SetDepositNonce(
) (*common.Hash, error) {
log.Debug().Msgf("Setting deposit nonce %d for %d", depositNonce, domainId)
return c.ExecuteTransaction(
context.Background(),
"adminSetDepositNonce",
opts,
domainId, depositNonce,
Expand All @@ -97,6 +102,7 @@ func (c *BridgeContract) AdminChangeRelayerThreshold(
) (*common.Hash, error) {
log.Debug().Msgf("Setting threshold %d", threshold)
return c.ExecuteTransaction(
context.Background(),
"adminChangeRelayerThreshold",
opts,
big.NewInt(0).SetUint64(threshold),
Expand All @@ -110,6 +116,7 @@ func (c *BridgeContract) SetBurnableInput(
) (*common.Hash, error) {
log.Debug().Msgf("Setting burnable input for %s", tokenContractAddr.String())
return c.ExecuteTransaction(
context.Background(),
"adminSetBurnable",
opts,
handlerAddr, tokenContractAddr,
Expand All @@ -123,6 +130,7 @@ func (c *BridgeContract) deposit(
opts transactor.TransactOptions,
) (*common.Hash, error) {
return c.ExecuteTransaction(
context.Background(),
"deposit",
opts,
destDomainID, resourceID, data,
Expand Down Expand Up @@ -210,6 +218,7 @@ func (c *BridgeContract) ExecuteProposal(
Str("handler", proposal.HandlerAddress.String()).
Msgf("Execute proposal")
return c.ExecuteTransaction(
context.Background(),
"executeProposal",
opts,
proposal.Source, proposal.DepositNonce, proposal.Data, proposal.ResourceId, true,
Expand All @@ -226,6 +235,7 @@ func (c *BridgeContract) VoteProposal(
Str("handler", proposal.HandlerAddress.String()).
Msgf("Vote proposal")
return c.ExecuteTransaction(
context.Background(),
"voteProposal",
opts,
proposal.Source, proposal.DepositNonce, proposal.ResourceId, proposal.Data,
Expand All @@ -248,6 +258,7 @@ func (c *BridgeContract) SimulateVoteProposal(proposal *proposal.Proposal) error
func (c *BridgeContract) Pause(opts transactor.TransactOptions) (*common.Hash, error) {
log.Debug().Msg("Pause transfers")
return c.ExecuteTransaction(
context.Background(),
"adminPauseTransfers",
opts,
)
Expand All @@ -256,6 +267,7 @@ func (c *BridgeContract) Pause(opts transactor.TransactOptions) (*common.Hash, e
func (c *BridgeContract) Unpause(opts transactor.TransactOptions) (*common.Hash, error) {
log.Debug().Msg("Unpause transfers")
return c.ExecuteTransaction(
context.Background(),
"adminUnpauseTransfers",
opts,
)
Expand All @@ -277,7 +289,7 @@ func (c *BridgeContract) Withdraw(
data.Write(common.LeftPadBytes(recipientAddress.Bytes(), 32))
data.Write(common.LeftPadBytes(amountOrTokenId.Bytes(), 32))

return c.ExecuteTransaction("adminWithdraw", opts, handlerAddress, data.Bytes())
return c.ExecuteTransaction(context.Background(), "adminWithdraw", opts, handlerAddress, data.Bytes())
}

func (c *BridgeContract) GetThreshold() (uint8, error) {
Expand Down
17 changes: 16 additions & 1 deletion chains/evm/calls/contracts/bridge/bridge_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bridge_test

import (
"context"
"encoding/hex"
"errors"
"math/big"
Expand Down Expand Up @@ -100,7 +101,7 @@ func (s *ProposalStatusTestSuite) TestPrepare_WithdrawInput_Success() {
recipientAddress := common.HexToAddress("0x8e5F72B158BEDf0ab50EDa78c70dFC118158C272")
amountOrTokenId := big.NewInt(1)

s.mockTransactor.EXPECT().Transact(&s.bridgeAddress, gomock.Any(), gomock.Any()).Times(1).Return(
s.mockTransactor.EXPECT().Transact(context.Background(), &s.bridgeAddress, gomock.Any(), gomock.Any()).Times(1).Return(
&common.Hash{}, nil,
)

Expand Down Expand Up @@ -128,6 +129,7 @@ func (s *ProposalStatusTestSuite) TestDeployContract_Success() {

func (s *ProposalStatusTestSuite) TestBridge_AddRelayer_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -142,6 +144,7 @@ func (s *ProposalStatusTestSuite) TestBridge_AddRelayer_Success() {

func (s *ProposalStatusTestSuite) TestBridge_AdminSetGenericResource_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -156,6 +159,7 @@ func (s *ProposalStatusTestSuite) TestBridge_AdminSetGenericResource_Success() {

func (s *ProposalStatusTestSuite) TestBridge_AdminSetResource_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -170,6 +174,7 @@ func (s *ProposalStatusTestSuite) TestBridge_AdminSetResource_Success() {

func (s *ProposalStatusTestSuite) TestBridge_SetDepositNonce_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -184,6 +189,7 @@ func (s *ProposalStatusTestSuite) TestBridge_SetDepositNonce_Success() {

func (s *ProposalStatusTestSuite) TestBridge_SetThresholdInput_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -198,6 +204,7 @@ func (s *ProposalStatusTestSuite) TestBridge_SetThresholdInput_Success() {

func (s *ProposalStatusTestSuite) TestBridge_SetBurnableInput_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -212,6 +219,7 @@ func (s *ProposalStatusTestSuite) TestBridge_SetBurnableInput_Success() {

func (s *ProposalStatusTestSuite) TestBridge_Erc20Deposit_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -226,6 +234,7 @@ func (s *ProposalStatusTestSuite) TestBridge_Erc20Deposit_Success() {

func (s *ProposalStatusTestSuite) TestBridge_Erc721Deposit_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -240,6 +249,7 @@ func (s *ProposalStatusTestSuite) TestBridge_Erc721Deposit_Success() {

func (s *ProposalStatusTestSuite) TestBridge_GenericDeposit_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -254,6 +264,7 @@ func (s *ProposalStatusTestSuite) TestBridge_GenericDeposit_Success() {

func (s *ProposalStatusTestSuite) TestBridge_ExecuteProposal_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -268,6 +279,7 @@ func (s *ProposalStatusTestSuite) TestBridge_ExecuteProposal_Success() {

func (s *ProposalStatusTestSuite) TestBridge_VoteProposal_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -293,6 +305,7 @@ func (s *ProposalStatusTestSuite) TestBridge_SimulateVoteProposal_Success() {

func (s *ProposalStatusTestSuite) TestBridge_Pause_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -307,6 +320,7 @@ func (s *ProposalStatusTestSuite) TestBridge_Pause_Success() {

func (s *ProposalStatusTestSuite) TestBridge_Unpause_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand All @@ -321,6 +335,7 @@ func (s *ProposalStatusTestSuite) TestBridge_Unpause_Success() {

func (s *ProposalStatusTestSuite) TestBridge_Withdraw_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
gomock.Any(),
gomock.Any(),
gomock.Any(),
Expand Down
9 changes: 5 additions & 4 deletions chains/evm/calls/contracts/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package contracts
import (
"context"
"fmt"

"github.com/ChainSafe/chainbridge-core/chains/evm/calls"
"github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor"
"github.com/ethereum/go-ethereum"
Expand Down Expand Up @@ -60,12 +61,12 @@ func (c *Contract) UnpackResult(method string, output []byte) ([]interface{}, er
return res, err
}

func (c *Contract) ExecuteTransaction(method string, opts transactor.TransactOptions, args ...interface{}) (*common.Hash, error) {
func (c *Contract) ExecuteTransaction(ctx context.Context, method string, opts transactor.TransactOptions, args ...interface{}) (*common.Hash, error) {
input, err := c.PackMethod(method, args...)
if err != nil {
return nil, err
}
h, err := c.Transact(&c.contractAddress, input, opts)
h, err := c.Transact(ctx, &c.contractAddress, input, opts)
if err != nil {
log.Error().
Str("contract", c.contractAddress.String()).
Expand All @@ -77,7 +78,7 @@ func (c *Contract) ExecuteTransaction(method string, opts transactor.TransactOpt
Str("txHash", h.String()).
Str("contract", c.contractAddress.String()).
Msgf("method %s executed", method)
return h, err
return h, nil
}

func (c *Contract) CallContract(method string, args ...interface{}) ([]interface{}, error) {
Expand Down Expand Up @@ -114,7 +115,7 @@ func (c *Contract) DeployContract(params ...interface{}) (common.Address, error)
return common.Address{}, err
}
opts := transactor.TransactOptions{GasLimit: DefaultDeployGasLimit}
hash, err := c.Transact(nil, append(c.bytecode, input...), opts)
hash, err := c.Transact(context.Background(), nil, append(c.bytecode, input...), opts)
if err != nil {
return common.Address{}, err
}
Expand Down
18 changes: 12 additions & 6 deletions chains/evm/calls/contracts/contract_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package contracts

import (
"context"
"errors"
"math/big"
"strings"
"testing"

"github.com/ChainSafe/chainbridge-core/chains/evm/calls/consts"
mock_calls "github.com/ChainSafe/chainbridge-core/chains/evm/calls/mock"
"github.com/ChainSafe/chainbridge-core/chains/evm/calls/transactor"
Expand All @@ -10,9 +15,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/suite"
"math/big"
"strings"
"testing"
)

type ContractTestSuite struct {
Expand Down Expand Up @@ -66,12 +68,13 @@ func (s *ContractTestSuite) TestContract_UnpackResult_InvalidRequest_Fail() {

func (s *ContractTestSuite) TestContract_ExecuteTransaction_ValidRequest_Success() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
&common.Address{},
gomock.Any(),
transactor.TransactOptions{},
).Return(&common.Hash{}, nil)
hash, err := s.contract.ExecuteTransaction(
"approve",
context.Background(), "approve",
transactor.TransactOptions{}, common.Address{}, big.NewInt(10),
)
s.Nil(err)
Expand All @@ -80,11 +83,13 @@ func (s *ContractTestSuite) TestContract_ExecuteTransaction_ValidRequest_Success

func (s *ContractTestSuite) TestContract_ExecuteTransaction_TransactError_Fail() {
s.mockTransactor.EXPECT().Transact(
context.Background(),
&common.Address{},
gomock.Any(),
transactor.TransactOptions{},
).Return(nil, errors.New("error"))
hash, err := s.contract.ExecuteTransaction(
context.Background(),
"approve",
transactor.TransactOptions{}, common.Address{}, big.NewInt(10),
)
Expand All @@ -94,6 +99,7 @@ func (s *ContractTestSuite) TestContract_ExecuteTransaction_TransactError_Fail()

func (s *ContractTestSuite) TestContract_ExecuteTransaction_InvalidRequest_Fail() {
hash, err := s.contract.ExecuteTransaction(
context.Background(),
"approve",
transactor.TransactOptions{}, common.Address{}, // missing one argument
)
Expand Down Expand Up @@ -149,7 +155,7 @@ func (s *ContractTestSuite) TestContract_DeployContract_InvalidRequest_Fail() {

func (s *ContractTestSuite) TestContract_DeployContract_TransactionError_Fail() {
s.mockTransactor.EXPECT().Transact(
nil, gomock.Any(), gomock.Any(),
context.Background(), nil, gomock.Any(), gomock.Any(),
).Times(1).Return(&common.Hash{}, errors.New("error"))
res, err := s.contract.DeployContract("TestERC721", "TST721", "")
s.Equal(common.Address{}, res)
Expand All @@ -158,7 +164,7 @@ func (s *ContractTestSuite) TestContract_DeployContract_TransactionError_Fail()

func (s *ContractTestSuite) TestContract_DeployContract_GetTxByHashError_Fail() {
s.mockTransactor.EXPECT().Transact(
nil, gomock.Any(), gomock.Any(),
context.Background(), nil, gomock.Any(), gomock.Any(),
).Times(1).Return(&common.Hash{}, nil)
s.mockContractCallerDispatcherClient.EXPECT().GetTransactionByHash(
common.Hash{},
Expand Down
Loading