Skip to content

Commit

Permalink
test(campaign): simulation improvements (#726)
Browse files Browse the repository at this point in the history
* override send-enabled params for simulation

* finalize `SimulateMsgSendVouchers`

Co-authored-by: Alex Johnson <alex.johnson@tendermint.com>
Co-authored-by: Lucas Bertrand <lucas.bertrand.22@gmail.com>
  • Loading branch information
3 people authored Apr 15, 2022
1 parent 0726841 commit d35cf06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
4 changes: 4 additions & 0 deletions app/simutil/app_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ func CustomAppStateFn(cdc codec.JSONCodec, simManager *module.SimulationManager)
})
}

// override bank parameters to always enable transfers
bankState.Params.SendEnabled = banktypes.SendEnabledParams{}
bankState.Params.DefaultSendEnabled = true

// change appState back
rawState[stakingtypes.ModuleName] = cdc.MustMarshalJSON(stakingState)
rawState[banktypes.ModuleName] = cdc.MustMarshalJSON(bankState)
Expand Down
3 changes: 1 addition & 2 deletions x/campaign/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ func SimulateMsgUnredeemVouchers(
}

// SimulateMsgSendVouchers simulates a Msg message from the bank module with vouchers
// TODO: This message constantly fails in simulation log, investigate why
func SimulateMsgSendVouchers(
ak types.AccountKeeper,
bk types.BankKeeper,
Expand All @@ -346,7 +345,7 @@ func SimulateMsgSendVouchers(
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
_, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, false)
if !found {
return simtypes.NoOpMsg(types.ModuleName, banktypes.TypeMsgSend, "skip send vouchers"), nil, nil
return simtypes.NoOpMsg(banktypes.ModuleName, banktypes.TypeMsgSend, "skip send vouchers"), nil, nil
}

// Select a random receiver account
Expand Down
20 changes: 5 additions & 15 deletions x/campaign/simulation/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,6 @@ func GetAccountWithVouchers(
}
}

// Look for accounts with at least 10 vouchers
if coin.Amount.Int64() < 10 {
return false
}

found = true
accountAddr = addr
return true
Expand All @@ -179,19 +174,14 @@ func GetAccountWithVouchers(
return 0, account, coins, false
}

// Fetch all the vouchers of the campaign owned by the account
// Fetch from the vouchers of the campaign owned by the account
bk.IterateAccountBalances(ctx, accountAddr, func(coin sdk.Coin) bool {
coinCampID, err := types.VoucherCampaign(coin.Denom)
if err == nil && coinCampID == campID {

// Get a portion of the balance
// If the balance is 1, we don't include it in the vouchers
// There is a issue: insufficient fees that can occur when the whole balance for a voucher is sent
// TODO: Investigate this issue
if coin.Amount.Int64() > 1 {
coin.Amount = coin.Amount.Quo(sdk.NewInt(2))
coins = append(coins, coin)
}
// retain a random portion of the balance in the range [0, coin.Amount)
retainAmt := sdk.NewInt(rand.Int63n(coin.Amount.Int64()))
coin.Amount = coin.Amount.Sub(retainAmt)
coins = append(coins, coin)
}
return false
})
Expand Down

0 comments on commit d35cf06

Please sign in to comment.