diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aea5de22..63f4cac18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### IMPROVEMENTS - [\#758](https://github.com/cosmos/evm/pull/758) Cleanup precompiles abi.json. +- [\#810](https://github.com/cosmos/evm/pull/810) Fix integration test suite to resolve lock contention problem from external app injection - [\#811](https://github.com/cosmos/evm/pull/811) Use sdk's DefaultBondDenom for default evm denom in genesis. ### FEATURES diff --git a/evmd/tests/integration/create_app.go b/evmd/tests/integration/create_app.go index 507f041b0..f1adb4854 100644 --- a/evmd/tests/integration/create_app.go +++ b/evmd/tests/integration/create_app.go @@ -2,6 +2,7 @@ package integration import ( "encoding/json" + "os" "github.com/cosmos/cosmos-sdk/client/flags" @@ -14,7 +15,6 @@ import ( "github.com/cosmos/evm/testutil/constants" feemarkettypes "github.com/cosmos/evm/x/feemarket/types" - clienthelpers "cosmossdk.io/client/v2/helpers" "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/baseapp" @@ -26,7 +26,9 @@ import ( // CreateEvmd creates an evm app for regular integration tests (non-mempool) // This version uses a noop mempool to avoid state issues during transaction processing func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func(*baseapp.BaseApp)) evm.EvmApp { - defaultNodeHome, err := clienthelpers.GetNodeHomeDirectory(".evmd") + // A temporary home directory is created and used to prevent race conditions + // related to home directory locks in chains that use the WASM module. + defaultNodeHome, err := os.MkdirTemp("", "evmd-temp-homedir") if err != nil { panic(err) } @@ -51,12 +53,17 @@ func CreateEvmd(chainID string, evmChainID uint64, customBaseAppOptions ...func( // SetupEvmd initializes a new evmd app with default genesis state. // It is used in IBC integration tests to create a new evmd app instance. func SetupEvmd() (ibctesting.TestingApp, map[string]json.RawMessage) { + defaultNodeHome, err := os.MkdirTemp("", "evmd-temp-homedir") + if err != nil { + panic(err) + } + app := evmd.NewExampleApp( log.NewNopLogger(), dbm.NewMemDB(), nil, true, - NewAppOptionsWithFlagHomeAndChainID("", constants.EighteenDecimalsChainID), + NewAppOptionsWithFlagHomeAndChainID(defaultNodeHome, constants.EighteenDecimalsChainID), ) // disable base fee for testing genesisState := app.DefaultGenesis() diff --git a/tests/integration/README.md b/tests/integration/README.md index a1d0bab62..cc82e986a 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -26,7 +26,9 @@ All tests defined here can be used by any client application that implements the You can find usage examples under `evmd/tests/integration`. For instance, if you want to test your own application with the Bank Precompile Integration Test Suite, -implement your own `CreateApp` function and pass it in as shown below: + +1. Refer to interfaces.go file and implement `EvmApp` interface in your own app. +2. Refer to the `evmd/tests/integration/create_app.go` file and implement your own `CreateApp` function and pass it in as shown below: ```go package integration diff --git a/tests/integration/eip712/test_eip712.go b/tests/integration/eip712/test_eip712.go index 762487911..324800776 100644 --- a/tests/integration/eip712/test_eip712.go +++ b/tests/integration/eip712/test_eip712.go @@ -71,8 +71,6 @@ func (s *TestSuite) SetupTest() { s.config = nw.GetEncodingConfig() s.clientCtx = client.Context{}.WithTxConfig(s.config.TxConfig) s.denom = evmtypes.GetEVMCoinDenom() - - sdk.GetConfig().SetBech32PrefixForAccount("cosmos", "") } // createTestAddress creates random test addresses for messages diff --git a/tests/integration/precompiles/bank/test_integration.go b/tests/integration/precompiles/bank/test_integration.go index 258d96694..c79f42c10 100644 --- a/tests/integration/precompiles/bank/test_integration.go +++ b/tests/integration/precompiles/bank/test_integration.go @@ -119,8 +119,8 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ... contractData ContractData passCheck testutil.LogCheckArgs - cosmosEVMTotalSupply, _ = new(big.Int).SetString("200003000000000000000000", 10) - xmplTotalSupply, _ = new(big.Int).SetString("200000000000000000000000", 10) + cosmosEVMTotalSupply *big.Int + xmplTotalSupply *big.Int ) BeforeEach(func() { @@ -155,6 +155,13 @@ func TestIntegrationSuite(t *testing.T, create network.CreateEvmApp, options ... err = is.network.NextBlock() Expect(err).ToNot(HaveOccurred(), "failed to advance block") + + // Get total supply from bank keeper + cosmosSupply := is.network.App.GetBankKeeper().GetSupply(is.network.GetContext(), is.bondDenom) + cosmosEVMTotalSupply = new(big.Int).Set(cosmosSupply.Amount.BigInt()) + + xmplSupply := is.network.App.GetBankKeeper().GetSupply(is.network.GetContext(), is.tokenDenom) + xmplTotalSupply = new(big.Int).Set(xmplSupply.Amount.BigInt()) }) Context("Direct precompile queries", func() { diff --git a/tests/integration/precompiles/bech32/test_bech32.go b/tests/integration/precompiles/bech32/test_bech32.go index a7f8367ea..b03d1182d 100644 --- a/tests/integration/precompiles/bech32/test_bech32.go +++ b/tests/integration/precompiles/bech32/test_bech32.go @@ -110,7 +110,7 @@ func (s *PrecompileTestSuite) TestRun() { input, err := s.precompile.Pack( bech32.HexToBech32Method, s.keyring.GetAddr(0), - "cosmos", + sdk.GetConfig().GetBech32AccountAddrPrefix(), ) s.Require().NoError(err, "failed to pack input") contract.Input = input @@ -136,7 +136,7 @@ func (s *PrecompileTestSuite) TestRun() { input, err := s.precompile.Pack( bech32.HexToBech32Method, common.BytesToAddress(valAddrBz), - "cosmosvaloper", + sdk.GetConfig().GetBech32ValidatorAddrPrefix(), ) s.Require().NoError(err, "failed to pack input") contract.Input = input @@ -159,7 +159,7 @@ func (s *PrecompileTestSuite) TestRun() { input, err := s.precompile.Pack( bech32.HexToBech32Method, s.keyring.GetAddr(0), - "cosmosvalcons", + sdk.GetConfig().GetBech32ConsensusAddrPrefix(), ) s.Require().NoError(err, "failed to pack input") contract.Input = input diff --git a/tests/integration/precompiles/bech32/test_methods.go b/tests/integration/precompiles/bech32/test_methods.go index 740c7fc92..4b0cef4b1 100644 --- a/tests/integration/precompiles/bech32/test_methods.go +++ b/tests/integration/precompiles/bech32/test_methods.go @@ -62,7 +62,7 @@ func (s *PrecompileTestSuite) TestHexToBech32() { func() []interface{} { return []interface{}{ s.keyring.GetAddr(0), - "cosmos", + sdk.GetConfig().GetBech32AccountAddrPrefix(), } }, func(data []byte) { @@ -108,7 +108,7 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { malleate func() []interface{} postCheck func(data []byte) expError bool - errContains string + errContains func() string }{ { "fail - invalid args length", @@ -117,7 +117,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { }, func([]byte) {}, true, - fmt.Sprintf(cmn.ErrInvalidNumberOfArgs, 1, 0), + func() string { + return fmt.Sprintf(cmn.ErrInvalidNumberOfArgs, 1, 0) + }, }, { "fail - empty bech32 address", @@ -128,7 +130,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { }, func([]byte) {}, true, - "invalid bech32 address", + func() string { + return "invalid bech32 address" + }, }, { "fail - invalid bech32 address", @@ -139,7 +143,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { }, func([]byte) {}, true, - fmt.Sprintf("invalid bech32 address: %s", "cosmos"), + func() string { + return fmt.Sprintf("invalid bech32 address: %s", "cosmos") + }, }, { "fail - decoding bech32 failed", @@ -150,7 +156,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { }, func([]byte) {}, true, - "decoding bech32 failed", + func() string { + return "decoding bech32 failed" + }, }, { "fail - invalid address format", @@ -161,7 +169,13 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { }, func([]byte) {}, true, - "address max length is 255", + func() string { + if addrVerifier := sdk.GetConfig().GetAddressVerifier(); addrVerifier != nil { + err := addrVerifier(sdk.AccAddress(make([]byte, 256))) + return err.Error() + } + return "address max length is 255" + }, }, { "success - valid bech32 address", @@ -179,7 +193,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { s.Require().Equal(s.keyring.GetAddr(0), addr) }, false, - "", + func() string { + return "" + }, }, } @@ -191,7 +207,7 @@ func (s *PrecompileTestSuite) TestBech32ToHex() { if tc.expError { s.Require().Error(err) - s.Require().ErrorContains(err, tc.errContains) + s.Require().ErrorContains(err, tc.errContains()) s.Require().Empty(bz) } else { s.Require().NoError(err) diff --git a/tests/integration/precompiles/distribution/test_event.go b/tests/integration/precompiles/distribution/test_event.go index 822c512b7..ce73fc511 100644 --- a/tests/integration/precompiles/distribution/test_event.go +++ b/tests/integration/precompiles/distribution/test_event.go @@ -58,7 +58,8 @@ func (s *PrecompileTestSuite) TestSetWithdrawAddressEvent() { err := cmn.UnpackLog(s.precompile.ABI, &setWithdrawerAddrEvent, distribution.EventTypeSetWithdrawAddress, *log) s.Require().NoError(err) s.Require().Equal(s.keyring.GetAddr(0), setWithdrawerAddrEvent.Caller) - s.Require().Equal(sdk.MustBech32ifyAddressBytes("cosmos", s.keyring.GetAddr(0).Bytes()), setWithdrawerAddrEvent.WithdrawerAddress) + bech32AddrPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix() + s.Require().Equal(sdk.MustBech32ifyAddressBytes(bech32AddrPrefix, s.keyring.GetAddr(0).Bytes()), setWithdrawerAddrEvent.WithdrawerAddress) }, 20000, false, diff --git a/tests/integration/precompiles/distribution/test_tx.go b/tests/integration/precompiles/distribution/test_tx.go index c4b868108..7de336190 100644 --- a/tests/integration/precompiles/distribution/test_tx.go +++ b/tests/integration/precompiles/distribution/test_tx.go @@ -7,7 +7,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" - evmaddress "github.com/cosmos/evm/encoding/address" cmn "github.com/cosmos/evm/precompiles/common" "github.com/cosmos/evm/precompiles/distribution" "github.com/cosmos/evm/precompiles/testutil" @@ -677,7 +676,7 @@ func (s *PrecompileTestSuite) TestDepositValidatorRewardsPoolMethod() { s.Require().True(success, "expected true, got false") val := s.network.GetValidators()[0] - valCodec := evmaddress.NewEvmCodec("cosmosvaloper") + valCodec := s.network.App.GetStakingKeeper().ValidatorAddressCodec() valBz, err := valCodec.StringToBytes(val.GetOperator()) s.Require().NoError(err) diff --git a/tests/integration/precompiles/staking/test_query.go b/tests/integration/precompiles/staking/test_query.go index b5165cfd0..46f94212b 100644 --- a/tests/integration/precompiles/staking/test_query.go +++ b/tests/integration/precompiles/staking/test_query.go @@ -504,7 +504,8 @@ func (s *PrecompileTestSuite) TestRedelegation() { { name: "success - no redelegation found", malleate: func(srcOperatorAddr, _ string) []interface{} { - nonExistentOperator := sdk.ValAddress([]byte("non-existent-operator")) + nonExistentAddr, _ := testutiltx.NewAccAddressAndKey() + nonExistentOperator := sdk.ValAddress(nonExistentAddr) return []interface{}{ s.keyring.GetAddr(0), srcOperatorAddr,