Skip to content

Commit

Permalink
integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed May 30, 2024
1 parent f302d73 commit 19738bf
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 679 deletions.
1 change: 1 addition & 0 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func NewAnteHandlerAndDepGenerator(options HandlerOptions) (sdk.AnteHandler, sdk
sdk.CustomDepWrappedAnteDecorator(ante.NewSigGasConsumeDecorator(options.AccountKeeper, sigGasConsumer), depdecorators.SignerDepDecorator{ReadOnly: true}),
sdk.CustomDepWrappedAnteDecorator(sequentialVerifyDecorator, depdecorators.SignerDepDecorator{ReadOnly: true}),
sdk.CustomDepWrappedAnteDecorator(ante.NewIncrementSequenceDecorator(options.AccountKeeper), depdecorators.SignerDepDecorator{ReadOnly: false}),
sdk.DefaultWrappedAnteDecorator(evmante.NewEVMAddressDecorator(options.EVMKeeper, options.EVMKeeper.AccountKeeper())),
sdk.DefaultWrappedAnteDecorator(antedecorators.NewAuthzNestedMessageDecorator()),
sdk.DefaultWrappedAnteDecorator(ibcante.NewAnteDecorator(options.IBCKeeper)),
sdk.DefaultWrappedAnteDecorator(dex.NewTickSizeMultipleDecorator(*options.DexKeeper)),
Expand Down
87 changes: 0 additions & 87 deletions contracts/test/AssociateTest.js

This file was deleted.

3 changes: 3 additions & 0 deletions docker/localnode/scripts/step2_genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ override_genesis '.app_state["gov"]["tally_params"]["threshold"]="0.5"'
override_genesis '.app_state["gov"]["tally_params"]["expedited_quorum"]="0.9"'
override_genesis '.app_state["gov"]["tally_params"]["expedited_threshold"]="0.9"'

# evm config
override_genesis '.app_state["evm"]["address_associations"]=[{"sei_address":"sei1m9qugvk4h66p6hunfajfg96ysc48zeq4m0d82c","eth_address":"0xF87A299e6bC7bEba58dbBe5a5Aa21d49bCD16D52"},{"sei_address":"sei1cjzphr67dug28rw9ueewrqllmxlqe5f0awulvy","eth_address":"0x70997970C51812dc3A010C7d01b50e0d17dc79C8"}]'

# add genesis accounts for each node
while read account; do
echo "Adding: $account"
Expand Down
4 changes: 4 additions & 0 deletions docker/localnode/scripts/step5_start_sei.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ echo "Starting the seid process for node $NODE_ID with invariant check interval=
seid start --chain-id sei --inv-check-period ${INVARIANT_CHECK_INTERVAL} > "$LOG_DIR/seid-$NODE_ID.log" 2>&1 &
echo "Node $NODE_ID seid is started now"
echo "Done" >> build/generated/launch.complete

sleep 5

printf "12345678\n" | seid tx evm send-to-cast-sei-addr admin 500000000000000000000usei -y --fees=300000usei --broadcast-mode=block
1 change: 0 additions & 1 deletion integration_test/evm_module/scripts/evm_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ cd contracts
npm ci
npx hardhat test --network seilocal test/EVMCompatabilityTest.js
npx hardhat test --network seilocal test/EVMPrecompileTest.js
npx hardhat test --network seilocal test/AssociateTest.js
4 changes: 2 additions & 2 deletions occ_tests/messages/test_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ func FundEVMSigner(tCtx *utils.TestContext, msg *utils.TestMessage) {
return
}
amounts := sdk.NewCoins(sdk.NewCoin("usei", sdk.NewInt(1000000000000000)), sdk.NewCoin("uusdc", sdk.NewInt(1000000000000000)))
tCtx.TestApp.BankKeeper.MintCoins(tCtx.Ctx, minttypes.ModuleName, amounts)
tCtx.TestApp.BankKeeper.SendCoinsFromModuleToAccount(tCtx.Ctx, minttypes.ModuleName, sdk.AccAddress(msg.EVMSigner.EvmAddress[:]), amounts)
_ = tCtx.TestApp.BankKeeper.MintCoins(tCtx.Ctx, minttypes.ModuleName, amounts)
_ = tCtx.TestApp.BankKeeper.SendCoinsFromModuleToAccount(tCtx.Ctx, minttypes.ModuleName, sdk.AccAddress(msg.EVMSigner.EvmAddress[:]), amounts)
}

// EVMTransferNonConflicting generates a list of EVM transfer messages that do not conflict with each other
Expand Down
8 changes: 0 additions & 8 deletions proto/evm/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ service Msg {
rpc Send(MsgSend) returns (MsgSendResponse);
rpc RegisterPointer(MsgRegisterPointer) returns (MsgRegisterPointerResponse);
rpc AssociateContractAddress(MsgAssociateContractAddress) returns (MsgAssociateContractAddressResponse);
rpc Associate(MsgAssociate) returns (MsgAssociateResponse);
}

message MsgEVMTransaction {
Expand Down Expand Up @@ -74,10 +73,3 @@ message MsgAssociateContractAddress {
}

message MsgAssociateContractAddressResponse {}

message MsgAssociate {
string sender = 1;
string custom_message = 2;
}

message MsgAssociateResponse {}
28 changes: 28 additions & 0 deletions x/evm/ante/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
sdkacltypes "github.com/cosmos/cosmos-sdk/types/accesscontrol"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -61,6 +62,9 @@ func (p *EVMPreprocessDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
derived := msg.Derived
evmAddr := derived.SenderEVMAddr
seiAddr := p.evmKeeper.GetSeiAddress(ctx, evmAddr)
ctx.EventManager().EmitEvent(sdk.NewEvent(evmtypes.EventTypeSigner,
sdk.NewAttribute(evmtypes.AttributeKeyEvmAddress, evmAddr.Hex()),
sdk.NewAttribute(evmtypes.AttributeKeySeiAddress, seiAddr.String())))
if !p.accountKeeper.HasAccount(ctx, seiAddr) {
p.accountKeeper.SetAccount(ctx, p.accountKeeper.NewAccountWithAddress(ctx, seiAddr))
}
Expand Down Expand Up @@ -236,6 +240,15 @@ func GetVersion(ctx sdk.Context, ethCfg *params.ChainConfig) derived.SignerVersi
}
}

type EVMAddressDecorator struct {
evmKeeper *evmkeeper.Keeper
accountKeeper *accountkeeper.AccountKeeper
}

func NewEVMAddressDecorator(evmKeeper *evmkeeper.Keeper, accountKeeper *accountkeeper.AccountKeeper) *EVMAddressDecorator {
return &EVMAddressDecorator{evmKeeper: evmKeeper, accountKeeper: accountKeeper}
}

// only used in simulation for historical txs
func migrateBalance(ctx sdk.Context, evmKeeper *evmkeeper.Keeper, evmAddr common.Address, seiAddr sdk.AccAddress) error {
castAddr := sdk.AccAddress(evmAddr[:])
Expand All @@ -254,3 +267,18 @@ func migrateBalance(ctx sdk.Context, evmKeeper *evmkeeper.Keeper, evmAddr common
evmKeeper.AccountKeeper().RemoveAccount(ctx, authtypes.NewBaseAccountWithAddress(castAddr))
return nil
}

//nolint:revive
func (p *EVMAddressDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
sigTx, ok := tx.(authsigning.SigVerifiableTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "invalid tx type")
}
signers := sigTx.GetSigners()
for _, signer := range signers {
ctx.EventManager().EmitEvent(sdk.NewEvent(evmtypes.EventTypeSigner,
sdk.NewAttribute(evmtypes.AttributeKeyEvmAddress, p.evmKeeper.GetEVMAddress(ctx, signer).Hex()),

Check warning on line 280 in x/evm/ante/preprocess.go

View check run for this annotation

Codecov / codecov/patch

x/evm/ante/preprocess.go#L280

Added line #L280 was not covered by tests
sdk.NewAttribute(evmtypes.AttributeKeySeiAddress, signer.String())))
}
return next(ctx, tx, simulate)
}
75 changes: 50 additions & 25 deletions x/evm/client/cli/native_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/sei-protocol/sei-chain/evmrpc"
"github.com/sei-protocol/sei-chain/precompiles"
"github.com/sei-protocol/sei-chain/precompiles/pointer"
Expand Down Expand Up @@ -56,6 +58,54 @@ func NativeSendTxCmd() *cobra.Command {
return cmd
}

func SendCastSeiAddrTxCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "send-to-cast-sei-addr [from_key_or_address] [amount]",
Short: `Send funds from one account to the direct cast of its EVM address.
Note, the '--from' flag is ignored as it is implied from [from_key_or_address].
When using '--dry-run' a key name cannot be used, only a bech32 address.`,
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
_ = cmd.Flags().Set(flags.FlagFrom, args[0])
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

coins, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return err
}

key, err := getPrivateKey(cmd)
if err != nil {
return err
}
testmsg := crypto.Keccak256([]byte("foo"))
sig, _ := crypto.Sign(testmsg, key)

recoveredPub, _ := crypto.Ecrecover(testmsg, sig)
pubKey, _ := crypto.UnmarshalPubkey(recoveredPub)
evmAddr := crypto.PubkeyToAddress(*pubKey)

msg := &banktypes.MsgSend{
FromAddress: clientCtx.GetFromAddress().String(),
ToAddress: sdk.AccAddress(evmAddr[:]).String(),
Amount: coins,
}
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}

func RegisterCwPointerCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "register-cw-pointer [pointer type] [erc address]",
Expand Down Expand Up @@ -177,28 +227,3 @@ func AssociateContractAddressCmd() *cobra.Command {

return cmd
}

func NativeAssociateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "native-associate [custom msg]",
Short: `Set address association for the sender.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

msg := types.NewMsgAssociate(clientCtx.GetFromAddress(), args[0])
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}

flags.AddTxFlagsToCmd(cmd)

return cmd
}
2 changes: 1 addition & 1 deletion x/evm/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(NewAddCWERC20PointerProposalTxCmd())
cmd.AddCommand(NewAddCWERC721PointerProposalTxCmd())
cmd.AddCommand(AssociateContractAddressCmd())
cmd.AddCommand(NativeAssociateCmd())
cmd.AddCommand(SendCastSeiAddrTxCmd())

return cmd
}
Expand Down
10 changes: 0 additions & 10 deletions x/evm/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/sei-protocol/sei-chain/testutil/keeper"
Expand Down Expand Up @@ -44,15 +43,6 @@ func TestGetChainID(t *testing.T) {
require.Equal(t, int64(713715), k.ChainID(ctx).Int64())
}

func TestGetVMBlockContext(t *testing.T) {
k, ctx := keeper.MockEVMKeeper()
moduleAddr := k.AccountKeeper().GetModuleAddress(authtypes.FeeCollectorName)
evmAddr := k.GetEVMAddress(ctx, moduleAddr)
k.DeleteAddressMapping(ctx, moduleAddr, evmAddr)
_, err := k.GetVMBlockContext(ctx, 0)
require.NotNil(t, err)
}

func TestGetHashFn(t *testing.T) {
k, ctx := keeper.MockEVMKeeper()
f := k.GetHashFn(ctx)
Expand Down
4 changes: 0 additions & 4 deletions x/evm/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,3 @@ func (server msgServer) AssociateContractAddress(goCtx context.Context, msg *typ
server.SetAddressMapping(ctx, addr, evmAddr)
return &types.MsgAssociateContractAddressResponse{}, nil
}

func (server msgServer) Associate(context.Context, *types.MsgAssociate) (*types.MsgAssociateResponse, error) {
return &types.MsgAssociateResponse{}, nil
}
Loading

0 comments on commit 19738bf

Please sign in to comment.