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
912 B

package p2p_test
import (
"bytes"
"encoding/hex"
"testing"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p"
)
// Transports are mainly tested by common tests in transport_test.go, we
// register a transport factory here to get included in those tests.
func init() {
var network *p2p.MemoryNetwork // shared by transports in the same test
testTransports["memory"] = func(t *testing.T) p2p.Transport {
if network == nil {
network = p2p.NewMemoryNetwork(log.TestingLogger())
}
i := byte(network.Size())
nodeID, err := p2p.NewNodeID(hex.EncodeToString(bytes.Repeat([]byte{i<<4 + i}, 20)))
require.NoError(t, err)
transport := network.CreateTransport(nodeID)
t.Cleanup(func() {
require.NoError(t, transport.Close())
network = nil // set up a new memory network for the next test
})
return transport
}
}