From fa3a2d294e6cddb51faca92e77358527dc9d23a0 Mon Sep 17 00:00:00 2001 From: skosito Date: Thu, 6 Jun 2024 22:16:35 +0200 Subject: [PATCH 1/8] fix typeddata todo --- rpc/backend/sign_tx_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/rpc/backend/sign_tx_test.go b/rpc/backend/sign_tx_test.go index 153e326cd6..d49e25d1ec 100644 --- a/rpc/backend/sign_tx_test.go +++ b/rpc/backend/sign_tx_test.go @@ -5,16 +5,19 @@ import ( "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" goethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/signer/core/apitypes" "github.com/evmos/ethermint/crypto/ethsecp256k1" + "github.com/evmos/ethermint/ethereum/eip712" "github.com/evmos/ethermint/tests" evmtypes "github.com/evmos/ethermint/x/evm/types" "google.golang.org/grpc/metadata" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" ) @@ -221,6 +224,9 @@ func (suite *BackendTestSuite) TestSign() { } func (suite *BackendTestSuite) TestSignTypedData() { + data := legacytx.StdSignBytes("0", 1, 1, 0, legacytx.StdFee{Gas: 10, Amount: sdk.Coins{}}, []sdk.Msg{&banktypes.MsgSend{}}, "", nil) + typedData, err := eip712.WrapTxToTypedData(0, data) + suite.Require().NoError(err) from, priv := tests.NewAddrKey() testCases := []struct { name string @@ -246,7 +252,16 @@ func (suite *BackendTestSuite) TestSignTypedData() { apitypes.TypedData{}, false, }, - // TODO (https://github.com/zeta-chain/node/issues/2302): Generate a TypedData msg + { + "sucess - valid typed data", + func() { + armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") + suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "") + }, + from, + typedData, + true, + }, } for _, tc := range testCases { From d4358d4df5f3839b6d12d82c09f6cd8d38db87e1 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 13:27:33 +0200 Subject: [PATCH 2/8] fix more todos --- rpc/backend/client_test.go | 2 +- rpc/backend/node_info_test.go | 46 +++++++++-------------------------- 2 files changed, 12 insertions(+), 36 deletions(-) diff --git a/rpc/backend/client_test.go b/rpc/backend/client_test.go index 74d6ae0bfd..7285e8b983 100644 --- a/rpc/backend/client_test.go +++ b/rpc/backend/client_test.go @@ -278,7 +278,7 @@ func RegisterABCIQueryWithOptions( client.On("ABCIQueryWithOptions", context.Background(), path, data, opts). Return(&tmrpctypes.ResultABCIQuery{ Response: abci.ResponseQuery{ - Value: []byte{2}, // TODO (https://github.com/zeta-chain/node/issues/2302) replace with data.Bytes(), + Value: data.Bytes(), Height: height, }, }, nil) diff --git a/rpc/backend/node_info_test.go b/rpc/backend/node_info_test.go index a98c433f11..1e7f4d52d5 100644 --- a/rpc/backend/node_info_test.go +++ b/rpc/backend/node_info_test.go @@ -96,48 +96,24 @@ func (suite *BackendTestSuite) TestSetGasPrice() { } } -// TODO (https://github.com/zeta-chain/node/issues/2302): Combine these 2 into one test since the code is identical -func (suite *BackendTestSuite) TestListAccounts() { +func (suite *BackendTestSuite) TestAccounts() { testCases := []struct { - name string - registerMock func() - expAddr []common.Address - expPass bool + name string + accountsRetrievalMethod func() ([]common.Address, error) + registerMock func() + expAddr []common.Address + expPass bool }{ { - "pass - returns empty address", + "pass - returns empty address from ListAccounts", + suite.backend.ListAccounts, func() {}, []common.Address{}, true, }, - } - - for _, tc := range testCases { - suite.Run(fmt.Sprintf("case %s", tc.name), func() { - suite.SetupTest() // reset test and queries - tc.registerMock() - - output, err := suite.backend.ListAccounts() - - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(tc.expAddr, output) - } else { - suite.Require().Error(err) - } - }) - } -} - -func (suite *BackendTestSuite) TestAccounts() { - testCases := []struct { - name string - registerMock func() - expAddr []common.Address - expPass bool - }{ { - "pass - returns empty address", + "pass - returns empty address from Accounts", + suite.backend.Accounts, func() {}, []common.Address{}, true, @@ -149,7 +125,7 @@ func (suite *BackendTestSuite) TestAccounts() { suite.SetupTest() // reset test and queries tc.registerMock() - output, err := suite.backend.Accounts() + output, err := tc.accountsRetrievalMethod() if tc.expPass { suite.Require().NoError(err) From e53986ca77eaa6addc8e21ab0070cecc6067d7a7 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 15:18:51 +0200 Subject: [PATCH 3/8] fix node info test todo --- rpc/backend/backend_suite_test.go | 13 +++++-- rpc/backend/call_tx.go | 2 +- rpc/backend/client_test.go | 24 ++++++++++++ rpc/backend/node_info_test.go | 64 +++++++++++++++++-------------- 4 files changed, 70 insertions(+), 33 deletions(-) diff --git a/rpc/backend/backend_suite_test.go b/rpc/backend/backend_suite_test.go index 0194d5902f..b1b362aa12 100644 --- a/rpc/backend/backend_suite_test.go +++ b/rpc/backend/backend_suite_test.go @@ -10,6 +10,7 @@ import ( dbm "github.com/cometbft/cometbft-db" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,8 +55,14 @@ func (suite *BackendTestSuite) SetupTest() { panic(err) } - // Create Account with set sequence - suite.acc = sdk.AccAddress(tests.GenerateAddress().Bytes()) + // Create Account with set sequence and import it in keyring + priv, err := ethsecp256k1.GenerateKey() + suite.Require().NoError(err) + + armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") + keyRing.ImportPrivKey("test_key", armor, "") + + suite.acc = sdk.AccAddress(priv.PubKey().Address().Bytes()) accounts := map[string]client.TestAccount{} accounts[suite.acc.String()] = client.TestAccount{ Address: suite.acc, @@ -63,7 +70,7 @@ func (suite *BackendTestSuite) SetupTest() { Seq: uint64(1), } - priv, err := ethsecp256k1.GenerateKey() + priv, err = ethsecp256k1.GenerateKey() suite.signer = tests.NewSigner(priv) suite.Require().NoError(err) diff --git a/rpc/backend/call_tx.go b/rpc/backend/call_tx.go index 9df59ffd06..95bedf5a42 100644 --- a/rpc/backend/call_tx.go +++ b/rpc/backend/call_tx.go @@ -252,7 +252,7 @@ func (b *Backend) SetTxDefaults(args evmtypes.TransactionArgs) (evmtypes.Transac } if args.Nonce == nil { // get the nonce from the account retriever - // ignore error in case tge account doesn't exist yet + // ignore error in case the account doesn't exist yet nonce, err := b.getAccountNonce(*args.From, true, 0, b.logger) if err != nil { nonce = 0 diff --git a/rpc/backend/client_test.go b/rpc/backend/client_test.go index 7285e8b983..a94716e2fe 100644 --- a/rpc/backend/client_test.go +++ b/rpc/backend/client_test.go @@ -12,12 +12,14 @@ import ( "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" evmtypes "github.com/evmos/ethermint/x/evm/types" mock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" rpc "github.com/zeta-chain/zetacore/rpc/types" ) @@ -52,6 +54,11 @@ func RegisterBroadcastTx(client *mocks.Client, tx types.Tx) { Return(&tmrpctypes.ResultBroadcastTx{}, nil) } +func RegisterBroadcastTxAny(client *mocks.Client) { + client.On("BroadcastTxSync", context.Background(), mock.Anything). + Return(&tmrpctypes.ResultBroadcastTx{}, nil) +} + func RegisterBroadcastTxError(client *mocks.Client, tx types.Tx) { client.On("BroadcastTxSync", context.Background(), tx). Return(nil, errortypes.ErrInvalidRequest) @@ -317,3 +324,20 @@ func RegisterABCIQueryAccount( }, }, nil) } + +func RegisterABCIQuerySimulate( + clients *mocks.Client, + opts tmrpcclient.ABCIQueryOptions, +) { + simResp := &tx.SimulateResponse{ + GasInfo: &sdk.GasInfo{GasWanted: uint64(21000), GasUsed: uint64(21000)}, + } + respBz, _ := simResp.Marshal() + clients.On("ABCIQueryWithOptions", context.Background(), "/cosmos.tx.v1beta1.Service/Simulate", mock.Anything, opts). + Return(&tmrpctypes.ResultABCIQuery{ + Response: abci.ResponseQuery{ + Value: respBz, + Height: 1, + }, + }, nil) +} diff --git a/rpc/backend/node_info_test.go b/rpc/backend/node_info_test.go index 1e7f4d52d5..a25677e38b 100644 --- a/rpc/backend/node_info_test.go +++ b/rpc/backend/node_info_test.go @@ -14,6 +14,7 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc/metadata" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" ) @@ -105,17 +106,17 @@ func (suite *BackendTestSuite) TestAccounts() { expPass bool }{ { - "pass - returns empty address from ListAccounts", + "pass - returns acc from keyring from ListAccounts", suite.backend.ListAccounts, func() {}, - []common.Address{}, + []common.Address{common.Address(suite.acc)}, true, }, { - "pass - returns empty address from Accounts", + "pass - returns acc from keyring from Accounts", suite.backend.Accounts, func() {}, - []common.Address{}, + []common.Address{common.Address(suite.acc)}, true, }, } @@ -248,31 +249,36 @@ func (suite *BackendTestSuite) TestSetEtherbase() { common.Address{}, false, }, - // TODO (https://github.com/zeta-chain/node/issues/2302): Finish this test case once ABCIQuery GetAccount is fixed - //{ - // "pass - set the etherbase for the miner", - // func() { - // client := suite.backend.clientCtx.Client.(*mocks.Client) - // queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) - // RegisterStatus(client) - // RegisterValidatorAccount(queryClient, suite.acc) - // c := sdk.NewDecCoin("azeta", sdk.NewIntFromBigInt(big.NewInt(1))) - // suite.backend.cfg.SetMinGasPrices(sdk.DecCoins{c}) - // delAddr, _ := suite.backend.GetCoinbase() - // account, _ := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, delAddr) - // delCommonAddr := common.BytesToAddress(delAddr.Bytes()) - // request := &authtypes.QueryAccountRequest{Address: sdk.AccAddress(delCommonAddr.Bytes()).String()} - // requestMarshal, _ := request.Marshal() - // RegisterABCIQueryAccount( - // client, - // requestMarshal, - // tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false}, - // account, - // ) - // }, - // common.Address{}, - // false, - //}, + { + "pass - set the etherbase for the miner", + func() { + var header metadata.MD + queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) + RegisterParams(queryClient, &header, 1) + suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry(codectypes.NewInterfaceRegistry()) + client := suite.backend.clientCtx.Client.(*mocks.Client) + RegisterStatus(client) + RegisterValidatorAccount(queryClient, suite.acc) + c := sdk.NewDecCoin("azeta", sdk.NewIntFromBigInt(big.NewInt(1))) + suite.backend.cfg.SetMinGasPrices(sdk.DecCoins{c}) + delAddr, _ := suite.backend.GetCoinbase() + account, _ := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, delAddr) + delCommonAddr := common.BytesToAddress(delAddr.Bytes()) + request := &authtypes.QueryAccountRequest{Address: sdk.AccAddress(delCommonAddr.Bytes()).String()} + requestMarshal, _ := request.Marshal() + RegisterUnconfirmedTxsEmpty(client, nil) + RegisterABCIQueryAccount( + client, + requestMarshal, + tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false}, + account, + ) + RegisterABCIQuerySimulate(client, tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false}) + RegisterBroadcastTxAny(client) + }, + common.Address{}, + true, + }, } for _, tc := range testCases { From 4851c742ab4b99eac6d6f9ed48e32081c51cb48e Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 16:54:23 +0200 Subject: [PATCH 4/8] fix tests --- rpc/backend/account_info_test.go | 7 +++++-- rpc/backend/client_test.go | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/rpc/backend/account_info_test.go b/rpc/backend/account_info_test.go index f54b743d5f..cebf650c7e 100644 --- a/rpc/backend/account_info_test.go +++ b/rpc/backend/account_info_test.go @@ -82,6 +82,7 @@ func (suite *BackendTestSuite) TestGetProof() { blockNrInvalid := rpctypes.NewBlockNumber(big.NewInt(1)) blockNr := rpctypes.NewBlockNumber(big.NewInt(4)) address1 := tests.GenerateAddress() + expProofValue := big.NewInt(2) testCases := []struct { name string @@ -93,7 +94,7 @@ func (suite *BackendTestSuite) TestGetProof() { expAccRes *rpctypes.AccountResult }{ { - "fail - BlockNumeber = 1 (invalidBlockNumber)", + "fail - BlockNumber = 1 (invalidBlockNumber)", address1, []string{}, rpctypes.BlockNumberOrHash{BlockNumber: &blockNrInvalid}, @@ -139,6 +140,7 @@ func (suite *BackendTestSuite) TestGetProof() { "store/evm/key", evmtypes.StateKey(address1, common.HexToHash("0x0").Bytes()), tmrpcclient.ABCIQueryOptions{Height: iavlHeight, Prove: true}, + expProofValue.Bytes(), ) RegisterABCIQueryWithOptions( client, @@ -146,6 +148,7 @@ func (suite *BackendTestSuite) TestGetProof() { "store/acc/key", authtypes.AddressStoreKey(sdk.AccAddress(address1.Bytes())), tmrpcclient.ABCIQueryOptions{Height: iavlHeight, Prove: true}, + expProofValue.Bytes(), ) }, true, @@ -159,7 +162,7 @@ func (suite *BackendTestSuite) TestGetProof() { StorageProof: []rpctypes.StorageResult{ { Key: "0x0", - Value: (*hexutil.Big)(big.NewInt(2)), + Value: (*hexutil.Big)(expProofValue), Proof: []string{""}, }, }, diff --git a/rpc/backend/client_test.go b/rpc/backend/client_test.go index a94716e2fe..640fd7e896 100644 --- a/rpc/backend/client_test.go +++ b/rpc/backend/client_test.go @@ -281,11 +281,12 @@ func RegisterABCIQueryWithOptions( path string, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions, + respValue []byte, ) { client.On("ABCIQueryWithOptions", context.Background(), path, data, opts). Return(&tmrpctypes.ResultABCIQuery{ Response: abci.ResponseQuery{ - Value: data.Bytes(), + Value: respValue, Height: height, }, }, nil) From b7bec934f170c524819ada4baac846d18f498a5f Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 17:21:51 +0200 Subject: [PATCH 5/8] revert importing suite.acc to keyring --- rpc/backend/backend_suite_test.go | 12 +++--------- rpc/backend/node_info_test.go | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/rpc/backend/backend_suite_test.go b/rpc/backend/backend_suite_test.go index b1b362aa12..18a74edfd8 100644 --- a/rpc/backend/backend_suite_test.go +++ b/rpc/backend/backend_suite_test.go @@ -10,7 +10,6 @@ import ( dbm "github.com/cometbft/cometbft-db" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/crypto" "github.com/cosmos/cosmos-sdk/crypto/keyring" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" @@ -55,14 +54,9 @@ func (suite *BackendTestSuite) SetupTest() { panic(err) } - // Create Account with set sequence and import it in keyring - priv, err := ethsecp256k1.GenerateKey() - suite.Require().NoError(err) + // Create Account with set sequence - armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") - keyRing.ImportPrivKey("test_key", armor, "") - - suite.acc = sdk.AccAddress(priv.PubKey().Address().Bytes()) + suite.acc = sdk.AccAddress(tests.GenerateAddress().Bytes()) accounts := map[string]client.TestAccount{} accounts[suite.acc.String()] = client.TestAccount{ Address: suite.acc, @@ -70,7 +64,7 @@ func (suite *BackendTestSuite) SetupTest() { Seq: uint64(1), } - priv, err = ethsecp256k1.GenerateKey() + priv, err := ethsecp256k1.GenerateKey() suite.signer = tests.NewSigner(priv) suite.Require().NoError(err) diff --git a/rpc/backend/node_info_test.go b/rpc/backend/node_info_test.go index a25677e38b..12ef47607c 100644 --- a/rpc/backend/node_info_test.go +++ b/rpc/backend/node_info_test.go @@ -5,6 +5,8 @@ import ( "math/big" tmrpcclient "github.com/cometbft/cometbft/rpc/client" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" @@ -109,14 +111,14 @@ func (suite *BackendTestSuite) TestAccounts() { "pass - returns acc from keyring from ListAccounts", suite.backend.ListAccounts, func() {}, - []common.Address{common.Address(suite.acc)}, + []common.Address{}, true, }, { "pass - returns acc from keyring from Accounts", suite.backend.Accounts, func() {}, - []common.Address{common.Address(suite.acc)}, + []common.Address{}, true, }, } @@ -252,6 +254,21 @@ func (suite *BackendTestSuite) TestSetEtherbase() { { "pass - set the etherbase for the miner", func() { + priv, err := ethsecp256k1.GenerateKey() + suite.Require().NoError(err) + + armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") + suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "") + + suite.acc = sdk.AccAddress(priv.PubKey().Address().Bytes()) + accounts := map[string]client.TestAccount{} + accounts[suite.acc.String()] = client.TestAccount{ + Address: suite.acc, + Num: uint64(1), + Seq: uint64(1), + } + + suite.backend.clientCtx = suite.backend.clientCtx.WithAccountRetriever(client.TestAccountRetriever{Accounts: accounts}) var header metadata.MD queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) RegisterParams(queryClient, &header, 1) From 8a0028560e1607827dcdbd4373e3f2035b5723c5 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 17:52:38 +0200 Subject: [PATCH 6/8] fix todo in account info tests --- rpc/backend/account_info_test.go | 46 +++++++++++++++++--------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/rpc/backend/account_info_test.go b/rpc/backend/account_info_test.go index cebf650c7e..2594af8aa2 100644 --- a/rpc/backend/account_info_test.go +++ b/rpc/backend/account_info_test.go @@ -5,6 +5,7 @@ import ( "math/big" tmrpcclient "github.com/cometbft/cometbft/rpc/client" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" @@ -418,27 +419,30 @@ func (suite *BackendTestSuite) TestGetTransactionCount() { false, hexutil.Uint64(0), }, - // TODO (https://github.com/zeta-chain/node/issues/2302): Error mocking the GetAccount call - problem with Any type - //{ - // "pass - returns the number of transactions at the given address up to the given block number", - // true, - // rpctypes.NewBlockNumber(big.NewInt(1)), - // func(addr common.Address, bn rpctypes.BlockNumber) { - // client := suite.backend.clientCtx.Client.(*mocks.Client) - // account, err := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, suite.acc) - // suite.Require().NoError(err) - // request := &authtypes.QueryAccountRequest{Address: sdk.AccAddress(suite.acc.Bytes()).String()} - // requestMarshal, _ := request.Marshal() - // RegisterABCIQueryAccount( - // client, - // requestMarshal, - // tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false}, - // account, - // ) - // }, - // true, - // hexutil.Uint64(0), - //}, + { + "pass - returns the number of transactions at the given address up to the given block number", + true, + rpctypes.NewBlockNumber(big.NewInt(1)), + func(addr common.Address, bn rpctypes.BlockNumber) { + var header metadata.MD + queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) + RegisterParams(queryClient, &header, 1) + suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry(codectypes.NewInterfaceRegistry()) + client := suite.backend.clientCtx.Client.(*mocks.Client) + account, err := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, suite.acc) + suite.Require().NoError(err) + request := &authtypes.QueryAccountRequest{Address: sdk.AccAddress(suite.acc.Bytes()).String()} + requestMarshal, _ := request.Marshal() + RegisterABCIQueryAccount( + client, + requestMarshal, + tmrpcclient.ABCIQueryOptions{Height: int64(1), Prove: false}, + account, + ) + }, + true, + hexutil.Uint64(1), + }, } for _, tc := range testCases { suite.Run(fmt.Sprintf("Case %s", tc.name), func() { From 9ddc0ea378e3d91ea76562afd0a3cc01e194a399 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 17:53:52 +0200 Subject: [PATCH 7/8] changelog --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 598ce8dd6a..c70184288a 100644 --- a/changelog.md +++ b/changelog.md @@ -54,6 +54,7 @@ * [2240](https://github.com/zeta-chain/node/pull/2240) - removed hard-coded Bitcoin regnet chainID in E2E withdraw tests * [2266](https://github.com/zeta-chain/node/pull/2266) - try fixing E2E test `crosschain_swap` failure `btc transaction not signed` * [2294](https://github.com/zeta-chain/node/pull/2294) - add and fix existing ethermint rpc unit test +* [2329](https://github.com/zeta-chain/node/pull/2329) - fix TODOs in rpc unit tests * [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts ### Fixes From 9aaaa48fe519ace4df98105a7f6ff0bbb2843b38 Mon Sep 17 00:00:00 2001 From: skosito Date: Fri, 7 Jun 2024 17:57:50 +0200 Subject: [PATCH 8/8] make generate --- rpc/backend/account_info_test.go | 4 +++- rpc/backend/client_test.go | 2 +- rpc/backend/node_info_test.go | 10 +++++++--- rpc/backend/sign_tx_test.go | 13 +++++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/rpc/backend/account_info_test.go b/rpc/backend/account_info_test.go index 2594af8aa2..111b6bfb4f 100644 --- a/rpc/backend/account_info_test.go +++ b/rpc/backend/account_info_test.go @@ -427,7 +427,9 @@ func (suite *BackendTestSuite) TestGetTransactionCount() { var header metadata.MD queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) RegisterParams(queryClient, &header, 1) - suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry(codectypes.NewInterfaceRegistry()) + suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry( + codectypes.NewInterfaceRegistry(), + ) client := suite.backend.clientCtx.Client.(*mocks.Client) account, err := suite.backend.clientCtx.AccountRetriever.GetAccount(suite.backend.clientCtx, suite.acc) suite.Require().NoError(err) diff --git a/rpc/backend/client_test.go b/rpc/backend/client_test.go index 640fd7e896..c94c7cc0e0 100644 --- a/rpc/backend/client_test.go +++ b/rpc/backend/client_test.go @@ -11,6 +11,7 @@ import ( "github.com/cometbft/cometbft/types" "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -19,7 +20,6 @@ import ( mock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" rpc "github.com/zeta-chain/zetacore/rpc/types" ) diff --git a/rpc/backend/node_info_test.go b/rpc/backend/node_info_test.go index 12ef47607c..7931cf4230 100644 --- a/rpc/backend/node_info_test.go +++ b/rpc/backend/node_info_test.go @@ -6,6 +6,7 @@ import ( tmrpcclient "github.com/cometbft/cometbft/rpc/client" "github.com/cosmos/cosmos-sdk/client" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" @@ -16,7 +17,6 @@ import ( "github.com/spf13/viper" "google.golang.org/grpc/metadata" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" ) @@ -268,11 +268,15 @@ func (suite *BackendTestSuite) TestSetEtherbase() { Seq: uint64(1), } - suite.backend.clientCtx = suite.backend.clientCtx.WithAccountRetriever(client.TestAccountRetriever{Accounts: accounts}) + suite.backend.clientCtx = suite.backend.clientCtx.WithAccountRetriever( + client.TestAccountRetriever{Accounts: accounts}, + ) var header metadata.MD queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) RegisterParams(queryClient, &header, 1) - suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry(codectypes.NewInterfaceRegistry()) + suite.backend.clientCtx = suite.backend.clientCtx.WithInterfaceRegistry( + codectypes.NewInterfaceRegistry(), + ) client := suite.backend.clientCtx.Client.(*mocks.Client) RegisterStatus(client) RegisterValidatorAccount(queryClient, suite.acc) diff --git a/rpc/backend/sign_tx_test.go b/rpc/backend/sign_tx_test.go index d49e25d1ec..d50f6fb6bd 100644 --- a/rpc/backend/sign_tx_test.go +++ b/rpc/backend/sign_tx_test.go @@ -6,6 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" ethtypes "github.com/ethereum/go-ethereum/core/types" @@ -17,7 +18,6 @@ import ( evmtypes "github.com/evmos/ethermint/x/evm/types" "google.golang.org/grpc/metadata" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/zeta-chain/zetacore/rpc/backend/mocks" ) @@ -224,7 +224,16 @@ func (suite *BackendTestSuite) TestSign() { } func (suite *BackendTestSuite) TestSignTypedData() { - data := legacytx.StdSignBytes("0", 1, 1, 0, legacytx.StdFee{Gas: 10, Amount: sdk.Coins{}}, []sdk.Msg{&banktypes.MsgSend{}}, "", nil) + data := legacytx.StdSignBytes( + "0", + 1, + 1, + 0, + legacytx.StdFee{Gas: 10, Amount: sdk.Coins{}}, + []sdk.Msg{&banktypes.MsgSend{}}, + "", + nil, + ) typedData, err := eip712.WrapTxToTypedData(0, data) suite.Require().NoError(err) from, priv := tests.NewAddrKey()