Skip to content

Commit

Permalink
feat: Adds validator qgb checks tests (celestiaorg#138)
Browse files Browse the repository at this point in the history
* first pass on tests fixes

* fixes the rest of unit tests

* remove unnecessary comments

* uses default eth address when starting sim network

* cosmetics

* comments failing test

* comments failing test

* adds orchestrator/ethereum address checks for validators when creating and editing

* uses correct error codes for eth/orch address errors

* uncomments test and fixes it from commit 434b308

* updates tests to be able to set orch/eth address when creating validators

* adds zero eth address check when creating/updating validator

* attempts to fix duplicate eth address in sim network

* adds validator check tests

* revert squashed changes

* uses unwrapped context for msg_server orch/eth validation

* increase DefaultGenTxGas to accomodate new qgb validator changes

* scaffolds an ethereum address from orchestrator address in staking simulation to have a deterministic way of creating it

* fix eth address creation from orch address in operations

* increase DefaultGenTxGas

* increase DefaultGenTxGas

* remove unnecessary eth address
  • Loading branch information
rach-id committed May 9, 2022
1 parent 1118ad6 commit c2d8ade
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 85 deletions.
24 changes: 18 additions & 6 deletions x/distribution/keeper/allocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addrs := simapp.AddTestAddrs(app, ctx, 3, sdk.NewInt(1234))
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, sdk.NewInt(100), true)
tstaking.CreateValidator(sdk.ValAddress(addrs[0]), valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)
val := app.StakingKeeper.Validator(ctx, valAddrs[0])

// allocate tokens
Expand All @@ -48,16 +50,20 @@ func TestAllocateTokensToManyValidators(t *testing.T) {
ctx := app.BaseApp.NewContext(false, tmproto.Header{})

addrs := simapp.AddTestAddrs(app, ctx, 2, sdk.NewInt(1234))
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
valAddrs := simapp.ConvertAddrsToValAddrs(addrs)
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// create second validator with 0% commission
randomEthAddress2, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDec(0), sdk.NewDec(0), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), sdk.AccAddress(valConsPk2.Address()), *randomEthAddress2, true)

abciValA := abci.Validator{
Address: valConsPk1.Address(),
Expand Down Expand Up @@ -123,16 +129,22 @@ func TestAllocateTokensTruncation(t *testing.T) {
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

// create validator with 10% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(110), true)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(110), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// create second validator with 10% commission
randomEthAddress2, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[1], valConsPk2, sdk.NewInt(100), sdk.AccAddress(valConsPk2.Address()), *randomEthAddress2, true)

// create third validator with 10% commission
randomEthAddress3, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(1, 1), sdk.NewDecWithPrec(1, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[2], valConsPk3, sdk.NewInt(100), sdk.AccAddress(valConsPk3.Address()), *randomEthAddress3, true)

abciValA := abci.Validator{
Address: valConsPk1.Address(),
Expand Down
36 changes: 26 additions & 10 deletions x/distribution/keeper/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func TestCalculateRewardsBasic(t *testing.T) {
valAddrs := simapp.ConvertAddrsToValAddrs(addr)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator and start new block
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -78,7 +80,9 @@ func TestCalculateRewardsAfterSlash(t *testing.T) {
// create validator with 50% commission
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
valPower := int64(100)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -139,9 +143,11 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) {
valAddrs := simapp.ConvertAddrsToValAddrs(addr)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
valPower := int64(100)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -214,8 +220,10 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) {
valAddrs := simapp.ConvertAddrsToValAddrs(addr)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -284,9 +292,11 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
app.AccountKeeper.SetModuleAccount(ctx, distrAcc)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
power := int64(100)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
valTokens := tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, power, true)
valTokens := tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, power, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// assert correct initial balance
expTokens := balanceTokens.Sub(valTokens)
Expand Down Expand Up @@ -314,7 +324,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) {
require.Equal(t, uint64(2), app.DistrKeeper.GetValidatorHistoricalReferenceCount(ctx))

// withdraw rewards
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
require.Nil(t, err)

// historical count should still be 2 (added one record, cleared one)
Expand Down Expand Up @@ -348,9 +358,11 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) {
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
valPower := int64(100)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -416,9 +428,11 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) {
valAddrs := simapp.ConvertAddrsToValAddrs(addr)

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
valPower := int64(100)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, true)
tstaking.CreateValidatorWithValPower(valAddrs[0], valConsPk1, valPower, sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -498,8 +512,10 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
tokens := sdk.DecCoins{sdk.NewDecCoinFromDec(sdk.DefaultBondDenom, sdk.NewDec(initial))}

// create validator with 50% commission
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

// end block to bond validator
staking.EndBlocker(ctx, app.StakingKeeper)
Expand Down Expand Up @@ -537,7 +553,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) {
app.DistrKeeper.AllocateTokensToValidator(ctx, val, tokens)

// first delegator withdraws
_, err := app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
_, err = app.DistrKeeper.WithdrawDelegationRewards(ctx, sdk.AccAddress(valAddrs[0]), valAddrs[0])
require.NoError(t, err)

// second delegator withdraws
Expand Down
4 changes: 3 additions & 1 deletion x/distribution/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ func (suite *KeeperTestSuite) TestGRPCDelegationRewards() {

tstaking := teststaking.NewHelper(suite.T(), ctx, app.StakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), true)
randomEthAddress, err := teststaking.RandomEthAddress()
suite.NoError(err)
tstaking.CreateValidator(valAddrs[0], valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

staking.EndBlocker(ctx, app.StakingKeeper)
ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1)
Expand Down
4 changes: 3 additions & 1 deletion x/distribution/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ func TestQueries(t *testing.T) {
// test delegation rewards query
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
tstaking.Commission = stakingtypes.NewCommissionRates(sdk.NewDecWithPrec(5, 1), sdk.NewDecWithPrec(5, 1), sdk.NewDec(0))
tstaking.CreateValidator(valOpAddr1, valConsPk1, sdk.NewInt(100), true)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.CreateValidator(valOpAddr1, valConsPk1, sdk.NewInt(100), sdk.AccAddress(valConsPk1.Address()), *randomEthAddress, true)

staking.EndBlocker(ctx, app.StakingKeeper)

Expand Down
8 changes: 6 additions & 2 deletions x/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign() {
power := int64(100)
stakingParams := suite.app.StakingKeeper.GetParams(ctx)
operatorAddr, val := valAddresses[0], pubkeys[0]
randomEthAddress, err := teststaking.RandomEthAddress()
suite.NoError(err)
tstaking := teststaking.NewHelper(suite.T(), ctx, suite.app.StakingKeeper)

selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
selfDelegation := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true)

// execute end-blocker and verify validator attributes
staking.EndBlocker(ctx, suite.app.StakingKeeper)
Expand Down Expand Up @@ -82,9 +84,11 @@ func (suite *KeeperTestSuite) TestHandleDoubleSign_TooOld() {
power := int64(100)
stakingParams := suite.app.StakingKeeper.GetParams(ctx)
operatorAddr, val := valAddresses[0], pubkeys[0]
randomEthAddress, err := teststaking.RandomEthAddress()
suite.NoError(err)
tstaking := teststaking.NewHelper(suite.T(), ctx, suite.app.StakingKeeper)

amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, true)
amt := tstaking.CreateValidatorWithValPower(operatorAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true)

// execute end-blocker and verify validator attributes
staking.EndBlocker(ctx, suite.app.StakingKeeper)
Expand Down
4 changes: 3 additions & 1 deletion x/slashing/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func TestBeginBlocker(t *testing.T) {

// bond the validator
power := int64(100)
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, true)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
amt := tstaking.CreateValidatorWithValPower(addr, pk, power, sdk.AccAddress(pk.Address()), *randomEthAddress, true)
staking.EndBlocker(ctx, app.StakingKeeper)
require.Equal(
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),
Expand Down
19 changes: 14 additions & 5 deletions x/slashing/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ func TestCannotUnjailUnlessJailed(t *testing.T) {
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
slh := slashing.NewHandler(app.SlashingKeeper)
addr, val := sdk.ValAddress(pks[0].Address()), pks[0]
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)

amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, sdk.AccAddress(val.Address()), *randomEthAddress, true)
staking.EndBlocker(ctx, app.StakingKeeper)
require.Equal(
t, app.BankKeeper.GetAllBalances(ctx, sdk.AccAddress(addr)),
Expand All @@ -58,7 +60,10 @@ func TestCannotUnjailUnlessMeetMinSelfDelegation(t *testing.T) {
slh := slashing.NewHandler(app.SlashingKeeper)
addr, val := sdk.ValAddress(pks[0].Address()), pks[0]
amt := app.StakingKeeper.TokensFromConsensusPower(ctx, 100)
msg := tstaking.CreateValidatorMsg(addr, val, amt)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)

msg := tstaking.CreateValidatorMsg(addr, val, amt, sdk.AccAddress(val.Address()), *randomEthAddress)
msg.MinSelfDelegation = amt
tstaking.Handle(msg, true)

Expand Down Expand Up @@ -91,8 +96,10 @@ func TestJailedValidatorDelegations(t *testing.T) {
stakingParams := app.StakingKeeper.GetParams(ctx)
app.StakingKeeper.SetParams(ctx, stakingParams)
valAddr, consAddr := sdk.ValAddress(pks[1].Address()), sdk.ConsAddress(pks[0].Address())
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)

amt := tstaking.CreateValidatorWithValPower(valAddr, pks[1], 10, true)
amt := tstaking.CreateValidatorWithValPower(valAddr, pks[1], 10, sdk.AccAddress(pks[1].Address()), *randomEthAddress, true)
staking.EndBlocker(ctx, app.StakingKeeper)

// set dummy signing info
Expand All @@ -106,7 +113,7 @@ func TestJailedValidatorDelegations(t *testing.T) {
// unbond validator total self-delegations (which should jail the validator)
valAcc := sdk.AccAddress(valAddr)
tstaking.Undelegate(valAcc, valAddr, amt, true)
_, err := app.StakingKeeper.CompleteUnbonding(ctx, sdk.AccAddress(valAddr), valAddr)
_, err = app.StakingKeeper.CompleteUnbonding(ctx, sdk.AccAddress(valAddr), valAddr)
require.Nil(t, err, "expected complete unbonding validator to be ok, got: %v", err)

// verify validator still exists and is jailed
Expand Down Expand Up @@ -150,10 +157,12 @@ func TestHandleAbsentValidator(t *testing.T) {

power := int64(100)
addr, val := sdk.ValAddress(pks[0].Address()), pks[0]
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
slh := slashing.NewHandler(app.SlashingKeeper)
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
amt := tstaking.CreateValidatorWithValPower(addr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true)
staking.EndBlocker(ctx, app.StakingKeeper)

require.Equal(
Expand Down
24 changes: 18 additions & 6 deletions x/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func TestUnJailNotBonded(t *testing.T) {
// create max (5) validators all with the same power
for i := uint32(0); i < p.MaxValidators; i++ {
addr, val := valAddrs[i], pks[i]
tstaking.CreateValidatorWithValPower(addr, val, 100, true)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.CreateValidatorWithValPower(addr, val, 100, sdk.AccAddress(val.Address()), *randomEthAddress, true)
}

staking.EndBlocker(ctx, app.StakingKeeper)
Expand All @@ -40,7 +42,9 @@ func TestUnJailNotBonded(t *testing.T) {
// create a 6th validator with less power than the cliff validator (won't be bonded)
addr, val := valAddrs[5], pks[5]
amt := app.StakingKeeper.TokensFromConsensusPower(ctx, 50)
msg := tstaking.CreateValidatorMsg(addr, val, amt)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
msg := tstaking.CreateValidatorMsg(addr, val, amt, sdk.AccAddress(val.Address()), *randomEthAddress)
msg.MinSelfDelegation = amt
tstaking.Handle(msg, true)

Expand Down Expand Up @@ -89,9 +93,11 @@ func TestHandleNewValidator(t *testing.T) {
addr, val := valAddrs[0], pks[0]
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
ctx = ctx.WithBlockHeight(app.SlashingKeeper.SignedBlocksWindow(ctx) + 1)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)

// Validator created
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, true)
amt := tstaking.CreateValidatorWithValPower(addr, val, 100, sdk.AccAddress(val.Address()), *randomEthAddress, true)

staking.EndBlocker(ctx, app.StakingKeeper)
require.Equal(
Expand Down Expand Up @@ -132,9 +138,11 @@ func TestHandleAlreadyJailed(t *testing.T) {
pks := simapp.CreateTestPubKeys(1)
addr, val := valAddrs[0], pks[0]
power := int64(100)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)

amt := tstaking.CreateValidatorWithValPower(addr, val, power, true)
amt := tstaking.CreateValidatorWithValPower(addr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true)

staking.EndBlocker(ctx, app.StakingKeeper)

Expand Down Expand Up @@ -194,8 +202,10 @@ func TestValidatorDippingInAndOut(t *testing.T) {
consAddr := sdk.ConsAddress(addr)
tstaking := teststaking.NewHelper(t, ctx, app.StakingKeeper)
valAddr := sdk.ValAddress(addr)
randomEthAddress, err := teststaking.RandomEthAddress()
require.NoError(t, err)

tstaking.CreateValidatorWithValPower(valAddr, val, power, true)
tstaking.CreateValidatorWithValPower(valAddr, val, power, sdk.AccAddress(val.Address()), *randomEthAddress, true)
staking.EndBlocker(ctx, app.StakingKeeper)

// 100 first blocks OK
Expand All @@ -206,7 +216,9 @@ func TestValidatorDippingInAndOut(t *testing.T) {
}

// kick first validator out of validator set
tstaking.CreateValidatorWithValPower(sdk.ValAddress(pks[1].Address()), pks[1], 101, true)
randomEthAddress2, err := teststaking.RandomEthAddress()
require.NoError(t, err)
tstaking.CreateValidatorWithValPower(sdk.ValAddress(pks[1].Address()), pks[1], 101, sdk.AccAddress(pks[1].Address()), *randomEthAddress2, true)
validatorUpdates := staking.EndBlocker(ctx, app.StakingKeeper)
require.Equal(t, 2, len(validatorUpdates))
tstaking.CheckValidator(valAddr, stakingtypes.Unbonding, false)
Expand Down
Loading

0 comments on commit c2d8ade

Please sign in to comment.