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.

34 lines
924 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. )
  10. // Transports are mainly tested by common tests in transport_test.go, we
  11. // register a transport factory here to get included in those tests.
  12. func init() {
  13. var network *p2p.MemoryNetwork // shared by transports in the same test
  14. testTransports["memory"] = func(t *testing.T) p2p.Transport {
  15. if network == nil {
  16. network = p2p.NewMemoryNetwork(log.TestingLogger(), 1)
  17. }
  18. i := byte(network.Size())
  19. nodeID, err := p2p.NewNodeID(hex.EncodeToString(bytes.Repeat([]byte{i<<4 + i}, 20)))
  20. require.NoError(t, err)
  21. transport := network.CreateTransport(nodeID)
  22. t.Cleanup(func() {
  23. require.NoError(t, transport.Close())
  24. network = nil // set up a new memory network for the next test
  25. })
  26. return transport
  27. }
  28. }