From 2dfd446b5c6e16bd7f2b77211c23d49de59806fc Mon Sep 17 00:00:00 2001 From: dreamer Date: Mon, 22 Apr 2024 11:51:03 +0800 Subject: [PATCH] fix test error --- modules/token/keeper/erc20.go | 2 +- modules/token/keeper/keeper_test.go | 6 +++++- simapp/mocks/evm.go | 18 +++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/modules/token/keeper/erc20.go b/modules/token/keeper/erc20.go index 041f1801..b08d1c0b 100644 --- a/modules/token/keeper/erc20.go +++ b/modules/token/keeper/erc20.go @@ -66,7 +66,7 @@ func (k Keeper) DeployERC20( contractArgs, err := contracts.TokenProxyContract.ABI.Pack( "", - params.Beacon, + common.HexToAddress(params.Beacon), initArgs, ) if err != nil { diff --git a/modules/token/keeper/keeper_test.go b/modules/token/keeper/keeper_test.go index 4e64887d..4aa47516 100644 --- a/modules/token/keeper/keeper_test.go +++ b/modules/token/keeper/keeper_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "testing" + "github.com/ethereum/go-ethereum/common" "github.com/stretchr/testify/suite" "github.com/cometbft/cometbft/crypto/tmhash" @@ -29,6 +30,7 @@ var ( add2 = sdk.AccAddress(tmhash.SumTruncated([]byte("tokenTest1"))) initAmt = sdkmath.NewIntWithDecimal(100000000, int(6)) initCoin = sdk.Coins{sdk.NewCoin(denom, initAmt)} + beacon = common.BytesToAddress(owner.Bytes()) ) type KeeperTestSuite struct { @@ -51,7 +53,9 @@ func (suite *KeeperTestSuite) SetupTest() { suite.app = app // set params - suite.keeper.SetParams(suite.ctx, v1.DefaultParams()) + params := v1.DefaultParams() + params.Beacon = beacon.String() + suite.keeper.SetParams(suite.ctx, params) // init tokens to addr err := suite.bk.MintCoins(suite.ctx, types.ModuleName, initCoin) diff --git a/simapp/mocks/evm.go b/simapp/mocks/evm.go index 89638e56..89e6fc8b 100644 --- a/simapp/mocks/evm.go +++ b/simapp/mocks/evm.go @@ -34,14 +34,22 @@ func (e *evm) ApplyMessage(ctx sdk.Context, msg core.Message, tracer vm.EVMLogge if isCreate { contractAddr := crypto.CreateAddress(msg.From(), msg.Nonce()) - data := msg.Data()[len(contracts.ERC20TokenContract.Bin):] - argss, err := contracts.ERC20TokenContract.ABI.Constructor.Inputs.Unpack(data) + data := msg.Data()[len(contracts.TokenProxyContract.Bin):] + args, err := contracts.TokenProxyContract.ABI.Constructor.Inputs.Unpack(data) if err != nil { return nil, err } - name, _ := argss[0].(string) - symbol, _ := argss[1].(string) - scale, _ := argss[2].(uint8) + + data = args[1].([]byte) + data = data[4:] + args, err = contracts.ERC20TokenContract.ABI.Methods[contracts.MethodInitialize].Inputs.Unpack(data) + if err != nil { + return nil, err + } + + name, _ := args[0].(string) + symbol, _ := args[1].(string) + scale, _ := args[2].(uint8) e.erc20s[contractAddr] = &erc20{ address: contractAddr, scale: scale,