Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Treglia committed Feb 28, 2019
1 parent 1deacab commit eca60dd
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 91 deletions.
10 changes: 5 additions & 5 deletions x/staking/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestStakingMsgs(t *testing.T) {
// create validator
description := NewDescription("foo_moniker", "", "", "")
createValidatorMsg := NewMsgCreateValidator(
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionMsg, sdk.OneInt(),
sdk.ValAddress(addr1), priv1.PubKey(), bondCoin, description, commissionMsg, sdk.OneUint(),
)

mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{createValidatorMsg}, []uint64{0}, []uint64{0}, true, true, priv1)
Expand All @@ -133,7 +133,7 @@ func TestStakingMsgs(t *testing.T) {

// addr1 create validator on behalf of addr2
createValidatorMsgOnBehalfOf := NewMsgCreateValidatorOnBehalfOf(
addr1, sdk.ValAddress(addr2), priv2.PubKey(), bondCoin, description, commissionMsg, sdk.OneInt(),
addr1, sdk.ValAddress(addr2), priv2.PubKey(), bondCoin, description, commissionMsg, sdk.OneUint(),
)

mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{createValidatorMsgOnBehalfOf}, []uint64{0, 0}, []uint64{1, 0}, true, true, priv1, priv2)
Expand All @@ -146,7 +146,7 @@ func TestStakingMsgs(t *testing.T) {
require.True(sdk.IntEq(t, bondTokens, validator.Tokens))

// check the bond that should have been created as well
checkDelegation(t, mApp, keeper, addr1, sdk.ValAddress(addr1), true, sdk.NewDecFromInt(bondTokens))
checkDelegation(t, mApp, keeper, addr1, sdk.ValAddress(addr1), true, sdk.NewDecFromUint(bondTokens))

// edit the validator
description = NewDescription("bar_moniker", "", "", "")
Expand All @@ -162,10 +162,10 @@ func TestStakingMsgs(t *testing.T) {

mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{delegateMsg}, []uint64{0}, []uint64{1}, true, true, priv2)
mock.CheckBalance(t, mApp, addr2, sdk.Coins{genCoin.Sub(bondCoin)})
checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), true, sdk.NewDecFromInt(bondTokens))
checkDelegation(t, mApp, keeper, addr2, sdk.ValAddress(addr1), true, sdk.NewDecFromUint(bondTokens))

// begin unbonding
beginUnbondingMsg := NewMsgUndelegate(addr2, sdk.ValAddress(addr1), sdk.NewDecFromInt(bondTokens))
beginUnbondingMsg := NewMsgUndelegate(addr2, sdk.ValAddress(addr1), sdk.NewDecFromUint(bondTokens))
mock.SignCheckDeliver(t, mApp.Cdc, mApp.BaseApp, []sdk.Msg{beginUnbondingMsg}, []uint64{0}, []uint64{2}, true, true, priv2)

// delegation should exist anymore
Expand Down
7 changes: 4 additions & 3 deletions x/staking/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ func InitGenesis(ctx sdk.Context, keeper Keeper, data types.GenesisState) (res [
panic("expected validator, not found")
}
update := validator.ABCIValidatorUpdate()
update.Power = lv.Power // keep the next-val-set offset, use the last power for the first block
update.Power = int64(lv.Power) // keep the next-val-set offset,
// use the last power for the first block
res = append(res, update)
}
} else {
Expand Down Expand Up @@ -111,7 +112,7 @@ func ExportGenesis(ctx sdk.Context, keeper Keeper) types.GenesisState {
return false
})
var lastValidatorPowers []types.LastValidatorPower
keeper.IterateLastValidatorPowers(ctx, func(addr sdk.ValAddress, power int64) (stop bool) {
keeper.IterateLastValidatorPowers(ctx, func(addr sdk.ValAddress, power uint64) (stop bool) {
lastValidatorPowers = append(lastValidatorPowers, types.LastValidatorPower{addr, power})
return false
})
Expand All @@ -134,7 +135,7 @@ func WriteValidators(ctx sdk.Context, keeper Keeper) (vals []tmtypes.GenesisVali
keeper.IterateLastValidators(ctx, func(_ int64, validator sdk.Validator) (stop bool) {
vals = append(vals, tmtypes.GenesisValidator{
PubKey: validator.GetConsPubKey(),
Power: validator.GetTendermintPower(),
Power: int64(validator.GetTendermintPower()),
Name: validator.GetMoniker(),
})

Expand Down
10 changes: 5 additions & 5 deletions x/staking/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ func TestInitGenesis(t *testing.T) {
validators[0].Description = NewDescription("hoop", "", "", "")
validators[0].Status = sdk.Bonded
validators[0].Tokens = valTokens
validators[0].DelegatorShares = sdk.NewDecFromInt(valTokens)
validators[0].DelegatorShares = sdk.NewDecFromUint(valTokens)
validators[1].OperatorAddr = sdk.ValAddress(keep.Addrs[1])
validators[1].ConsPubKey = keep.PKs[1]
validators[1].Description = NewDescription("bloop", "", "", "")
validators[1].Status = sdk.Bonded
validators[1].Tokens = valTokens
validators[1].DelegatorShares = sdk.NewDecFromInt(valTokens)
validators[1].DelegatorShares = sdk.NewDecFromUint(valTokens)

genesisState := types.NewGenesisState(pool, params, validators, delegations)
vals, err := InitGenesis(ctx, keeper, genesisState)
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {

// Assigning 2 to the first 100 vals, 1 to the rest
pool := keeper.GetPool(ctx)
bondedTokens := sdk.TokensFromTendermintPower(int64(200 + (size - 100)))
bondedTokens := sdk.TokensFromTendermintPower(uint64(200 + (size - 100)))
pool.BondedTokens = bondedTokens

params := keeper.GetParams(ctx)
Expand All @@ -94,7 +94,7 @@ func TestInitGenesisLargeValidatorSet(t *testing.T) {
tokens = sdk.TokensFromTendermintPower(2)
}
validators[i].Tokens = tokens
validators[i].DelegatorShares = sdk.NewDecFromInt(tokens)
validators[i].DelegatorShares = sdk.NewDecFromUint(tokens)
}

genesisState := types.NewGenesisState(pool, params, validators, delegations)
Expand All @@ -113,7 +113,7 @@ func TestValidateGenesis(t *testing.T) {
genValidators1 := make([]types.Validator, 1, 5)
pk := ed25519.GenPrivKey().PubKey()
genValidators1[0] = types.NewValidator(sdk.ValAddress(pk.Address()), pk, types.NewDescription("", "", "", ""))
genValidators1[0].Tokens = sdk.OneInt()
genValidators1[0].Tokens = sdk.OneUint()
genValidators1[0].DelegatorShares = sdk.OneDec()

tests := []struct {
Expand Down
Loading

0 comments on commit eca60dd

Please sign in to comment.