From 28296a360e460274662589d20f039ac7fbdc42c6 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Wed, 23 Jan 2019 12:40:05 -0500 Subject: [PATCH 1/2] reconcile SimulateDeductFee with auth/ante fee deduction --- x/auth/simulation/fake.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/x/auth/simulation/fake.go b/x/auth/simulation/fake.go index 809f758b5a63..e61f276ce83d 100644 --- a/x/auth/simulation/fake.go +++ b/x/auth/simulation/fake.go @@ -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, ok := initCoins.SafeMinus(fees) + if ok { + 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" From f0ab20db5692fbc7271f4d2e649947c326bdaa62 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Thu, 24 Jan 2019 12:37:01 -0500 Subject: [PATCH 2/2] Update fake.go --- x/auth/simulation/fake.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/auth/simulation/fake.go b/x/auth/simulation/fake.go index e61f276ce83d..98b42fc3e988 100644 --- a/x/auth/simulation/fake.go +++ b/x/auth/simulation/fake.go @@ -35,8 +35,8 @@ func SimulateDeductFee(m auth.AccountKeeper, f auth.FeeCollectionKeeper) simulat } fees := sdk.Coins{sdk.NewCoin(initCoins[denomIndex].Denom, amt)} - newCoins, ok := initCoins.SafeMinus(fees) - if ok { + newCoins, hasNeg := initCoins.SafeMinus(fees) + if hasNeg { event(fmt.Sprintf("auth/SimulateDeductFee/false")) return action, nil, nil }