validator.Operator, sdk.Dec

This commit is contained in:
Christopher Goes 2018-08-20 17:10:43 +02:00
parent 98a5844310
commit 800ac2844e
4 changed files with 16 additions and 16 deletions

View File

@ -59,18 +59,18 @@ func appStateFn(r *rand.Rand, keys []crypto.PrivKey, accs []sdk.AccAddress) json
numInitiallyBonded := int64(50)
for i := 0; i < int(numInitiallyBonded); i++ {
validator := stake.NewValidator(accs[i], keys[i].PubKey(), stake.Description{})
validator.Tokens = sdk.NewRat(100)
validator.DelegatorShares = sdk.NewRat(100)
delegation := stake.Delegation{accs[i], accs[i], sdk.NewRat(100), 0}
validator.Tokens = sdk.NewDec(100)
validator.DelegatorShares = sdk.NewDec(100)
delegation := stake.Delegation{accs[i], accs[i], sdk.NewDec(100), 0}
validators = append(validators, validator)
delegations = append(delegations, delegation)
}
stakeGenesis.Pool.LooseTokens = sdk.NewRat(int64(100*250) + (numInitiallyBonded * 100))
stakeGenesis.Pool.LooseTokens = sdk.NewDec(int64(100*250) + (numInitiallyBonded * 100))
stakeGenesis.Validators = validators
stakeGenesis.Bonds = delegations
// No inflation, for now
stakeGenesis.Params.InflationMax = sdk.NewRat(0)
stakeGenesis.Params.InflationMin = sdk.NewRat(0)
stakeGenesis.Params.InflationMax = sdk.NewDec(0)
stakeGenesis.Params.InflationMin = sdk.NewDec(0)
genesis := GenesisState{
Accounts: genesisAccounts,
StakeData: stakeGenesis,

View File

@ -39,7 +39,7 @@ func SimulateMsgSubmitProposal(k gov.Keeper, sk stake.Keeper) simulation.TestAnd
if result.IsOK() {
// Update pool to keep invariants
pool := sk.GetPool(ctx)
pool.LooseTokens = pool.LooseTokens.Sub(sdk.NewRatFromInt(deposit.AmountOf(denom)))
pool.LooseTokens = pool.LooseTokens.Sub(sdk.NewDecFromInt(deposit.AmountOf(denom)))
sk.SetPool(ctx, pool)
write()
}
@ -66,7 +66,7 @@ func SimulateMsgDeposit(k gov.Keeper, sk stake.Keeper) simulation.TestAndRunTx {
if result.IsOK() {
// Update pool to keep invariants
pool := sk.GetPool(ctx)
pool.LooseTokens = pool.LooseTokens.Sub(sdk.NewRatFromInt(deposit.AmountOf(denom)))
pool.LooseTokens = pool.LooseTokens.Sub(sdk.NewDecFromInt(deposit.AmountOf(denom)))
sk.SetPool(ctx, pool)
write()
}

View File

@ -102,8 +102,8 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
keeper.SetParams(ctx, params)
// create a random pool
pool.LooseTokens = sdk.NewRat(10000)
pool.BondedTokens = sdk.NewRat(1234)
pool.LooseTokens = sdk.NewDec(10000)
pool.BondedTokens = sdk.NewDec(1234)
keeper.SetPool(ctx, pool)
validators := make([]types.Validator, numVals)
@ -123,13 +123,13 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
// remove enough tokens to kick out the validator below the current cliff
// validator and next in line cliff validator
nextCliffVal, pool, _ = nextCliffVal.RemoveDelShares(pool, sdk.NewRat(21))
nextCliffVal, pool, _ = nextCliffVal.RemoveDelShares(pool, sdk.NewDec(21))
keeper.SetPool(ctx, pool)
nextCliffVal = keeper.UpdateValidator(ctx, nextCliffVal)
// require the cliff validator has changed
cliffVal := validators[numVals-maxVals-1]
require.Equal(t, cliffVal.Owner, sdk.AccAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, cliffVal.Operator, sdk.AccAddress(keeper.GetCliffValidator(ctx)))
// require the cliff validator power has changed
cliffPower := keeper.GetCliffValidatorPower(ctx)
@ -142,7 +142,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
// require all the validators have their respective statuses
for valIdx, status := range expectedValStatus {
valAddr := validators[valIdx].Owner
valAddr := validators[valIdx].Operator
val, _ := keeper.GetValidator(ctx, valAddr)
require.Equal(
@ -213,7 +213,7 @@ func TestCliffValidatorChange(t *testing.T) {
// assert new cliff validator due to power rank construction
newCliffVal = validators[numVals-maxVals+2]
require.Equal(t, newCliffVal.Owner, sdk.AccAddress(keeper.GetCliffValidator(ctx)))
require.Equal(t, newCliffVal.Operator, sdk.AccAddress(keeper.GetCliffValidator(ctx)))
// assert cliff validator power should have been updated
cliffPower = keeper.GetCliffValidatorPower(ctx)

View File

@ -236,8 +236,8 @@ func Setup(mapp *mock.App, k stake.Keeper) simulation.RandSetup {
return func(r *rand.Rand, privKeys []crypto.PrivKey) {
ctx := mapp.NewContext(false, abci.Header{})
gen := stake.DefaultGenesisState()
gen.Params.InflationMax = sdk.NewRat(0)
gen.Params.InflationMin = sdk.NewRat(0)
gen.Params.InflationMax = sdk.NewDec(0)
gen.Params.InflationMin = sdk.NewDec(0)
stake.InitGenesis(ctx, k, gen)
params := k.GetParams(ctx)
denom := params.BondDenom