Skip to content

Commit

Permalink
make generate
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed May 31, 2024
1 parent 96d0617 commit d22101a
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 50 deletions.
43 changes: 39 additions & 4 deletions rpc/backend/account_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"google.golang.org/grpc/metadata"

"github.com/evmos/ethermint/rpc/backend/mocks"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"google.golang.org/grpc/metadata"

rpctypes "github.com/zeta-chain/zetacore/rpc/types"
)

func (suite *BackendTestSuite) TestGetCode() {
blockNr := rpctypes.NewBlockNumber(big.NewInt(1))
contractCode := []byte("0xef616c92f3cfc9e92dc270d6acff9cea213cecc7020a76ee4395af09bdceb4837a1ebdb5735e11e7d3adb6104e0c3ac55180b4ddf5e54d022cc5e8837f6a4f971b")
contractCode := []byte(
"0xef616c92f3cfc9e92dc270d6acff9cea213cecc7020a76ee4395af09bdceb4837a1ebdb5735e11e7d3adb6104e0c3ac55180b4ddf5e54d022cc5e8837f6a4f971b",
)

testCases := []struct {
name string
Expand Down Expand Up @@ -224,7 +226,40 @@ func (suite *BackendTestSuite) TestGetStorageAt() {
RegisterStorageAt(queryClient, addr, key, storage)
},
true,
hexutil.Bytes{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
hexutil.Bytes{
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
},
},
}
for _, tc := range testCases {
Expand Down
16 changes: 10 additions & 6 deletions rpc/backend/backend_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,24 @@ import (
"testing"

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/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/suite"

"github.com/evmos/ethermint/app"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
"github.com/evmos/ethermint/crypto/hd"
"github.com/evmos/ethermint/encoding"
"github.com/evmos/ethermint/indexer"
"github.com/evmos/ethermint/rpc/backend/mocks"
rpctypes "github.com/zeta-chain/zetacore/rpc/types"

"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"github.com/stretchr/testify/suite"

rpctypes "github.com/zeta-chain/zetacore/rpc/types"
)

type BackendTestSuite struct {
Expand Down Expand Up @@ -169,7 +167,13 @@ func (suite *BackendTestSuite) buildFormattedBlock(
func (suite *BackendTestSuite) generateTestKeyring(clientDir string) (keyring.Keyring, error) {
buf := bufio.NewReader(os.Stdin)
encCfg := encoding.MakeConfig(app.ModuleBasics)
return keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, clientDir, buf, encCfg.Codec, []keyring.Option{hd.EthSecp256k1Option()}...)
return keyring.New(
sdk.KeyringServiceName(),
keyring.BackendTest,
clientDir,
buf,
encCfg.Codec,
[]keyring.Option{hd.EthSecp256k1Option()}...)
}

func (suite *BackendTestSuite) signAndEncodeEthTx(msgEthereumTx *evmtypes.MsgEthereumTx) []byte {
Expand Down
4 changes: 2 additions & 2 deletions rpc/backend/blocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/trie"
"google.golang.org/grpc/metadata"

"github.com/evmos/ethermint/rpc/backend/mocks"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
"google.golang.org/grpc/metadata"

ethrpc "github.com/zeta-chain/zetacore/rpc/types"
)

Expand Down
13 changes: 10 additions & 3 deletions rpc/backend/call_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"github.com/evmos/ethermint/rpc/backend/mocks"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
rpctypes "github.com/zeta-chain/zetacore/rpc/types"
"google.golang.org/grpc/metadata"

rpctypes "github.com/zeta-chain/zetacore/rpc/types"
)

func (suite *BackendTestSuite) TestResend() {
Expand Down Expand Up @@ -400,7 +401,10 @@ func (suite *BackendTestSuite) TestDoCall() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBlock(client, 1, bz)
RegisterEthCallError(queryClient, &evmtypes.EthCallRequest{Args: argsBz, ChainId: suite.backend.chainID.Int64()})
RegisterEthCallError(
queryClient,
&evmtypes.EthCallRequest{Args: argsBz, ChainId: suite.backend.chainID.Int64()},
)
},
rpctypes.BlockNumber(1),
callArgs,
Expand All @@ -413,7 +417,10 @@ func (suite *BackendTestSuite) TestDoCall() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBlock(client, 1, bz)
RegisterEthCall(queryClient, &evmtypes.EthCallRequest{Args: argsBz, ChainId: suite.backend.chainID.Int64()})
RegisterEthCall(
queryClient,
&evmtypes.EthCallRequest{Args: argsBz, ChainId: suite.backend.chainID.Int64()},
)
},
rpctypes.BlockNumber(1),
callArgs,
Expand Down
22 changes: 14 additions & 8 deletions rpc/backend/chain_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common/hexutil"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/evmos/ethermint/tests"
rpc "github.com/zeta-chain/zetacore/rpc/types"
"google.golang.org/grpc/metadata"

"github.com/cometbft/cometbft/abci/types"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/ethereum/go-ethereum/common/hexutil"
ethrpc "github.com/ethereum/go-ethereum/rpc"
"github.com/evmos/ethermint/rpc/backend/mocks"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
feemarkettypes "github.com/evmos/ethermint/x/feemarket/types"
"google.golang.org/grpc/metadata"

rpc "github.com/zeta-chain/zetacore/rpc/types"
)

func (suite *BackendTestSuite) TestBaseFee() {
Expand Down Expand Up @@ -424,7 +423,14 @@ func (suite *BackendTestSuite) TestFeeHistory() {
OldestBlock: (*hexutil.Big)(big.NewInt(1)),
BaseFee: []*hexutil.Big{(*hexutil.Big)(big.NewInt(1)), (*hexutil.Big)(big.NewInt(1))},
GasUsedRatio: []float64{0},
Reward: [][]*hexutil.Big{{(*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0)), (*hexutil.Big)(big.NewInt(0))}},
Reward: [][]*hexutil.Big{
{
(*hexutil.Big)(big.NewInt(0)),
(*hexutil.Big)(big.NewInt(0)),
(*hexutil.Big)(big.NewInt(0)),
(*hexutil.Big)(big.NewInt(0)),
},
},
},
sdk.AccAddress(tests.GenerateAddress().Bytes()),
true,
Expand Down
40 changes: 30 additions & 10 deletions rpc/backend/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ import (
"context"
"testing"

"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/libs/bytes"
tmrpcclient "github.com/cometbft/cometbft/rpc/client"
tmrpctypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/rpc/backend/mocks"
rpc "github.com/zeta-chain/zetacore/rpc/types"

evmtypes "github.com/evmos/ethermint/x/evm/types"
mock "github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

rpc "github.com/zeta-chain/zetacore/rpc/types"
)

// Client defines a mocked object that implements the Tendermint JSON-RPC Client
Expand Down Expand Up @@ -269,7 +268,13 @@ func RegisterBlockByHashNotFound(client *mocks.Client, hash common.Hash, tx []by
Return(nil, nil)
}

func RegisterABCIQueryWithOptions(client *mocks.Client, height int64, path string, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions) {
func RegisterABCIQueryWithOptions(
client *mocks.Client,
height int64,
path string,
data bytes.HexBytes,
opts tmrpcclient.ABCIQueryOptions,
) {
client.On("ABCIQueryWithOptions", context.Background(), path, data, opts).
Return(&tmrpctypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Expand All @@ -279,13 +284,28 @@ func RegisterABCIQueryWithOptions(client *mocks.Client, height int64, path strin
}, nil)
}

func RegisterABCIQueryWithOptionsError(clients *mocks.Client, path string, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions) {
func RegisterABCIQueryWithOptionsError(
clients *mocks.Client,
path string,
data bytes.HexBytes,
opts tmrpcclient.ABCIQueryOptions,
) {
clients.On("ABCIQueryWithOptions", context.Background(), path, data, opts).
Return(nil, errortypes.ErrInvalidRequest)
}

func RegisterABCIQueryAccount(clients *mocks.Client, data bytes.HexBytes, opts tmrpcclient.ABCIQueryOptions, acc client.Account) {
baseAccount := authtypes.NewBaseAccount(acc.GetAddress(), acc.GetPubKey(), acc.GetAccountNumber(), acc.GetSequence())
func RegisterABCIQueryAccount(
clients *mocks.Client,
data bytes.HexBytes,
opts tmrpcclient.ABCIQueryOptions,
acc client.Account,
) {
baseAccount := authtypes.NewBaseAccount(
acc.GetAddress(),
acc.GetPubKey(),
acc.GetAccountNumber(),
acc.GetSequence(),
)
accAny, _ := codectypes.NewAnyWithValue(baseAccount)
accResponse := authtypes.QueryAccountResponse{Account: accAny}
respBz, _ := accResponse.Marshal()
Expand Down
24 changes: 18 additions & 6 deletions rpc/backend/evm_query_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"strconv"
"testing"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
errortypes "github.com/cosmos/cosmos-sdk/types/errors"
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
"github.com/ethereum/go-ethereum/common"
"github.com/evmos/ethermint/rpc/backend/mocks"
rpc "github.com/zeta-chain/zetacore/rpc/types"

sdkmath "cosmossdk.io/math"
"github.com/evmos/ethermint/tests"
evmtypes "github.com/evmos/ethermint/x/evm/types"
mock "github.com/stretchr/testify/mock"
Expand All @@ -23,6 +21,8 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"

rpc "github.com/zeta-chain/zetacore/rpc/types"
)

// QueryClient defines a mocked object that implements the ethermint GRPC
Expand All @@ -33,7 +33,11 @@ import (
var _ evmtypes.QueryClient = &mocks.EVMQueryClient{}

// TraceTransaction
func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgEthereumTx, predecessors []*evmtypes.MsgEthereumTx) {
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}).
Expand All @@ -54,8 +58,16 @@ func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx *
// TraceBlock
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}).
queryClient.On(
"TraceBlock",
rpc.ContextWithHeight(1),
&evmtypes.QueryTraceBlockRequest{
Txs: txs,
BlockNumber: 1,
TraceConfig: &evmtypes.TraceConfig{},
ChainId: 9000,
},
).
Return(&evmtypes.QueryTraceBlockResponse{Data: data}, nil)
}

Expand Down
6 changes: 5 additions & 1 deletion rpc/backend/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/ethermint/rpc/backend/mocks"
evmtypes "github.com/evmos/ethermint/x/evm/types"

ethrpc "github.com/zeta-chain/zetacore/rpc/types"
)

Expand All @@ -16,7 +17,10 @@ func (suite *BackendTestSuite) TestGetLogs() {
block := tmtypes.MakeBlock(1, []tmtypes.Tx{bz}, nil, nil)
logs := make([]*evmtypes.Log, 0, 1)
var log evmtypes.Log
json.Unmarshal([]byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d}, &log)
json.Unmarshal(
[]byte{0x7b, 0x22, 0x74, 0x65, 0x73, 0x74, 0x22, 0x3a, 0x20, 0x22, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x22, 0x7d},
&log,
)
logs = append(logs, &log)

testCases := []struct {
Expand Down
10 changes: 8 additions & 2 deletions rpc/backend/sign_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,10 @@ func (suite *BackendTestSuite) TestSign() {

responseBz, err := suite.backend.Sign(tc.fromAddr, tc.inputBz)
if tc.expPass {
signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress((sdk.AccAddress)(from.Bytes()), tc.inputBz)
signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress(
(sdk.AccAddress)(from.Bytes()),
tc.inputBz,
)
signature[goethcrypto.RecoveryIDOffset] += 27
suite.Require().NoError(err)
suite.Require().Equal((hexutil.Bytes)(signature), responseBz)
Expand Down Expand Up @@ -255,7 +258,10 @@ func (suite *BackendTestSuite) TestSignTypedData() {
if tc.expPass {
sigHash, _, err := apitypes.TypedDataAndHash(tc.inputTypedData)
suite.Require().NoError(err)
signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress((sdk.AccAddress)(from.Bytes()), sigHash)
signature, _, err := suite.backend.clientCtx.Keyring.SignByAddress(
(sdk.AccAddress)(from.Bytes()),
sigHash,
)
signature[goethcrypto.RecoveryIDOffset] += 27
suite.Require().NoError(err)
suite.Require().Equal((hexutil.Bytes)(signature), responseBz)
Expand Down
Loading

0 comments on commit d22101a

Please sign in to comment.