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.

31 lines
678 B

  1. package factory
  2. import (
  3. "encoding/hex"
  4. "strings"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/libs/rand"
  8. "github.com/tendermint/tendermint/types"
  9. )
  10. // NodeID returns a valid NodeID based on an inputted string
  11. func NodeID(t *testing.T, str string) types.NodeID {
  12. t.Helper()
  13. id, err := types.NewNodeID(strings.Repeat(str, 2*types.NodeIDByteLength))
  14. require.NoError(t, err)
  15. return id
  16. }
  17. // RandomNodeID returns a randomly generated valid NodeID
  18. func RandomNodeID(t *testing.T) types.NodeID {
  19. t.Helper()
  20. id, err := types.NewNodeID(hex.EncodeToString(rand.Bytes(types.NodeIDByteLength)))
  21. require.NoError(t, err)
  22. return id
  23. }