From a814e5ce66e4068306733b8b97411001feb8ce72 Mon Sep 17 00:00:00 2001 From: frog power 4000 Date: Thu, 21 Feb 2019 12:35:55 -0500 Subject: [PATCH] Merge PR #3679: Consistent Operators * Minus->Sub Plus->Add Div->Quo * pending * Update PENDING.md Co-Authored-By: rigelrozanski * fix * typo --- PENDING.md | 2 ++ client/lcd/lcd_test.go | 30 +++++++++---------- docs/_attic/sdk/core/examples/app1.go | 4 +-- types/coin.go | 38 ++++++++++++------------ types/coin_benchmark_test.go | 4 +-- types/coin_test.go | 24 +++++++-------- types/dec_coin.go | 34 ++++++++++----------- types/dec_coin_test.go | 10 +++---- types/decimal_test.go | 6 ++-- types/int.go | 12 ++++---- types/int_test.go | 14 ++++----- types/staking.go | 2 +- types/uint.go | 8 ++--- types/uint_test.go | 20 ++++++------- x/auth/account.go | 18 +++++------ x/auth/account_test.go | 8 ++--- x/auth/ante.go | 4 +-- x/auth/feekeeper.go | 2 +- x/auth/simulation/fake.go | 4 +-- x/bank/keeper.go | 12 ++++---- x/bank/keeper_test.go | 4 +-- x/bank/msgs.go | 4 +-- x/bank/simulation/invariants.go | 2 +- x/bank/simulation/msgs.go | 8 ++--- x/distribution/keeper/allocation.go | 16 +++++----- x/distribution/keeper/delegation.go | 10 +++---- x/distribution/keeper/delegation_test.go | 10 +++---- x/distribution/keeper/hooks.go | 4 +-- x/distribution/keeper/keeper.go | 2 +- x/distribution/keeper/querier.go | 2 +- x/distribution/keeper/validator.go | 6 ++-- x/gov/keeper.go | 4 +-- x/gov/keeper_test.go | 14 ++++----- x/mock/app.go | 2 +- x/slashing/app_test.go | 2 +- x/staking/app_test.go | 8 ++--- x/staking/handler_test.go | 20 ++++++------- 37 files changed, 188 insertions(+), 186 deletions(-) diff --git a/PENDING.md b/PENDING.md index d95004516..86b89e082 100644 --- a/PENDING.md +++ b/PENDING.md @@ -45,6 +45,8 @@ ### SDK +* \#3679 Consistent operators across Coins, DecCoins, Int, Dec + replaced: Minus->Sub Plus->Add Div->Quo * [\#3665] Overhaul sdk.Uint type in preparation for Coins Int -> Uint migration. * \#3691 Cleanup error messages * \#3456 Integrate in the Int.ToDec() convenience function diff --git a/client/lcd/lcd_test.go b/client/lcd/lcd_test.go index 90083c98a..41f569949 100644 --- a/client/lcd/lcd_test.go +++ b/client/lcd/lcd_test.go @@ -127,7 +127,7 @@ func TestCoinSend(t *testing.T) { // query sender acc = getAccount(t, port, addr) coins := acc.GetCoins() - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, sdk.DefaultBondDenom, coins[0].Denom) require.Equal(t, expectedBalance.Amount.SubRaw(1), coins[0].Amount) @@ -186,7 +186,7 @@ func TestCoinSend(t *testing.T) { require.Equal(t, uint32(0), resultTx.Code) acc = getAccount(t, port, addr) - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.Equal(t, expectedBalance.Amount.SubRaw(1), acc.GetCoins().AmountOf(sdk.DefaultBondDenom)) } @@ -209,7 +209,7 @@ func TestCoinSendAccAuto(t *testing.T) { // query sender acc = getAccount(t, port, addr) coins := acc.GetCoins() - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, sdk.DefaultBondDenom, coins[0].Denom) require.Equal(t, expectedBalance.Amount.SubRaw(1), coins[0].Amount) @@ -465,7 +465,7 @@ func TestBonding(t *testing.T) { // verify balance acc = getAccount(t, port, addr) coins := acc.GetCoins() - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(sdk.DefaultBondDenom)) expectedBalance = coins[0] @@ -499,7 +499,7 @@ func TestBonding(t *testing.T) { // sender should have not received any coins as the unbonding has only just begun acc = getAccount(t, port, addr) coins = acc.GetCoins() - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.True(t, expectedBalance.Amount.LT(coins.AmountOf(sdk.DefaultBondDenom)) || expectedBalance.Amount.Equal(coins.AmountOf(sdk.DefaultBondDenom)), @@ -517,7 +517,7 @@ func TestBonding(t *testing.T) { ubd := getUnbondingDelegation(t, port, addr, operAddrs[0]) require.Len(t, ubd.Entries, 1) - require.Equal(t, delTokens.DivRaw(2), ubd.Entries[0].Balance) + require.Equal(t, delTokens.QuoRaw(2), ubd.Entries[0].Balance) // test redelegation rdTokens := sdk.TokensFromTendermintPower(30) @@ -528,7 +528,7 @@ func TestBonding(t *testing.T) { // verify balance after paying fees acc = getAccount(t, port, addr) - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.True(t, expectedBalance.Amount.LT(coins.AmountOf(sdk.DefaultBondDenom)) || expectedBalance.Amount.Equal(coins.AmountOf(sdk.DefaultBondDenom)), @@ -612,7 +612,7 @@ func TestSubmitProposal(t *testing.T) { // verify balance acc = getAccount(t, port, addr) - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom)) // query proposal @@ -648,7 +648,7 @@ func TestDeposit(t *testing.T) { // verify balance acc = getAccount(t, port, addr) coins := acc.GetCoins() - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(sdk.DefaultBondDenom)) expectedBalance = coins[0] @@ -663,7 +663,7 @@ func TestDeposit(t *testing.T) { // verify balance after deposit and fee acc = getAccount(t, port, addr) - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(depositTokens), acc.GetCoins().AmountOf(sdk.DefaultBondDenom)) // query tx @@ -705,7 +705,7 @@ func TestVote(t *testing.T) { // verify balance acc = getAccount(t, port, addr) coins := acc.GetCoins() - expectedBalance := initialBalance[0].Minus(fees[0]) + expectedBalance := initialBalance[0].Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(proposalTokens), coins.AmountOf(sdk.DefaultBondDenom)) expectedBalance = coins[0] @@ -721,7 +721,7 @@ func TestVote(t *testing.T) { // verify balance after vote and fee acc = getAccount(t, port, addr) coins = acc.GetCoins() - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.Equal(t, expectedBalance.Amount, coins.AmountOf(sdk.DefaultBondDenom)) expectedBalance = coins[0] @@ -745,7 +745,7 @@ func TestVote(t *testing.T) { // verify balance acc = getAccount(t, port, addr) coins = acc.GetCoins() - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.Equal(t, expectedBalance.Amount.Sub(delTokens), coins.AmountOf(sdk.DefaultBondDenom)) expectedBalance = coins[0] @@ -758,7 +758,7 @@ func TestVote(t *testing.T) { // verify balance acc = getAccount(t, port, addr) - expectedBalance = expectedBalance.Minus(fees[0]) + expectedBalance = expectedBalance.Sub(fees[0]) require.Equal(t, expectedBalance.Amount, acc.GetCoins().AmountOf(sdk.DefaultBondDenom)) tally = getTally(t, port, proposalID) @@ -792,7 +792,7 @@ func TestProposalsQuery(t *testing.T) { defer cleanup() depositParam := getDepositParam(t, port) - halfMinDeposit := depositParam.MinDeposit.AmountOf(sdk.DefaultBondDenom).DivRaw(2) + halfMinDeposit := depositParam.MinDeposit.AmountOf(sdk.DefaultBondDenom).QuoRaw(2) getVotingParam(t, port) getTallyingParam(t, port) diff --git a/docs/_attic/sdk/core/examples/app1.go b/docs/_attic/sdk/core/examples/app1.go index 8cf30f4bb..c103b5a29 100644 --- a/docs/_attic/sdk/core/examples/app1.go +++ b/docs/_attic/sdk/core/examples/app1.go @@ -151,7 +151,7 @@ func handleFrom(store sdk.KVStore, from sdk.AccAddress, amt sdk.Coins) sdk.Resul } // Deduct msg amount from sender account. - senderCoins := acc.Coins.Minus(amt) + senderCoins := acc.Coins.Sub(amt) // If any coin has negative amount, return insufficient coins error. if senderCoins.IsAnyNegative() { @@ -188,7 +188,7 @@ func handleTo(store sdk.KVStore, to sdk.AccAddress, amt sdk.Coins) sdk.Result { } // Add amount to receiver's old coins - receiverCoins := acc.Coins.Plus(amt) + receiverCoins := acc.Coins.Add(amt) // Update receiver account acc.Coins = receiverCoins diff --git a/types/coin.go b/types/coin.go index f969d2c43..1122c859b 100644 --- a/types/coin.go +++ b/types/coin.go @@ -86,7 +86,7 @@ func (coin Coin) IsEqual(other Coin) bool { // Adds amounts of two coins with same denom. If the coins differ in denom then // it panics. -func (coin Coin) Plus(coinB Coin) Coin { +func (coin Coin) Add(coinB Coin) Coin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, coinB.Denom)) } @@ -96,7 +96,7 @@ func (coin Coin) Plus(coinB Coin) Coin { // Subtracts amounts of two coins with same denom. If the coins differ in denom // then it panics. -func (coin Coin) Minus(coinB Coin) Coin { +func (coin Coin) Sub(coinB Coin) Coin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("invalid coin denominations; %s, %s", coin.Denom, coinB.Denom)) } @@ -178,27 +178,27 @@ func (coins Coins) IsValid() bool { } } -// Plus adds two sets of coins. +// Add adds two sets of coins. // // e.g. // {2A} + {A, 2B} = {3A, 2B} // {2A} + {0B} = {2A} // -// NOTE: Plus operates under the invariant that coins are sorted by +// NOTE: Add operates under the invariant that coins are sorted by // denominations. // -// CONTRACT: Plus will never return Coins where one Coin has a non-positive +// CONTRACT: Add will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins Coins) Plus(coinsB Coins) Coins { - return coins.safePlus(coinsB) +func (coins Coins) Add(coinsB Coins) Coins { + return coins.safeAdd(coinsB) } -// safePlus will perform addition of two coins sets. If both coin sets are +// safeAdd will perform addition of two coins sets. If both coin sets are // empty, then an empty set is returned. If only a single set is empty, the // other set is returned. Otherwise, the coins are compared in order of their // denomination and addition only occurs when the denominations match, otherwise // the coin is simply added to the sum assuming it's not zero. -func (coins Coins) safePlus(coinsB Coins) Coins { +func (coins Coins) safeAdd(coinsB Coins) Coins { sum := ([]Coin)(nil) indexA, indexB := 0, 0 lenA, lenB := len(coins), len(coinsB) @@ -228,7 +228,7 @@ func (coins Coins) safePlus(coinsB Coins) Coins { indexA++ case 0: // coin A denom == coin B denom - res := coinA.Plus(coinB) + res := coinA.Add(coinB) if !res.IsZero() { sum = append(sum, res) } @@ -246,17 +246,17 @@ func (coins Coins) safePlus(coinsB Coins) Coins { } } -// Minus subtracts a set of coins from another. +// Sub subtracts a set of coins from another. // // e.g. // {2A, 3B} - {A} = {A, 3B} // {2A} - {0B} = {2A} // {A, B} - {A} = {B} // -// CONTRACT: Minus will never return Coins where one Coin has a non-positive +// CONTRACT: Sub will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins Coins) Minus(coinsB Coins) Coins { - diff, hasNeg := coins.SafeMinus(coinsB) +func (coins Coins) Sub(coinsB Coins) Coins { + diff, hasNeg := coins.SafeSub(coinsB) if hasNeg { panic("negative coin amount") } @@ -264,17 +264,17 @@ func (coins Coins) Minus(coinsB Coins) Coins { return diff } -// SafeMinus performs the same arithmetic as Minus but returns a boolean if any +// SafeSub performs the same arithmetic as Sub but returns a boolean if any // negative coin amount was returned. -func (coins Coins) SafeMinus(coinsB Coins) (Coins, bool) { - diff := coins.safePlus(coinsB.negative()) +func (coins Coins) SafeSub(coinsB Coins) (Coins, bool) { + diff := coins.safeAdd(coinsB.negative()) return diff, diff.IsAnyNegative() } // IsAllGT returns true if for every denom in coins, the denom is present at a // greater amount in coinsB. func (coins Coins) IsAllGT(coinsB Coins) bool { - diff, _ := coins.SafeMinus(coinsB) + diff, _ := coins.SafeSub(coinsB) if len(diff) == 0 { return false } @@ -285,7 +285,7 @@ func (coins Coins) IsAllGT(coinsB Coins) bool { // IsAllGTE returns true iff for every denom in coins, the denom is present at // an equal or greater amount in coinsB. func (coins Coins) IsAllGTE(coinsB Coins) bool { - diff, _ := coins.SafeMinus(coinsB) + diff, _ := coins.SafeSub(coinsB) if len(diff) == 0 { return true } diff --git a/types/coin_benchmark_test.go b/types/coin_benchmark_test.go index 9c13bf772..93a3fc891 100644 --- a/types/coin_benchmark_test.go +++ b/types/coin_benchmark_test.go @@ -21,7 +21,7 @@ func BenchmarkCoinsAdditionIntersect(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - coinsA.Plus(coinsB) + coinsA.Add(coinsB) } } } @@ -50,7 +50,7 @@ func BenchmarkCoinsAdditionNoIntersect(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - coinsA.Plus(coinsB) + coinsA.Add(coinsB) } } } diff --git a/types/coin_test.go b/types/coin_test.go index 3bbc497f6..50dd8bb52 100644 --- a/types/coin_test.go +++ b/types/coin_test.go @@ -47,7 +47,7 @@ func TestIsEqualCoin(t *testing.T) { } } -func TestPlusCoin(t *testing.T) { +func TestAddCoin(t *testing.T) { cases := []struct { inputOne Coin inputTwo Coin @@ -61,15 +61,15 @@ func TestPlusCoin(t *testing.T) { for tcIndex, tc := range cases { if tc.shouldPanic { - require.Panics(t, func() { tc.inputOne.Plus(tc.inputTwo) }) + require.Panics(t, func() { tc.inputOne.Add(tc.inputTwo) }) } else { - res := tc.inputOne.Plus(tc.inputTwo) + res := tc.inputOne.Add(tc.inputTwo) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", tcIndex) } } } -func TestMinusCoin(t *testing.T) { +func TestSubCoin(t *testing.T) { cases := []struct { inputOne Coin inputTwo Coin @@ -85,9 +85,9 @@ func TestMinusCoin(t *testing.T) { for tcIndex, tc := range cases { if tc.shouldPanic { - require.Panics(t, func() { tc.inputOne.Minus(tc.inputTwo) }) + require.Panics(t, func() { tc.inputOne.Sub(tc.inputTwo) }) } else { - res := tc.inputOne.Minus(tc.inputTwo) + res := tc.inputOne.Sub(tc.inputTwo) require.Equal(t, tc.expected, res, "difference of coins is incorrect, tc #%d", tcIndex) } } @@ -97,7 +97,7 @@ func TestMinusCoin(t *testing.T) { inputTwo Coin expected int64 }{NewInt64Coin(testDenom1, 1), NewInt64Coin(testDenom1, 1), 0} - res := tc.inputOne.Minus(tc.inputTwo) + res := tc.inputOne.Sub(tc.inputTwo) require.Equal(t, tc.expected, res.Amount.Int64()) } @@ -205,7 +205,7 @@ func TestEqualCoins(t *testing.T) { } } -func TestPlusCoins(t *testing.T) { +func TestAddCoins(t *testing.T) { zero := NewInt(0) one := NewInt(1) two := NewInt(2) @@ -223,13 +223,13 @@ func TestPlusCoins(t *testing.T) { } for tcIndex, tc := range cases { - res := tc.inputOne.Plus(tc.inputTwo) + res := tc.inputOne.Add(tc.inputTwo) assert.True(t, res.IsValid()) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", tcIndex) } } -func TestMinusCoins(t *testing.T) { +func TestSubCoins(t *testing.T) { zero := NewInt(0) one := NewInt(1) two := NewInt(2) @@ -249,9 +249,9 @@ func TestMinusCoins(t *testing.T) { for i, tc := range testCases { if tc.shouldPanic { - require.Panics(t, func() { tc.inputOne.Minus(tc.inputTwo) }) + require.Panics(t, func() { tc.inputOne.Sub(tc.inputTwo) }) } else { - res := tc.inputOne.Minus(tc.inputTwo) + res := tc.inputOne.Sub(tc.inputTwo) assert.True(t, res.IsValid()) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", i) } diff --git a/types/dec_coin.go b/types/dec_coin.go index 8a687e8d3..538ea1c8c 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -99,7 +99,7 @@ func (coin DecCoin) IsEqual(other DecCoin) bool { } // Adds amounts of two coins with same denom -func (coin DecCoin) Plus(coinB DecCoin) DecCoin { +func (coin DecCoin) Add(coinB DecCoin) DecCoin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom)) } @@ -107,7 +107,7 @@ func (coin DecCoin) Plus(coinB DecCoin) DecCoin { } // Subtracts amounts of two coins with same denom -func (coin DecCoin) Minus(coinB DecCoin) DecCoin { +func (coin DecCoin) Sub(coinB DecCoin) DecCoin { if coin.Denom != coinB.Denom { panic(fmt.Sprintf("coin denom different: %v %v\n", coin.Denom, coinB.Denom)) } @@ -179,29 +179,29 @@ func (coins DecCoins) TruncateDecimal() (Coins, DecCoins) { for i, coin := range coins { truncated, change := coin.TruncateDecimal() out[i] = truncated - changeSum = changeSum.Plus(DecCoins{change}) + changeSum = changeSum.Add(DecCoins{change}) } return out, changeSum } -// Plus adds two sets of DecCoins. +// Add adds two sets of DecCoins. // -// NOTE: Plus operates under the invariant that coins are sorted by +// NOTE: Add operates under the invariant that coins are sorted by // denominations. // -// CONTRACT: Plus will never return Coins where one Coin has a non-positive +// CONTRACT: Add will never return Coins where one Coin has a non-positive // amount. In otherwords, IsValid will always return true. -func (coins DecCoins) Plus(coinsB DecCoins) DecCoins { - return coins.safePlus(coinsB) +func (coins DecCoins) Add(coinsB DecCoins) DecCoins { + return coins.safeAdd(coinsB) } -// safePlus will perform addition of two DecCoins sets. If both coin sets are +// safeAdd will perform addition of two DecCoins sets. If both coin sets are // empty, then an empty set is returned. If only a single set is empty, the // other set is returned. Otherwise, the coins are compared in order of their // denomination and addition only occurs when the denominations match, otherwise // the coin is simply added to the sum assuming it's not zero. -func (coins DecCoins) safePlus(coinsB DecCoins) DecCoins { +func (coins DecCoins) safeAdd(coinsB DecCoins) DecCoins { sum := ([]DecCoin)(nil) indexA, indexB := 0, 0 lenA, lenB := len(coins), len(coinsB) @@ -231,7 +231,7 @@ func (coins DecCoins) safePlus(coinsB DecCoins) DecCoins { indexA++ case 0: // coin A denom == coin B denom - res := coinA.Plus(coinB) + res := coinA.Add(coinB) if !res.IsZero() { sum = append(sum, res) } @@ -261,9 +261,9 @@ func (coins DecCoins) negative() DecCoins { return res } -// Minus subtracts a set of DecCoins from another (adds the inverse). -func (coins DecCoins) Minus(coinsB DecCoins) DecCoins { - diff, hasNeg := coins.SafeMinus(coinsB) +// Sub subtracts a set of DecCoins from another (adds the inverse). +func (coins DecCoins) Sub(coinsB DecCoins) DecCoins { + diff, hasNeg := coins.SafeSub(coinsB) if hasNeg { panic("negative coin amount") } @@ -271,10 +271,10 @@ func (coins DecCoins) Minus(coinsB DecCoins) DecCoins { return diff } -// SafeMinus performs the same arithmetic as Minus but returns a boolean if any +// SafeSub performs the same arithmetic as Sub but returns a boolean if any // negative coin amount was returned. -func (coins DecCoins) SafeMinus(coinsB DecCoins) (DecCoins, bool) { - diff := coins.safePlus(coinsB.negative()) +func (coins DecCoins) SafeSub(coinsB DecCoins) (DecCoins, bool) { + diff := coins.safeAdd(coinsB.negative()) return diff, diff.IsAnyNegative() } diff --git a/types/dec_coin_test.go b/types/dec_coin_test.go index ba7f49add..a5a0b7876 100644 --- a/types/dec_coin_test.go +++ b/types/dec_coin_test.go @@ -60,22 +60,22 @@ func TestDecCoinIsPositive(t *testing.T) { require.False(t, dc.IsPositive()) } -func TestPlusDecCoin(t *testing.T) { +func TestAddDecCoin(t *testing.T) { decCoinA1 := NewDecCoinFromDec(testDenom1, NewDecWithPrec(11, 1)) decCoinA2 := NewDecCoinFromDec(testDenom1, NewDecWithPrec(22, 1)) decCoinB1 := NewDecCoinFromDec(testDenom2, NewDecWithPrec(11, 1)) // regular add - res := decCoinA1.Plus(decCoinA1) + res := decCoinA1.Add(decCoinA1) require.Equal(t, decCoinA2, res, "sum of coins is incorrect") // bad denom add require.Panics(t, func() { - decCoinA1.Plus(decCoinB1) + decCoinA1.Add(decCoinB1) }, "expected panic on sum of different denoms") } -func TestPlusDecCoins(t *testing.T) { +func TestAddDecCoins(t *testing.T) { one := NewDec(1) zero := NewDec(0) two := NewDec(2) @@ -91,7 +91,7 @@ func TestPlusDecCoins(t *testing.T) { } for tcIndex, tc := range cases { - res := tc.inputOne.Plus(tc.inputTwo) + res := tc.inputOne.Add(tc.inputTwo) require.Equal(t, tc.expected, res, "sum of coins is incorrect, tc #%d", tcIndex) } } diff --git a/types/decimal_test.go b/types/decimal_test.go index 2193d841f..e0009236f 100644 --- a/types/decimal_test.go +++ b/types/decimal_test.go @@ -157,7 +157,7 @@ func TestDecsEqual(t *testing.T) { func TestArithmetic(t *testing.T) { tests := []struct { d1, d2 Dec - expMul, expDiv, expAdd, expSub Dec + expMul, expQuo, expAdd, expSub Dec }{ // d1 d2 MUL DIV ADD SUB {NewDec(0), NewDec(0), NewDec(0), NewDec(0), NewDec(0), NewDec(0)}, @@ -192,8 +192,8 @@ func TestArithmetic(t *testing.T) { if tc.d2.IsZero() { // panic for divide by zero require.Panics(t, func() { tc.d1.Quo(tc.d2) }) } else { - resDiv := tc.d1.Quo(tc.d2) - require.True(t, tc.expDiv.Equal(resDiv), "exp %v, res %v, tc %d", tc.expDiv.String(), resDiv.String(), tcIndex) + resQuo := tc.d1.Quo(tc.d2) + require.True(t, tc.expQuo.Equal(resQuo), "exp %v, res %v, tc %d", tc.expQuo.String(), resQuo.String(), tcIndex) } } } diff --git a/types/int.go b/types/int.go index 00dbef2d1..35b754daf 100644 --- a/types/int.go +++ b/types/int.go @@ -31,7 +31,7 @@ func sub(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Sub(i, i2) } func mul(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mul(i, i2) } -func div(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Div(i, i2) } +func div(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Quo(i, i2) } func mod(i *big.Int, i2 *big.Int) *big.Int { return new(big.Int).Mod(i, i2) } @@ -276,8 +276,8 @@ func (i Int) MulRaw(i2 int64) Int { return i.Mul(NewInt(i2)) } -// Div divides Int with Int -func (i Int) Div(i2 Int) (res Int) { +// Quo divides Int with Int +func (i Int) Quo(i2 Int) (res Int) { // Check division-by-zero if i2.i.Sign() == 0 { panic("Division by zero") @@ -285,9 +285,9 @@ func (i Int) Div(i2 Int) (res Int) { return Int{div(i.i, i2.i)} } -// DivRaw divides Int with int64 -func (i Int) DivRaw(i2 int64) Int { - return i.Div(NewInt(i2)) +// QuoRaw divides Int with int64 +func (i Int) QuoRaw(i2 int64) Int { + return i.Quo(NewInt(i2)) } // Mod returns remainder after dividing with Int diff --git a/types/int_test.go b/types/int_test.go index 2fef894a4..5251d4665 100644 --- a/types/int_test.go +++ b/types/int_test.go @@ -69,7 +69,7 @@ func TestIntPanic(t *testing.T) { require.Panics(t, func() { intmin.Sub(OneInt()) }) // Division-by-zero check - require.Panics(t, func() { i1.Div(NewInt(0)) }) + require.Panics(t, func() { i1.Quo(NewInt(0)) }) } // Tests below uses randomness @@ -126,11 +126,11 @@ func TestArithInt(t *testing.T) { {i1.Add(i2), n1 + n2}, {i1.Sub(i2), n1 - n2}, {i1.Mul(i2), n1 * n2}, - {i1.Div(i2), n1 / n2}, + {i1.Quo(i2), n1 / n2}, {i1.AddRaw(n2), n1 + n2}, {i1.SubRaw(n2), n1 - n2}, {i1.MulRaw(n2), n1 * n2}, - {i1.DivRaw(n2), n1 / n2}, + {i1.QuoRaw(n2), n1 / n2}, {MinInt(i1, i2), minint(n1, n2)}, {MaxInt(i1, i2), maxint(n1, n2)}, {i1.Neg(), -n1}, @@ -188,11 +188,11 @@ func TestImmutabilityAllInt(t *testing.T) { func(i *Int) { _ = i.Add(randint()) }, func(i *Int) { _ = i.Sub(randint()) }, func(i *Int) { _ = i.Mul(randint()) }, - func(i *Int) { _ = i.Div(randint()) }, + func(i *Int) { _ = i.Quo(randint()) }, func(i *Int) { _ = i.AddRaw(rand.Int63()) }, func(i *Int) { _ = i.SubRaw(rand.Int63()) }, func(i *Int) { _ = i.MulRaw(rand.Int63()) }, - func(i *Int) { _ = i.DivRaw(rand.Int63()) }, + func(i *Int) { _ = i.QuoRaw(rand.Int63()) }, func(i *Int) { _ = i.Neg() }, func(i *Int) { _ = i.IsZero() }, func(i *Int) { _ = i.Sign() }, @@ -240,11 +240,11 @@ func TestImmutabilityArithInt(t *testing.T) { intarith(Int.Add, (*big.Int).Add), intarith(Int.Sub, (*big.Int).Sub), intarith(Int.Mul, (*big.Int).Mul), - intarith(Int.Div, (*big.Int).Div), + intarith(Int.Quo, (*big.Int).Quo), intarithraw(Int.AddRaw, (*big.Int).Add), intarithraw(Int.SubRaw, (*big.Int).Sub), intarithraw(Int.MulRaw, (*big.Int).Mul), - intarithraw(Int.DivRaw, (*big.Int).Div), + intarithraw(Int.QuoRaw, (*big.Int).Quo), } for i := 0; i < 100; i++ { diff --git a/types/staking.go b/types/staking.go index d9143fa4e..51961f39c 100644 --- a/types/staking.go +++ b/types/staking.go @@ -46,7 +46,7 @@ var PowerReduction = NewIntFromBigInt(new(big.Int).Exp(big.NewInt(10), big.NewIn // TokensToTendermintPower - convert input tokens to potential tendermint power func TokensToTendermintPower(tokens Int) int64 { - return (tokens.Div(PowerReduction)).Int64() + return (tokens.Quo(PowerReduction)).Int64() } // TokensFromTendermintPower - convert input power to tokens diff --git a/types/uint.go b/types/uint.go index cdbba5217..d6e129e69 100644 --- a/types/uint.go +++ b/types/uint.go @@ -91,11 +91,11 @@ func (u Uint) Mul(u2 Uint) (res Uint) { // Mul multiplies two Uints func (u Uint) MulUint64(u2 uint64) (res Uint) { return u.Mul(NewUint(u2)) } -// Div divides Uint with Uint -func (u Uint) Div(u2 Uint) (res Uint) { return NewUintFromBigInt(div(u.i, u2.i)) } +// Quo divides Uint with Uint +func (u Uint) Quo(u2 Uint) (res Uint) { return NewUintFromBigInt(div(u.i, u2.i)) } -// Div divides Uint with uint64 -func (u Uint) DivUint64(u2 uint64) Uint { return u.Div(NewUint(u2)) } +// Quo divides Uint with uint64 +func (u Uint) QuoUint64(u2 uint64) Uint { return u.Quo(NewUint(u2)) } // Return the minimum of the Uints func MinUint(u1, u2 Uint) Uint { return NewUintFromBigInt(min(u1.i, u2.i)) } diff --git a/types/uint_test.go b/types/uint_test.go index 8c1c7a8e8..a3115512b 100644 --- a/types/uint_test.go +++ b/types/uint_test.go @@ -35,8 +35,8 @@ func TestUintPanics(t *testing.T) { require.True(t, u1.SubUint64(0).Equal(ZeroUint())) require.True(t, u2.Add(OneUint()).Sub(OneUint()).Equal(OneUint())) // i2 == 1 require.True(t, u2.Add(OneUint()).Mul(NewUint(5)).Equal(NewUint(10))) // i2 == 10 - require.True(t, NewUint(7).Div(NewUint(2)).Equal(NewUint(3))) - require.True(t, NewUint(0).Div(NewUint(2)).Equal(ZeroUint())) + require.True(t, NewUint(7).Quo(NewUint(2)).Equal(NewUint(3))) + require.True(t, NewUint(0).Quo(NewUint(2)).Equal(ZeroUint())) require.True(t, NewUint(5).MulUint64(4).Equal(NewUint(20))) require.True(t, NewUint(5).MulUint64(0).Equal(ZeroUint())) @@ -45,10 +45,10 @@ func TestUintPanics(t *testing.T) { // divs by zero require.Panics(t, func() { OneUint().Mul(ZeroUint().SubUint64(uint64(1))) }) - require.Panics(t, func() { OneUint().DivUint64(0) }) - require.Panics(t, func() { OneUint().Div(ZeroUint()) }) - require.Panics(t, func() { ZeroUint().DivUint64(0) }) - require.Panics(t, func() { OneUint().Div(ZeroUint().Sub(OneUint())) }) + require.Panics(t, func() { OneUint().QuoUint64(0) }) + require.Panics(t, func() { OneUint().Quo(ZeroUint()) }) + require.Panics(t, func() { ZeroUint().QuoUint64(0) }) + require.Panics(t, func() { OneUint().Quo(ZeroUint().Sub(OneUint())) }) require.Panics(t, func() { uintmax.Add(OneUint()) }) require.Panics(t, func() { uintmin.Sub(OneUint()) }) @@ -108,10 +108,10 @@ func TestArithUint(t *testing.T) { }{ {u1.Add(u2), n1 + n2}, {u1.Mul(u2), n1 * n2}, - {u1.Div(u2), n1 / n2}, + {u1.Quo(u2), n1 / n2}, {u1.AddUint64(n2), n1 + n2}, {u1.MulUint64(n2), n1 * n2}, - {u1.DivUint64(n2), n1 / n2}, + {u1.QuoUint64(n2), n1 / n2}, {MinUint(u1, u2), minuint(n1, n2)}, {MaxUint(u1, u2), maxuint(n1, n2)}, } @@ -168,11 +168,11 @@ func TestImmutabilityAllUint(t *testing.T) { func(i *Uint) { _ = i.Add(NewUint(rand.Uint64())) }, func(i *Uint) { _ = i.Sub(NewUint(rand.Uint64() % i.Uint64())) }, func(i *Uint) { _ = i.Mul(randuint()) }, - func(i *Uint) { _ = i.Div(randuint()) }, + func(i *Uint) { _ = i.Quo(randuint()) }, func(i *Uint) { _ = i.AddUint64(rand.Uint64()) }, func(i *Uint) { _ = i.SubUint64(rand.Uint64() % i.Uint64()) }, func(i *Uint) { _ = i.MulUint64(rand.Uint64()) }, - func(i *Uint) { _ = i.DivUint64(rand.Uint64()) }, + func(i *Uint) { _ = i.QuoUint64(rand.Uint64()) }, func(i *Uint) { _ = i.IsZero() }, func(i *Uint) { _ = i.Equal(randuint()) }, func(i *Uint) { _ = i.GT(randuint()) }, diff --git a/x/auth/account.go b/x/auth/account.go index a17f1758b..0983565ec 100644 --- a/x/auth/account.go +++ b/x/auth/account.go @@ -233,7 +233,7 @@ func (bva BaseVestingAccount) spendableCoins(vestingCoins sdk.Coins) sdk.Coins { spendableCoin := sdk.NewCoin(coin.Denom, min) if !spendableCoin.IsZero() { - spendableCoins = spendableCoins.Plus(sdk.Coins{spendableCoin}) + spendableCoins = spendableCoins.Add(sdk.Coins{spendableCoin}) } } @@ -270,15 +270,15 @@ func (bva *BaseVestingAccount) trackDelegation(vestingCoins, amount sdk.Coins) { if !x.IsZero() { xCoin := sdk.NewCoin(coin.Denom, x) - bva.DelegatedVesting = bva.DelegatedVesting.Plus(sdk.Coins{xCoin}) + bva.DelegatedVesting = bva.DelegatedVesting.Add(sdk.Coins{xCoin}) } if !y.IsZero() { yCoin := sdk.NewCoin(coin.Denom, y) - bva.DelegatedFree = bva.DelegatedFree.Plus(sdk.Coins{yCoin}) + bva.DelegatedFree = bva.DelegatedFree.Add(sdk.Coins{yCoin}) } - bva.Coins = bva.Coins.Minus(sdk.Coins{coin}) + bva.Coins = bva.Coins.Sub(sdk.Coins{coin}) } } @@ -304,15 +304,15 @@ func (bva *BaseVestingAccount) TrackUndelegation(amount sdk.Coins) { if !x.IsZero() { xCoin := sdk.NewCoin(coin.Denom, x) - bva.DelegatedFree = bva.DelegatedFree.Minus(sdk.Coins{xCoin}) + bva.DelegatedFree = bva.DelegatedFree.Sub(sdk.Coins{xCoin}) } if !y.IsZero() { yCoin := sdk.NewCoin(coin.Denom, y) - bva.DelegatedVesting = bva.DelegatedVesting.Minus(sdk.Coins{yCoin}) + bva.DelegatedVesting = bva.DelegatedVesting.Sub(sdk.Coins{yCoin}) } - bva.Coins = bva.Coins.Plus(sdk.Coins{coin}) + bva.Coins = bva.Coins.Add(sdk.Coins{coin}) } } @@ -417,7 +417,7 @@ func (cva ContinuousVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coin // GetVestingCoins returns the total number of vesting coins. If no coins are // vesting, nil is returned. func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins { - return cva.OriginalVesting.Minus(cva.GetVestedCoins(blockTime)) + return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime)) } // SpendableCoins returns the total number of spendable coins per denom for a @@ -480,7 +480,7 @@ func (dva DelayedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins { // GetVestingCoins returns the total number of vesting coins for a delayed // vesting account. func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins { - return dva.OriginalVesting.Minus(dva.GetVestedCoins(blockTime)) + return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime)) } // SpendableCoins returns the total number of spendable coins for a delayed diff --git a/x/auth/account_test.go b/x/auth/account_test.go index 7d4fb5346..d8f7c6fa8 100644 --- a/x/auth/account_test.go +++ b/x/auth/account_test.go @@ -181,14 +181,14 @@ func TestSpendableCoinsContVestingAcc(t *testing.T) { // receive some coins recvAmt := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)} - cva.SetCoins(cva.GetCoins().Plus(recvAmt)) + cva.SetCoins(cva.GetCoins().Add(recvAmt)) // require that all vested coins (50%) are spendable plus any received spendableCoins = cva.SpendableCoins(now.Add(12 * time.Hour)) require.Equal(t, sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 100)}, spendableCoins) // spend all spendable coins - cva.SetCoins(cva.GetCoins().Minus(spendableCoins)) + cva.SetCoins(cva.GetCoins().Sub(spendableCoins)) // require that no more coins are spendable spendableCoins = cva.SpendableCoins(now.Add(12 * time.Hour)) @@ -362,7 +362,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { // receive some coins recvAmt := sdk.Coins{sdk.NewInt64Coin(stakeDenom, 50)} - dva.SetCoins(dva.GetCoins().Plus(recvAmt)) + dva.SetCoins(dva.GetCoins().Add(recvAmt)) // require that only received coins are spendable since the account is still // vesting @@ -370,7 +370,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) { require.Equal(t, recvAmt, spendableCoins) // spend all spendable coins - dva.SetCoins(dva.GetCoins().Minus(spendableCoins)) + dva.SetCoins(dva.GetCoins().Sub(spendableCoins)) // require that no more coins are spendable spendableCoins = dva.SpendableCoins(now.Add(12 * time.Hour)) diff --git a/x/auth/ante.go b/x/auth/ante.go index a4131f4c8..fc6e8f5ad 100644 --- a/x/auth/ante.go +++ b/x/auth/ante.go @@ -304,7 +304,7 @@ func DeductFees(blockTime time.Time, acc Account, fee StdFee) (Account, sdk.Resu } // get the resulting coins deducting the fees - newCoins, ok := coins.SafeMinus(feeAmount) + newCoins, ok := coins.SafeSub(feeAmount) if ok { return nil, sdk.ErrInsufficientFunds( fmt.Sprintf("insufficient funds to pay for fees; %s < %s", coins, feeAmount), @@ -314,7 +314,7 @@ func DeductFees(blockTime time.Time, acc Account, fee StdFee) (Account, sdk.Resu // Validate the account has enough "spendable" coins as this will cover cases // such as vesting accounts. spendableCoins := acc.SpendableCoins(blockTime) - if _, hasNeg := spendableCoins.SafeMinus(feeAmount); hasNeg { + if _, hasNeg := spendableCoins.SafeSub(feeAmount); hasNeg { return nil, sdk.ErrInsufficientFunds( fmt.Sprintf("insufficient funds to pay for fees; %s < %s", spendableCoins, feeAmount), ).Result() diff --git a/x/auth/feekeeper.go b/x/auth/feekeeper.go index 2b37a1402..aa8cf9212 100644 --- a/x/auth/feekeeper.go +++ b/x/auth/feekeeper.go @@ -49,7 +49,7 @@ func (fck FeeCollectionKeeper) setCollectedFees(ctx sdk.Context, coins sdk.Coins // AddCollectedFees - add to the fee pool func (fck FeeCollectionKeeper) AddCollectedFees(ctx sdk.Context, coins sdk.Coins) sdk.Coins { - newCoins := fck.GetCollectedFees(ctx).Plus(coins) + newCoins := fck.GetCollectedFees(ctx).Add(coins) fck.setCollectedFees(ctx, newCoins) return newCoins diff --git a/x/auth/simulation/fake.go b/x/auth/simulation/fake.go index c037d74c2..f28c27cd9 100644 --- a/x/auth/simulation/fake.go +++ b/x/auth/simulation/fake.go @@ -40,13 +40,13 @@ func SimulateDeductFee(m auth.AccountKeeper, f auth.FeeCollectionKeeper) simulat // balance. fees := sdk.Coins{sdk.NewCoin(randCoin.Denom, amt)} spendableCoins := stored.SpendableCoins(ctx.BlockHeader().Time) - if _, hasNeg := spendableCoins.SafeMinus(fees); hasNeg { + if _, hasNeg := spendableCoins.SafeSub(fees); hasNeg { event(fmt.Sprintf("auth/SimulateDeductFee/false")) return action, nil, nil } // get the new account balance - newCoins, hasNeg := initCoins.SafeMinus(fees) + newCoins, hasNeg := initCoins.SafeSub(fees) if hasNeg { event(fmt.Sprintf("auth/SimulateDeductFee/false")) return action, nil, nil diff --git a/x/bank/keeper.go b/x/bank/keeper.go index e7a93ce71..de605f25a 100644 --- a/x/bank/keeper.go +++ b/x/bank/keeper.go @@ -228,14 +228,14 @@ func subtractCoins(ctx sdk.Context, ak auth.AccountKeeper, addr sdk.AccAddress, // For non-vesting accounts, spendable coins will simply be the original coins. // So the check here is sufficient instead of subtracting from oldCoins. - _, hasNeg := spendableCoins.SafeMinus(amt) + _, hasNeg := spendableCoins.SafeSub(amt) if hasNeg { return amt, nil, sdk.ErrInsufficientCoins( fmt.Sprintf("insufficient account funds; %s < %s", spendableCoins, amt), ) } - newCoins := oldCoins.Minus(amt) // should not panic as spendable coins was already checked + newCoins := oldCoins.Sub(amt) // should not panic as spendable coins was already checked err := setCoins(ctx, ak, addr, newCoins) tags := sdk.NewTags(TagKeySender, addr.String()) @@ -245,7 +245,7 @@ func subtractCoins(ctx sdk.Context, ak auth.AccountKeeper, addr sdk.AccAddress, // AddCoins adds amt to the coins at the addr. func addCoins(ctx sdk.Context, am auth.AccountKeeper, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, sdk.Tags, sdk.Error) { oldCoins := getCoins(ctx, am, addr) - newCoins := oldCoins.Plus(amt) + newCoins := oldCoins.Add(amt) if newCoins.IsAnyNegative() { return amt, nil, sdk.ErrInsufficientCoins( @@ -321,7 +321,7 @@ func delegateCoins( oldCoins := acc.GetCoins() - _, hasNeg := oldCoins.SafeMinus(amt) + _, hasNeg := oldCoins.SafeSub(amt) if hasNeg { return nil, sdk.ErrInsufficientCoins( fmt.Sprintf("insufficient account funds; %s < %s", oldCoins, amt), @@ -368,7 +368,7 @@ func trackDelegation(acc auth.Account, blockTime time.Time, amount sdk.Coins) er return nil } - return acc.SetCoins(acc.GetCoins().Minus(amount)) + return acc.SetCoins(acc.GetCoins().Sub(amount)) } func trackUndelegation(acc auth.Account, amount sdk.Coins) error { @@ -378,5 +378,5 @@ func trackUndelegation(acc auth.Account, amount sdk.Coins) error { return nil } - return acc.SetCoins(acc.GetCoins().Plus(amount)) + return acc.SetCoins(acc.GetCoins().Add(amount)) } diff --git a/x/bank/keeper_test.go b/x/bank/keeper_test.go index 23e6321ab..cb277882e 100644 --- a/x/bank/keeper_test.go +++ b/x/bank/keeper_test.go @@ -230,7 +230,7 @@ func TestVestingAccountSend(t *testing.T) { require.Error(t, err) // receive some coins - vacc.SetCoins(origCoins.Plus(sendCoins)) + vacc.SetCoins(origCoins.Add(sendCoins)) input.ak.SetAccount(ctx, vacc) // require that all vested coins are spendable plus any received @@ -268,7 +268,7 @@ func TestVestingAccountReceive(t *testing.T) { // require the coins are spendable vacc = input.ak.GetAccount(ctx, addr1).(*auth.ContinuousVestingAccount) - require.Equal(t, origCoins.Plus(sendCoins), vacc.GetCoins()) + require.Equal(t, origCoins.Add(sendCoins), vacc.GetCoins()) require.Equal(t, vacc.SpendableCoins(now), sendCoins) // require coins are spendable plus any that have vested diff --git a/x/bank/msgs.go b/x/bank/msgs.go index 11479ff73..eb047d09f 100644 --- a/x/bank/msgs.go +++ b/x/bank/msgs.go @@ -163,14 +163,14 @@ func ValidateInputsOutputs(inputs []Input, outputs []Output) sdk.Error { if err := in.ValidateBasic(); err != nil { return err.TraceSDK("") } - totalIn = totalIn.Plus(in.Coins) + totalIn = totalIn.Add(in.Coins) } for _, out := range outputs { if err := out.ValidateBasic(); err != nil { return err.TraceSDK("") } - totalOut = totalOut.Plus(out.Coins) + totalOut = totalOut.Add(out.Coins) } // make sure inputs and outputs match diff --git a/x/bank/simulation/invariants.go b/x/bank/simulation/invariants.go index 70ca9b9db..7448b4687 100644 --- a/x/bank/simulation/invariants.go +++ b/x/bank/simulation/invariants.go @@ -32,7 +32,7 @@ func TotalCoinsInvariant(ak auth.AccountKeeper, totalSupplyFn func() sdk.Coins) chkAccount := func(acc auth.Account) bool { coins := acc.GetCoins() - totalCoins = totalCoins.Plus(coins) + totalCoins = totalCoins.Add(coins) return false } diff --git a/x/bank/simulation/msgs.go b/x/bank/simulation/msgs.go index a3b47823d..1e4c529a9 100644 --- a/x/bank/simulation/msgs.go +++ b/x/bank/simulation/msgs.go @@ -122,11 +122,11 @@ func sendAndVerifyMsgSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, msg b fromAcc = mapper.GetAccount(ctx, msg.FromAddress) toAcc = mapper.GetAccount(ctx, msg.ToAddress) - if !initialFromAddrCoins.Minus(msg.Amount).IsEqual(fromAcc.GetCoins()) { + if !initialFromAddrCoins.Sub(msg.Amount).IsEqual(fromAcc.GetCoins()) { return fmt.Errorf("fromAddress %s had an incorrect amount of coins", fromAcc.GetAddress()) } - if !initialToAddrCoins.Plus(msg.Amount).IsEqual(toAcc.GetCoins()) { + if !initialToAddrCoins.Add(msg.Amount).IsEqual(toAcc.GetCoins()) { return fmt.Errorf("toAddress %s had an incorrect amount of coins", toAcc.GetAddress()) } @@ -249,13 +249,13 @@ func sendAndVerifyMsgMultiSend(app *baseapp.BaseApp, mapper auth.AccountKeeper, for i := 0; i < len(msg.Inputs); i++ { terminalInputCoins := mapper.GetAccount(ctx, msg.Inputs[i].Address).GetCoins() - if !initialInputAddrCoins[i].Minus(msg.Inputs[i].Coins).IsEqual(terminalInputCoins) { + if !initialInputAddrCoins[i].Sub(msg.Inputs[i].Coins).IsEqual(terminalInputCoins) { return fmt.Errorf("input #%d had an incorrect amount of coins", i) } } for i := 0; i < len(msg.Outputs); i++ { terminalOutputCoins := mapper.GetAccount(ctx, msg.Outputs[i].Address).GetCoins() - if !terminalOutputCoins.IsEqual(initialOutputAddrCoins[i].Plus(msg.Outputs[i].Coins)) { + if !terminalOutputCoins.IsEqual(initialOutputAddrCoins[i].Add(msg.Outputs[i].Coins)) { return fmt.Errorf("output #%d had an incorrect amount of coins", i) } } diff --git a/x/distribution/keeper/allocation.go b/x/distribution/keeper/allocation.go index f43b018ff..646784204 100644 --- a/x/distribution/keeper/allocation.go +++ b/x/distribution/keeper/allocation.go @@ -20,7 +20,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, sumPrecommitPower, totalPower in // temporary workaround to keep CanWithdrawInvariant happy // general discussions here: https://github.com/cosmos/cosmos-sdk/issues/2906#issuecomment-441867634 if totalPower == 0 { - feePool.CommunityPool = feePool.CommunityPool.Plus(feesCollected) + feePool.CommunityPool = feePool.CommunityPool.Add(feesCollected) k.SetFeePool(ctx, feePool) return } @@ -37,7 +37,7 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, sumPrecommitPower, totalPower in // pay proposer proposerValidator := k.stakingKeeper.ValidatorByConsAddr(ctx, proposer) k.AllocateTokensToValidator(ctx, proposerValidator, proposerReward) - remaining := feesCollected.Minus(proposerReward) + remaining := feesCollected.Sub(proposerReward) // calculate fraction allocated to validators communityTax := k.GetCommunityTax(ctx) @@ -53,16 +53,16 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, sumPrecommitPower, totalPower in powerFraction := sdk.NewDec(vote.Validator.Power).Quo(sdk.NewDec(totalPower)) reward := feesCollected.MulDec(voteMultiplier).MulDec(powerFraction) k.AllocateTokensToValidator(ctx, validator, reward) - remaining = remaining.Minus(reward) + remaining = remaining.Sub(reward) } // allocate community funding - feePool.CommunityPool = feePool.CommunityPool.Plus(remaining) + feePool.CommunityPool = feePool.CommunityPool.Add(remaining) k.SetFeePool(ctx, feePool) // update outstanding rewards outstanding := k.GetOutstandingRewards(ctx) - outstanding = outstanding.Plus(feesCollected.Minus(remaining)) + outstanding = outstanding.Add(feesCollected.Sub(remaining)) k.SetOutstandingRewards(ctx, outstanding) } @@ -71,15 +71,15 @@ func (k Keeper) AllocateTokens(ctx sdk.Context, sumPrecommitPower, totalPower in func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val sdk.Validator, tokens sdk.DecCoins) { // split tokens between validator and delegators according to commission commission := tokens.MulDec(val.GetCommission()) - shared := tokens.Minus(commission) + shared := tokens.Sub(commission) // update current commission currentCommission := k.GetValidatorAccumulatedCommission(ctx, val.GetOperator()) - currentCommission = currentCommission.Plus(commission) + currentCommission = currentCommission.Add(commission) k.SetValidatorAccumulatedCommission(ctx, val.GetOperator(), currentCommission) // update current rewards currentRewards := k.GetValidatorCurrentRewards(ctx, val.GetOperator()) - currentRewards.Rewards = currentRewards.Rewards.Plus(shared) + currentRewards.Rewards = currentRewards.Rewards.Add(shared) k.SetValidatorCurrentRewards(ctx, val.GetOperator(), currentRewards) } diff --git a/x/distribution/keeper/delegation.go b/x/distribution/keeper/delegation.go index 6738deb92..af140474c 100644 --- a/x/distribution/keeper/delegation.go +++ b/x/distribution/keeper/delegation.go @@ -40,7 +40,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val sdk.Valid // return staking * (ending - starting) starting := k.GetValidatorHistoricalRewards(ctx, val.GetOperator(), startingPeriod) ending := k.GetValidatorHistoricalRewards(ctx, val.GetOperator(), endingPeriod) - difference := ending.CumulativeRewardRatio.Minus(starting.CumulativeRewardRatio) + difference := ending.CumulativeRewardRatio.Sub(starting.CumulativeRewardRatio) if difference.IsAnyNegative() { panic("negative rewards should not be possible") } @@ -66,7 +66,7 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val sdk.Validator, d k.IterateValidatorSlashEventsBetween(ctx, del.GetValidatorAddr(), startingHeight, endingHeight, func(height uint64, event types.ValidatorSlashEvent) (stop bool) { endingPeriod := event.ValidatorPeriod - rewards = rewards.Plus(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) + rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) // note: necessary to truncate so we don't allow withdrawing more rewards than owed stake = stake.MulTruncate(sdk.OneDec().Sub(event.Fraction)) startingPeriod = endingPeriod @@ -76,7 +76,7 @@ func (k Keeper) calculateDelegationRewards(ctx sdk.Context, val sdk.Validator, d } // calculate rewards for final period - rewards = rewards.Plus(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) + rewards = rewards.Add(k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)) return } @@ -101,9 +101,9 @@ func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val sdk.Validator, de coins, remainder := rewards.TruncateDecimal() outstanding := k.GetOutstandingRewards(ctx) - k.SetOutstandingRewards(ctx, outstanding.Minus(rewards)) + k.SetOutstandingRewards(ctx, outstanding.Sub(rewards)) feePool := k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Plus(remainder) + feePool.CommunityPool = feePool.CommunityPool.Add(remainder) k.SetFeePool(ctx, feePool) // add coins to user account diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index c4a422f75..d62e4b8e1 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -118,10 +118,10 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { rewards = k.calculateDelegationRewards(ctx, val, del, endingPeriod) // rewards should be half the tokens - require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, initial.DivRaw(2).ToDec()}}, rewards) + require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, initial.QuoRaw(2).ToDec()}}, rewards) // commission should be the other half - require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, initial.DivRaw(2).ToDec()}}, + require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, initial.QuoRaw(2).ToDec()}}, k.GetValidatorAccumulatedCommission(ctx, valOpAddr1)) } @@ -307,7 +307,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { require.Equal(t, uint64(2), k.GetValidatorHistoricalReferenceCount(ctx)) // assert correct balance - exp := balanceTokens.Sub(valTokens).Add(initial.DivRaw(2)) + exp := balanceTokens.Sub(valTokens).Add(initial.QuoRaw(2)) require.Equal(t, sdk.Coins{sdk.NewCoin(sdk.DefaultBondDenom, exp)}, ak.GetAccount(ctx, sdk.AccAddress(valOpAddr1)).GetCoins(), @@ -540,7 +540,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { // commission should be zero require.True(t, k.GetValidatorAccumulatedCommission(ctx, valOpAddr1).IsZero()) - totalRewards = k.GetOutstandingRewards(ctx).Plus(tokens) + totalRewards = k.GetOutstandingRewards(ctx).Add(tokens) k.SetOutstandingRewards(ctx, totalRewards) // allocate some more rewards @@ -567,7 +567,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { // commission should be half initial require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, sdk.NewDec(initial / 2)}}, k.GetValidatorAccumulatedCommission(ctx, valOpAddr1)) - totalRewards = k.GetOutstandingRewards(ctx).Plus(tokens) + totalRewards = k.GetOutstandingRewards(ctx).Add(tokens) k.SetOutstandingRewards(ctx, totalRewards) // allocate some more rewards diff --git a/x/distribution/keeper/hooks.go b/x/distribution/keeper/hooks.go index 49d09b317..0466e8f7e 100644 --- a/x/distribution/keeper/hooks.go +++ b/x/distribution/keeper/hooks.go @@ -29,12 +29,12 @@ func (h Hooks) AfterValidatorRemoved(ctx sdk.Context, _ sdk.ConsAddress, valAddr // remainder to community pool feePool := h.k.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Plus(remainder) + feePool.CommunityPool = feePool.CommunityPool.Add(remainder) h.k.SetFeePool(ctx, feePool) // update outstanding outstanding := h.k.GetOutstandingRewards(ctx) - h.k.SetOutstandingRewards(ctx, outstanding.Minus(commission)) + h.k.SetOutstandingRewards(ctx, outstanding.Sub(commission)) // add to validator account accAddr := sdk.AccAddress(valAddr) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 1d38ebcc7..4a57c9bba 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -85,7 +85,7 @@ func (k Keeper) WithdrawValidatorCommission(ctx sdk.Context, valAddr sdk.ValAddr // update outstanding outstanding := k.GetOutstandingRewards(ctx) - k.SetOutstandingRewards(ctx, outstanding.Minus(sdk.NewDecCoins(coins))) + k.SetOutstandingRewards(ctx, outstanding.Sub(sdk.NewDecCoins(coins))) accAddr := sdk.AccAddress(valAddr) withdrawAddr := k.GetDelegatorWithdrawAddr(ctx, accAddr) diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index d8948f2fb..2d7428369 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -229,7 +229,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue endingPeriod := k.incrementValidatorPeriod(ctx, val) rewards := k.calculateDelegationRewards(ctx, val, del, endingPeriod) - totalRewards = totalRewards.Plus(rewards) + totalRewards = totalRewards.Add(rewards) return false }, ) diff --git a/x/distribution/keeper/validator.go b/x/distribution/keeper/validator.go index fcb54651f..21ffa24a3 100644 --- a/x/distribution/keeper/validator.go +++ b/x/distribution/keeper/validator.go @@ -31,8 +31,8 @@ func (k Keeper) incrementValidatorPeriod(ctx sdk.Context, val sdk.Validator) uin // ergo we instead add to the community pool feePool := k.GetFeePool(ctx) outstanding := k.GetOutstandingRewards(ctx) - feePool.CommunityPool = feePool.CommunityPool.Plus(rewards.Rewards) - outstanding = outstanding.Minus(rewards.Rewards) + feePool.CommunityPool = feePool.CommunityPool.Add(rewards.Rewards) + outstanding = outstanding.Sub(rewards.Rewards) k.SetFeePool(ctx, feePool) k.SetOutstandingRewards(ctx, outstanding) @@ -49,7 +49,7 @@ func (k Keeper) incrementValidatorPeriod(ctx sdk.Context, val sdk.Validator) uin k.decrementReferenceCount(ctx, val.GetOperator(), rewards.Period-1) // set new historical rewards with reference count of 1 - k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), rewards.Period, types.NewValidatorHistoricalRewards(historical.Plus(current), 1)) + k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), rewards.Period, types.NewValidatorHistoricalRewards(historical.Add(current), 1)) // set current rewards, incrementing period by 1 k.SetValidatorCurrentRewards(ctx, val.GetOperator(), types.NewValidatorCurrentRewards(sdk.DecCoins{}, rewards.Period+1)) diff --git a/x/gov/keeper.go b/x/gov/keeper.go index 9616791dd..2ea507977 100644 --- a/x/gov/keeper.go +++ b/x/gov/keeper.go @@ -387,7 +387,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd } // Update proposal - proposal.SetTotalDeposit(proposal.GetTotalDeposit().Plus(depositAmount)) + proposal.SetTotalDeposit(proposal.GetTotalDeposit().Add(depositAmount)) keeper.SetProposal(ctx, proposal) // Check if deposit has provided sufficient total funds to transition the proposal into the voting period @@ -403,7 +403,7 @@ func (keeper Keeper) AddDeposit(ctx sdk.Context, proposalID uint64, depositorAdd newDeposit := Deposit{depositorAddr, proposalID, depositAmount} keeper.setDeposit(ctx, proposalID, depositorAddr, newDeposit) } else { - currDeposit.Amount = currDeposit.Amount.Plus(depositAmount) + currDeposit.Amount = currDeposit.Amount.Add(depositAmount) keeper.setDeposit(ctx, proposalID, depositorAddr, currDeposit) } diff --git a/x/gov/keeper_test.go b/x/gov/keeper_test.go index 452450553..44861877d 100644 --- a/x/gov/keeper_test.go +++ b/x/gov/keeper_test.go @@ -93,7 +93,7 @@ func TestDeposits(t *testing.T) { require.Equal(t, fourSteak, deposit.Amount) require.Equal(t, addrs[0], deposit.Depositor) require.Equal(t, fourSteak, keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - require.Equal(t, addr0Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[0])) + require.Equal(t, addr0Initial.Sub(fourSteak), keeper.ck.GetCoins(ctx, addrs[0])) // Check a second deposit from same address err, votingStarted = keeper.AddDeposit(ctx, proposalID, addrs[0], fiveSteak) @@ -101,10 +101,10 @@ func TestDeposits(t *testing.T) { require.False(t, votingStarted) deposit, found = keeper.GetDeposit(ctx, proposalID, addrs[0]) require.True(t, found) - require.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) + require.Equal(t, fourSteak.Add(fiveSteak), deposit.Amount) require.Equal(t, addrs[0], deposit.Depositor) - require.Equal(t, fourSteak.Plus(fiveSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - require.Equal(t, addr0Initial.Minus(fourSteak).Minus(fiveSteak), keeper.ck.GetCoins(ctx, addrs[0])) + require.Equal(t, fourSteak.Add(fiveSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) + require.Equal(t, addr0Initial.Sub(fourSteak).Sub(fiveSteak), keeper.ck.GetCoins(ctx, addrs[0])) // Check third deposit from a new address err, votingStarted = keeper.AddDeposit(ctx, proposalID, addrs[1], fourSteak) @@ -114,8 +114,8 @@ func TestDeposits(t *testing.T) { require.True(t, found) require.Equal(t, addrs[1], deposit.Depositor) require.Equal(t, fourSteak, deposit.Amount) - require.Equal(t, fourSteak.Plus(fiveSteak).Plus(fourSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) - require.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1])) + require.Equal(t, fourSteak.Add(fiveSteak).Add(fourSteak), keeper.GetProposal(ctx, proposalID).GetTotalDeposit()) + require.Equal(t, addr1Initial.Sub(fourSteak), keeper.ck.GetCoins(ctx, addrs[1])) // Check that proposal moved to voting period require.True(t, keeper.GetProposal(ctx, proposalID).GetVotingStartTime().Equal(ctx.BlockHeader().Time)) @@ -125,7 +125,7 @@ func TestDeposits(t *testing.T) { require.True(t, depositsIterator.Valid()) keeper.cdc.MustUnmarshalBinaryLengthPrefixed(depositsIterator.Value(), &deposit) require.Equal(t, addrs[0], deposit.Depositor) - require.Equal(t, fourSteak.Plus(fiveSteak), deposit.Amount) + require.Equal(t, fourSteak.Add(fiveSteak), deposit.Amount) depositsIterator.Next() keeper.cdc.MustUnmarshalBinaryLengthPrefixed(depositsIterator.Value(), &deposit) require.Equal(t, addrs[1], deposit.Depositor) diff --git a/x/mock/app.go b/x/mock/app.go index 1864e3941..a5dad50e6 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -304,7 +304,7 @@ func RandomSetGenesis(r *rand.Rand, app *App, addrs []sdk.AccAddress, denoms []s } } - app.TotalCoinsSupply = app.TotalCoinsSupply.Plus(coins) + app.TotalCoinsSupply = app.TotalCoinsSupply.Add(coins) baseAcc := auth.NewBaseAccountWithAddress(addrs[i]) (&baseAcc).SetCoins(coins) diff --git a/x/slashing/app_test.go b/x/slashing/app_test.go index 2ede44922..51c89a022 100644 --- a/x/slashing/app_test.go +++ b/x/slashing/app_test.go @@ -112,7 +112,7 @@ func TestSlashingMsgs(t *testing.T) { sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commission, sdk.OneInt(), ) mock.SignCheckDeliver(t, mapp.Cdc, mapp.BaseApp, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) - mock.CheckBalance(t, mapp, addr1, sdk.Coins{genCoin.Minus(bondCoin)}) + mock.CheckBalance(t, mapp, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) mapp.BeginBlock(abci.RequestBeginBlock{}) validator := checkValidator(t, mapp, stakingKeeper, addr1, true) diff --git a/x/staking/app_test.go b/x/staking/app_test.go index 9ed74d3d6..0b87e21bd 100644 --- a/x/staking/app_test.go +++ b/x/staking/app_test.go @@ -123,7 +123,7 @@ func TestStakingMsgs(t *testing.T) { ) mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1) - mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Minus(bondCoin)}) + mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Sub(bondCoin)}) mApp.BeginBlock(abci.RequestBeginBlock{}) validator := checkValidator(t, mApp, keeper, sdk.ValAddress(addr1), true) @@ -137,7 +137,7 @@ func TestStakingMsgs(t *testing.T) { ) mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{createValidatorMsgOnBehalfOf}, []uint64{0, 0}, []uint64{1, 0}, true, true, priv1, priv2) - mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Minus(bondCoin).Minus(bondCoin)}) + mock.CheckBalance(t, mApp, addr1, sdk.Coins{genCoin.Sub(bondCoin).Sub(bondCoin)}) mApp.BeginBlock(abci.RequestBeginBlock{}) validator = checkValidator(t, mApp, keeper, sdk.ValAddress(addr2), true) @@ -161,7 +161,7 @@ func TestStakingMsgs(t *testing.T) { delegateMsg := NewMsgDelegate(addr2, sdk.ValAddress(addr1), bondCoin) mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{delegateMsg}, []uint64{0}, []uint64{1}, true, true, priv2) - mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Minus(bondCoin)}) + mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Sub(bondCoin)}) checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), true, bondTokens.ToDec()) // begin unbonding @@ -172,5 +172,5 @@ func TestStakingMsgs(t *testing.T) { checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), false, sdk.Dec{}) // balance should be the same because bonding not yet complete - mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Minus(bondCoin)}) + mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Sub(bondCoin)}) } diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 523f0311d..0079da718 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -74,7 +74,7 @@ func TestValidatorByPowerIndex(t *testing.T) { validator, found = keeper.GetValidator(ctx, validatorAddr) require.True(t, found) require.Equal(t, sdk.Unbonding, validator.Status) // ensure is unbonding - require.Equal(t, initBond.DivRaw(2), validator.Tokens) // ensure tokens slashed + require.Equal(t, initBond.QuoRaw(2), validator.Tokens) // ensure tokens slashed keeper.Unjail(ctx, consAddr0) // the old power record should have been deleted as the power changed @@ -951,7 +951,7 @@ func TestMultipleRedelegationAtSameTime(t *testing.T) { // begin a redelegate selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) msgBeginRedelegate := NewMsgBeginRedelegate(selfDelAddr, - valAddr, valAddr2, valTokens.DivRaw(2).ToDec()) + valAddr, valAddr2, valTokens.QuoRaw(2).ToDec()) got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) @@ -1003,7 +1003,7 @@ func TestMultipleRedelegationAtUniqueTimes(t *testing.T) { // begin a redelegate selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) msgBeginRedelegate := NewMsgBeginRedelegate(selfDelAddr, - valAddr, valAddr2, valTokens.DivRaw(2).ToDec()) + valAddr, valAddr2, valTokens.QuoRaw(2).ToDec()) got = handleMsgBeginRedelegate(ctx, msgBeginRedelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) @@ -1051,7 +1051,7 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) { // begin an unbonding delegation selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) - msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, valTokens.DivRaw(2).ToDec()) + msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, valTokens.QuoRaw(2).ToDec()) got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) @@ -1097,7 +1097,7 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) { // begin an unbonding delegation selfDelAddr := sdk.AccAddress(valAddr) // (the validator is it's own delegator) - msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, valTokens.DivRaw(2).ToDec()) + msgUndelegate := NewMsgUndelegate(selfDelAddr, valAddr, valTokens.QuoRaw(2).ToDec()) got = handleMsgUndelegate(ctx, msgUndelegate, keeper) require.True(t, got.IsOK(), "expected no error, %v", got) @@ -1239,7 +1239,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { ubd, found := keeper.GetUnbondingDelegation(ctx, del, valA) require.True(t, found) require.Len(t, ubd.Entries, 1) - require.Equal(t, ubdTokens.DivRaw(2), ubd.Entries[0].Balance) + require.Equal(t, ubdTokens.QuoRaw(2), ubd.Entries[0].Balance) // redelegation should have been slashed by half redelegation, found := keeper.GetRedelegation(ctx, del, valA, valB) @@ -1249,12 +1249,12 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { // destination delegation should have been slashed by half delegation, found = keeper.GetDelegation(ctx, del, valB) require.True(t, found) - require.Equal(t, rdTokens.DivRaw(2).ToDec(), delegation.Shares) + require.Equal(t, rdTokens.QuoRaw(2).ToDec(), delegation.Shares) // validator power should have been reduced by half validator, found := keeper.GetValidator(ctx, valA) require.True(t, found) - require.Equal(t, valTokens.DivRaw(2), validator.GetBondedTokens()) + require.Equal(t, valTokens.QuoRaw(2), validator.GetBondedTokens()) // slash the validator for an infraction committed after the unbonding and redelegation begin ctx = ctx.WithBlockHeight(3) @@ -1264,7 +1264,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { ubd, found = keeper.GetUnbondingDelegation(ctx, del, valA) require.True(t, found) require.Len(t, ubd.Entries, 1) - require.Equal(t, ubdTokens.DivRaw(2), ubd.Entries[0].Balance) + require.Equal(t, ubdTokens.QuoRaw(2), ubd.Entries[0].Balance) // redelegation should be unchanged redelegation, found = keeper.GetRedelegation(ctx, del, valA, valB) @@ -1274,7 +1274,7 @@ func TestBondUnbondRedelegateSlashTwice(t *testing.T) { // destination delegation should be unchanged delegation, found = keeper.GetDelegation(ctx, del, valB) require.True(t, found) - require.Equal(t, rdTokens.DivRaw(2).ToDec(), delegation.Shares) + require.Equal(t, rdTokens.QuoRaw(2).ToDec(), delegation.Shares) // end blocker EndBlocker(ctx, keeper)