Skip to content

Commit

Permalink
status update for power reduction test
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh committed Nov 9, 2020
1 parent be1012c commit ebb7698
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 33 deletions.
4 changes: 2 additions & 2 deletions x/staking/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func getBaseSimappWithCustomKeeper() (*codec.LegacyAmino, *simapp.SimApp, sdk.Co
}

// generateAddresses generates numAddrs of normal AccAddrs and ValAddrs
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount int64) ([]sdk.AccAddress, []sdk.ValAddress) {
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, sdk.NewInt(accAmount))
func generateAddresses(app *simapp.SimApp, ctx sdk.Context, numAddrs int, accAmount sdk.Int) ([]sdk.AccAddress, []sdk.ValAddress) {
addrDels := simapp.AddTestAddrsIncremental(app, ctx, numAddrs, accAmount)
addrVals := simapp.ConvertAddrsToValAddrs(addrDels)

return addrDels, addrVals
Expand Down
2 changes: 1 addition & 1 deletion x/staking/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
func bootstrapGenesisTest(t *testing.T, power int64, numAddrs int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress) {
_, app, ctx := getBaseSimappWithCustomKeeper()

addrDels, _ := generateAddresses(app, ctx, numAddrs, 10000)
addrDels, _ := generateAddresses(app, ctx, numAddrs, sdk.NewInt(10000))

amt := sdk.TokensFromConsensusPower(power)
totalSupply := sdk.NewCoins(sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), amt.MulRaw(int64(len(addrDels)))))
Expand Down
76 changes: 46 additions & 30 deletions x/staking/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/golang/protobuf/proto"
)

func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmount int64) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmount sdk.Int) (*simapp.SimApp, sdk.Context, []sdk.AccAddress, []sdk.ValAddress) {
_, app, ctx := getBaseSimappWithCustomKeeper()

addrDels, addrVals := generateAddresses(app, ctx, numAddrs, accAmount)
Expand All @@ -44,7 +44,7 @@ func bootstrapHandlerGenesisTest(t *testing.T, power int64, numAddrs int, accAmo

func TestValidatorByPowerIndex(t *testing.T) {
initPower := int64(1000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, 10000000000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, sdk.TokensFromConsensusPower(initPower))
validatorAddr, validatorAddr3 := valAddrs[0], valAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -121,7 +121,7 @@ func TestValidatorByPowerIndex(t *testing.T) {

func TestDuplicatesMsgCreateValidator(t *testing.T) {
initPower := int64(1000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, 10000000000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 10, sdk.TokensFromConsensusPower(initPower))

addr1, addr2 := valAddrs[0], valAddrs[1]
pk1, pk2 := PKs[0], PKs[1]
Expand Down Expand Up @@ -164,7 +164,8 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
}

func TestInvalidPubKeyTypeMsgCreateValidator(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 1, 1000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, sdk.TokensFromConsensusPower(initPower))
ctx = ctx.WithConsensusParams(&abci.ConsensusParams{
Validator: &tmproto.ValidatorParams{PubKeyTypes: []string{tmtypes.ABCIPubKeyTypeEd25519}},
})
Expand All @@ -178,7 +179,8 @@ func TestInvalidPubKeyTypeMsgCreateValidator(t *testing.T) {
}

func TestLegacyValidatorDelegations(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 100000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))

tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
valAddr := valAddrs[0]
Expand Down Expand Up @@ -258,7 +260,7 @@ func TestLegacyValidatorDelegations(t *testing.T) {
func TestIncrementsMsgDelegate(t *testing.T) {
initPower := int64(1000)
initBond := sdk.TokensFromConsensusPower(initPower)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, 1000000000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))

params := app.StakingKeeper.GetParams(ctx)
validatorAddr, delegatorAddr := valAddrs[0], delAddrs[1]
Expand All @@ -281,7 +283,7 @@ func TestIncrementsMsgDelegate(t *testing.T) {
require.Equal(t, bondAmount, bond.Shares.RoundInt())

bondedTokens := app.StakingKeeper.TotalBondedTokens(ctx)
require.True(t, bondAmount.Equal(bondedTokens))
require.Equal(t, bondAmount.Int64(), bondedTokens.Int64())

for i := int64(0); i < 5; i++ {
ctx = ctx.WithBlockHeight(i)
Expand Down Expand Up @@ -317,7 +319,7 @@ func TestIncrementsMsgDelegate(t *testing.T) {
func TestEditValidatorDecreaseMinSelfDelegation(t *testing.T) {
initPower := int64(100)
initBond := sdk.TokensFromConsensusPower(100)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, 1000000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, sdk.TokensFromConsensusPower(initPower))

validatorAddr := valAddrs[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
Expand Down Expand Up @@ -349,7 +351,7 @@ func TestEditValidatorIncreaseMinSelfDelegationBeyondCurrentBond(t *testing.T) {
initPower := int64(100)
initBond := sdk.TokensFromConsensusPower(100)

app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, 1000000000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
validatorAddr := valAddrs[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -379,7 +381,7 @@ func TestEditValidatorIncreaseMinSelfDelegationBeyondCurrentBond(t *testing.T) {
func TestIncrementsMsgUnbond(t *testing.T) {
initPower := int64(1000)

app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, 1000000000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
params := app.StakingKeeper.GetParams(ctx)
denom := params.BondDenom
Expand Down Expand Up @@ -436,13 +438,13 @@ func TestIncrementsMsgUnbond(t *testing.T) {
gotDelegatorShares := validator.DelegatorShares.RoundInt()
gotDelegatorAcc := app.BankKeeper.GetBalance(ctx, delegatorAddr, params.BondDenom).Amount

require.True(t, expBond.Equal(gotBond),
require.Equal(t, expBond.Int64(), gotBond.Int64(),
"i: %v\nexpBond: %v\ngotBond: %v\nvalidator: %v\nbond: %v\n",
i, expBond, gotBond, validator, bond)
require.True(t, expDelegatorShares.Equal(gotDelegatorShares),
require.Equal(t, expDelegatorShares.Int64(), gotDelegatorShares.Int64(),
"i: %v\nexpDelegatorShares: %v\ngotDelegatorShares: %v\nvalidator: %v\nbond: %v\n",
i, expDelegatorShares, gotDelegatorShares, validator, bond)
require.True(t, expDelegatorAcc.Equal(gotDelegatorAcc),
require.Equal(t, expDelegatorAcc.Int64(), gotDelegatorAcc.Int64(),
"i: %v\nexpDelegatorAcc: %v\ngotDelegatorAcc: %v\nvalidator: %v\nbond: %v\n",
i, expDelegatorAcc, gotDelegatorAcc, validator, bond)
}
Expand All @@ -468,7 +470,7 @@ func TestIncrementsMsgUnbond(t *testing.T) {
func TestMultipleMsgCreateValidator(t *testing.T) {
initPower := int64(1000)
initTokens := sdk.TokensFromConsensusPower(initPower)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, 1000000000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, sdk.TokensFromConsensusPower(initPower))

params := app.StakingKeeper.GetParams(ctx)
blockTime := time.Now().UTC()
Expand Down Expand Up @@ -499,7 +501,7 @@ func TestMultipleMsgCreateValidator(t *testing.T) {
balanceGot := app.BankKeeper.GetBalance(ctx, delegatorAddrs[i], params.BondDenom).Amount

require.Equal(t, i+1, len(validators), "expected %d validators got %d, validators: %v", i+1, len(validators), validators)
require.Equal(t, amt, val.DelegatorShares.RoundInt(), "expected %d shares, got %d", 10, val.DelegatorShares)
require.Equal(t, amt, val.DelegatorShares.RoundInt(), "expected %d shares, got %d", amt, val.DelegatorShares)
require.Equal(t, balanceExpd, balanceGot, "expected account to have %d, got %d", balanceExpd, balanceGot)
}

Expand Down Expand Up @@ -536,7 +538,8 @@ func TestMultipleMsgCreateValidator(t *testing.T) {
}

func TestMultipleMsgDelegate(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 50, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 50, sdk.TokensFromConsensusPower(initPower))
validatorAddr, delegatorAddrs := valAddrs[0], delAddrs[1:]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
var amount int64 = 10
Expand Down Expand Up @@ -569,7 +572,8 @@ func TestMultipleMsgDelegate(t *testing.T) {
}

func TestJailValidator(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
validatorAddr, delegatorAddr := valAddrs[0], delAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
var amt int64 = 10
Expand Down Expand Up @@ -607,7 +611,8 @@ func TestJailValidator(t *testing.T) {
}

func TestValidatorQueue(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
validatorAddr, delegatorAddr := valAddrs[0], delAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -653,7 +658,8 @@ func TestValidatorQueue(t *testing.T) {
}

func TestUnbondingPeriod(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 1, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, sdk.TokensFromConsensusPower(initPower))
validatorAddr := valAddrs[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -691,7 +697,8 @@ func TestUnbondingPeriod(t *testing.T) {
}

func TestUnbondingFromUnbondingValidator(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
validatorAddr, delegatorAddr := valAddrs[0], delAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -723,7 +730,8 @@ func TestUnbondingFromUnbondingValidator(t *testing.T) {
}

func TestRedelegationPeriod(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
validatorAddr, validatorAddr2 := valAddrs[0], valAddrs[1]
denom := app.StakingKeeper.GetParams(ctx).BondDenom
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
Expand All @@ -740,7 +748,7 @@ func TestRedelegationPeriod(t *testing.T) {

// balance should have been subtracted after creation
amt2 := app.BankKeeper.GetBalance(ctx, sdk.AccAddress(validatorAddr), denom).Amount
require.True(t, amt1.Sub(sdk.NewInt(10)).Equal(amt2), "expected coins to be subtracted")
require.Equal(t, amt1.Sub(sdk.NewInt(10)).Int64(), amt2.Int64(), "expected coins to be subtracted")

tstaking.CreateValidator(validatorAddr2, PKs[1], 10, true)
bal1 := app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(validatorAddr))
Expand Down Expand Up @@ -773,7 +781,8 @@ func TestRedelegationPeriod(t *testing.T) {
}

func TestTransitiveRedelegation(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 3, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, sdk.TokensFromConsensusPower(initPower))

val1, val2, val3 := valAddrs[0], valAddrs[1], valAddrs[2]
blockTime := time.Now().UTC()
Expand Down Expand Up @@ -806,7 +815,8 @@ func TestTransitiveRedelegation(t *testing.T) {
}

func TestMultipleRedelegationAtSameTime(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
valAddr := valAddrs[0]
valAddr2 := valAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
Expand Down Expand Up @@ -849,7 +859,8 @@ func TestMultipleRedelegationAtSameTime(t *testing.T) {
}

func TestMultipleRedelegationAtUniqueTimes(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 2, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 2, sdk.TokensFromConsensusPower(initPower))
valAddr := valAddrs[0]
valAddr2 := valAddrs[1]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
Expand Down Expand Up @@ -895,7 +906,8 @@ func TestMultipleRedelegationAtUniqueTimes(t *testing.T) {
}

func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 1, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, sdk.TokensFromConsensusPower(initPower))
valAddr := valAddrs[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -934,7 +946,8 @@ func TestMultipleUnbondingDelegationAtSameTime(t *testing.T) {
}

func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 1, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 1, sdk.TokensFromConsensusPower(initPower))
valAddr := valAddrs[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down Expand Up @@ -981,7 +994,8 @@ func TestMultipleUnbondingDelegationAtUniqueTimes(t *testing.T) {
}

func TestUnbondingWhenExcessValidators(t *testing.T) {
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 3, 1000000000)
initPower := int64(1000)
app, ctx, _, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, sdk.TokensFromConsensusPower(initPower))
val1 := valAddrs[0]
val2 := valAddrs[1]
val3 := valAddrs[2]
Expand Down Expand Up @@ -1020,7 +1034,8 @@ func TestUnbondingWhenExcessValidators(t *testing.T) {
}

func TestBondUnbondRedelegateSlashTwice(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 3, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, sdk.TokensFromConsensusPower(initPower))
valA, valB, del := valAddrs[0], valAddrs[1], delAddrs[2]
consAddr0 := sdk.ConsAddress(PKs[0].Address())
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
Expand Down Expand Up @@ -1124,7 +1139,8 @@ func TestInvalidMsg(t *testing.T) {
}

func TestInvalidCoinDenom(t *testing.T) {
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, 1000, 3, 1000000000)
initPower := int64(1000)
app, ctx, delAddrs, valAddrs := bootstrapHandlerGenesisTest(t, initPower, 3, sdk.TokensFromConsensusPower(initPower))
valA, valB, delAddr := valAddrs[0], valAddrs[1], delAddrs[2]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

Expand Down

0 comments on commit ebb7698

Please sign in to comment.