Skip to content

Commit

Permalink
test: Fix tracing tests mock error
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 committed Feb 1, 2024
1 parent 1fd7052 commit 793a176
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
11 changes: 9 additions & 2 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ import (
// To use a mock method it has to be registered in a given test.
var _ evmtypes.QueryClient = &mocks.EVMQueryClient{}

// {"failed": false, "test": "hello"}
var data = []byte{
0x7B, 0x22, 0x66, 0x61, 0x69, 0x6C, 0x65, 0x64,
0x22, 0x3A, 0x20, 0x66, 0x61, 0x6C, 0x73, 0x65,
0x2C, 0x20, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22,
0x3A, 0x20, 0x22, 0x68, 0x65, 0x6C, 0x6C, 0x6F,
0x22, 0x7D,
}

// TraceTransaction
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}).
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}).
Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil)
}
Expand Down
19 changes: 9 additions & 10 deletions rpc/backend/tracing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
tmlog "github.com/tendermint/tendermint/libs/log"
tmrpctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)
Expand Down Expand Up @@ -50,15 +49,15 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
testCases := []struct {
name string
registerMock func()
block *types.Block
block *tmtypes.Block
responseBlock []*abci.ResponseDeliverTx
expResult interface{}
expPass bool
}{
{
"fail - tx not found",
func() {},
&types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{}}},
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{}}},
[]*abci.ResponseDeliverTx{
{
Code: 0,
Expand All @@ -84,7 +83,7 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlockError(client, 1)
},
&types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{txBz}}},
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
{
Code: 0,
Expand All @@ -100,18 +99,18 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
},
},
},
map[string]interface{}{"test": "hello"},
map[string]interface{}{"failed": false, "test": "hello"},
false,
},
{
"pass - transaction found in a block with multiple transactions",
func() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
client := suite.backend.clientCtx.Client.(*mocks.Client)
RegisterBlockMultipleTxs(client, 1, []types.Tx{txBz, txBz2})
RegisterBlockMultipleTxs(client, 1, []tmtypes.Tx{txBz, txBz2})
RegisterTraceTransactionWithPredecessors(queryClient, msgEthereumTx, []*evmtypes.MsgEthereumTx{msgEthereumTx})
},
&types.Block{Header: types.Header{Height: 1, ChainID: ChainID}, Data: types.Data{Txs: []types.Tx{txBz, txBz2}}},
&tmtypes.Block{Header: tmtypes.Header{Height: 1, ChainID: ChainID}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz, txBz2}}},
[]*abci.ResponseDeliverTx{
{
Code: 0,
Expand Down Expand Up @@ -140,7 +139,7 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
},
},
},
map[string]interface{}{"test": "hello"},
map[string]interface{}{"failed": false, "test": "hello"},
true,
},
{
Expand All @@ -151,7 +150,7 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
RegisterBlock(client, 1, txBz)
RegisterTraceTransaction(queryClient, msgEthereumTx)
},
&types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{txBz}}},
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
{
Code: 0,
Expand All @@ -167,7 +166,7 @@ func (suite *BackendTestSuite) TestTraceTransaction() {
},
},
},
map[string]interface{}{"test": "hello"},
map[string]interface{}{"failed": false, "test": "hello"},
true,
},
}
Expand Down

0 comments on commit 793a176

Please sign in to comment.