fix: fix the test cases
This commit is contained in:
parent
fc06fbfb48
commit
f89c866f50
@ -60,7 +60,7 @@ func (suite *AnteTestSuite) StateDB() *statedb.StateDB {
|
|||||||
func (suite *AnteTestSuite) SetupTest() {
|
func (suite *AnteTestSuite) SetupTest() {
|
||||||
checkTx := false
|
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 {
|
if suite.enableFeemarket {
|
||||||
// setup feemarketGenesis params
|
// setup feemarketGenesis params
|
||||||
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
feemarketGenesis := feemarkettypes.DefaultGenesisState()
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
"cosmossdk.io/math"
|
||||||
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
evmtypes "github.com/tharsis/ethermint/x/evm/types"
|
||||||
|
|
||||||
// . "github.com/onsi/ginkgo"
|
// . "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
|
// Deploys erc20 contract, commits block and returns contract address
|
||||||
func (s *IntegrationTestSuite) deployERC20Contract() (transaction common.Hash, contractAddr common.Address) {
|
func (s *IntegrationTestSuite) deployERC20Contract() (transaction common.Hash, contractAddr common.Address) {
|
||||||
owner := common.BytesToAddress(s.network.Validators[0].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)
|
ctorArgs, err := evmtypes.ERC20Contract.ABI.Pack("", owner, supply)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -25,7 +25,7 @@ func cosmosAddressFromArg(addr string) (sdk.AccAddress, error) {
|
|||||||
// Strip 0x prefix if exists
|
// Strip 0x prefix if exists
|
||||||
addr = strings.TrimPrefix(addr, "0x")
|
addr = strings.TrimPrefix(addr, "0x")
|
||||||
|
|
||||||
return sdk.AccAddressFromHex(addr)
|
return sdk.AccAddressFromHexUnsafe(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddressFormats(t *testing.T) {
|
func TestAddressFormats(t *testing.T) {
|
||||||
@ -59,7 +59,7 @@ func TestAddressFormats(t *testing.T) {
|
|||||||
|
|
||||||
func TestCosmosToEthereumTypes(t *testing.T) {
|
func TestCosmosToEthereumTypes(t *testing.T) {
|
||||||
hexString := "0x3B98D72760f7bbA69d62Ed6F48278451251948E7"
|
hexString := "0x3B98D72760f7bbA69d62Ed6F48278451251948E7"
|
||||||
cosmosAddr, err := sdk.AccAddressFromHex(hexString[2:])
|
cosmosAddr, err := sdk.AccAddressFromHexUnsafe(hexString[2:])
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
cosmosFormatted := cosmosAddr.String()
|
cosmosFormatted := cosmosAddr.String()
|
||||||
@ -81,7 +81,7 @@ func TestCosmosToEthereumTypes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAddressToCosmosAddress(t *testing.T) {
|
func TestAddressToCosmosAddress(t *testing.T) {
|
||||||
baseAddr, err := sdk.AccAddressFromHex("6A98D72760f7bbA69d62Ed6F48278451251948E7")
|
baseAddr, err := sdk.AccAddressFromHexUnsafe("6A98D72760f7bbA69d62Ed6F48278451251948E7")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Test cosmos string back to address
|
// Test cosmos string back to address
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
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)
|
err = suite.app.BankKeeper.SendCoinsFromModuleToAccount(suite.ctx, types.ModuleName, suite.address.Bytes(), amt)
|
||||||
require.NoError(b, err)
|
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()
|
suite.Commit()
|
||||||
|
|
||||||
return &suite, contractAddr
|
return &suite, contractAddr
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
|
"cosmossdk.io/math"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/core/vm"
|
"github.com/ethereum/go-ethereum/core/vm"
|
||||||
@ -522,7 +523,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
|||||||
}, false, 0, false},
|
}, false, 0, false},
|
||||||
// estimate gas of an erc20 contract deployment, the exact gas number is checked with geth
|
// estimate gas of an erc20 contract deployment, the exact gas number is checked with geth
|
||||||
{"contract deployment", func() {
|
{"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)
|
suite.Require().NoError(err)
|
||||||
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
||||||
args = types.TransactionArgs{
|
args = types.TransactionArgs{
|
||||||
@ -532,7 +533,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
|||||||
}, true, 1186778, false},
|
}, true, 1186778, false},
|
||||||
// estimate gas of an erc20 transfer, the exact gas number is checked with geth
|
// estimate gas of an erc20 transfer, the exact gas number is checked with geth
|
||||||
{"erc20 transfer", func() {
|
{"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()
|
suite.Commit()
|
||||||
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -557,7 +558,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
|||||||
gasCap = 20000
|
gasCap = 20000
|
||||||
}, false, 0, true},
|
}, false, 0, true},
|
||||||
{"contract deployment w/ enableFeemarket", func() {
|
{"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)
|
suite.Require().NoError(err)
|
||||||
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
data := append(types.ERC20Contract.Bin, ctorArgs...)
|
||||||
args = types.TransactionArgs{
|
args = types.TransactionArgs{
|
||||||
@ -566,7 +567,7 @@ func (suite *KeeperTestSuite) TestEstimateGas() {
|
|||||||
}
|
}
|
||||||
}, true, 1186778, true},
|
}, true, 1186778, true},
|
||||||
{"erc20 transfer w/ enableFeemarket", func() {
|
{"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()
|
suite.Commit()
|
||||||
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
transferData, err := types.ERC20Contract.ABI.Pack("transfer", common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), big.NewInt(1000))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
@ -692,11 +693,11 @@ func (suite *KeeperTestSuite) TestTraceTx() {
|
|||||||
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
||||||
suite.Require().NoError(vmdb.Commit())
|
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()
|
suite.Commit()
|
||||||
// Generate token transfer transaction
|
// Generate token transfer transaction
|
||||||
firstTx := 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"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
txMsg = suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt())
|
||||||
suite.Commit()
|
suite.Commit()
|
||||||
|
|
||||||
predecessors = append(predecessors, firstTx)
|
predecessors = append(predecessors, firstTx)
|
||||||
@ -712,10 +713,10 @@ func (suite *KeeperTestSuite) TestTraceTx() {
|
|||||||
suite.enableFeemarket = tc.enableFeemarket
|
suite.enableFeemarket = tc.enableFeemarket
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
// Deploy contract
|
// 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()
|
suite.Commit()
|
||||||
// Generate token transfer transaction
|
// 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()
|
suite.Commit()
|
||||||
|
|
||||||
tc.malleate()
|
tc.malleate()
|
||||||
@ -822,11 +823,11 @@ func (suite *KeeperTestSuite) TestTraceBlock() {
|
|||||||
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
vmdb.SetNonce(suite.address, vmdb.GetNonce(suite.address)+1)
|
||||||
suite.Require().NoError(vmdb.Commit())
|
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()
|
suite.Commit()
|
||||||
// create multiple transactions in the same block
|
// create multiple transactions in the same block
|
||||||
firstTx := 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"), sdk.NewIntWithDecimal(1, 18).BigInt())
|
secondTx := suite.TransferERC20Token(suite.T(), contractAddr, suite.address, common.HexToAddress("0x378c50D9264C63F3F92B806d4ee56E9D86FfB3Ec"), math.NewIntWithDecimal(1, 18).BigInt())
|
||||||
suite.Commit()
|
suite.Commit()
|
||||||
// overwrite txs to include only the ones on new block
|
// overwrite txs to include only the ones on new block
|
||||||
txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx)
|
txs = append([]*types.MsgEthereumTx{}, firstTx, secondTx)
|
||||||
@ -843,10 +844,10 @@ func (suite *KeeperTestSuite) TestTraceBlock() {
|
|||||||
suite.enableFeemarket = tc.enableFeemarket
|
suite.enableFeemarket = tc.enableFeemarket
|
||||||
suite.SetupTest()
|
suite.SetupTest()
|
||||||
// Deploy contract
|
// 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()
|
suite.Commit()
|
||||||
// Generate token transfer transaction
|
// 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()
|
suite.Commit()
|
||||||
|
|
||||||
txs = append(txs, txMsg)
|
txs = append(txs, txMsg)
|
||||||
@ -881,7 +882,7 @@ func (suite *KeeperTestSuite) TestNonceInQuery() {
|
|||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
|
address := common.BytesToAddress(priv.PubKey().Address().Bytes())
|
||||||
suite.Require().Equal(uint64(0), suite.app.EvmKeeper.GetNonce(suite.ctx, address))
|
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
|
// accupy nonce 0
|
||||||
_ = suite.DeployTestContract(suite.T(), address, supply)
|
_ = suite.DeployTestContract(suite.T(), address, supply)
|
||||||
|
@ -8,6 +8,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cmath "cosmossdk.io/math"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
@ -44,7 +46,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/version"
|
"github.com/tendermint/tendermint/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
var testTokens = sdk.NewIntWithDecimal(1000, 18)
|
var testTokens = cmath.NewIntWithDecimal(1000, 18)
|
||||||
|
|
||||||
type KeeperTestSuite struct {
|
type KeeperTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
@ -148,6 +150,7 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) {
|
|||||||
|
|
||||||
valAddr := sdk.ValAddress(suite.address.Bytes())
|
valAddr := sdk.ValAddress(suite.address.Bytes())
|
||||||
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
|
validator, err := stakingtypes.NewValidator(valAddr, priv.PubKey(), stakingtypes.Description{})
|
||||||
|
require.NoError(t, err)
|
||||||
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
|
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
|
err = suite.app.StakingKeeper.SetValidatorByConsAddr(suite.ctx, validator)
|
||||||
|
Loading…
Reference in New Issue
Block a user