From 95fe6af342e0869826b1ba8c94373b0933b8c46c Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Thu, 14 Apr 2022 11:33:45 -0400 Subject: [PATCH 1/5] fix txIndex on getBlockBynumber --- rpc/ethereum/backend/backend.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rpc/ethereum/backend/backend.go b/rpc/ethereum/backend/backend.go index c337444120..51565b28f0 100644 --- a/rpc/ethereum/backend/backend.go +++ b/rpc/ethereum/backend/backend.go @@ -362,6 +362,7 @@ func (e *EVMBackend) EthBlockFromTendermint( } txResults := resBlockResult.TxsResults + txIndex := uint64(0) for i, txBz := range block.Txs { tx, err := e.clientCtx.TxConfig.TxDecoder()(txBz) @@ -394,7 +395,7 @@ func (e *EVMBackend) EthBlockFromTendermint( tx, common.BytesToHash(block.Hash()), uint64(block.Height), - uint64(i), + txIndex, baseFee, ) if err != nil { @@ -402,6 +403,7 @@ func (e *EVMBackend) EthBlockFromTendermint( continue } ethRPCTxs = append(ethRPCTxs, rpcTx) + txIndex++ } } From dc4195308981bef6d92f10f04bf9383ae1a10696 Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Thu, 14 Apr 2022 11:46:31 -0400 Subject: [PATCH 2/5] test EthBatchTransactions --- tests/e2e/integration_test.go | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index 0052ee2ca0..27424aec20 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -4,6 +4,10 @@ import ( "bytes" "context" "fmt" + "github.com/cosmos/cosmos-sdk/client/flags" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" + "github.com/tharsis/ethermint/rpc/ethereum/types" "math/big" "testing" @@ -747,3 +751,85 @@ func (s *IntegrationTestSuite) TestPendingTransactionFilter() { s.Require().NoError(err) s.Require().Equal([]common.Hash{signedTx.Hash()}, filterResult) } + +//TODO add transactionIndex tests once we have OpenRPC interfaces +func (s *IntegrationTestSuite) TestBatchETHTransactions() { + const ethTxs = 2 + txBuilder := s.network.Validators[0].ClientCtx.TxConfig.NewTxBuilder() + builder, ok := txBuilder.(authtx.ExtensionOptionsTxBuilder) + s.Require().True(ok) + + recipient := common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec") + accountNonce := s.getAccountNonce(recipient) + feeAmount := sdk.ZeroInt() + + var gasLimit uint64 + var msgs []sdk.Msg + + for i := 0; i < ethTxs; i++ { + chainId, err := s.network.Validators[0].JSONRPCClient.ChainID(s.ctx) + s.Require().NoError(err) + + gasPrice := s.getGasPrice() + from := common.BytesToAddress(s.network.Validators[0].Address) + nonce := accountNonce + uint64(i) + 1 + + msgTx := evmtypes.NewTx( + chainId, + nonce, + &recipient, + big.NewInt(10), + 100000, + gasPrice, + big.NewInt(200), + nil, + nil, + nil, + ) + msgTx.From = from.Hex() + err = msgTx.Sign(s.ethSigner, s.network.Validators[0].ClientCtx.Keyring) + s.Require().NoError(err) + + msgs = append(msgs, msgTx.GetMsgs()...) + txData, err := evmtypes.UnpackTxData(msgTx.Data) + s.Require().NoError(err) + feeAmount = feeAmount.Add(sdk.NewIntFromBigInt(txData.Fee())) + gasLimit = gasLimit + txData.GetGas() + } + + option, err := codectypes.NewAnyWithValue(&evmtypes.ExtensionOptionsEthereumTx{}) + s.Require().NoError(err) + + queryClient := types.NewQueryClient(s.network.Validators[0].ClientCtx) + res, err := queryClient.Params(s.ctx, &evmtypes.QueryParamsRequest{}) + + fees := make(sdk.Coins, 0) + if feeAmount.Sign() > 0 { + fees = append(fees, sdk.NewCoin(res.GetParams().EvmDenom, feeAmount)) + } + + builder.SetExtensionOptions(option) + err = builder.SetMsgs(msgs...) + s.Require().NoError(err) + builder.SetFeeAmount(fees) + builder.SetGasLimit(gasLimit) + + tx := builder.GetTx() + txEncoder := s.network.Validators[0].ClientCtx.TxConfig.TxEncoder() + txBytes, err := txEncoder(tx) + s.Require().NoError(err) + + syncCtx := s.network.Validators[0].ClientCtx.WithBroadcastMode(flags.BroadcastBlock) + txResponse, err := syncCtx.BroadcastTx(txBytes) + s.Require().NoError(err) + s.Require().Equal(uint32(0), txResponse.Code) + + block, err := s.network.Validators[0].JSONRPCClient.BlockByNumber(s.ctx, big.NewInt(txResponse.Height)) + s.Require().NoError(err) + + txs := block.Transactions() + s.Require().Len(txs, ethTxs) + for i, tx := range txs { + s.Require().Equal(accountNonce+uint64(i)+1, tx.Nonce()) + } +} From 824142425a8e3f3741c1de5805681970006ff33e Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Thu, 14 Apr 2022 11:51:01 -0400 Subject: [PATCH 3/5] changelog update --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd348e29d7..d49c1ce9fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,9 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (deps) [tharsis#1046](https://github.com/tharsis/ethermint/pull/1046) Bump Cosmos SDK version to [`v0.45.3`](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.45.3) +### Bug Fixes +* (rpc) [tharsis#1050](https://github.com/tharsis/ethermint/pull/1050) `eth_getBlockByNumber` fix on batch transactions + ## [v0.13.0] - 2022-04-05 ### API Breaking From 3320e0f2fe7a9703ac62f654722265e67b4813d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Federico=20Kunze=20K=C3=BCllmer?= <31522760+fedekunze@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:41:08 +0200 Subject: [PATCH 4/5] Apply suggestions from code review --- tests/e2e/integration_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index 27424aec20..d4b30cb861 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -752,7 +752,7 @@ func (s *IntegrationTestSuite) TestPendingTransactionFilter() { s.Require().Equal([]common.Hash{signedTx.Hash()}, filterResult) } -//TODO add transactionIndex tests once we have OpenRPC interfaces +// TODO: add transactionIndex tests once we have OpenRPC interfaces func (s *IntegrationTestSuite) TestBatchETHTransactions() { const ethTxs = 2 txBuilder := s.network.Validators[0].ClientCtx.TxConfig.NewTxBuilder() @@ -805,7 +805,7 @@ func (s *IntegrationTestSuite) TestBatchETHTransactions() { fees := make(sdk.Coins, 0) if feeAmount.Sign() > 0 { - fees = append(fees, sdk.NewCoin(res.GetParams().EvmDenom, feeAmount)) + fees = feees.Add(sdk.Coin{Denom: res.Params.EvmDenom, Amount: feeAmount}) } builder.SetExtensionOptions(option) From a232d644d59ef6d46b1d7340048f0b199830e4cc Mon Sep 17 00:00:00 2001 From: Freddy Caceres Date: Sat, 16 Apr 2022 13:21:30 -0400 Subject: [PATCH 5/5] fix breaking changes --- tests/e2e/integration_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index d4b30cb861..520c864348 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -136,7 +136,6 @@ func (s *IntegrationTestSuite) TestBlock() { s.Require().NotNil(blockByNum) // compare the ethereum header with the tendermint header - s.Require().Equal(len(block.Block.Txs), len(blockByNum.Body().Transactions)) s.Require().Equal(block.Block.LastBlockID.Hash.Bytes(), blockByNum.Header().ParentHash.Bytes()) hash := common.BytesToHash(block.Block.Hash()) @@ -147,7 +146,12 @@ func (s *IntegrationTestSuite) TestBlock() { blockByHash, err := s.network.Validators[0].JSONRPCClient.BlockByHash(s.ctx, hash) s.Require().NoError(err) s.Require().NotNil(blockByHash) - s.Require().Equal(blockByNum, blockByHash) + + //Compare blockByNumber and blockByHash results + s.Require().Equal(blockByNum.Hash(), blockByHash.Hash()) + s.Require().Equal(blockByNum.Transactions().Len(), blockByHash.Transactions().Len()) + s.Require().Equal(blockByNum.ParentHash(), blockByHash.ParentHash()) + s.Require().Equal(blockByNum.Root(), blockByHash.Root()) // TODO: parse Tm block to Ethereum and compare } @@ -805,7 +809,7 @@ func (s *IntegrationTestSuite) TestBatchETHTransactions() { fees := make(sdk.Coins, 0) if feeAmount.Sign() > 0 { - fees = feees.Add(sdk.Coin{Denom: res.Params.EvmDenom, Amount: feeAmount}) + fees = fees.Add(sdk.Coin{Denom: res.Params.EvmDenom, Amount: feeAmount}) } builder.SetExtensionOptions(option)