Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Sep 6, 2024
1 parent c6c6c0c commit f68f3f7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
26 changes: 24 additions & 2 deletions rpc/backend/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ func (suite *BackendTestSuite) TestHeaderByNumber() {
var expResultBlock *tmrpctypes.ResultBlock

_, bz := suite.buildEthereumTx()
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())

testCases := []struct {
name string
Expand Down Expand Up @@ -1241,6 +1242,7 @@ func (suite *BackendTestSuite) TestHeaderByNumber() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFeeError(queryClient)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1256,6 +1258,7 @@ func (suite *BackendTestSuite) TestHeaderByNumber() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1271,6 +1274,7 @@ func (suite *BackendTestSuite) TestHeaderByNumber() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1283,7 +1287,7 @@ func (suite *BackendTestSuite) TestHeaderByNumber() {
header, err := suite.backend.HeaderByNumber(tc.blockNumber)

if tc.expPass {
expHeader := ethrpc.EthHeaderFromTendermint(expResultBlock.Block.Header, ethtypes.Bloom{}, tc.baseFee)
expHeader := ethrpc.EthHeaderFromTendermint(expResultBlock.Block.Header, ethtypes.Bloom{}, tc.baseFee, validator)
suite.Require().NoError(err)
suite.Require().Equal(expHeader, header)
} else {
Expand All @@ -1299,6 +1303,8 @@ func (suite *BackendTestSuite) TestHeaderByHash() {
_, bz := suite.buildEthereumTx()
block := tmtypes.MakeBlock(1, []tmtypes.Tx{bz}, nil, nil)
emptyBlock := tmtypes.MakeBlock(1, []tmtypes.Tx{}, nil, nil)
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())
emptyBlock.Header.ProposerAddress = validator.Bytes()

testCases := []struct {
name string
Expand Down Expand Up @@ -1351,6 +1357,7 @@ func (suite *BackendTestSuite) TestHeaderByHash() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFeeError(queryClient)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1366,6 +1373,7 @@ func (suite *BackendTestSuite) TestHeaderByHash() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1381,6 +1389,7 @@ func (suite *BackendTestSuite) TestHeaderByHash() {

queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
true,
},
Expand All @@ -1393,7 +1402,7 @@ func (suite *BackendTestSuite) TestHeaderByHash() {
header, err := suite.backend.HeaderByHash(tc.hash)

if tc.expPass {
expHeader := ethrpc.EthHeaderFromTendermint(expResultBlock.Block.Header, ethtypes.Bloom{}, tc.baseFee)
expHeader := ethrpc.EthHeaderFromTendermint(expResultBlock.Block.Header, ethtypes.Bloom{}, tc.baseFee, validator)
suite.Require().NoError(err)
suite.Require().Equal(expHeader, header)
} else {
Expand All @@ -1406,6 +1415,8 @@ func (suite *BackendTestSuite) TestHeaderByHash() {
func (suite *BackendTestSuite) TestEthBlockByNumber() {
msgEthereumTx, bz := suite.buildEthereumTx()
emptyBlock := tmtypes.MakeBlock(1, []tmtypes.Tx{}, nil, nil)
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())
emptyBlock.Header.ProposerAddress = validator.Bytes()

testCases := []struct {
name string
Expand Down Expand Up @@ -1449,12 +1460,14 @@ func (suite *BackendTestSuite) TestEthBlockByNumber() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
baseFee := sdkmath.NewInt(1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
ethtypes.NewBlock(
ethrpc.EthHeaderFromTendermint(
emptyBlock.Header,
ethtypes.Bloom{},
sdkmath.NewInt(1).BigInt(),
validator,
),
[]*ethtypes.Transaction{},
nil,
Expand All @@ -1475,12 +1488,14 @@ func (suite *BackendTestSuite) TestEthBlockByNumber() {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
baseFee := sdkmath.NewInt(1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
ethtypes.NewBlock(
ethrpc.EthHeaderFromTendermint(
emptyBlock.Header,
ethtypes.Bloom{},
sdkmath.NewInt(1).BigInt(),
validator,
),
[]*ethtypes.Transaction{msgEthereumTx.AsTransaction()},
nil,
Expand Down Expand Up @@ -1520,6 +1535,9 @@ func (suite *BackendTestSuite) TestEthBlockByNumber() {
func (suite *BackendTestSuite) TestEthBlockFromTendermintBlock() {
msgEthereumTx, bz := suite.buildEthereumTx()
emptyBlock := tmtypes.MakeBlock(1, []tmtypes.Tx{}, nil, nil)
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())
emptyBlock.Header.ProposerAddress = validator.Bytes()
consAddress := sdk.ConsAddress(emptyBlock.Header.ProposerAddress).String()

testCases := []struct {
name string
Expand All @@ -1543,12 +1561,14 @@ func (suite *BackendTestSuite) TestEthBlockFromTendermintBlock() {
func(baseFee sdkmath.Int, blockNum int64) {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccountWithConsAddress(queryClient, validator, consAddress)
},
ethtypes.NewBlock(
ethrpc.EthHeaderFromTendermint(
emptyBlock.Header,
ethtypes.Bloom{},
sdkmath.NewInt(1).BigInt(),
validator,
),
[]*ethtypes.Transaction{},
nil,
Expand Down Expand Up @@ -1578,12 +1598,14 @@ func (suite *BackendTestSuite) TestEthBlockFromTendermintBlock() {
func(baseFee sdkmath.Int, blockNum int64) {
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
ethtypes.NewBlock(
ethrpc.EthHeaderFromTendermint(
emptyBlock.Header,
ethtypes.Bloom{},
sdkmath.NewInt(1).BigInt(),
validator,
),
[]*ethtypes.Transaction{msgEthereumTx.AsTransaction()},
nil,
Expand Down
12 changes: 12 additions & 0 deletions rpc/backend/call_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"math/big"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp"
Expand All @@ -22,6 +23,7 @@ func (suite *BackendTestSuite) TestResend() {
gasPrice := new(hexutil.Big)
toAddr := tests.GenerateAddress()
chainID := (*hexutil.Big)(suite.backend.chainID)
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())
callArgs := evmtypes.TransactionArgs{
From: nil,
To: &toAddr,
Expand Down Expand Up @@ -67,6 +69,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFeeDisabled(queryClient)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand All @@ -89,6 +92,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand All @@ -108,6 +112,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFeeDisabled(queryClient)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand Down Expand Up @@ -161,6 +166,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand All @@ -184,6 +190,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand All @@ -208,6 +215,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterParams(queryClient, &header, 1)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterUnconfirmedTxsError(client, nil)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand Down Expand Up @@ -236,6 +244,7 @@ func (suite *BackendTestSuite) TestResend() {
RegisterParams(queryClient, &header, 1)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterUnconfirmedTxsEmpty(client, nil)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand Down Expand Up @@ -437,6 +446,7 @@ func (suite *BackendTestSuite) TestDoCall() {

func (suite *BackendTestSuite) TestGasPrice() {
defaultGasPrice := (*hexutil.Big)(big.NewInt(1))
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())

testCases := []struct {
name string
Expand All @@ -456,6 +466,7 @@ func (suite *BackendTestSuite) TestGasPrice() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, sdkmath.NewInt(1))
RegisterValidatorAccount(queryClient, validator)
},
defaultGasPrice,
true,
Expand All @@ -472,6 +483,7 @@ func (suite *BackendTestSuite) TestGasPrice() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, sdkmath.NewInt(1))
RegisterValidatorAccount(queryClient, validator)
},
defaultGasPrice,
false,
Expand Down
7 changes: 7 additions & 0 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ func RegisterValidatorAccount(queryClient *mocks.EVMQueryClient, validator sdk.A
Return(&evmtypes.QueryValidatorAccountResponse{AccountAddress: validator.String()}, nil)
}

func RegisterValidatorAccountWithConsAddress(queryClient *mocks.EVMQueryClient, validator sdk.AccAddress, consAddress string) {
queryClient.On("ValidatorAccount", rpc.ContextWithHeight(1), &evmtypes.QueryValidatorAccountRequest{
ConsAddress: consAddress,
}).
Return(&evmtypes.QueryValidatorAccountResponse{AccountAddress: validator.String()}, nil)
}

func RegisterValidatorAccountError(queryClient *mocks.EVMQueryClient) {
queryClient.On("ValidatorAccount", rpc.ContextWithHeight(1), &evmtypes.QueryValidatorAccountRequest{}).
Return(nil, status.Error(codes.InvalidArgument, "empty request"))
Expand Down
5 changes: 4 additions & 1 deletion rpc/backend/sign_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func (suite *BackendTestSuite) TestSendTransaction() {
Gas: &gas,
Nonce: &nonce,
}

hash := common.Hash{}
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())

testCases := []struct {
name string
Expand Down Expand Up @@ -79,6 +79,7 @@ func (suite *BackendTestSuite) TestSendTransaction() {
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
evmtypes.TransactionArgs{
From: &from,
Expand Down Expand Up @@ -110,6 +111,7 @@ func (suite *BackendTestSuite) TestSendTransaction() {
txEncoder := suite.backend.clientCtx.TxConfig.TxEncoder()
txBytes, _ := txEncoder(tx)
RegisterBroadcastTxError(client, txBytes)
RegisterValidatorAccount(queryClient, validator)
},
callArgsDefault,
common.Hash{},
Expand All @@ -135,6 +137,7 @@ func (suite *BackendTestSuite) TestSendTransaction() {
txEncoder := suite.backend.clientCtx.TxConfig.TxEncoder()
txBytes, _ := txEncoder(tx)
RegisterBroadcastTx(client, txBytes)
RegisterValidatorAccount(queryClient, validator)
},
callArgsDefault,
hash,
Expand Down

0 comments on commit f68f3f7

Please sign in to comment.