diff --git a/x/evm/keeper/address.go b/x/evm/keeper/address.go index 99f13cc1ce..2f65f205cd 100644 --- a/x/evm/keeper/address.go +++ b/x/evm/keeper/address.go @@ -1,6 +1,7 @@ package keeper import ( + wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" "github.com/sei-protocol/sei-chain/x/evm/types" @@ -27,6 +28,12 @@ func (k *Keeper) DeleteAddressMapping(ctx sdk.Context, seiAddress sdk.AccAddress } func (k *Keeper) GetEVMAddress(ctx sdk.Context, seiAddress sdk.AccAddress) (common.Address, bool) { + // CW address has a different length and should always be considered associated + // Note that this association is one-way since CW address is longer than EOA address + // and would need to be cropped. + if len(seiAddress) == wasmtypes.ContractAddrLen { + return common.BytesToAddress(seiAddress), true + } store := ctx.KVStore(k.storeKey) bz := store.Get(types.SeiAddressToEVMAddressKey(seiAddress)) addr := common.Address{} diff --git a/x/evm/keeper/address_test.go b/x/evm/keeper/address_test.go index 825dfb5658..9e91425490 100644 --- a/x/evm/keeper/address_test.go +++ b/x/evm/keeper/address_test.go @@ -4,6 +4,8 @@ import ( "bytes" "testing" + wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper" + "github.com/ethereum/go-ethereum/common" "github.com/sei-protocol/sei-chain/testutil/keeper" "github.com/stretchr/testify/require" ) @@ -50,3 +52,11 @@ func TestGetAddressOrDefault(t *testing.T) { defaultSeiAddr := k.GetSeiAddressOrDefault(ctx, evmAddr) require.True(t, bytes.Equal(defaultSeiAddr, evmAddr[:])) } + +func TestGetEVMAddressForCW(t *testing.T) { + k, ctx := keeper.MockEVMKeeper() + cwAddr := wasmkeeper.BuildContractAddress(123, 456) + cwEvmAddr, associated := k.GetEVMAddress(ctx, cwAddr) + require.True(t, associated) + require.Equal(t, common.BytesToAddress(cwAddr), cwEvmAddr) +}