From df52384b48ac162fea53ae3caffb7a0938b30735 Mon Sep 17 00:00:00 2001 From: poorphd Date: Tue, 9 Jul 2024 23:35:13 +0900 Subject: [PATCH] fix: NoOpMsg types --- .../{operations.go => operation.go} | 92 ++++++++++--------- x/coinswap/simulation/operation_test.go | 6 +- x/coinswap/types/msgs.go | 25 ----- x/erc20/simulation/operation.go | 18 ++-- x/erc20/types/msg.go | 5 - 5 files changed, 60 insertions(+), 86 deletions(-) rename x/coinswap/simulation/{operations.go => operation.go} (76%) diff --git a/x/coinswap/simulation/operations.go b/x/coinswap/simulation/operation.go similarity index 76% rename from x/coinswap/simulation/operations.go rename to x/coinswap/simulation/operation.go index d1b25848..17fec55b 100644 --- a/x/coinswap/simulation/operations.go +++ b/x/coinswap/simulation/operation.go @@ -28,6 +28,12 @@ const ( OpWeightMsgRemoveLiquidity = "op_weight_msg_remove_liquidity" ) +var ( + TypeMsgSwapOrder = sdk.MsgTypeURL(&types.MsgSwapOrder{}) + TypeMsgAddLiquidity = sdk.MsgTypeURL(&types.MsgAddLiquidity{}) + TypeMsgRemoveLiquidity = sdk.MsgTypeURL(&types.MsgRemoveLiquidity{}) +) + func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, @@ -99,31 +105,31 @@ func SimulateMsgAddLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk types.B exactStandardAmt := simtypes.RandomAmount(r, spendable.AmountOf(standardDenom)) if !exactStandardAmt.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "standardAmount should be positive"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "standardAmount should be positive"), nil, nil } maxToken = RandomSpendableToken(r, spendable) if maxToken.Denom == standardDenom { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "tokenDenom should not be standardDenom"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "tokenDenom should not be standardDenom"), nil, err } _, err = k.GetMaximumSwapAmount(ctx, maxToken.Denom) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, err.Error()), nil, nil } if strings.HasPrefix(maxToken.Denom, types.LptTokenPrefix) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "tokenDenom should not be liquidity token"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "tokenDenom should not be liquidity token"), nil, err } if !maxToken.Amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "maxToken must is positive"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "maxToken must is positive"), nil, err } poolId := types.GetPoolId(maxToken.Denom) pool, has := k.GetPool(ctx, poolId) if has { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "pool not found"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "pool not found"), nil, err } reservePool, err := k.GetPoolBalances(ctx, pool.EscrowAddress) @@ -136,7 +142,7 @@ func SimulateMsgAddLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk types.B minLiquidity = liquidity.Mul(exactStandardAmt).Quo(standardReserveAmt) if !maxToken.Amount.Sub(reservePool.AmountOf(maxToken.GetDenom()).Mul(exactStandardAmt).Quo(standardReserveAmt)).IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "insufficient funds"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "insufficient funds"), nil, err } params := k.GetParams(ctx) @@ -147,7 +153,7 @@ func SimulateMsgAddLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk types.B spendTotal = spendTotal.Add(exactStandardAmt) } if spendable.AmountOf(poolCreationFee.Denom).LT(spendTotal) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgAddLiquidity, "insufficient funds"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "insufficient funds"), nil, err } } @@ -165,7 +171,7 @@ func SimulateMsgAddLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk types.B if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coinsTemp) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "unable to generate fees"), nil, nil } } @@ -184,11 +190,11 @@ func SimulateMsgAddLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk types.B ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "unable to generate mock tx"), nil, err } if _, _, err := app.SimDeliver(txGen.TxEncoder(), tx); err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgAddLiquidity, "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, ""), nil, nil @@ -214,7 +220,7 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank standardDenom, _ := k.GetStandardDenom(ctx) if spendable.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "spendable is zero"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "spendable is zero"), nil, err } // sold coin @@ -222,25 +228,25 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank _, err = k.GetMaximumSwapAmount(ctx, inputCoin.Denom) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } if strings.HasPrefix(inputCoin.Denom, types.LptTokenPrefix) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should not be liquidity token"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin should not be liquidity token"), nil, err } if !inputCoin.Amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin must is positive"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin must is positive"), nil, err } poolId := types.GetPoolId(inputCoin.Denom) pool, has := k.GetPool(ctx, poolId) if !has { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil } if _, err := k.GetPoolBalancesByLptDenom(ctx, pool.LptDenom); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil } // bought coin @@ -250,34 +256,34 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank return false }) if coins.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "total supply is zero"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "total supply is zero"), nil, err } outputCoin = RandomTotalToken(r, coins) _, err = k.GetMaximumSwapAmount(ctx, inputCoin.Denom) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } if strings.HasPrefix(outputCoin.Denom, types.LptTokenPrefix) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "outputCoin should not be liquidity token"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "outputCoin should not be liquidity token"), nil, err } if !outputCoin.Amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "outputCoin must is positive"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "outputCoin must is positive"), nil, err } poolId = types.GetPoolId(outputCoin.Denom) pool, has = k.GetPool(ctx, poolId) if !has { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil } if _, err := k.GetPoolBalancesByLptDenom(ctx, pool.LptDenom); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil } if outputCoin.Denom == inputCoin.Denom { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "outputCoin denom and inputcoin denom should not be the same"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "outputCoin denom and inputcoin denom should not be the same"), nil, nil } isDoubleSwap := (outputCoin.Denom != standardDenom) && (inputCoin.Denom != standardDenom) @@ -286,26 +292,26 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank if isBuyOrder && isDoubleSwap { inputCoin, outputCoin, err = doubleSwapBill(inputCoin, outputCoin, ctx, k) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } } else if isBuyOrder && !isDoubleSwap { inputCoin, outputCoin, err = singleSwapBill(inputCoin, outputCoin, ctx, k) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } } else if !isBuyOrder && isDoubleSwap { inputCoin, outputCoin, err = doubleSwapSellOrder(inputCoin, outputCoin, ctx, k) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } } else if !isBuyOrder && !isDoubleSwap { inputCoin, outputCoin, err = singleSwapSellOrder(inputCoin, outputCoin, ctx, k) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, err.Error()), nil, nil } } if !outputCoin.Amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "outputCoin must is positive"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "outputCoin must is positive"), nil, err } deadline := randDeadline(r) @@ -327,7 +333,7 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coinsTemp) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "unable to generate fees"), nil, nil } } @@ -345,11 +351,11 @@ func SimulateMsgSwapOrder(k keeper.Keeper, ak types.AccountKeeper, bk types.Bank ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "unable to generate mock tx"), nil, err } if _, _, err := app.SimDeliver(txGen.TxEncoder(), tx); err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSwapOrder, "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, ""), nil, nil @@ -375,23 +381,23 @@ func SimulateMsgRemoveLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk type spendable := bk.SpendableCoins(ctx, account.GetAddress()) if spendable.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "spendable is zero"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "spendable is zero"), nil, err } token := RandomSpendableToken(r, spendable) if token.Denom == standardDenom { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRemoveLiquidity, "tokenDenom should not be standardDenom"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "tokenDenom should not be standardDenom"), nil, err } pool, has := k.GetPoolByLptDenom(ctx, token.Denom) if !has { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "inputCoin should exist in the pool"), nil, nil } reservePool, err := k.GetPoolBalancesByLptDenom(ctx, pool.LptDenom) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSwapOrder, "inputCoin should exist in the pool"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "inputCoin should exist in the pool"), nil, nil } standardReserveAmt := reservePool.AmountOf(standardDenom) @@ -401,20 +407,20 @@ func SimulateMsgRemoveLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk type liquidityReserve := bk.GetSupply(ctx, token.Denom).Amount if !withdrawLiquidity.IsValid() || !withdrawLiquidity.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRemoveLiquidity, "invalid withdrawLiquidity"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "invalid withdrawLiquidity"), nil, nil } if liquidityReserve.LT(withdrawLiquidity.Amount) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil } minToken = withdrawLiquidity.Amount.Mul(tokenReserveAmt).Quo(liquidityReserve) if tokenReserveAmt.LT(minToken) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil } minStandardAmt = withdrawLiquidity.Amount.Mul(standardReserveAmt).Quo(liquidityReserve) if standardReserveAmt.LT(minStandardAmt) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "insufficient funds"), nil, nil } deadline := randDeadline(r) @@ -431,7 +437,7 @@ func SimulateMsgRemoveLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk type if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coinsTemp) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "unable to generate fees"), nil, nil } } @@ -450,11 +456,11 @@ func SimulateMsgRemoveLiquidity(k keeper.Keeper, ak types.AccountKeeper, bk type ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "unable to generate mock tx"), nil, err } if _, _, err := app.SimDeliver(txGen.TxEncoder(), tx); err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, TypeMsgRemoveLiquidity, "unable to deliver tx"), nil, nil } return simtypes.NewOperationMsg(msg, true, ""), nil, nil diff --git a/x/coinswap/simulation/operation_test.go b/x/coinswap/simulation/operation_test.go index 5f7e58b4..3df06f99 100644 --- a/x/coinswap/simulation/operation_test.go +++ b/x/coinswap/simulation/operation_test.go @@ -44,9 +44,9 @@ func TestWeightedOperations(t *testing.T) { opMsgRoute string opMsgName string }{ - {params.DefaultWeightMsgAddLiquidity, types.ModuleName, types.TypeMsgAddLiquidity}, - {params.DefaultWeightMsgSwapOrder, types.ModuleName, types.TypeMsgSwapOrder}, - {params.DefaultWeightMsgRemoveLiquidity, types.ModuleName, types.TypeMsgRemoveLiquidity}, + {params.DefaultWeightMsgAddLiquidity, types.ModuleName, sdk.MsgTypeURL(&types.MsgAddLiquidity{})}, + {params.DefaultWeightMsgSwapOrder, types.ModuleName, sdk.MsgTypeURL(&types.MsgSwapOrder{})}, + {params.DefaultWeightMsgRemoveLiquidity, types.ModuleName, sdk.MsgTypeURL(&types.MsgRemoveLiquidity{})}, } for i, w := range weightedOps { diff --git a/x/coinswap/types/msgs.go b/x/coinswap/types/msgs.go index 13c5a0ce..0df84f59 100644 --- a/x/coinswap/types/msgs.go +++ b/x/coinswap/types/msgs.go @@ -18,13 +18,6 @@ const ( LptTokenPrefix = "lpt" // LptTokenFormat defines the name of liquidity token LptTokenFormat = "lpt-%d" - - // TypeMsgAddLiquidity defines the type of MsgAddLiquidity - TypeMsgAddLiquidity = "add_liquidity" - // TypeMsgRemoveLiquidity defines the type of MsgRemoveLiquidity - TypeMsgRemoveLiquidity = "remove_liquidity" - // TypeMsgSwapOrder defines the type of MsgSwapOrder - TypeMsgSwapOrder = "swap_order" ) /* --------------------------------------------------------------------------- */ @@ -52,12 +45,6 @@ func NewMsgSwapOrder( } } -// Route implements Msg. -func (msg MsgSwapOrder) Route() string { return RouterKey } - -// Type implements Msg. -func (msg MsgSwapOrder) Type() string { return TypeMsgSwapOrder } - // ValidateBasic implements Msg. func (msg MsgSwapOrder) ValidateBasic() error { if err := ValidateInput(msg.Input); err != nil { @@ -110,12 +97,6 @@ func NewMsgAddLiquidity( } } -// Route implements Msg. -func (msg MsgAddLiquidity) Route() string { return RouterKey } - -// Type implements Msg. -func (msg MsgAddLiquidity) Type() string { return TypeMsgAddLiquidity } - // ValidateBasic implements Msg. func (msg MsgAddLiquidity) ValidateBasic() error { if err := ValidateMaxToken(msg.MaxToken); err != nil { @@ -175,12 +156,6 @@ func NewMsgRemoveLiquidity( } } -// Route implements Msg. -func (msg MsgRemoveLiquidity) Route() string { return RouterKey } - -// Type implements Msg. -func (msg MsgRemoveLiquidity) Type() string { return TypeMsgRemoveLiquidity } - // ValidateBasic implements Msg. func (msg MsgRemoveLiquidity) ValidateBasic() error { if err := ValidateMinToken(msg.MinToken); err != nil { diff --git a/x/erc20/simulation/operation.go b/x/erc20/simulation/operation.go index 65de0221..9dda50ec 100644 --- a/x/erc20/simulation/operation.go +++ b/x/erc20/simulation/operation.go @@ -69,7 +69,7 @@ func SimulateMsgConvertCoin(k keeper.Keeper, ak types.AccountKeeper, bk types.Ba if len(pairs) == 0 { _, err := SimulateRegisterCoin(r, ctx, accs, k, bk) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertCoin, "no pairs available"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertCoin{}), "no pairs available"), nil, nil } pairs = k.GetTokenPairs(ctx) } @@ -77,7 +77,7 @@ func SimulateMsgConvertCoin(k keeper.Keeper, ak types.AccountKeeper, bk types.Ba // randomly pick one pair pair := pairs[r.Intn(len(pairs))] if !pair.Enabled { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertCoin, "token pair is not enabled"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertCoin{}), "token pair is not enabled"), nil, nil } baseDenom := pair.GetDenom() @@ -96,7 +96,7 @@ func SimulateMsgConvertCoin(k keeper.Keeper, ak types.AccountKeeper, bk types.Ba } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertCoin, "no account has coins"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertCoin{}), "no account has coins"), nil, nil } priv, _ := ethsecp256k1.GenerateKey() @@ -134,11 +134,9 @@ func SimulateMsgConvertErc20(k keeper.Keeper, ak types.AccountKeeper, bk types.B pairs := k.GetTokenPairs(ctx) if len(pairs) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertERC20, "no pairs available"), nil, nil - _, err := SimulateRegisterERC20(r, ctx, accs, k, ak, bk, ek, fk) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertERC20, "no pairs available"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertERC20{}), "no pairs available"), nil, nil } pairs = k.GetTokenPairs(ctx) } @@ -146,7 +144,7 @@ func SimulateMsgConvertErc20(k keeper.Keeper, ak types.AccountKeeper, bk types.B // randomly pick one pair pair := pairs[r.Intn(len(pairs))] if !pair.Enabled { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertCoin, "token pair is not enabled"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertERC20{}), "token pair is not enabled"), nil, nil } erc20ABI := contracts.ERC20MinterBurnerDecimalsContract.ABI @@ -161,11 +159,11 @@ func SimulateMsgConvertErc20(k keeper.Keeper, ak types.AccountKeeper, bk types.B before := k.BalanceOf(ctx, erc20ABI, contractAddr, receiver) _, err := k.CallEVM(ctx, erc20ABI, deployer, contractAddr, true, "mint", receiver, mintAmt.BigInt()) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertERC20, "no account has native ERC20"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertERC20{}), "no account has native ERC20"), nil, nil } after := k.BalanceOf(ctx, erc20ABI, contractAddr, receiver) if after.Cmp(before.Add(before, mintAmt.BigInt())) != 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertERC20, "no account has native ERC20"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertERC20{}), "no account has native ERC20"), nil, nil } } @@ -184,7 +182,7 @@ func SimulateMsgConvertErc20(k keeper.Keeper, ak types.AccountKeeper, bk types.B } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgConvertERC20, "no account has native ERC20"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgConvertERC20{}), "no account has native ERC20"), nil, nil } msg := types.NewMsgConvertERC20(sdkmath.NewIntFromBigInt(erc20Balance), simAccount.Address, pair.GetERC20Contract(), common.BytesToAddress(simAccount.Address.Bytes())) diff --git a/x/erc20/types/msg.go b/x/erc20/types/msg.go index 45304fa8..69c201f5 100644 --- a/x/erc20/types/msg.go +++ b/x/erc20/types/msg.go @@ -18,11 +18,6 @@ var ( _ sdk.Msg = &MsgConvertERC20{} ) -const ( - TypeMsgConvertCoin = "convert_coin" - TypeMsgConvertERC20 = "convert_ERC20" -) - // NewMsgConvertCoin creates a new instance of MsgConvertCoin func NewMsgConvertCoin(coin sdk.Coin, receiver common.Address, sender sdk.AccAddress) *MsgConvertCoin { // nolint: interfacer return &MsgConvertCoin{