Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Add loose/bonded token supply invariants back to simulation #2162

Merged
merged 6 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ BREAKING CHANGES
* [x/stake] [#1013] TendermintUpdates now uses transient store
* [x/gov] [#2195] Governance uses BFT Time
* [x/gov] \#2256 Removed slashing for governance non-voting validators
* [simulation] \#2162 Added back correct supply invariants

* SDK
* [core] [\#1807](https://github.com/cosmos/cosmos-sdk/issues/1807) Switch from use of rational to decimal
Expand Down
14 changes: 7 additions & 7 deletions x/stake/simulation/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func AllInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) simula
func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) simulation.Invariant {
return func(app *baseapp.BaseApp) error {
ctx := app.NewContext(false, abci.Header{})
//pool := k.GetPool(ctx)
pool := k.GetPool(ctx)

loose := sdk.ZeroInt()
bonded := sdk.ZeroDec()
Expand All @@ -59,14 +59,14 @@ func SupplyInvariants(ck bank.Keeper, k stake.Keeper, am auth.AccountMapper) sim
})

// Loose tokens should equal coin supply plus unbonding delegations plus tokens on unbonded validators
// XXX TODO https://github.com/cosmos/cosmos-sdk/issues/2063#issuecomment-413720872
// 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)
if pool.LooseTokens.RoundInt64() != loose.Int64() {
return fmt.Errorf("expected loose tokens to equal total steak held by accounts - pool.LooseTokens: %v, sum of account tokens: %v", pool.LooseTokens.RoundInt64(), loose.Int64())
}

// Bonded tokens should equal sum of tokens with bonded validators
// XXX TODO https://github.com/cosmos/cosmos-sdk/issues/2063#issuecomment-413720872
// require.True(t, pool.BondedTokens.RoundInt64() == bonded.RoundInt64(), "expected bonded tokens to equal total steak held by bonded validators - pool.BondedTokens: %v, sum of bonded validator tokens: %v\nlog: %s",
// pool.BondedTokens.RoundInt64(), bonded.RoundInt64(), log)
if pool.BondedTokens.RoundInt64() != bonded.RoundInt64() {
return fmt.Errorf("expected bonded tokens to equal total steak held by bonded validators - pool.BondedTokens: %v, sum of bonded validator tokens: %v", pool.BondedTokens.RoundInt64(), bonded.RoundInt64())
}

// TODO Inflation check on total supply
return nil
Expand Down