Update InitGenesis tests for x/stake

This commit is contained in:
Christopher Goes 2018-04-03 20:50:31 +02:00
parent 8fad09a659
commit cfb3ba75af
No known key found for this signature in database
GPG Key ID: E828D98232D328D3
3 changed files with 53 additions and 11 deletions

View File

@ -3,7 +3,6 @@ package stake
import (
"bytes"
"encoding/json"
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire"
@ -356,7 +355,7 @@ func (k Keeper) GetParams(ctx sdk.Context) (params Params) {
store := ctx.KVStore(k.storeKey)
b := store.Get(ParamKey)
if b == nil {
panic(errors.New("Stored params should not have been nil"))
panic("Stored params should not have been nil")
}
err := k.cdc.UnmarshalBinary(b, &params)
@ -386,7 +385,7 @@ func (k Keeper) GetPool(ctx sdk.Context) (gs Pool) {
store := ctx.KVStore(k.storeKey)
b := store.Get(PoolKey)
if b == nil {
panic(errors.New("Stored pool should not have been nil"))
panic("Stored pool should not have been nil")
}
err := k.cdc.UnmarshalBinary(b, &gs)
if err != nil {

View File

@ -2,6 +2,7 @@ package stake
import (
"bytes"
"encoding/json"
"testing"
sdk "github.com/cosmos/cosmos-sdk/types"
@ -573,3 +574,51 @@ func TestPool(t *testing.T) {
resPool = keeper.GetPool(ctx)
assert.Equal(t, expPool, resPool)
}
func TestInitGenesis(t *testing.T) {
ctx, _, keeper := createTestInput(t, nil, false, 0)
encoded := json.RawMessage(`{
"params": {
"inflation_rate_change": {
"num": 13,
"denom": 100
},
"inflation_max": {
"num": 20,
"denom": 100
},
"inflation_min": {
"num": 7,
"denom": 100
},
"goal_bonded": {
"num": 67,
"denom": 100
},
"max_validators": 100,
"bond_denom": "fermion"
},
"pool": {
"total_supply": 0,
"bonded_shares": {
"num": 0,
"denom": 1
},
"unbonded_shares": {
"num": 0,
"denom": 1
},
"bonded_pool": 0,
"unbonded_pool": 0,
"inflation_last_time": 0,
"inflation": {
"num": 7,
"denom": 100
}
}
}`)
err := keeper.InitGenesis(ctx, encoded)
require.Nil(t, err)
require.Equal(t, keeper.GetPool(ctx), initialPool())
require.Equal(t, keeper.GetParams(ctx), defaultParams())
}

View File

@ -2,7 +2,6 @@ package stake
import (
"encoding/hex"
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
@ -149,13 +148,8 @@ func createTestInput(t *testing.T, sender sdk.Address, isCheckTx bool, initCoins
)
ck := bank.NewCoinKeeper(accountMapper)
keeper := NewKeeper(ctx, cdc, keyStake, ck)
encoded, err := json.Marshal(GenesisState{initialPool(), defaultParams()})
if err != nil {
panic(err)
}
if err = keeper.InitGenesis(ctx, encoded); err != nil {
panic(err)
}
keeper.setPool(ctx, initialPool())
keeper.setParams(ctx, defaultParams())
// fill all the addresses with some coins
for _, addr := range addrs {