Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(campaign): simulation improvements #726

Merged
merged 4 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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