Skip to content

Commit

Permalink
Merge pull request #3375 from cosmos/bez/3355-sim-failure-debug
Browse files Browse the repository at this point in the history
Simulation Fee Deduction Fixes
  • Loading branch information
alexanderbez authored Jan 24, 2019
2 parents 74aa423 + f0ab20d commit af18304
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions x/auth/simulation/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,25 @@ func SimulateDeductFee(m auth.AccountKeeper, f auth.FeeCollectionKeeper) simulat
return action, nil, nil
}

coins := sdk.Coins{sdk.NewCoin(initCoins[denomIndex].Denom, amt)}
err = stored.SetCoins(initCoins.Minus(coins))
if err != nil {
panic(err)
fees := sdk.Coins{sdk.NewCoin(initCoins[denomIndex].Denom, amt)}
newCoins, hasNeg := initCoins.SafeMinus(fees)
if hasNeg {
event(fmt.Sprintf("auth/SimulateDeductFee/false"))
return action, nil, nil
}
m.SetAccount(ctx, stored)
if !coins.IsNotNegative() {
panic("setting negative fees")

if _, hasNeg := initCoins.SafeMinus(fees); hasNeg {
event(fmt.Sprintf("auth/SimulateDeductFee/false"))
return action, nil, nil
}

f.AddCollectedFees(ctx, coins)
err = stored.SetCoins(newCoins)
if err != nil {
panic(err)
}

m.SetAccount(ctx, stored)
f.AddCollectedFees(ctx, fees)
event(fmt.Sprintf("auth/SimulateDeductFee/true"))

action = "TestDeductFee"
Expand Down

0 comments on commit af18304

Please sign in to comment.