You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1008 B

  1. package factory
  2. import (
  3. "context"
  4. "sort"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/types"
  8. )
  9. func Validator(ctx context.Context, votingPower int64) (*types.Validator, types.PrivValidator, error) {
  10. privVal := types.NewMockPV()
  11. pubKey, err := privVal.GetPubKey(ctx)
  12. if err != nil {
  13. return nil, nil, err
  14. }
  15. val := types.NewValidator(pubKey, votingPower)
  16. return val, privVal, nil
  17. }
  18. func ValidatorSet(ctx context.Context, t *testing.T, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) {
  19. var (
  20. valz = make([]*types.Validator, numValidators)
  21. privValidators = make([]types.PrivValidator, numValidators)
  22. )
  23. t.Helper()
  24. for i := 0; i < numValidators; i++ {
  25. val, privValidator, err := Validator(ctx, votingPower)
  26. require.NoError(t, err)
  27. valz[i] = val
  28. privValidators[i] = privValidator
  29. }
  30. sort.Sort(types.PrivValidatorsByAddress(privValidators))
  31. return types.NewValidatorSet(valz), privValidators
  32. }