From c92a00de40d763a2002f96464cc89ec40a988cde Mon Sep 17 00:00:00 2001 From: StrathCole Date: Mon, 6 May 2024 16:06:31 +0200 Subject: [PATCH] - fix tests (dyncomm ante, determinism) --- app/testing/test_suite.go | 2 +- custom/bank/simulation/operations.go | 45 +++++++++++----------------- x/dyncomm/ante/ante_test.go | 2 +- 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/app/testing/test_suite.go b/app/testing/test_suite.go index aa3ea943d..a7e05f195 100644 --- a/app/testing/test_suite.go +++ b/app/testing/test_suite.go @@ -40,7 +40,7 @@ import ( // SimAppChainID hardcoded chainID for simulation const ( - SimAppChainID = "terra-app" + SimAppChainID = "" ) var emptyWasmOpts []wasm.Option diff --git a/custom/bank/simulation/operations.go b/custom/bank/simulation/operations.go index 5474880d5..9245ecf46 100644 --- a/custom/bank/simulation/operations.go +++ b/custom/bank/simulation/operations.go @@ -8,12 +8,12 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" "github.com/cosmos/cosmos-sdk/codec" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/x/bank/types" banksim "github.com/cosmos/cosmos-sdk/x/bank/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/cosmos/cosmos-sdk/x/simulation" - simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) @@ -145,7 +145,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { // random number of inputs/outputs between [1, 3] - inputs := make([]types.Input, r.Intn(3)+1) + inputs := make([]types.Input, 1) outputs := make([]types.Output, r.Intn(3)+1) // collect signer privKeys @@ -153,34 +153,23 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope // use map to check if address already exists as input usedAddrs := make(map[string]bool) + simAccount, _, coins, skip := randomSendFields(r, ctx, accs, bk, ak) - var totalSentCoins sdk.Coins - for i := range inputs { - // generate random input fields, ignore to address - simAccount, _, coins, skip := randomSendFields(r, ctx, accs, bk, ak) - - // make sure account is fresh and not used in previous input - for usedAddrs[simAccount.Address.String()] { - simAccount, _, coins, skip = randomSendFields(r, ctx, accs, bk, ak) - } - - if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, "skip all transfers"), nil, nil - } + if skip { + return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, "skip all transfers"), nil, nil + } - // set input address in used address map - usedAddrs[simAccount.Address.String()] = true + // set input address in used address map + usedAddrs[simAccount.Address.String()] = true - // set signer privkey - privs[i] = simAccount.PrivKey + // set signer privkey + privs[0] = simAccount.PrivKey - // set next input and accumulate total sent coins - inputs[i] = types.NewInput(simAccount.Address, coins) - totalSentCoins = totalSentCoins.Add(coins...) - } + // set next input and accumulate total sent coins + inputs[0] = types.NewInput(simAccount.Address, coins) // Check send_enabled status of each sent coin denom - if err := bk.IsSendEnabledCoins(ctx, totalSentCoins...); err != nil { + if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, err.Error()), nil, nil } @@ -190,12 +179,12 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope var outCoins sdk.Coins // split total sent coins into random subsets for output if o == len(outputs)-1 { - outCoins = totalSentCoins + outCoins = coins } else { // take random subset of remaining coins for output // and update remaining coins - outCoins = simtypes.RandSubsetCoins(r, totalSentCoins) - totalSentCoins = totalSentCoins.Sub(outCoins...) + outCoins = simtypes.RandSubsetCoins(r, coins) + coins = coins.Sub(outCoins...) } outputs[o] = types.NewOutput(outAddr.Address, outCoins) diff --git a/x/dyncomm/ante/ante_test.go b/x/dyncomm/ante/ante_test.go index 24e96f863..dd8136530 100644 --- a/x/dyncomm/ante/ante_test.go +++ b/x/dyncomm/ante/ante_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" "github.com/classic-terra/core/v3/app" core "github.com/classic-terra/core/v3/types" - "github.com/gogo/protobuf/proto" + proto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" "github.com/cosmos/cosmos-sdk/client"