From 2a3a818d23dc54209d8d33efb3b14a668385e6b2 Mon Sep 17 00:00:00 2001 From: deep-quality-dev <84747155+deep-quality-dev@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:33:01 +0100 Subject: [PATCH] Fix backend unit tests (#104) * Update unit tests in rpc backend. * Update unit tests in rpc backend. * Fix unit test * Correct function name --- app/ante/fee_checker_test.go | 2 +- cmd/swisstronikd/cmd/config.go | 8 ++++-- ethereum/eip712/preprocess_test.go | 12 ++++---- ibc/testing/chain.go | 2 +- rpc/backend/account_info.go | 2 +- rpc/backend/backend.go | 10 +++---- rpc/backend/backend_suite_test.go | 1 - rpc/backend/blocks.go | 6 ++-- rpc/backend/call_tx_test.go | 9 +++--- rpc/backend/chain_info.go | 10 +++---- rpc/backend/chain_info_test.go | 24 ++++++++-------- rpc/backend/client_test.go | 19 ++++++------- rpc/backend/evm_query_client_test.go | 18 ++++++------ rpc/backend/feemarket_query_client_test.go | 3 +- rpc/backend/filters_test.go | 9 +++--- rpc/backend/node_info.go | 5 ++++ rpc/backend/node_info_test.go | 4 +-- rpc/backend/sign_tx_test.go | 13 ++++----- rpc/backend/tracing.go | 1 + rpc/backend/tracing_test.go | 32 +++++++++++++--------- rpc/backend/tx_info.go | 8 +++--- rpc/backend/tx_info_test.go | 12 ++++---- rpc/backend/utils.go | 15 ++++------ tests/rpc/net_test.go | 2 +- tests/rpc/ws_test.go | 20 ++++++++++---- x/evm/keeper/state_transition_test.go | 6 ++-- x/evm/types/msg_sgxvm.go | 10 +++---- x/evm/types/tx_data_test.go | 2 +- 28 files changed, 140 insertions(+), 125 deletions(-) diff --git a/app/ante/fee_checker_test.go b/app/ante/fee_checker_test.go index 07086657..5174ef44 100644 --- a/app/ante/fee_checker_test.go +++ b/app/ante/fee_checker_test.go @@ -39,7 +39,7 @@ func (m MockEVMKeeper) GetParams(ctx sdk.Context) evmtypes.Params { } func (m MockEVMKeeper) ChainID() *big.Int { - return big.NewInt(9000) + return big.NewInt(1291) } func TestSDKTxFeeChecker(t *testing.T) { diff --git a/cmd/swisstronikd/cmd/config.go b/cmd/swisstronikd/cmd/config.go index ef4ffdb8..b84238b4 100644 --- a/cmd/swisstronikd/cmd/config.go +++ b/cmd/swisstronikd/cmd/config.go @@ -2,12 +2,13 @@ package cmd import ( "fmt" + + "github.com/cosmos/cosmos-sdk/client/flags" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/spf13/cobra" "swisstronik/app" evmtypes "swisstronik/types" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/client/flags" ) func InitSDKConfig() { @@ -27,10 +28,11 @@ func InitSDKConfig() { // Set global coin type to be used in HD wallets config.SetCoinType(evmtypes.Bip44CoinType) - config.SetPurpose(sdk.Purpose) + config.SetPurpose(sdk.Purpose) // Set and seal config config.Seal() + } // ValidateChainID wraps a cobra command with a RunE function with base 10 integer chain-id verification. diff --git a/ethereum/eip712/preprocess_test.go b/ethereum/eip712/preprocess_test.go index 3b576ea0..3c4b30ec 100644 --- a/ethereum/eip712/preprocess_test.go +++ b/ethereum/eip712/preprocess_test.go @@ -25,12 +25,12 @@ import ( // Testing Constants var ( - chainId = "ethermint_9000-1" + chainId = "swisstronik_1291-1" ctx = client.Context{}.WithTxConfig( encoding.MakeConfig(app.ModuleBasics).TxConfig, ) ) -var feePayerAddress = "ethm17xpfvakm2amg962yls6f84z3kell8c5lthdzgl" +var feePayerAddress = "swtr1x9djmrsvrf60xze5vj4pv52khjhskyqpzratt8" type TestCaseStruct struct { txBuilder client.TxBuilder @@ -44,7 +44,7 @@ type TestCaseStruct struct { func TestLedgerPreprocessing(t *testing.T) { // Update bech32 prefix - sdk.GetConfig().SetBech32PrefixForAccount("ethm", "") + sdk.GetConfig().SetBech32PrefixForAccount("swtr", "") testCases := []TestCaseStruct{ createBasicTestCase(t), @@ -67,7 +67,7 @@ func TestLedgerPreprocessing(t *testing.T) { require.True(t, len(hasExtOptsTx.GetExtensionOptions()) == 1) expectedExt := types.ExtensionOptionsWeb3Tx{ - TypedDataChainID: 9000, + TypedDataChainID: 1291, FeePayer: feePayerAddress, FeePayerSig: tc.expectedSignatureBytes, } @@ -167,7 +167,7 @@ func createBasicTestCase(t *testing.T) TestCaseStruct { Sequence: 0, } - txBuilder.SetSignatures(sigsV2) + _ = txBuilder.SetSignatures(sigsV2) return TestCaseStruct{ txBuilder: txBuilder, expectedFeePayer: feePayer.String(), @@ -209,7 +209,7 @@ func createPopulatedTestCase(t *testing.T) TestCaseStruct { ), } - txBuilder.SetMsgs(&msgSend) + _ = txBuilder.SetMsgs(&msgSend) return TestCaseStruct{ txBuilder: txBuilder, diff --git a/ibc/testing/chain.go b/ibc/testing/chain.go index 8f3893e2..88b86d54 100644 --- a/ibc/testing/chain.go +++ b/ibc/testing/chain.go @@ -41,7 +41,7 @@ import ( ) // ChainIDPrefix defines the default chain ID prefix for test chains -var ChainIDPrefix = "swisstronik_9000-" +var ChainIDPrefix = "swisstronik_1291-" func init() { ibcgotesting.ChainIDPrefix = ChainIDPrefix diff --git a/rpc/backend/account_info.go b/rpc/backend/account_info.go index cdfadc57..b0169c69 100644 --- a/rpc/backend/account_info.go +++ b/rpc/backend/account_info.go @@ -21,7 +21,6 @@ import ( "math/big" errorsmod "cosmossdk.io/errors" - sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -29,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/pkg/errors" + rpctypes "swisstronik/rpc/types" evmtypes "swisstronik/x/evm/types" ) diff --git a/rpc/backend/backend.go b/rpc/backend/backend.go index 4a4d8038..dde5736c 100644 --- a/rpc/backend/backend.go +++ b/rpc/backend/backend.go @@ -20,11 +20,6 @@ import ( "math/big" "time" - rpctypes "swisstronik/rpc/types" - "swisstronik/server/config" - ethermint "swisstronik/types" - evmtypes "swisstronik/x/evm/types" - "github.com/cometbft/cometbft/libs/log" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" "github.com/cosmos/cosmos-sdk/client" @@ -37,6 +32,11 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/signer/core/apitypes" + + rpctypes "swisstronik/rpc/types" + "swisstronik/server/config" + ethermint "swisstronik/types" + evmtypes "swisstronik/x/evm/types" ) // BackendI implements the Cosmos and EVM backend. diff --git a/rpc/backend/backend_suite_test.go b/rpc/backend/backend_suite_test.go index a67fcd08..d273547e 100644 --- a/rpc/backend/backend_suite_test.go +++ b/rpc/backend/backend_suite_test.go @@ -8,7 +8,6 @@ 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" diff --git a/rpc/backend/blocks.go b/rpc/backend/blocks.go index 8d5e6eb5..06a808c1 100644 --- a/rpc/backend/blocks.go +++ b/rpc/backend/blocks.go @@ -21,9 +21,6 @@ import ( "math/big" "strconv" - rpctypes "swisstronik/rpc/types" - evmtypes "swisstronik/x/evm/types" - tmrpcclient "github.com/cometbft/cometbft/rpc/client" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -35,6 +32,9 @@ import ( "github.com/pkg/errors" "google.golang.org/grpc" "google.golang.org/grpc/metadata" + + rpctypes "swisstronik/rpc/types" + evmtypes "swisstronik/x/evm/types" ) // BlockNumber returns the current block number in abci app state. Because abci diff --git a/rpc/backend/call_tx_test.go b/rpc/backend/call_tx_test.go index f8cdcafa..aef30c87 100644 --- a/rpc/backend/call_tx_test.go +++ b/rpc/backend/call_tx_test.go @@ -450,6 +450,7 @@ func (suite *BackendTestSuite) TestDoCall() { }) } } + func (suite *BackendTestSuite) TestGasPrice() { defaultGasPrice := (*hexutil.Big)(big.NewInt(1)) @@ -468,8 +469,8 @@ func (suite *BackendTestSuite) TestGasPrice() { feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient) RegisterFeeMarketParams(feeMarketClient, 1) RegisterParams(queryClient, &header, 1) - RegisterBlock(client, 1, nil) - RegisterBlockResults(client, 1) + _, _ = RegisterBlock(client, 1, nil) + _, _ = RegisterBlockResults(client, 1) RegisterBaseFee(queryClient, sdk.NewInt(1)) }, defaultGasPrice, @@ -484,8 +485,8 @@ func (suite *BackendTestSuite) TestGasPrice() { feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient) RegisterFeeMarketParamsError(feeMarketClient, 1) RegisterParams(queryClient, &header, 1) - RegisterBlock(client, 1, nil) - RegisterBlockResults(client, 1) + _, _ = RegisterBlock(client, 1, nil) + _, _ = RegisterBlockResults(client, 1) RegisterBaseFee(queryClient, sdk.NewInt(1)) }, defaultGasPrice, diff --git a/rpc/backend/chain_info.go b/rpc/backend/chain_info.go index 3fe2de57..6b6a22fe 100644 --- a/rpc/backend/chain_info.go +++ b/rpc/backend/chain_info.go @@ -20,11 +20,6 @@ import ( "math/big" "strconv" - rpctypes "swisstronik/rpc/types" - ethermint "swisstronik/types" - evmtypes "swisstronik/x/evm/types" - feemarkettypes "swisstronik/x/feemarket/types" - tmrpcclient "github.com/cometbft/cometbft/rpc/client" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -33,6 +28,11 @@ import ( "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rpc" "github.com/pkg/errors" + + rpctypes "swisstronik/rpc/types" + ethermint "swisstronik/types" + evmtypes "swisstronik/x/evm/types" + feemarkettypes "swisstronik/x/feemarket/types" ) // ChainID is the EIP-155 replay-protection chain id for the current ethereum chain config. diff --git a/rpc/backend/chain_info_test.go b/rpc/backend/chain_info_test.go index 8742c47a..3d99c38b 100644 --- a/rpc/backend/chain_info_test.go +++ b/rpc/backend/chain_info_test.go @@ -4,18 +4,16 @@ import ( "fmt" "math/big" - rpc "swisstronik/rpc/types" - "swisstronik/tests" - - "github.com/ethereum/go-ethereum/common/hexutil" - ethrpc "github.com/ethereum/go-ethereum/rpc" - "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" + "google.golang.org/grpc/metadata" "swisstronik/rpc/backend/mocks" + rpc "swisstronik/rpc/types" + "swisstronik/tests" evmtypes "swisstronik/x/evm/types" feemarkettypes "swisstronik/x/feemarket/types" ) @@ -153,7 +151,7 @@ func (suite *BackendTestSuite) TestBaseFee() { } func (suite *BackendTestSuite) TestChainId() { - expChainId := (*hexutil.Big)(big.NewInt(9000)) + expChainId := (*hexutil.Big)(big.NewInt(1291)) testCases := []struct { name string registerMock func() @@ -375,7 +373,7 @@ func (suite *BackendTestSuite) TestFeeHistory() { func(validator sdk.AccAddress) { client := suite.backend.clientCtx.Client.(*mocks.Client) suite.backend.cfg.JSONRPC.FeeHistoryCap = 2 - RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) + _, _ = RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) RegisterBlockResultsError(client, 1) }, 1, @@ -391,8 +389,8 @@ func (suite *BackendTestSuite) TestFeeHistory() { queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) client := suite.backend.clientCtx.Client.(*mocks.Client) suite.backend.cfg.JSONRPC.FeeHistoryCap = 2 - RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) - RegisterBlockResults(client, 1) + _, _ = RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) + _, _ = RegisterBlockResults(client, 1) RegisterBaseFeeError(queryClient) RegisterValidatorAccount(queryClient, validator) RegisterConsensusParams(client, 1) @@ -411,8 +409,8 @@ func (suite *BackendTestSuite) TestFeeHistory() { queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) client := suite.backend.clientCtx.Client.(*mocks.Client) suite.backend.cfg.JSONRPC.FeeHistoryCap = 2 - RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) - RegisterBlockResults(client, 1) + _, _ = RegisterBlock(client, ethrpc.BlockNumber(1).Int64(), nil) + _, _ = RegisterBlockResults(client, 1) RegisterBaseFee(queryClient, baseFee) RegisterValidatorAccount(queryClient, validator) RegisterConsensusParams(client, 1) diff --git a/rpc/backend/client_test.go b/rpc/backend/client_test.go index a488559c..9993c9f2 100644 --- a/rpc/backend/client_test.go +++ b/rpc/backend/client_test.go @@ -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" - - "swisstronik/rpc/backend/mocks" - rpc "swisstronik/rpc/types" - evmtypes "swisstronik/x/evm/types" - 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" mock "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + "swisstronik/rpc/backend/mocks" + rpc "swisstronik/rpc/types" + evmtypes "swisstronik/x/evm/types" ) // Client defines a mocked object that implements the Tendermint JSON-RPC Client @@ -142,7 +141,7 @@ func RegisterBlockNotFound( func TestRegisterBlock(t *testing.T) { client := mocks.NewClient(t) height := rpc.BlockNumber(1).Int64() - RegisterBlock(client, height, nil) + _, _ = RegisterBlock(client, height, nil) res, err := client.Block(rpc.ContextWithHeight(height), &height) @@ -219,7 +218,7 @@ func RegisterBlockResultsError(client *mocks.Client, height int64) { func TestRegisterBlockResults(t *testing.T) { client := mocks.NewClient(t) height := int64(1) - RegisterBlockResults(client, height) + _, _ = RegisterBlockResults(client, height) res, err := client.BlockResults(rpc.ContextWithHeight(height), &height) expRes := &tmrpctypes.ResultBlockResults{ diff --git a/rpc/backend/evm_query_client_test.go b/rpc/backend/evm_query_client_test.go index d815648a..97cc7d87 100644 --- a/rpc/backend/evm_query_client_test.go +++ b/rpc/backend/evm_query_client_test.go @@ -7,11 +7,6 @@ import ( "strconv" "testing" - "swisstronik/rpc/backend/mocks" - rpc "swisstronik/rpc/types" - "swisstronik/tests" - evmtypes "swisstronik/x/evm/types" - sdk "github.com/cosmos/cosmos-sdk/types" errortypes "github.com/cosmos/cosmos-sdk/types/errors" grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" @@ -22,6 +17,11 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + + "swisstronik/rpc/backend/mocks" + rpc "swisstronik/rpc/types" + "swisstronik/tests" + evmtypes "swisstronik/x/evm/types" ) // QueryClient defines a mocked object that implements the ethermint GRPC @@ -35,18 +35,18 @@ var _ evmtypes.QueryClient = &mocks.EVMQueryClient{} func RegisterTraceTransactionWithPredecessors(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgHandleTx, predecessors []*evmtypes.MsgHandleTx) { 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}). + &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, Predecessors: predecessors, ChainId: 1291}). Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } func RegisterTraceTransaction(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgHandleTx) { 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), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 1291}). Return(&evmtypes.QueryTraceTxResponse{Data: data}, nil) } func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx *evmtypes.MsgHandleTx) { - queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 9000}). + queryClient.On("TraceTx", rpc.ContextWithHeight(1), &evmtypes.QueryTraceTxRequest{Msg: msgEthTx, BlockNumber: 1, ChainId: 1291}). Return(nil, errortypes.ErrInvalidRequest) } @@ -54,7 +54,7 @@ func RegisterTraceTransactionError(queryClient *mocks.EVMQueryClient, msgEthTx * func RegisterTraceBlock(queryClient *mocks.EVMQueryClient, txs []*evmtypes.MsgHandleTx) { 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}). + &evmtypes.QueryTraceBlockRequest{Txs: txs, BlockNumber: 1, TraceConfig: &evmtypes.TraceConfig{}, ChainId: 1291}). Return(&evmtypes.QueryTraceBlockResponse{Data: data}, nil) } diff --git a/rpc/backend/feemarket_query_client_test.go b/rpc/backend/feemarket_query_client_test.go index 787c18f5..a18e8d42 100644 --- a/rpc/backend/feemarket_query_client_test.go +++ b/rpc/backend/feemarket_query_client_test.go @@ -1,10 +1,11 @@ package backend import ( + sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "swisstronik/rpc/backend/mocks" rpc "swisstronik/rpc/types" feemarkettypes "swisstronik/x/feemarket/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) var _ feemarkettypes.QueryClient = &mocks.FeeMarketQueryClient{} diff --git a/rpc/backend/filters_test.go b/rpc/backend/filters_test.go index b2298e88..79c3c80c 100644 --- a/rpc/backend/filters_test.go +++ b/rpc/backend/filters_test.go @@ -6,6 +6,7 @@ import ( tmtypes "github.com/cometbft/cometbft/types" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" + "swisstronik/rpc/backend/mocks" ethrpc "swisstronik/rpc/types" evmtypes "swisstronik/x/evm/types" @@ -16,7 +17,7 @@ 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 { @@ -50,7 +51,7 @@ func (suite *BackendTestSuite) TestGetLogs() { "fail - error getting block results", func(hash common.Hash) { client := suite.backend.clientCtx.Client.(*mocks.Client) - RegisterBlockByHash(client, hash, bz) + _, _ = RegisterBlockByHash(client, hash, bz) RegisterBlockResultsError(client, 1) }, common.Hash{}, @@ -61,8 +62,8 @@ func (suite *BackendTestSuite) TestGetLogs() { "success - getting logs with block hash", func(hash common.Hash) { client := suite.backend.clientCtx.Client.(*mocks.Client) - RegisterBlockByHash(client, hash, bz) - RegisterBlockResultsWithEventLog(client, ethrpc.BlockNumber(1).Int64()) + _, _ = RegisterBlockByHash(client, hash, bz) + _, _ = RegisterBlockResultsWithEventLog(client, ethrpc.BlockNumber(1).Int64()) }, common.BytesToHash(block.Hash()), [][]*ethtypes.Log{evmtypes.LogsToEthereum(logs)}, diff --git a/rpc/backend/node_info.go b/rpc/backend/node_info.go index 55830e54..0107407d 100644 --- a/rpc/backend/node_info.go +++ b/rpc/backend/node_info.go @@ -35,6 +35,7 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/crypto" "swisstronik/crypto/ethsecp256k1" + rpctypes "swisstronik/rpc/types" "swisstronik/server/config" ethermint "swisstronik/types" @@ -289,6 +290,10 @@ func (b *Backend) SetGasPrice(gasPrice hexutil.Big) bool { c := sdk.NewDecCoin(unit, sdk.NewIntFromBigInt(gasPrice.ToInt())) appConf.SetMinGasPrices(sdk.DecCoins{c}) + if b.clientCtx.Viper.ConfigFileUsed() == "" { + b.logger.Debug("could not write empty config file") + return false + } sdkconfig.WriteConfigFile(b.clientCtx.Viper.ConfigFileUsed(), appConf) b.logger.Info("Your configuration file was modified. Please RESTART your node.", "gas-price", c.String()) return true diff --git a/rpc/backend/node_info_test.go b/rpc/backend/node_info_test.go index 2cd503c2..e4ff0672 100644 --- a/rpc/backend/node_info_test.go +++ b/rpc/backend/node_info_test.go @@ -4,14 +4,14 @@ import ( "fmt" "math/big" - "google.golang.org/grpc/metadata" - tmrpcclient "github.com/cometbft/cometbft/rpc/client" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/spf13/viper" + "google.golang.org/grpc/metadata" + "swisstronik/crypto/ethsecp256k1" "swisstronik/rpc/backend/mocks" ethermint "swisstronik/types" diff --git a/rpc/backend/sign_tx_test.go b/rpc/backend/sign_tx_test.go index c6f578a6..e6644823 100644 --- a/rpc/backend/sign_tx_test.go +++ b/rpc/backend/sign_tx_test.go @@ -3,12 +3,6 @@ package backend import ( "fmt" - "swisstronik/crypto/ethsecp256k1" - "swisstronik/rpc/backend/mocks" - "swisstronik/tests" - "swisstronik/utils" - evmtypes "swisstronik/x/evm/types" - "github.com/cosmos/cosmos-sdk/crypto" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" @@ -17,6 +11,12 @@ import ( goethcrypto "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/signer/core/apitypes" "google.golang.org/grpc/metadata" + + "swisstronik/crypto/ethsecp256k1" + "swisstronik/rpc/backend/mocks" + "swisstronik/tests" + "swisstronik/utils" + evmtypes "swisstronik/x/evm/types" ) func (suite *BackendTestSuite) TestSendTransaction() { @@ -83,7 +83,6 @@ func (suite *BackendTestSuite) TestSendTransaction() { _, err = RegisterBlockResults(client, 1) suite.Require().NoError(err) RegisterBaseFee(queryClient, baseFee) - RegisterParamsWithoutHeader(queryClient, 1) }, evmtypes.TransactionArgs{ From: &from, diff --git a/rpc/backend/tracing.go b/rpc/backend/tracing.go index 8a1aa207..32d245ae 100644 --- a/rpc/backend/tracing.go +++ b/rpc/backend/tracing.go @@ -23,6 +23,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" "github.com/pkg/errors" + rpctypes "swisstronik/rpc/types" evmtypes "swisstronik/x/evm/types" ) diff --git a/rpc/backend/tracing_test.go b/rpc/backend/tracing_test.go index 47f62566..9d4f234b 100644 --- a/rpc/backend/tracing_test.go +++ b/rpc/backend/tracing_test.go @@ -3,12 +3,6 @@ package backend import ( "fmt" - "swisstronik/crypto/ethsecp256k1" - "swisstronik/indexer" - "swisstronik/rpc/backend/mocks" - "swisstronik/utils" - evmtypes "swisstronik/x/evm/types" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmlog "github.com/cometbft/cometbft/libs/log" @@ -18,6 +12,12 @@ import ( "github.com/cosmos/cosmos-sdk/crypto" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" + + "swisstronik/crypto/ethsecp256k1" + "swisstronik/indexer" + "swisstronik/rpc/backend/mocks" + "swisstronik/utils" + evmtypes "swisstronik/x/evm/types" ) func (suite *BackendTestSuite) TestTraceTransaction() { @@ -34,18 +34,18 @@ func (suite *BackendTestSuite) TestTraceTransaction() { RegisterParamsWithoutHeader(queryClient, 1) armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1") - suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "") + _ = suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "") ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig()) txEncoder := suite.backend.clientCtx.TxConfig.TxEncoder() msgHandleTx.From = from.String() - msgHandleTx.Sign(ethSigner, suite.signer) + _ = msgHandleTx.Sign(ethSigner, suite.signer) tx, _ := msgHandleTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), utils.BaseDenom) txBz, _ := txEncoder(tx) msgHandleTx2.From = from.String() - msgHandleTx2.Sign(ethSigner, suite.signer) + _ = msgHandleTx2.Sign(ethSigner, suite.signer) tx2, _ := msgHandleTx.BuildTx(suite.backend.clientCtx.TxConfig.NewTxBuilder(), utils.BaseDenom) txBz2, _ := txEncoder(tx2) @@ -108,9 +108,13 @@ func (suite *BackendTestSuite) TestTraceTransaction() { { "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}) + var ( + queryClient = suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) + client = suite.backend.clientCtx.Client.(*mocks.Client) + height int64 = 1 + ) + _, err := RegisterBlockMultipleTxs(client, height, []types.Tx{txBz, txBz2}) + suite.Require().NoError(err) RegisterTraceTransactionWithPredecessors(queryClient, msgHandleTx, []*evmtypes.MsgHandleTx{msgHandleTx}) }, &types.Block{Header: types.Header{Height: 1, ChainID: ChainID}, Data: types.Data{Txs: []types.Tx{txBz, txBz2}}}, @@ -150,7 +154,7 @@ func (suite *BackendTestSuite) TestTraceTransaction() { func() { queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) client := suite.backend.clientCtx.Client.(*mocks.Client) - RegisterBlock(client, 1, txBz) + _, _ = RegisterBlock(client, 1, txBz) RegisterTraceTransaction(queryClient, msgHandleTx) }, &types.Block{Header: types.Header{Height: 1}, Data: types.Data{Txs: []types.Tx{txBz}}}, @@ -225,7 +229,9 @@ func (suite *BackendTestSuite) TestTraceBlock() { "fail - cannot unmarshal data", func() { queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient) + //client := suite.backend.clientCtx.Client.(*mocks.Client) RegisterTraceBlock(queryClient, []*evmtypes.MsgHandleTx{msgEthTx}) + //RegisterConsensusParams(client, 1) }, []*evmtypes.TxTraceResult{}, &resBlockFilled, diff --git a/rpc/backend/tx_info.go b/rpc/backend/tx_info.go index 843e86d5..1950d91a 100644 --- a/rpc/backend/tx_info.go +++ b/rpc/backend/tx_info.go @@ -20,10 +20,6 @@ import ( "math" "math/big" - rpctypes "swisstronik/rpc/types" - ethermint "swisstronik/types" - evmtypes "swisstronik/x/evm/types" - errorsmod "cosmossdk.io/errors" tmrpcclient "github.com/cometbft/cometbft/rpc/client" tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" @@ -33,6 +29,10 @@ import ( ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/pkg/errors" + + rpctypes "swisstronik/rpc/types" + ethermint "swisstronik/types" + evmtypes "swisstronik/x/evm/types" ) // GetTransactionByHash returns the Ethereum format transaction identified by Ethereum transaction hash diff --git a/rpc/backend/tx_info_test.go b/rpc/backend/tx_info_test.go index 0f318d66..ceaedebb 100644 --- a/rpc/backend/tx_info_test.go +++ b/rpc/backend/tx_info_test.go @@ -4,12 +4,6 @@ import ( "fmt" "math/big" - "swisstronik/indexer" - "swisstronik/rpc/backend/mocks" - rpctypes "swisstronik/rpc/types" - ethermint "swisstronik/types" - evmtypes "swisstronik/x/evm/types" - dbm "github.com/cometbft/cometbft-db" abci "github.com/cometbft/cometbft/abci/types" tmlog "github.com/cometbft/cometbft/libs/log" @@ -19,6 +13,12 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "google.golang.org/grpc/metadata" + + "swisstronik/indexer" + "swisstronik/rpc/backend/mocks" + rpctypes "swisstronik/rpc/types" + ethermint "swisstronik/types" + evmtypes "swisstronik/x/evm/types" ) func (suite *BackendTestSuite) TestGetTransactionByHash() { diff --git a/rpc/backend/utils.go b/rpc/backend/utils.go index a1f8c6de..e6fed891 100644 --- a/rpc/backend/utils.go +++ b/rpc/backend/utils.go @@ -22,24 +22,21 @@ import ( "sort" "strings" + abci "github.com/cometbft/cometbft/abci/types" + "github.com/cometbft/cometbft/libs/log" + "github.com/cometbft/cometbft/proto/tendermint/crypto" + tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus/misc" ethtypes "github.com/ethereum/go-ethereum/core/types" - - abci "github.com/cometbft/cometbft/abci/types" - "github.com/cometbft/cometbft/libs/log" - tmrpctypes "github.com/cometbft/cometbft/rpc/core/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" "swisstronik/rpc/types" evmtypes "swisstronik/x/evm/types" - - "github.com/cometbft/cometbft/proto/tendermint/crypto" ) type txGasAndReward struct { diff --git a/tests/rpc/net_test.go b/tests/rpc/net_test.go index 5d45cfd9..8c37bb7f 100644 --- a/tests/rpc/net_test.go +++ b/tests/rpc/net_test.go @@ -13,7 +13,7 @@ func TestNet_Version(t *testing.T) { var res string err := json.Unmarshal(rpcRes.Result, &res) require.NoError(t, err) - require.Equal(t, "9000", res) + require.Equal(t, "1291", res) } func TestNet_Listening(t *testing.T) { diff --git a/tests/rpc/ws_test.go b/tests/rpc/ws_test.go index ea591808..59d311cb 100644 --- a/tests/rpc/ws_test.go +++ b/tests/rpc/ws_test.go @@ -32,7 +32,9 @@ func TestWsSingleRequest(t *testing.T) { wc, _, err := websocket.DefaultDialer.Dial(wsUrl, nil) require.NoError(t, err) - defer wc.Close() + defer func() { + _ = wc.Close() + }() wsWriteMessage(t, wc, `{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}`) @@ -41,7 +43,7 @@ func TestWsSingleRequest(t *testing.T) { msg := jsonUnmarshal(t, mb) result, ok := msg["result"].(string) require.True(t, ok) - require.Equal(t, "9000", result) + require.Equal(t, "1291", result) } func TestWsBatchRequest(t *testing.T) { @@ -49,7 +51,9 @@ func TestWsBatchRequest(t *testing.T) { wc, _, err := websocket.DefaultDialer.Dial(wsUrl, nil) require.NoError(t, err) - defer wc.Close() + defer func() { + _ = wc.Close() + }() wsWriteMessage(t, wc, `[{"jsonrpc":"2.0","method":"net_version","params":[],"id":1},{"jsonrpc":"2.0","method":"eth_protocolVersion","params":[],"id":2}]`) @@ -65,7 +69,7 @@ func TestWsBatchRequest(t *testing.T) { resNetVersion := msg[0] result, ok := resNetVersion["result"].(string) require.True(t, ok) - require.Equal(t, "9000", result) + require.Equal(t, "1291", result) id, ok := resNetVersion["id"].(float64) require.True(t, ok) require.Equal(t, 1, int(id)) @@ -85,7 +89,9 @@ func TestWsEth_subscribe_newHeads(t *testing.T) { wc, _, err := websocket.DefaultDialer.Dial(wsUrl, nil) require.NoError(t, err) - defer wc.Close() + defer func() { + _ = wc.Close() + }() wsWriteMessage(t, wc, `{"id":1,"method":"eth_subscribe","params":["newHeads",{}]}`) @@ -114,7 +120,9 @@ func TestWsEth_subscribe_log(t *testing.T) { wc, _, err := websocket.DefaultDialer.Dial(wsUrl, nil) require.NoError(t, err) - defer wc.Close() + defer func() { + _ = wc.Close() + }() wsWriteMessage(t, wc, fmt.Sprintf(`{"jsonrpc":"2.0","id":1,"method":"eth_subscribe","params":["logs",{"topics":["%s", "%s"]}]}`, helloTopic, worldTopic)) diff --git a/x/evm/keeper/state_transition_test.go b/x/evm/keeper/state_transition_test.go index 4bdc6a8e..b86d0413 100644 --- a/x/evm/keeper/state_transition_test.go +++ b/x/evm/keeper/state_transition_test.go @@ -349,13 +349,13 @@ func (suite *KeeperTestSuite) TestResetGasMeterAndConsumeGas() { func (suite *KeeperTestSuite) TestEVMConfig() { proposerAddress := suite.ctx.BlockHeader().ProposerAddress - cfg, err := suite.app.EvmKeeper.EVMConfig(suite.ctx, proposerAddress, big.NewInt(9000)) + cfg, err := suite.app.EvmKeeper.EVMConfig(suite.ctx, proposerAddress, big.NewInt(1291)) suite.Require().NoError(err) suite.Require().Equal(types.DefaultParams(), cfg.Params) // london hardfork is enabled by default suite.Require().Equal(big.NewInt(0), cfg.BaseFee) suite.Require().Equal(suite.address, cfg.CoinBase) - suite.Require().Equal(types.DefaultParams().ChainConfig.EthereumConfig(big.NewInt(9000)), cfg.ChainConfig) + suite.Require().Equal(types.DefaultParams().ChainConfig.EthereumConfig(big.NewInt(1291)), cfg.ChainConfig) } func (suite *KeeperTestSuite) TestContractDeployment() { @@ -382,7 +382,7 @@ func (suite *KeeperTestSuite) createContractMsgTx(nonce uint64, signer ethtypes. } ethTx := ethtypes.NewTx(contractCreateTx) ethMsg := &types.MsgHandleTx{} - ethMsg.FromEthereumTx(ethTx) + _ = ethMsg.FromEthereumTx(ethTx) ethMsg.From = suite.address.Hex() return ethMsg, ethMsg.Sign(signer, suite.signer) diff --git a/x/evm/types/msg_sgxvm.go b/x/evm/types/msg_sgxvm.go index 7c354e26..8dab04e0 100644 --- a/x/evm/types/msg_sgxvm.go +++ b/x/evm/types/msg_sgxvm.go @@ -5,9 +5,8 @@ import ( "fmt" "math/big" - sdkmath "cosmossdk.io/math" - errorsmod "cosmossdk.io/errors" + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/client" codectypes "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keyring" @@ -16,13 +15,12 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/ante" "github.com/cosmos/cosmos-sdk/x/auth/signing" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - - "swisstronik/types" - - "swisstronik/crypto/deoxys" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" ethtypes "github.com/ethereum/go-ethereum/core/types" + "swisstronik/crypto/deoxys" + + "swisstronik/types" ) var ( diff --git a/x/evm/types/tx_data_test.go b/x/evm/types/tx_data_test.go index 7d2db408..0dbfe1ad 100644 --- a/x/evm/types/tx_data_test.go +++ b/x/evm/types/tx_data_test.go @@ -67,7 +67,7 @@ func TestTxData_DeriveChainID(t *testing.T) { "Ethereum mainnet", &LegacyTx{V: big.NewInt(37).Bytes()}, big.NewInt(1), }, { - "chain ID 9000", &LegacyTx{V: big.NewInt(18035).Bytes()}, big.NewInt(9000), + "chain ID 1291", &LegacyTx{V: big.NewInt(2617).Bytes()}, big.NewInt(1291), }, { "bit len 64", &LegacyTx{V: bitLen64.Bytes()}, big.NewInt(4611686018427387886),