Skip to content

Commit

Permalink
Merge branch 'develop' into chore/codecov-monitoringc
Browse files Browse the repository at this point in the history
  • Loading branch information
giunatale authored Apr 21, 2022
2 parents 07d5f0a + d775e6a commit 75414ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions x/campaign/simulation/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func SimulateMsgBurnVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
campID, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, false)
campID, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, false)
if !found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBurnVouchers, "skip burn vouchers"), nil, nil
}
Expand All @@ -292,7 +292,7 @@ func SimulateMsgRedeemVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
campID, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, true)
campID, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, true)
if !found {
return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgRedeemVouchers, "skip redeem vouchers"), nil, nil
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func SimulateMsgSendVouchers(
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
_, simAccount, vouchers, found := GetAccountWithVouchers(ctx, bk, k, accs, false)
_, simAccount, vouchers, found := GetAccountWithVouchers(r, ctx, bk, k, accs, false)
if !found {
return simtypes.NoOpMsg(banktypes.ModuleName, banktypes.TypeMsgSend, "skip send vouchers"), nil, nil
}
Expand Down
10 changes: 6 additions & 4 deletions x/campaign/simulation/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func GetSharesFromCampaign(r *rand.Rand, ctx sdk.Context, k keeper.Keeper, campI

// GetAccountWithVouchers returns an account that has vouchers for a campaign
func GetAccountWithVouchers(
r *rand.Rand,
ctx sdk.Context,
bk types.BankKeeper,
k keeper.Keeper,
Expand Down Expand Up @@ -178,10 +179,11 @@ func GetAccountWithVouchers(
bk.IterateAccountBalances(ctx, accountAddr, func(coin sdk.Coin) bool {
coinCampID, err := types.VoucherCampaign(coin.Denom)
if err == nil && coinCampID == campID {
// 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)
// fetch a part of each voucher hold by the account
amt, err := simtypes.RandPositiveInt(r, coin.Amount)
if err == nil {
coins = append(coins, sdk.NewCoin(coin.Denom, amt))
}
}
return false
})
Expand Down
6 changes: 3 additions & 3 deletions x/campaign/simulation/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
}

t.Run("no account", func(t *testing.T) {
_, _, _, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
_, _, _, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
require.False(t, found)
})

Expand All @@ -236,7 +236,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
campaign.MainnetID = tk.LaunchKeeper.AppendChain(ctx, chain)
campaign.CampaignID = tk.CampaignKeeper.AppendCampaign(ctx, campaign)
mint(acc.Address, sample.Vouchers(r, campaign.CampaignID))
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, false)
require.True(t, found)
require.EqualValues(t, campaign.CampaignID, campID)
require.False(t, coins.Empty())
Expand All @@ -249,7 +249,7 @@ func TestGetAccountWithVouchers(t *testing.T) {
campaign.MainnetInitialized = false
campaign.CampaignID = tk.CampaignKeeper.AppendCampaign(ctx, campaign)
mint(acc.Address, sample.Vouchers(r, campaign.CampaignID))
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, true)
campID, acc, coins, found := simcampaign.GetAccountWithVouchers(r, ctx, tk.BankKeeper, *tk.CampaignKeeper, accs, true)
require.True(t, found)
require.EqualValues(t, campaign.CampaignID, campID)
require.False(t, coins.Empty())
Expand Down

0 comments on commit 75414ff

Please sign in to comment.