Simulate minting, fix bug where pool was not updated

This commit is contained in:
Christopher Goes 2018-10-19 23:01:23 +02:00
parent 843ccaf615
commit 1afb5bf9d2
5 changed files with 16 additions and 11 deletions

View File

@ -51,7 +51,7 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
// Randomly generate some genesis accounts
for _, acc := range accs {
coins := sdk.Coins{sdk.Coin{"steak", sdk.NewInt(100)}}
coins := sdk.Coins{sdk.Coin{"steak", sdk.NewInt(10000)}}
genesisAccounts = append(genesisAccounts, GenesisAccount{
Address: acc.Address,
Coins: coins,
@ -73,20 +73,16 @@ func appStateFn(r *rand.Rand, accs []simulation.Account) json.RawMessage {
valAddrs[i] = valAddr
validator := stake.NewValidator(valAddr, accs[i].PubKey, stake.Description{})
validator.Tokens = sdk.NewDec(100)
validator.DelegatorShares = sdk.NewDec(100)
delegation := stake.Delegation{accs[i].Address, valAddr, sdk.NewDec(100), 0}
validator.Tokens = sdk.NewDec(10000)
validator.DelegatorShares = sdk.NewDec(10000)
delegation := stake.Delegation{accs[i].Address, valAddr, sdk.NewDec(10000), 0}
validators = append(validators, validator)
delegations = append(delegations, delegation)
}
stakeGenesis.Pool.LooseTokens = sdk.NewDec(int64(100*250) + (numInitiallyBonded * 100))
stakeGenesis.Pool.LooseTokens = sdk.NewDec(int64(10000*250) + (numInitiallyBonded * 10000))
stakeGenesis.Validators = validators
stakeGenesis.Bonds = delegations
// No inflation, for now
mintGenesis := mint.DefaultGenesisState()
mintGenesis.Params.InflationMax = sdk.NewDec(0)
mintGenesis.Params.InflationMin = sdk.NewDec(0)
genesis := GenesisState{
Accounts: genesisAccounts,

View File

@ -21,5 +21,8 @@ func BeginBlocker(ctx sdk.Context, k Keeper) {
minter.InflationLastTime = blockTime
minter, mintedCoin := minter.ProcessProvisions(params, totalSupply, bondedRatio)
k.fck.AddCollectedFees(ctx, sdk.Coins{mintedCoin})
pool := k.sk.GetPool(ctx)
pool.LooseTokens = pool.LooseTokens.Add(sdk.NewDecFromInt(mintedCoin.Amount))
k.sk.SetPool(ctx, pool)
k.SetMinter(ctx, minter)
}

View File

@ -1,9 +1,14 @@
package mint
import sdk "github.com/cosmos/cosmos-sdk/types"
import (
sdk "github.com/cosmos/cosmos-sdk/types"
stake "github.com/cosmos/cosmos-sdk/x/stake"
)
// expected stake keeper
type StakeKeeper interface {
GetPool(ctx sdk.Context) stake.Pool
SetPool(ctx sdk.Context, pool stake.Pool)
TotalPower(ctx sdk.Context) sdk.Dec
BondedRatio(ctx sdk.Context) sdk.Dec
InflateSupply(ctx sdk.Context, newTokens sdk.Dec)

View File

@ -6,7 +6,7 @@ import (
// GenesisState - all distribution state that must be provided at genesis
type GenesisState struct {
Minter Minter `json:"Minter"` // minter object
Minter Minter `json:"minter"` // minter object
Params Params `json:"params"` // inflation params
}

View File

@ -40,6 +40,7 @@ func (m Minter) ProcessProvisions(params Params, totalSupply, bondedRatio sdk.De
m.Inflation = m.NextInflation(params, bondedRatio)
provisionsDec := m.Inflation.Mul(totalSupply).Quo(hrsPerYr)
provisions = sdk.NewCoin(params.MintDenom, provisionsDec.TruncateInt())
return m, provisions
}