Skip to content

Commit

Permalink
add big validator set test
Browse files Browse the repository at this point in the history
  • Loading branch information
fbac committed Nov 25, 2024
1 parent c243f17 commit 8a4953b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions precompiles/staking/method_get_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,53 @@ func Test_GetValidators(t *testing.T) {
require.Len(t, list, 1)
require.Equal(t, validator.GetOperator().String(), list[0])
})

t.Run(" should return staker's validator list - heavy test with 100 validators", func(t *testing.T) {
/* ARRANGE */
s := newTestSuite(t)

// Create staker.
stakerEVMAddr := sample.EthAddress()
stakerCosmosAddr, err := precompiletypes.GetCosmosAddress(s.sdkKeepers.BankKeeper, stakerEVMAddr)
require.NoError(t, err)

// Create 100 validators, and stake on each of them.
for n := range 100 {
validator := sample.Validator(t, rand.New(rand.NewSource(int64(n))))
s.sdkKeepers.StakingKeeper.SetValidator(s.ctx, validator)

stakeThroughCosmosAPI(
t,
s.ctx,
s.sdkKeepers.BankKeeper,
s.sdkKeepers.StakingKeeper,
validator,
stakerCosmosAddr,
math.NewInt(100),
)
}

/* ACT */
// Call getValidatorListForDelegator.
getValidatorsMethod := s.stkContractABI.Methods[GetValidatorsMethodName]

s.mockVMContract.Input = packInputArgs(
t,
getValidatorsMethod,
[]interface{}{stakerEVMAddr}...,
)

bytes, err := s.stkContract.Run(s.mockEVM, s.mockVMContract, false)
require.NoError(t, err)

res, err := getValidatorsMethod.Outputs.Unpack(bytes)
require.NoError(t, err)
require.NotEmpty(t, res)

list, ok := res[0].([]string)
require.True(t, ok)

// The returned list should contain 100 entries.
require.Len(t, list, 100)
})
}

0 comments on commit 8a4953b

Please sign in to comment.