From 975533377be35e4c2b755a7782041876a2fe8bfa Mon Sep 17 00:00:00 2001 From: mmsqe Date: Wed, 25 Sep 2024 15:53:31 +0800 Subject: [PATCH] Problem: no time in Transaction (#531) * Problem: no time in Transaction * update deps --- go.mod | 2 +- go.sum | 4 +- gomod2nix.toml | 4 +- rpc/backend/blocks_test.go | 10 ++++- rpc/backend/evm_query_client_test.go | 55 ++++++++++++++++++++++++++-- 5 files changed, 66 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 3c0f63db35..a01f282b91 100644 --- a/go.mod +++ b/go.mod @@ -254,7 +254,7 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 github.com/cockroachdb/pebble => github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811 // release/v1.11.x - github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 + github.com/ethereum/go-ethereum => github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240925072350-e05e994a492f // Fix upstream GHSA-h395-qcrw-5vmq vulnerability. // TODO Remove it: https://github.com/cosmos/cosmos-sdk/issues/10409 github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.7.0 diff --git a/go.sum b/go.sum index 5a1a9c20dc..1cc14f5b31 100644 --- a/go.sum +++ b/go.sum @@ -421,8 +421,8 @@ github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2 h github.com/crypto-org-chain/cosmos-sdk/x/tx v0.0.0-20240911084450-6870ba130be2/go.mod h1:RTiTs4hkXG6IvYGknvB8p79YgjYJdcbzLUOGJChsPnY= github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e h1:FFpE6+Y4o5GxkeGwUcETM6amgohh7msWvWf1MDqueVc= github.com/crypto-org-chain/go-block-stm v0.0.0-20240912024944-1cd89976aa5e/go.mod h1:iwQTX9xMX8NV9k3o2BiWXA0SswpsZrDk5q3gA7nWYiE= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7 h1:V43F3JFcqG4MUThf9W/DytnPblpR6CcaLBw2Wx6zTgE= -github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240425065928-ebb09502e7a7/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= +github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240925072350-e05e994a492f h1:jR3nEDZMhGtZODqWFVbaTJ2X26k5r7nkiRk39i+SJ10= +github.com/crypto-org-chain/go-ethereum v1.10.20-0.20240925072350-e05e994a492f/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/gomod2nix.toml b/gomod2nix.toml index aafb878fe2..21f1e828e2 100644 --- a/gomod2nix.toml +++ b/gomod2nix.toml @@ -248,8 +248,8 @@ schema = 3 version = "v1.6.1" hash = "sha256-zOpoaepCfPLmU9iQji/Ait+SVEHI9eF3rwtW0h/8lho=" [mod."github.com/ethereum/go-ethereum"] - version = "v1.10.20-0.20240425065928-ebb09502e7a7" - hash = "sha256-lE4G5FaRb3MVi9FFVn+WlwsSTOB4SbjmVboKyQ5yB0A=" + version = "v1.10.20-0.20240925072350-e05e994a492f" + hash = "sha256-lDIqRLUrXYCb9mmFBY/+WW+ee69+IkxOgqjHVyo4ij0=" replaced = "github.com/crypto-org-chain/go-ethereum" [mod."github.com/fatih/color"] version = "v1.16.0" diff --git a/rpc/backend/blocks_test.go b/rpc/backend/blocks_test.go index 151b45b77d..cf36189793 100644 --- a/rpc/backend/blocks_test.go +++ b/rpc/backend/blocks_test.go @@ -1,6 +1,7 @@ package backend import ( + "encoding/json" "fmt" "math/big" @@ -1177,7 +1178,14 @@ func (suite *BackendTestSuite) TestEthMsgsFromTendermintBlock() { suite.SetupTest() // reset test and queries msgs := suite.backend.EthMsgsFromTendermintBlock(tc.resBlock, tc.blockRes) - suite.Require().Equal(tc.expMsgs, msgs) + suite.Require().Equal(len(tc.expMsgs), len(msgs)) + for i, expMsg := range tc.expMsgs { + expBytes, err := json.Marshal(expMsg) + suite.Require().Nil(err) + bytes, err := json.Marshal(msgs[i]) + suite.Require().Nil(err) + suite.Require().Equal(expBytes, bytes) + } }) } } diff --git a/rpc/backend/evm_query_client_test.go b/rpc/backend/evm_query_client_test.go index f052d1442b..0b73443436 100644 --- a/rpc/backend/evm_query_client_test.go +++ b/rpc/backend/evm_query_client_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "slices" "strconv" "testing" @@ -35,13 +36,48 @@ var _ evmtypes.QueryClient = &mocks.EVMQueryClient{} func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} queryClient.On("TraceTx", rpc.ContextWithHeight(1), - &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: 9000}). + mock.MatchedBy(func(req *evmtypes.QueryTraceTxRequest) bool { + if req.BlockNumber != 1 { + return false + } + bytes, _ := json.Marshal(msgEthTx) + bytes2, _ := json.Marshal(req.Msg) + if slices.Compare(bytes, bytes2) != 0 { + return false + } + if len(req.Predecessors) != len(predecessors) { + return false + } + bytes, _ = json.Marshal(req.Predecessors) + bytes2, _ = json.Marshal(predecessors) + if slices.Compare(bytes, bytes2) != 0 { + return false + } + if req.ChainId != 9000 { + return false + } + return true + })). Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } func RegisterTraceTransaction(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} - queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 9000}). + queryClient.On("TraceTx", rpc.ContextWithHeight(1), + mock.MatchedBy(func(req *evmtypes.QueryTraceTxRequest) bool { + if req.BlockNumber != 1 { + return false + } + bytes, _ := json.Marshal(msgEthTx) + bytes2, _ := json.Marshal(req.Msg) + if slices.Compare(bytes, bytes2) != 0 { + return false + } + if req.ChainId != 9000 { + return false + } + return true + })). Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } @@ -54,7 +90,20 @@ func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx * func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgEthereumTx) { data := []byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d} queryClient.On("TraceBlock", rpc.ContextWithHeight(1), - &evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: 9000}). + mock.MatchedBy(func(req *evmtypes.QueryTraceBlockRequest) bool { + if req.BlockNumber != 1 { + return false + } + bytes, _ := json.Marshal(txs) + bytes2, _ := json.Marshal(req.Txs) + if slices.Compare(bytes, bytes2) != 0 { + return false + } + if req.ChainId != 9000 { + return false + } + return true + })). Return(&evmtypes.QueryTraceBlockResponse{Data: data}, nil) }