refactor!: Coins Add and Sub Consistency (#11689)
This commit is contained in:
parent
40c9de81ab
commit
ddc23bc4b2
|
@ -85,6 +85,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||||
|
|
||||||
### API Breaking Changes
|
### API Breaking Changes
|
||||||
|
|
||||||
|
* (types) [\#11689](https://github.com/cosmos/cosmos-sdk/pull/11689) Make `Coins#Sub` and `Coins#SafeSub` consistent with `Coins#Add`.
|
||||||
* (store)[\#11152](https://github.com/cosmos/cosmos-sdk/pull/11152) Remove `keep-every` from pruning options.
|
* (store)[\#11152](https://github.com/cosmos/cosmos-sdk/pull/11152) Remove `keep-every` from pruning options.
|
||||||
* [\#10950](https://github.com/cosmos/cosmos-sdk/pull/10950) Add `envPrefix` parameter to `cmd.Execute`.
|
* [\#10950](https://github.com/cosmos/cosmos-sdk/pull/10950) Add `envPrefix` parameter to `cmd.Execute`.
|
||||||
* (x/mint) [\#10441](https://github.com/cosmos/cosmos-sdk/pull/10441) The `NewAppModule` function now accepts an inflation calculation function as an argument.
|
* (x/mint) [\#10441](https://github.com/cosmos/cosmos-sdk/pull/10441) The `NewAppModule` function now accepts an inflation calculation function as an argument.
|
||||||
|
|
|
@ -393,8 +393,8 @@ func (coins Coins) DenomsSubsetOf(coinsB Coins) bool {
|
||||||
//
|
//
|
||||||
// CONTRACT: Sub 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.
|
// amount. In otherwords, IsValid will always return true.
|
||||||
func (coins Coins) Sub(coinsB Coins) Coins {
|
func (coins Coins) Sub(coinsB ...Coin) Coins {
|
||||||
diff, hasNeg := coins.SafeSub(coinsB)
|
diff, hasNeg := coins.SafeSub(coinsB...)
|
||||||
if hasNeg {
|
if hasNeg {
|
||||||
panic("negative coin amount")
|
panic("negative coin amount")
|
||||||
}
|
}
|
||||||
|
@ -405,8 +405,8 @@ func (coins Coins) Sub(coinsB Coins) Coins {
|
||||||
// SafeSub performs the same arithmetic as Sub but returns a boolean if any
|
// SafeSub performs the same arithmetic as Sub but returns a boolean if any
|
||||||
// negative coin amount was returned.
|
// negative coin amount was returned.
|
||||||
// The function panics if `coins` or `coinsB` are not sorted (ascending).
|
// The function panics if `coins` or `coinsB` are not sorted (ascending).
|
||||||
func (coins Coins) SafeSub(coinsB Coins) (Coins, bool) {
|
func (coins Coins) SafeSub(coinsB ...Coin) (Coins, bool) {
|
||||||
diff := coins.safeAdd(coinsB.negative())
|
diff := coins.safeAdd(NewCoins(coinsB...).negative())
|
||||||
return diff, diff.IsAnyNegative()
|
return diff, diff.IsAnyNegative()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -496,9 +496,9 @@ func (s *coinTestSuite) TestSubCoins() {
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
if tc.shouldPanic {
|
if tc.shouldPanic {
|
||||||
assert.Panics(func() { tc.inputOne.Sub(tc.inputTwo) })
|
assert.Panics(func() { tc.inputOne.Sub(tc.inputTwo...) })
|
||||||
} else {
|
} else {
|
||||||
res := tc.inputOne.Sub(tc.inputTwo)
|
res := tc.inputOne.Sub(tc.inputTwo...)
|
||||||
assert.True(res.IsValid())
|
assert.True(res.IsValid())
|
||||||
assert.Equal(tc.expected, res, "sum of coins is incorrect, tc #%d", i)
|
assert.Equal(tc.expected, res, "sum of coins is incorrect, tc #%d", i)
|
||||||
}
|
}
|
||||||
|
|
|
@ -917,7 +917,7 @@ func (s *IntegrationTestSuite) TestCLIMultisignSortSignatures() {
|
||||||
|
|
||||||
err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
err = val1.ClientCtx.Codec.UnmarshalJSON(resp.Bytes(), &balRes)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
diff, _ := balRes.Balances.SafeSub(intialCoins)
|
diff, _ := balRes.Balances.SafeSub(intialCoins...)
|
||||||
s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))
|
s.Require().Equal(sendTokens.Amount, diff.AmountOf(s.cfg.BondDenom))
|
||||||
|
|
||||||
// Generate multisig transaction.
|
// Generate multisig transaction.
|
||||||
|
|
|
@ -115,9 +115,9 @@ func (s *MWTestSuite) TestTips() {
|
||||||
s.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: ctx.BlockHeight()}})
|
s.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: ctx.BlockHeight()}})
|
||||||
|
|
||||||
// Make sure tip is correctly transferred to feepayer, and fee is paid.
|
// Make sure tip is correctly transferred to feepayer, and fee is paid.
|
||||||
expTipperRegens := initialRegens.Sub(tc.tip)
|
expTipperRegens := initialRegens.Sub(tc.tip...)
|
||||||
expFeePayerRegens := initialRegens.Add(tc.tip...)
|
expFeePayerRegens := initialRegens.Add(tc.tip...)
|
||||||
expFeePayerAtoms := initialAtoms.Sub(tc.fee)
|
expFeePayerAtoms := initialAtoms.Sub(tc.fee...)
|
||||||
s.Require().True(expTipperRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, tipper.acc.GetAddress(), "regen").Amount))
|
s.Require().True(expTipperRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, tipper.acc.GetAddress(), "regen").Amount))
|
||||||
s.Require().True(expFeePayerRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "regen").Amount))
|
s.Require().True(expFeePayerRegens.AmountOf("regen").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "regen").Amount))
|
||||||
s.Require().True(expFeePayerAtoms.AmountOf("atom").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "atom").Amount))
|
s.Require().True(expFeePayerAtoms.AmountOf("atom").Equal(s.app.BankKeeper.GetBalance(ctx, feePayer.acc.GetAddress(), "atom").Amount))
|
||||||
|
|
|
@ -41,7 +41,7 @@ func NewBaseVestingAccount(baseAccount *authtypes.BaseAccount, originalVesting s
|
||||||
//
|
//
|
||||||
// CONTRACT: Delegated vesting coins and vestingCoins must be sorted.
|
// CONTRACT: Delegated vesting coins and vestingCoins must be sorted.
|
||||||
func (bva BaseVestingAccount) LockedCoinsFromVesting(vestingCoins sdk.Coins) sdk.Coins {
|
func (bva BaseVestingAccount) LockedCoinsFromVesting(vestingCoins sdk.Coins) sdk.Coins {
|
||||||
lockedCoins := vestingCoins.Sub(vestingCoins.Min(bva.DelegatedVesting))
|
lockedCoins := vestingCoins.Sub(vestingCoins.Min(bva.DelegatedVesting)...)
|
||||||
if lockedCoins == nil {
|
if lockedCoins == nil {
|
||||||
return sdk.Coins{}
|
return sdk.Coins{}
|
||||||
}
|
}
|
||||||
|
@ -111,12 +111,12 @@ func (bva *BaseVestingAccount) TrackUndelegation(amount sdk.Coins) {
|
||||||
|
|
||||||
if !x.IsZero() {
|
if !x.IsZero() {
|
||||||
xCoin := sdk.NewCoin(coin.Denom, x)
|
xCoin := sdk.NewCoin(coin.Denom, x)
|
||||||
bva.DelegatedFree = bva.DelegatedFree.Sub(sdk.Coins{xCoin})
|
bva.DelegatedFree = bva.DelegatedFree.Sub(xCoin)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !y.IsZero() {
|
if !y.IsZero() {
|
||||||
yCoin := sdk.NewCoin(coin.Denom, y)
|
yCoin := sdk.NewCoin(coin.Denom, y)
|
||||||
bva.DelegatedVesting = bva.DelegatedVesting.Sub(sdk.Coins{yCoin})
|
bva.DelegatedVesting = bva.DelegatedVesting.Sub(yCoin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ func (cva ContinuousVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coin
|
||||||
// GetVestingCoins returns the total number of vesting coins. If no coins are
|
// GetVestingCoins returns the total number of vesting coins. If no coins are
|
||||||
// vesting, nil is returned.
|
// vesting, nil is returned.
|
||||||
func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
func (cva ContinuousVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
||||||
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime))
|
return cva.OriginalVesting.Sub(cva.GetVestedCoins(blockTime)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
||||||
|
@ -374,7 +374,7 @@ func (pva PeriodicVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins
|
||||||
// GetVestingCoins returns the total number of vesting coins. If no coins are
|
// GetVestingCoins returns the total number of vesting coins. If no coins are
|
||||||
// vesting, nil is returned.
|
// vesting, nil is returned.
|
||||||
func (pva PeriodicVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
func (pva PeriodicVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
||||||
return pva.OriginalVesting.Sub(pva.GetVestedCoins(blockTime))
|
return pva.OriginalVesting.Sub(pva.GetVestedCoins(blockTime)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
||||||
|
@ -485,7 +485,7 @@ func (dva DelayedVestingAccount) GetVestedCoins(blockTime time.Time) sdk.Coins {
|
||||||
// GetVestingCoins returns the total number of vesting coins for a delayed
|
// GetVestingCoins returns the total number of vesting coins for a delayed
|
||||||
// vesting account.
|
// vesting account.
|
||||||
func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
func (dva DelayedVestingAccount) GetVestingCoins(blockTime time.Time) sdk.Coins {
|
||||||
return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime))
|
return dva.OriginalVesting.Sub(dva.GetVestedCoins(blockTime)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
// LockedCoins returns the set of coins that are not spendable (i.e. locked),
|
||||||
|
|
|
@ -242,7 +242,7 @@ func TestSpendableCoinsDelVestingAcc(t *testing.T) {
|
||||||
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
|
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
|
||||||
dva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount)
|
dva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount)
|
||||||
lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour))
|
lockedCoins = dva.LockedCoins(now.Add(12 * time.Hour))
|
||||||
require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount)))
|
require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount...)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackDelegationDelVestingAcc(t *testing.T) {
|
func TestTrackDelegationDelVestingAcc(t *testing.T) {
|
||||||
|
@ -600,7 +600,7 @@ func TestSpendableCoinsPermLockedVestingAcc(t *testing.T) {
|
||||||
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
|
delegatedAmount := sdk.NewCoins(sdk.NewInt64Coin(stakeDenom, 50))
|
||||||
plva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount)
|
plva.TrackDelegation(now.Add(12*time.Hour), origCoins, delegatedAmount)
|
||||||
lockedCoins = plva.LockedCoins(now.Add(12 * time.Hour))
|
lockedCoins = plva.LockedCoins(now.Add(12 * time.Hour))
|
||||||
require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount)))
|
require.True(t, lockedCoins.IsEqual(origCoins.Sub(delegatedAmount...)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
|
func TestTrackDelegationPermLockedVestingAcc(t *testing.T) {
|
||||||
|
|
|
@ -220,7 +220,7 @@ func (s *TestSuite) TestDispatchAction() {
|
||||||
require.Len(authzs, 1)
|
require.Len(authzs, 1)
|
||||||
authorization := authzs[0].(*banktypes.SendAuthorization)
|
authorization := authzs[0].(*banktypes.SendAuthorization)
|
||||||
require.NotNil(authorization)
|
require.NotNil(authorization)
|
||||||
require.Equal(authorization.SpendLimit, coins100.Sub(coins10))
|
require.Equal(authorization.SpendLimit, coins100.Sub(coins10...))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -102,7 +102,7 @@ func SimulateMsgGrant(ak authz.AccountKeeper, bk authz.BankKeeper, _ keeper.Keep
|
||||||
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err
|
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, err.Error()), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
spendLimit := spendableCoins.Sub(fees)
|
spendLimit := spendableCoins.Sub(fees...)
|
||||||
if spendLimit == nil {
|
if spendLimit == nil {
|
||||||
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, "spend limit is nil"), nil, nil
|
return simtypes.NoOpMsg(authz.ModuleName, TypeMsgGrant, "spend limit is nil"), nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() {
|
||||||
supplyAfterBurn, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
|
supplyAfterBurn, _, err := keeper.GetPaginatedTotalSupply(ctx, &query.PageRequest{})
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, authtypes.Burner).String())
|
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, authtypes.Burner).String())
|
||||||
suite.Require().Equal(supplyAfterInflation.Sub(initCoins), supplyAfterBurn)
|
suite.Require().Equal(supplyAfterInflation.Sub(initCoins...), supplyAfterBurn)
|
||||||
|
|
||||||
// test same functionality on module account with multiple permissions
|
// test same functionality on module account with multiple permissions
|
||||||
suite.
|
suite.
|
||||||
|
@ -304,7 +304,7 @@ func (suite *IntegrationTestSuite) TestSupply_BurnCoins() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName()).String())
|
suite.Require().Equal(sdk.NewCoins().String(), getCoinsByName(ctx, keeper, authKeeper, multiPermAcc.GetName()).String())
|
||||||
suite.Require().Equal(supplyAfterInflation.Sub(initCoins), supplyAfterBurn)
|
suite.Require().Equal(supplyAfterInflation.Sub(initCoins...), supplyAfterBurn)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
|
func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
|
||||||
|
@ -331,7 +331,7 @@ func (suite *IntegrationTestSuite) TestSendCoinsNewAccount() {
|
||||||
acc2Balances := app.BankKeeper.GetAllBalances(ctx, addr2)
|
acc2Balances := app.BankKeeper.GetAllBalances(ctx, addr2)
|
||||||
acc1Balances = app.BankKeeper.GetAllBalances(ctx, addr1)
|
acc1Balances = app.BankKeeper.GetAllBalances(ctx, addr1)
|
||||||
suite.Require().Equal(sendAmt, acc2Balances)
|
suite.Require().Equal(sendAmt, acc2Balances)
|
||||||
updatedAcc1Bal := balances.Sub(sendAmt)
|
updatedAcc1Bal := balances.Sub(sendAmt...)
|
||||||
suite.Require().Len(acc1Balances, len(updatedAcc1Bal))
|
suite.Require().Len(acc1Balances, len(updatedAcc1Bal))
|
||||||
suite.Require().Equal(acc1Balances, updatedAcc1Bal)
|
suite.Require().Equal(acc1Balances, updatedAcc1Bal)
|
||||||
suite.Require().NotNil(app.AccountKeeper.GetAccount(ctx, addr2))
|
suite.Require().NotNil(app.AccountKeeper.GetAccount(ctx, addr2))
|
||||||
|
@ -713,7 +713,7 @@ func (suite *IntegrationTestSuite) TestSpendableCoins() {
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
|
ctx = ctx.WithBlockTime(now.Add(12 * time.Hour))
|
||||||
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
|
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
|
||||||
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.SpendableCoins(ctx, addr1))
|
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.SpendableCoins(ctx, addr1))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestVestingAccountSend() {
|
func (suite *IntegrationTestSuite) TestVestingAccountSend() {
|
||||||
|
@ -806,10 +806,10 @@ func (suite *IntegrationTestSuite) TestVestingAccountReceive() {
|
||||||
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.ContinuousVestingAccount)
|
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.ContinuousVestingAccount)
|
||||||
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
|
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
|
||||||
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
|
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
|
||||||
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)), sendCoins)
|
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)...), sendCoins)
|
||||||
|
|
||||||
// require coins are spendable plus any that have vested
|
// require coins are spendable plus any that have vested
|
||||||
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))), origCoins)
|
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))...), origCoins)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() {
|
func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() {
|
||||||
|
@ -845,10 +845,10 @@ func (suite *IntegrationTestSuite) TestPeriodicVestingAccountReceive() {
|
||||||
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.PeriodicVestingAccount)
|
vacc = app.AccountKeeper.GetAccount(ctx, addr1).(*vesting.PeriodicVestingAccount)
|
||||||
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
|
balances := app.BankKeeper.GetAllBalances(ctx, addr1)
|
||||||
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
|
suite.Require().Equal(origCoins.Add(sendCoins...), balances)
|
||||||
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)), sendCoins)
|
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now)...), sendCoins)
|
||||||
|
|
||||||
// require coins are spendable plus any that have vested
|
// require coins are spendable plus any that have vested
|
||||||
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))), origCoins)
|
suite.Require().Equal(balances.Sub(vacc.LockedCoins(now.Add(12*time.Hour))...), origCoins)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *IntegrationTestSuite) TestDelegateCoins() {
|
func (suite *IntegrationTestSuite) TestDelegateCoins() {
|
||||||
|
@ -879,7 +879,7 @@ func (suite *IntegrationTestSuite) TestDelegateCoins() {
|
||||||
|
|
||||||
// require the ability for a non-vesting account to delegate
|
// require the ability for a non-vesting account to delegate
|
||||||
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
|
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins))
|
||||||
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr2))
|
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr2))
|
||||||
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
||||||
|
|
||||||
// require the ability for a vesting account to delegate
|
// require the ability for a vesting account to delegate
|
||||||
|
@ -945,7 +945,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {
|
||||||
err := app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins)
|
err := app.BankKeeper.DelegateCoins(ctx, addr2, addrModule, delCoins)
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
|
|
||||||
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr2))
|
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr2))
|
||||||
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
||||||
|
|
||||||
// require the ability for a non-vesting account to undelegate
|
// require the ability for a non-vesting account to undelegate
|
||||||
|
@ -957,7 +957,7 @@ func (suite *IntegrationTestSuite) TestUndelegateCoins() {
|
||||||
// require the ability for a vesting account to delegate
|
// require the ability for a vesting account to delegate
|
||||||
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr1, addrModule, delCoins))
|
suite.Require().NoError(app.BankKeeper.DelegateCoins(ctx, addr1, addrModule, delCoins))
|
||||||
|
|
||||||
suite.Require().Equal(origCoins.Sub(delCoins), app.BankKeeper.GetAllBalances(ctx, addr1))
|
suite.Require().Equal(origCoins.Sub(delCoins...), app.BankKeeper.GetAllBalances(ctx, addr1))
|
||||||
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
suite.Require().Equal(delCoins, app.BankKeeper.GetAllBalances(ctx, addrModule))
|
||||||
|
|
||||||
// require the ability for a vesting account to undelegate
|
// require the ability for a vesting account to undelegate
|
||||||
|
@ -1095,7 +1095,7 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
|
||||||
case types.EventTypeCoinBurn:
|
case types.EventTypeCoinBurn:
|
||||||
burnedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
burnedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
supply = supply.Sub(burnedCoins)
|
supply = supply.Sub(burnedCoins...)
|
||||||
|
|
||||||
case types.EventTypeCoinMint:
|
case types.EventTypeCoinMint:
|
||||||
mintedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
mintedCoins, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
||||||
|
@ -1107,7 +1107,7 @@ func (suite *IntegrationTestSuite) TestBalanceTrackingEvents() {
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
spender, err := sdk.AccAddressFromBech32((string)(e.Attributes[0].Value))
|
spender, err := sdk.AccAddressFromBech32((string)(e.Attributes[0].Value))
|
||||||
suite.Require().NoError(err)
|
suite.Require().NoError(err)
|
||||||
balances[spender.String()] = balances[spender.String()].Sub(coinsSpent)
|
balances[spender.String()] = balances[spender.String()].Sub(coinsSpent...)
|
||||||
|
|
||||||
case types.EventTypeCoinReceived:
|
case types.EventTypeCoinReceived:
|
||||||
coinsRecv, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
coinsRecv, err := sdk.ParseCoinsNormalized((string)(e.Attributes[1].Value))
|
||||||
|
|
|
@ -187,7 +187,7 @@ func (k BaseSendKeeper) subUnlockedCoins(ctx sdk.Context, addr sdk.AccAddress, a
|
||||||
locked := sdk.NewCoin(coin.Denom, lockedCoins.AmountOf(coin.Denom))
|
locked := sdk.NewCoin(coin.Denom, lockedCoins.AmountOf(coin.Denom))
|
||||||
spendable := balance.Sub(locked)
|
spendable := balance.Sub(locked)
|
||||||
|
|
||||||
_, hasNeg := sdk.Coins{spendable}.SafeSub(sdk.Coins{coin})
|
_, hasNeg := sdk.Coins{spendable}.SafeSub(coin)
|
||||||
if hasNeg {
|
if hasNeg {
|
||||||
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
|
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, "%s is smaller than %s", spendable, coin)
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ func (k BaseViewKeeper) spendableCoins(ctx sdk.Context, addr sdk.AccAddress) (sp
|
||||||
total = k.GetAllBalances(ctx, addr)
|
total = k.GetAllBalances(ctx, addr)
|
||||||
locked := k.LockedCoins(ctx, addr)
|
locked := k.LockedCoins(ctx, addr)
|
||||||
|
|
||||||
spendable, hasNeg := total.SafeSub(locked)
|
spendable, hasNeg := total.SafeSub(locked...)
|
||||||
if hasNeg {
|
if hasNeg {
|
||||||
spendable = sdk.NewCoins()
|
spendable = sdk.NewCoins()
|
||||||
return
|
return
|
||||||
|
|
|
@ -130,7 +130,7 @@ func sendMsgSend(
|
||||||
account := ak.GetAccount(ctx, from)
|
account := ak.GetAccount(ctx, from)
|
||||||
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(msg.Amount)
|
coins, hasNeg := spendable.SafeSub(msg.Amount...)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -219,7 +219,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope
|
||||||
// take random subset of remaining coins for output
|
// take random subset of remaining coins for output
|
||||||
// and update remaining coins
|
// and update remaining coins
|
||||||
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
|
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
|
||||||
totalSentCoins = totalSentCoins.Sub(outCoins)
|
totalSentCoins = totalSentCoins.Sub(outCoins...)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs[o] = types.NewOutput(outAddr.Address, outCoins)
|
outputs[o] = types.NewOutput(outAddr.Address, outCoins)
|
||||||
|
@ -286,7 +286,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe
|
||||||
// take random subset of remaining coins for output
|
// take random subset of remaining coins for output
|
||||||
// and update remaining coins
|
// and update remaining coins
|
||||||
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
|
outCoins = simtypes.RandSubsetCoins(r, totalSentCoins)
|
||||||
totalSentCoins = totalSentCoins.Sub(outCoins)
|
totalSentCoins = totalSentCoins.Sub(outCoins...)
|
||||||
}
|
}
|
||||||
|
|
||||||
outputs[i] = types.NewOutput(moduleAccounts[i].Address, outCoins)
|
outputs[i] = types.NewOutput(moduleAccounts[i].Address, outCoins)
|
||||||
|
@ -351,7 +351,7 @@ func sendMsgMultiSend(
|
||||||
feePayer := ak.GetAccount(ctx, addr)
|
feePayer := ak.GetAccount(ctx, addr)
|
||||||
spendable := bk.SpendableCoins(ctx, feePayer.GetAddress())
|
spendable := bk.SpendableCoins(ctx, feePayer.GetAddress())
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins)
|
coins, hasNeg := spendable.SafeSub(msg.Inputs[0].Coins...)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (a SendAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authz.AcceptRes
|
||||||
if !ok {
|
if !ok {
|
||||||
return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
|
return authz.AcceptResponse{}, sdkerrors.ErrInvalidType.Wrap("type mismatch")
|
||||||
}
|
}
|
||||||
limitLeft, isNegative := a.SpendLimit.SafeSub(mSend.Amount)
|
limitLeft, isNegative := a.SpendLimit.SafeSub(mSend.Amount...)
|
||||||
if isNegative {
|
if isNegative {
|
||||||
return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit")
|
return authz.AcceptResponse{}, sdkerrors.ErrInsufficientFunds.Wrapf("requested amount is more than spend limit")
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ func SimulateMsgFundCommunityPool(ak types.AccountKeeper, bk types.BankKeeper, k
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(fundAmount)
|
coins, hasNeg := spendable.SafeSub(fundAmount...)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -25,7 +25,7 @@ func (a *BasicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg) (bo
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.SpendLimit != nil {
|
if a.SpendLimit != nil {
|
||||||
left, invalid := a.SpendLimit.SafeSub(fee)
|
left, invalid := a.SpendLimit.SafeSub(fee...)
|
||||||
if invalid {
|
if invalid {
|
||||||
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "basic allowance")
|
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "basic allowance")
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,13 +30,13 @@ func (a *PeriodicAllowance) Accept(ctx sdk.Context, fee sdk.Coins, _ []sdk.Msg)
|
||||||
|
|
||||||
// deduct from both the current period and the max amount
|
// deduct from both the current period and the max amount
|
||||||
var isNeg bool
|
var isNeg bool
|
||||||
a.PeriodCanSpend, isNeg = a.PeriodCanSpend.SafeSub(fee)
|
a.PeriodCanSpend, isNeg = a.PeriodCanSpend.SafeSub(fee...)
|
||||||
if isNeg {
|
if isNeg {
|
||||||
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "period limit")
|
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "period limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.Basic.SpendLimit != nil {
|
if a.Basic.SpendLimit != nil {
|
||||||
a.Basic.SpendLimit, isNeg = a.Basic.SpendLimit.SafeSub(fee)
|
a.Basic.SpendLimit, isNeg = a.Basic.SpendLimit.SafeSub(fee...)
|
||||||
if isNeg {
|
if isNeg {
|
||||||
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "absolute limit")
|
return false, sdkerrors.Wrap(ErrFeeLimitExceeded, "absolute limit")
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (a *PeriodicAllowance) tryResetPeriod(blockTime time.Time) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set PeriodCanSpend to the lesser of Basic.SpendLimit and PeriodSpendLimit
|
// set PeriodCanSpend to the lesser of Basic.SpendLimit and PeriodSpendLimit
|
||||||
if _, isNeg := a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit); isNeg && !a.Basic.SpendLimit.Empty() {
|
if _, isNeg := a.Basic.SpendLimit.SafeSub(a.PeriodSpendLimit...); isNeg && !a.Basic.SpendLimit.Empty() {
|
||||||
a.PeriodCanSpend = a.Basic.SpendLimit
|
a.PeriodCanSpend = a.Basic.SpendLimit
|
||||||
} else {
|
} else {
|
||||||
a.PeriodCanSpend = a.PeriodSpendLimit
|
a.PeriodCanSpend = a.PeriodSpendLimit
|
||||||
|
|
|
@ -131,8 +131,8 @@ func TestPeriodicFeeValidAllow(t *testing.T) {
|
||||||
blockTime: oneHour,
|
blockTime: oneHour,
|
||||||
accept: true,
|
accept: true,
|
||||||
remove: false,
|
remove: false,
|
||||||
remainsPeriod: smallAtom.Sub(oneAtom),
|
remainsPeriod: smallAtom.Sub(oneAtom...),
|
||||||
remains: smallAtom.Sub(oneAtom),
|
remains: smallAtom.Sub(oneAtom...),
|
||||||
periodReset: oneHour.Add(tenMinutes), // one step from last reset, not now
|
periodReset: oneHour.Add(tenMinutes), // one step from last reset, not now
|
||||||
},
|
},
|
||||||
"period reset no spend limit": {
|
"period reset no spend limit": {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestDeposits(t *testing.T) {
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake, sdk.NewCoins(proposal.TotalDeposit...))
|
require.Equal(t, fourStake, sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
||||||
|
|
||||||
// Check a second deposit from same address
|
// Check a second deposit from same address
|
||||||
votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fiveStake)
|
votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[0], fiveStake)
|
||||||
|
@ -60,7 +60,7 @@ func TestDeposits(t *testing.T) {
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
require.Equal(t, fourStake.Add(fiveStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr0Initial.Sub(fourStake).Sub(fiveStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
require.Equal(t, addr0Initial.Sub(fourStake...).Sub(fiveStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
||||||
|
|
||||||
// Check third deposit from a new address
|
// Check third deposit from a new address
|
||||||
votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[1], fourStake)
|
votingStarted, err = app.GovKeeper.AddDeposit(ctx, proposalID, TestAddrs[1], fourStake)
|
||||||
|
@ -73,7 +73,7 @@ func TestDeposits(t *testing.T) {
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
require.Equal(t, fourStake.Add(fiveStake...).Add(fourStake...), sdk.NewCoins(proposal.TotalDeposit...))
|
||||||
require.Equal(t, addr1Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]))
|
require.Equal(t, addr1Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[1]))
|
||||||
|
|
||||||
// Check that proposal moved to voting period
|
// Check that proposal moved to voting period
|
||||||
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
proposal, ok = app.GovKeeper.GetProposal(ctx, proposalID)
|
||||||
|
@ -109,5 +109,5 @@ func TestDeposits(t *testing.T) {
|
||||||
app.GovKeeper.DeleteAndBurnDeposits(ctx, proposalID)
|
app.GovKeeper.DeleteAndBurnDeposits(ctx, proposalID)
|
||||||
deposits = app.GovKeeper.GetDeposits(ctx, proposalID)
|
deposits = app.GovKeeper.GetDeposits(ctx, proposalID)
|
||||||
require.Len(t, deposits, 0)
|
require.Len(t, deposits, 0)
|
||||||
require.Equal(t, addr0Initial.Sub(fourStake), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
require.Equal(t, addr0Initial.Sub(fourStake...), app.BankKeeper.GetAllBalances(ctx, TestAddrs[0]))
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ func SimulateMsgSubmitProposal(
|
||||||
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
||||||
|
|
||||||
var fees sdk.Coins
|
var fees sdk.Coins
|
||||||
coins, hasNeg := spendable.SafeSub(deposit)
|
coins, hasNeg := spendable.SafeSub(deposit...)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -248,7 +248,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Ke
|
||||||
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
spendable := bk.SpendableCoins(ctx, account.GetAddress())
|
||||||
|
|
||||||
var fees sdk.Coins
|
var fees sdk.Coins
|
||||||
coins, hasNeg := spendable.SafeSub(deposit)
|
coins, hasNeg := spendable.SafeSub(deposit...)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -81,7 +81,7 @@ func SimulateMsgSend(
|
||||||
return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, err.Error()), nil, err
|
return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, err.Error()), nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
spendLimit := spendableCoins.Sub(fees)
|
spendLimit := spendableCoins.Sub(fees...)
|
||||||
if spendLimit == nil {
|
if spendLimit == nil {
|
||||||
return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, "spend limit is nil"), nil, nil
|
return simtypes.NoOpMsg(nft.ModuleName, TypeMsgSend, "spend limit is nil"), nil, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [
|
||||||
var fees sdk.Coins
|
var fees sdk.Coins
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg)
|
coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg...)
|
||||||
if hasNeg {
|
if hasNeg {
|
||||||
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err
|
return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ func TestSlashUnbondingDelegation(t *testing.T) {
|
||||||
// balance decreased
|
// balance decreased
|
||||||
require.Equal(t, sdk.NewInt(5), ubd.Entries[0].Balance)
|
require.Equal(t, sdk.NewInt(5), ubd.Entries[0].Balance)
|
||||||
newUnbondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
|
newUnbondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress())
|
||||||
diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances)
|
diffTokens := oldUnbondedPoolBalances.Sub(newUnbondedPoolBalances...)
|
||||||
require.True(t, diffTokens.AmountOf(app.StakingKeeper.BondDenom(ctx)).Equal(sdk.NewInt(5)))
|
require.True(t, diffTokens.AmountOf(app.StakingKeeper.BondDenom(ctx)).Equal(sdk.NewInt(5)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ func TestSlashRedelegation(t *testing.T) {
|
||||||
|
|
||||||
// pool bonded tokens should decrease
|
// pool bonded tokens should decrease
|
||||||
burnedCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), slashAmount))
|
burnedCoins := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), slashAmount))
|
||||||
require.Equal(t, balances.Sub(burnedCoins), app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()))
|
require.Equal(t, balances.Sub(burnedCoins...), app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// tests Slash at a future height (must panic)
|
// tests Slash at a future height (must panic)
|
||||||
|
@ -220,7 +220,7 @@ func TestSlashAtNegativeHeight(t *testing.T) {
|
||||||
|
|
||||||
// pool bonded shares decreased
|
// pool bonded shares decreased
|
||||||
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String())
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ func TestSlashValidatorAtCurrentHeight(t *testing.T) {
|
||||||
|
|
||||||
// pool bonded shares decreased
|
// pool bonded shares decreased
|
||||||
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String())
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 5).String(), diffTokens.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||||
|
|
||||||
// bonded tokens burned
|
// bonded tokens burned
|
||||||
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances := app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens := oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 3), diffTokens)
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 3), diffTokens)
|
||||||
|
|
||||||
// read updated validator
|
// read updated validator
|
||||||
|
@ -316,7 +316,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||||
|
|
||||||
// bonded tokens burned again
|
// bonded tokens burned again
|
||||||
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 6), diffTokens)
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 6), diffTokens)
|
||||||
|
|
||||||
// read updated validator
|
// read updated validator
|
||||||
|
@ -342,7 +342,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||||
|
|
||||||
// bonded tokens burned again
|
// bonded tokens burned again
|
||||||
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 9), diffTokens)
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 9), diffTokens)
|
||||||
|
|
||||||
// read updated validator
|
// read updated validator
|
||||||
|
@ -368,7 +368,7 @@ func TestSlashWithUnbondingDelegation(t *testing.T) {
|
||||||
|
|
||||||
// just 1 bonded token burned again since that's all the validator now has
|
// just 1 bonded token burned again since that's all the validator now has
|
||||||
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
newBondedPoolBalances = app.BankKeeper.GetAllBalances(ctx, bondedPool.GetAddress())
|
||||||
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
diffTokens = oldBondedPoolBalances.Sub(newBondedPoolBalances...).AmountOf(app.StakingKeeper.BondDenom(ctx))
|
||||||
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 10), diffTokens)
|
require.Equal(t, app.StakingKeeper.TokensFromConsensusPower(ctx, 10), diffTokens)
|
||||||
|
|
||||||
// apply TM updates
|
// apply TM updates
|
||||||
|
|
|
@ -135,7 +135,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k k
|
||||||
|
|
||||||
var fees sdk.Coins
|
var fees sdk.Coins
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(sdk.Coins{selfDelegation})
|
coins, hasNeg := spendable.SafeSub(selfDelegation)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -277,7 +277,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k keeper.K
|
||||||
|
|
||||||
var fees sdk.Coins
|
var fees sdk.Coins
|
||||||
|
|
||||||
coins, hasNeg := spendable.SafeSub(sdk.Coins{bondAmt})
|
coins, hasNeg := spendable.SafeSub(bondAmt)
|
||||||
if !hasNeg {
|
if !hasNeg {
|
||||||
fees, err = simtypes.RandomFees(r, ctx, coins)
|
fees, err = simtypes.RandomFees(r, ctx, coins)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue