github.com/ari-anchor/sei-tendermint@v0.0.0-20230519144642-dc826b7b56bb/internal/test/factory/p2p.go (about)

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