Skip to content

Commit

Permalink
- fix tests (dyncomm ante, determinism)
Browse files Browse the repository at this point in the history
  • Loading branch information
StrathCole committed May 6, 2024
1 parent 1208de6 commit c92a00d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/testing/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

// SimAppChainID hardcoded chainID for simulation
const (
SimAppChainID = "terra-app"
SimAppChainID = ""
)

var emptyWasmOpts []wasm.Option
Expand Down
45 changes: 17 additions & 28 deletions custom/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -145,42 +145,31 @@ 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
privs := make([]cryptotypes.PrivKey, len(inputs))

// 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
}

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion x/dyncomm/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c92a00d

Please sign in to comment.