From f89c866f50811c5e8b824444e6c2911867fcadb9 Mon Sep 17 00:00:00 2001 From: Sai Kumar Date: Mon, 6 Jun 2022 18:18:02 +0530 Subject: [PATCH] fix: fix the test cases --- app/ante/utils_test.go | 2 +- tests/e2e/integration_test.go | 4 ++-- x/evm/client/cli/utils_test.go | 6 +++--- x/evm/keeper/benchmark_test.go | 3 ++- x/evm/keeper/grpc_query_test.go | 31 ++++++++++++++++--------------- x/evm/keeper/keeper_test.go | 5 ++++- 6 files changed, 28 insertions(+), 23 deletions(-) diff --git a/app/ante/utils_test.go b/app/ante/utils_test.go index 8f22ed4f..a12e41ad 100644 --- a/app/ante/utils_test.go +++ b/app/ante/utils_test.go @@ -60,7 +60,7 @@ func (suite *AnteTestSuite) StateDB() *statedb.StateDB { func (suite *AnteTestSuite) SetupTest() { checkTx := false - suite.app = app.Setup(checkTx, func(app *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState { + suite.app = app.Setup(suite.T(), checkTx, func(app *app.EthermintApp, genesis simapp.GenesisState) simapp.GenesisState { if suite.enableFeemarket { // setup feemarketGenesis params feemarketGenesis := feemarkettypes.DefaultGenesisState() diff --git a/tests/e2e/integration_test.go b/tests/e2e/integration_test.go index 0052ee2c..1396c557 100644 --- a/tests/e2e/integration_test.go +++ b/tests/e2e/integration_test.go @@ -7,7 +7,7 @@ import ( "math/big" "testing" - sdk "github.com/cosmos/cosmos-sdk/types" + "cosmossdk.io/math" evmtypes "github.com/tharsis/ethermint/x/evm/types" // . "github.com/onsi/ginkgo" @@ -567,7 +567,7 @@ func (s *IntegrationTestSuite) deployContract(data []byte) (transaction common.H // Deploys erc20 contract, commits block and returns contract address func (s *IntegrationTestSuite) deployERC20Contract() (transaction common.Hash, contractAddr common.Address) { owner := common.BytesToAddress(s.network.Validators[0].Address) - supply := sdk.NewIntWithDecimal(1000, 18).BigInt() + supply := math.NewIntWithDecimal(1000, 18).BigInt() ctorArgs, err := evmtypes.ERC20Contract.ABI.Pack("", owner, supply) s.Require().NoError(err) diff --git a/x/evm/client/cli/utils_test.go b/x/evm/client/cli/utils_test.go index 70c718ba..c6a335a4 100644 --- a/x/evm/client/cli/utils_test.go +++ b/x/evm/client/cli/utils_test.go @@ -25,7 +25,7 @@ func cosmosAddressFromArg(addr string) (sdk.AccAddress, error) { // Strip 0x prefix if exists addr = strings.TrimPrefix(addr, "0x") - return sdk.AccAddressFromHex(addr) + return sdk.AccAddressFromHexUnsafe(addr) } func TestAddressFormats(t *testing.T) { @@ -59,7 +59,7 @@ func TestAddressFormats(t *testing.T) { func TestCosmosToEthereumTypes(t *testing.T) { hexString := "0x3B98D72760f7bbA69d62Ed6F48278451251948E7" - cosmosAddr, err := sdk.AccAddressFromHex(hexString[2:]) + cosmosAddr, err := sdk.AccAddressFromHexUnsafe(hexString[2:]) require.NoError(t, err) cosmosFormatted := cosmosAddr.String() @@ -81,7 +81,7 @@ func TestCosmosToEthereumTypes(t *testing.T) { } func TestAddressToCosmosAddress(t *testing.T) { - baseAddr, err := sdk.AccAddressFromHex("6A98D72760f7bbA69d62Ed6F48278451251948E7") + baseAddr, err := sdk.AccAddressFromHexUnsafe("6A98D72760f7bbA69d62Ed6F48278451251948E7") require.NoError(t, err) // Test cosmos string back to address diff --git a/x/evm/keeper/benchmark_test.go b/x/evm/keeper/benchmark_test.go index 5664ffdd..889d0b78 100644 --- a/x/evm/keeper/benchmark_test.go +++ b/x/evm/keeper/benchmark_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "cosmossdk.io/math" "github.com/stretchr/testify/require" sdk "github.com/cosmos/cosmos-sdk/types" @@ -25,7 +26,7 @@ func SetupContract(b *testing.B) (*KeeperTestSuite, common.Address) { err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt) require.NoError(b, err) - contractAddr := suite.DeployTestContract(b, suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(b, suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() return &suite, contractAddr diff --git a/x/evm/keeper/grpc_query_test.go b/x/evm/keeper/grpc_query_test.go index 690e67b7..da9f8fc6 100644 --- a/x/evm/keeper/grpc_query_test.go +++ b/x/evm/keeper/grpc_query_test.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" + "cosmossdk.io/math" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/vm" @@ -522,7 +523,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() { }, false, 0, false}, // estimate gas of an erc20 contract deployment, the exact gas number is checked with geth {"contract deployment", func() { - ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Require().NoError(err) data := append(types.ERC20Contract.Bin, ctorArgs...) args = types.TransactionArgs{ @@ -532,7 +533,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() { }, true, 1186778, false}, // estimate gas of an erc20 transfer, the exact gas number is checked with geth {"erc20 transfer", func() { - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000)) suite.Require().NoError(err) @@ -557,7 +558,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() { gasCap = 20000 }, false, 0, true}, {"contract deployment w/ enableFeemarket", func() { - ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + ctorArgs, err := types.ERC20Contract.ABI.Pack("", &suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Require().NoError(err) data := append(types.ERC20Contract.Bin, ctorArgs...) args = types.TransactionArgs{ @@ -566,7 +567,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() { } }, true, 1186778, true}, {"erc20 transfer w/ enableFeemarket", func() { - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000)) suite.Require().NoError(err) @@ -692,11 +693,11 @@ func (suite *KeeperTestSuite) TestTraceTx() { vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1) suite.Require().NoError(vmdb.Commit()) - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() // Generate token transfer transaction - firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) - txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) + firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) + txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) suite.Commit() predecessors = append(predecessors, firstTx) @@ -712,10 +713,10 @@ func (suite *KeeperTestSuite) TestTraceTx() { suite.enableFeemarket = tc.enableFeemarket suite.SetupTest() // Deploy contract - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() // Generate token transfer transaction - txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) + txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) suite.Commit() tc.malleate() @@ -822,11 +823,11 @@ func (suite *KeeperTestSuite) TestTraceBlock() { vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1) suite.Require().NoError(vmdb.Commit()) - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() // create multiple transactions in the same block - firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) - secondTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) + firstTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) + secondTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) suite.Commit() // overwrite txs to include only the ones on new block txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx) @@ -843,10 +844,10 @@ func (suite *KeeperTestSuite) TestTraceBlock() { suite.enableFeemarket = tc.enableFeemarket suite.SetupTest() // Deploy contract - contractAddr := suite.DeployTestContract(suite.T(), suite.address, sdk.NewIntWithDecimal(1000, 18).BigInt()) + contractAddr := suite.DeployTestContract(suite.T(), suite.address, math.NewIntWithDecimal(1000, 18).BigInt()) suite.Commit() // Generate token transfer transaction - txMsg := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), sdk.NewIntWithDecimal(1, 18).BigInt()) + txMsg := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt()) suite.Commit() txs = append(txs, txMsg) @@ -881,7 +882,7 @@ func (suite *KeeperTestSuite) TestNonceInQuery() { suite.Require().NoError(err) address := common.BytesToAddress(priv.PubKey().Address().Bytes()) suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetNonce(suite.ctx, address)) - supply := sdk.NewIntWithDecimal(1000, 18).BigInt() + supply := math.NewIntWithDecimal(1000, 18).BigInt() // accupy nonce 0 _ = suite.DeployTestContract(suite.T(), address, supply) diff --git a/x/evm/keeper/keeper_test.go b/x/evm/keeper/keeper_test.go index d3d7f3f3..c059b4ee 100644 --- a/x/evm/keeper/keeper_test.go +++ b/x/evm/keeper/keeper_test.go @@ -8,6 +8,8 @@ import ( "testing" "time" + cmath "cosmossdk.io/math" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" @@ -44,7 +46,7 @@ import ( "github.com/tendermint/tendermint/version" ) -var testTokens = sdk.NewIntWithDecimal(1000, 18) +var testTokens = cmath.NewIntWithDecimal(1000, 18) type KeeperTestSuite struct { suite.Suite @@ -148,6 +150,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { valAddr := sdk.ValAddress(suite.address.Bytes()) validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{}) + require.NoError(t, err) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator) require.NoError(t, err) err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)