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.

36 lines
968 B

  1. package p2p_test
  2. import (
  3. "bytes"
  4. "encoding/hex"
  5. "testing"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/internal/p2p"
  8. "github.com/tendermint/tendermint/libs/log"
  9. "github.com/tendermint/tendermint/types"
  10. )
  11. // Transports are mainly tested by common tests in transport_test.go, we
  12. // register a transport factory here to get included in those tests.
  13. func init() {
  14. var network *p2p.MemoryNetwork // shared by transports in the same test
  15. testTransports["memory"] = func(t *testing.T) p2p.Transport {
  16. if network == nil {
  17. network = p2p.NewMemoryNetwork(log.NewNopLogger(), 1)
  18. }
  19. i := byte(network.Size())
  20. nodeID, err := types.NewNodeID(hex.EncodeToString(bytes.Repeat([]byte{i<<4 + i}, 20)))
  21. require.NoError(t, err)
  22. transport := network.CreateTransport(nodeID)
  23. t.Cleanup(func() {
  24. require.NoError(t, transport.Close())
  25. network = nil // set up a new memory network for the next test
  26. })
  27. return transport
  28. }
  29. }