Fix loose tokens invariant
This commit is contained in:
parent
05ceff5212
commit
cea2be6107
|
@ -43,6 +43,7 @@ type Validator interface {
|
||||||
GetOwner() AccAddress // owner AccAddress to receive/return validators coins
|
GetOwner() AccAddress // owner AccAddress to receive/return validators coins
|
||||||
GetPubKey() crypto.PubKey // validation pubkey
|
GetPubKey() crypto.PubKey // validation pubkey
|
||||||
GetPower() Rat // validation power
|
GetPower() Rat // validation power
|
||||||
|
GetTokens() Rat // validation tokens
|
||||||
GetDelegatorShares() Rat // Total out standing delegator shares
|
GetDelegatorShares() Rat // Total out standing delegator shares
|
||||||
GetBondHeight() int64 // height in which the validator became active
|
GetBondHeight() int64 // height in which the validator became active
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,8 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) sim
|
||||||
ctx := app.NewContext(false, abci.Header{})
|
ctx := app.NewContext(false, abci.Header{})
|
||||||
pool := k.GetPool(ctx)
|
pool := k.GetPool(ctx)
|
||||||
|
|
||||||
// Loose tokens should equal coin supply plus unbonding delegations
|
|
||||||
loose := sdk.ZeroInt()
|
loose := sdk.ZeroInt()
|
||||||
|
bonded := sdk.ZeroRat()
|
||||||
am.IterateAccounts(ctx, func(acc auth.Account) bool {
|
am.IterateAccounts(ctx, func(acc auth.Account) bool {
|
||||||
loose = loose.Add(acc.GetCoins().AmountOf("steak"))
|
loose = loose.Add(acc.GetCoins().AmountOf("steak"))
|
||||||
return false
|
return false
|
||||||
|
@ -40,18 +40,22 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) sim
|
||||||
loose = loose.Add(ubd.Balance.Amount)
|
loose = loose.Add(ubd.Balance.Amount)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
require.True(t, pool.LooseTokens.RoundInt64() == loose.Int64(), "expected loose tokens to equal total steak held by accounts - pool.LooseTokens: %v, sum of account tokens: %v\nlog: %s",
|
|
||||||
pool.LooseTokens.RoundInt64(), loose.Int64(), log)
|
|
||||||
|
|
||||||
// Bonded tokens should equal sum of tokens with bonded validators
|
|
||||||
bonded := sdk.ZeroRat()
|
|
||||||
k.IterateValidators(ctx, func(_ int64, validator sdk.Validator) bool {
|
k.IterateValidators(ctx, func(_ int64, validator sdk.Validator) bool {
|
||||||
switch validator.GetStatus() {
|
switch validator.GetStatus() {
|
||||||
case sdk.Bonded:
|
case sdk.Bonded:
|
||||||
bonded = bonded.Add(validator.GetPower())
|
bonded = bonded.Add(validator.GetPower())
|
||||||
|
case sdk.Unbonding:
|
||||||
|
case sdk.Unbonded:
|
||||||
|
loose = loose.Add(validator.GetTokens().RoundInt())
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Loose tokens should equal coin supply plus unbonding delegations plus tokens on unbonded validators
|
||||||
|
require.True(t, pool.LooseTokens.RoundInt64() == loose.Int64(), "expected loose tokens to equal total steak held by accounts - pool.LooseTokens: %v, sum of account tokens: %v\nlog: %s",
|
||||||
|
pool.LooseTokens.RoundInt64(), loose.Int64(), log)
|
||||||
|
|
||||||
|
// Bonded tokens should equal sum of tokens with bonded validators
|
||||||
require.True(t, pool.BondedTokens.Equal(bonded), "expected bonded tokens to equal total steak held by bonded validators\nlog: %s", log)
|
require.True(t, pool.BondedTokens.Equal(bonded), "expected bonded tokens to equal total steak held by bonded validators\nlog: %s", log)
|
||||||
|
|
||||||
// TODO Inflation check on total supply
|
// TODO Inflation check on total supply
|
||||||
|
|
|
@ -406,6 +406,7 @@ func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
|
||||||
func (v Validator) GetOwner() sdk.AccAddress { return v.Owner }
|
func (v Validator) GetOwner() sdk.AccAddress { return v.Owner }
|
||||||
func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey }
|
func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey }
|
||||||
func (v Validator) GetPower() sdk.Rat { return v.BondedTokens() }
|
func (v Validator) GetPower() sdk.Rat { return v.BondedTokens() }
|
||||||
|
func (v Validator) GetTokens() sdk.Rat { return v.Tokens }
|
||||||
func (v Validator) GetDelegatorShares() sdk.Rat { return v.DelegatorShares }
|
func (v Validator) GetDelegatorShares() sdk.Rat { return v.DelegatorShares }
|
||||||
func (v Validator) GetBondHeight() int64 { return v.BondHeight }
|
func (v Validator) GetBondHeight() int64 { return v.BondHeight }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue