Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions evmd/tests/integration/create_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"encoding/json"
"os"

"github.com/cosmos/cosmos-sdk/client/flags"

Expand All @@ -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"
Expand All @@ -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)
}
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/integration/eip712/test_eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions tests/integration/precompiles/bank/test_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/precompiles/bech32/test_bech32.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
34 changes: 25 additions & 9 deletions tests/integration/precompiles/bech32/test_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *PrecompileTestSuite) TestHexToBech32() {
func() []interface{} {
return []interface{}{
s.keyring.GetAddr(0),
"cosmos",
sdk.GetConfig().GetBech32AccountAddrPrefix(),
}
},
func(data []byte) {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -128,7 +130,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() {
},
func([]byte) {},
true,
"invalid bech32 address",
func() string {
return "invalid bech32 address"
},
},
{
"fail - invalid bech32 address",
Expand All @@ -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",
Expand All @@ -150,7 +156,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() {
},
func([]byte) {},
true,
"decoding bech32 failed",
func() string {
return "decoding bech32 failed"
},
},
{
"fail - invalid address format",
Expand All @@ -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",
Expand All @@ -179,7 +193,9 @@ func (s *PrecompileTestSuite) TestBech32ToHex() {
s.Require().Equal(s.keyring.GetAddr(0), addr)
},
false,
"",
func() string {
return ""
},
},
}

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/precompiles/distribution/test_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/precompiles/distribution/test_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion tests/integration/precompiles/staking/test_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading