From 4b5a5d20572b89a34ed0abc2e0f80bd4a8cfdaf7 Mon Sep 17 00:00:00 2001 From: Bryan White Date: Mon, 29 May 2023 14:27:06 +0200 Subject: [PATCH] wip: checkpoint --- go.sum | 2 + internal/testutil/bus.go | 7 +- .../testutil/constructors/constructors.go | 135 +++++---- internal/testutil/module.go | 41 +++ internal/testutil/network.go | 73 +++++ internal/testutil/p2p/network.go | 49 +--- internal/testutil/runtime/genesis.go | 28 +- p2p/integration/background_gossip_test.go | 26 +- p2p/integration/peer_discovery.feature | 96 ++++--- p2p/integration/peer_discovery_test.go | 262 ++++++++++++++---- p2p/module.go | 2 +- p2p/module_raintree_test.go | 165 ++++++----- p2p/module_test.go | 3 +- p2p/transport_encryption_test.go | 3 +- 14 files changed, 587 insertions(+), 305 deletions(-) create mode 100644 internal/testutil/module.go create mode 100644 internal/testutil/network.go diff --git a/go.sum b/go.sum index e6bfcade0d..2726611803 100644 --- a/go.sum +++ b/go.sum @@ -694,6 +694,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pokt-network/go-mockdns v0.0.1 h1:1Kb/kIFH6bNtY9F1bFhJyMRMCc7WyiqfGg0hotBZ1JI= +github.com/pokt-network/go-mockdns v0.0.1/go.mod h1:lgRN6+KxQBawyIghpnl5CezHFGS9VLzvtVlwxvzXTQ4= github.com/pokt-network/gocuke v0.0.1 h1:qJ/Ryf+hi5L6T9lsOZDNbiAclHkLlDio5/eVKQEYhgE= github.com/pokt-network/gocuke v0.0.1/go.mod h1:BowLKW4++696gTTU33teodtIhjjyaphEbhQT9D5Refw= github.com/pokt-network/smt v0.4.0 h1:fodLphes/EtQw+nr6Zc5giSJdnjIkM2BY6cGTOfTaqo= diff --git a/internal/testutil/bus.go b/internal/testutil/bus.go index 972965eca5..1f83597a39 100644 --- a/internal/testutil/bus.go +++ b/internal/testutil/bus.go @@ -75,8 +75,11 @@ func WithBusEventHandler( ) *mock_modules.MockBus { t.Helper() - handler := handlerFactory(t, busMock) - busMock.EXPECT().PublishEventToBus(gomock.Any()).Do(handler).AnyTimes() + if handlerFactory != nil { + handler := handlerFactory(t, busMock) + busMock.EXPECT().PublishEventToBus(gomock.Any()).Do(handler).AnyTimes() + } + return busMock } diff --git a/internal/testutil/constructors/constructors.go b/internal/testutil/constructors/constructors.go index 3fd96a39a5..5491c981a7 100644 --- a/internal/testutil/constructors/constructors.go +++ b/internal/testutil/constructors/constructors.go @@ -1,6 +1,7 @@ package constructors import ( + "github.com/foxcpp/go-mockdns" libp2pHost "github.com/libp2p/go-libp2p/core/host" mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" "github.com/pokt-network/pocket/internal/testutil/bus" @@ -25,6 +26,7 @@ type serviceURLStr = string func NewBusesMocknetAndP2PModules( t gocuke.TestingT, count int, + dnsSrv *mockdns.Server, genesisState *genesis.GenesisState, busEventHandlerFactory testutil.BusEventHandlerFactory, ) ( @@ -32,78 +34,92 @@ func NewBusesMocknetAndP2PModules( libp2pNetworkMock mocknet.Mocknet, p2pModules map[serviceURLStr]modules.P2PModule, ) { - // TODO_THIS_COMMIT: refactor - dnsSrv := testutil.MinimalDNSMock(t) - - libp2pNetworkMock = mocknet.New() - // destroy mocknet on test cleanup - t.Cleanup(func() { - err := libp2pNetworkMock.Close() - require.NoError(t, err) - }) - - buses = make(map[serviceURLStr]*mock_modules.MockBus) - p2pModules = make(map[serviceURLStr]modules.P2PModule) - // CONSIDERATION: using an iterator/generator would prevent unintentional - // ID collisions - privKeys := testutil.LoadLocalnetPrivateKeys(t, count) - // CONSIDERATION: using an iterator/generator would prevent unintentional - // serviceURL collisions - serviceURLs := p2p_testutil.SequentialServiceURLs(t, count) - for i, serviceURL := range serviceURLs { - if len(privKeys) <= i { - t.Logf("WARNING: not enough private keys for %d service URLs", len(serviceURLs)) - break - } - - privKey := privKeys[i] - busMock := bus_testutil.NewBus(t, privKey, serviceURL, genesisState, busEventHandlerFactory) - buses[serviceURL] = busMock - - // TODO_THIS_COMMIT: refactor - _ = consensus_testutil.BaseConsensusMock(t, busMock) - _ = persistence_testutil.BasePersistenceMock(t, busMock, genesisState) - - // -- option 1 - _ = telemetry_testutil.BaseTelemetryMock(t, busMock) - - // -- option 2 - //_ = telemetry_testutil.WithTimeSeriesAgent( - // t, telemetry_testutil.MinimalTelemetryMock(t, busMock), - //) - - // MUST register DNS before instantiating P2PModule - testutil.AddServiceURLZone(t, dnsSrv, serviceURL) - - host := p2p_testutil.NewMocknetHost(t, libp2pNetworkMock, privKey) - p2pModules[serviceURL] = NewP2PModuleWithHost(t, busMock, host) - } + libp2pNetworkMock = p2p_testutil.NewLibp2pNetworkMock(t) + serviceURLKeyMap := testutil.SequentialServiceURLPrivKeyMap(t, count) + + buses, p2pModules = NewBusesAndP2PModules( + t, busEventHandlerFactory, + dnsSrv, + genesisState, + libp2pNetworkMock, + serviceURLKeyMap, + ) err := libp2pNetworkMock.LinkAll() require.NoError(t, err) return buses, libp2pNetworkMock, p2pModules } -// TODO_THIS_TEST: need this? -func NewP2PModules( +// TODO_THIS_COMMIT: rename / move, if possible +func NewP2PModule( t gocuke.TestingT, - privKeys []cryptoPocket.PrivateKey, + // TODO_THIS_COMMIT: get these from the bus instead + serviceURL string, + privKey cryptoPocket.PrivateKey, + // -- busMock *mock_modules.MockBus, + genesisState *genesis.GenesisState, + dnsSrv *mockdns.Server, + libp2pNetworkMock mocknet.Mocknet, + // TODO_THIS_COMMIT: consider *p2p.P2PModule instead +) modules.P2PModule { + _ = consensus_testutil.BaseConsensusMock(t, busMock) + _ = persistence_testutil.BasePersistenceMock(t, busMock, genesisState) + + // -- option 1 + _ = telemetry_testutil.BaseTelemetryMock(t, busMock) + + // -- option 2 + //_ = telemetry_testutil.WithTimeSeriesAgent( + // t, telemetry_testutil.MinimalTelemetryMock(t, busMock), + //) + + // MUST register DNS before instantiating P2PModule + testutil.AddServiceURLZone(t, dnsSrv, serviceURL) + + host := testutil.NewMocknetHost(t, libp2pNetworkMock, privKey) + return NewP2PModuleWithHost(t, busMock, host) +} + +// TODO_THIS_TEST: need this? +func NewBusesAndP2PModules( + t gocuke.TestingT, + busEventHandlerFactory testutil.BusEventHandlerFactory, + dnsSrv *mockdns.Server, + genesisState *genesis.GenesisState, libp2pNetworkMock mocknet.Mocknet, + serviceURLKeyMap map[serviceURLStr]cryptoPocket.PrivateKey, ) ( + busMocks map[serviceURLStr]*mock_modules.MockBus, + // TODO_THIS_COMMIT: consider *p2p.P2PModule instead p2pModules map[serviceURLStr]modules.P2PModule, ) { - // CONSIDERATION: using an iterator/generator would prevent unintentional - // serviceURL collisions - serviceURLs := p2p_testutil.SequentialServiceURLs(t, len(privKeys)) - _ = p2p_testutil.SetupMockNetPeers(t, libp2pNetworkMock, privKeys, serviceURLs) - - for i, serviceURL := range serviceURLs { - host := libp2pNetworkMock.Hosts()[i] - // TECHDEBT: refactor - p2pModules[serviceURL] = NewP2PModuleWithHost(t, busMock, host) + busMocks = make(map[serviceURLStr]*mock_modules.MockBus) + p2pModules = make(map[serviceURLStr]modules.P2PModule) + + for serviceURL, privKey := range serviceURLKeyMap { + busMock := bus_testutil.NewBus( + t, privKey, + serviceURL, + genesisState, + busEventHandlerFactory, + ) + busMocks[serviceURL] = busMock + + p2pModules[serviceURL] = NewP2PModule( + t, serviceURL, + // TODO_THIS_COMMIT: send via busMock instead + privKey, + busMock, + // TODO_THIS_COMMIT: send via busMock instead + genesisState, + // TODO_THIS_COMMIT: send via busMock instead (?) + dnsSrv, + // TODO_THIS_COMMIT: send via busMock instead (?) + libp2pNetworkMock, + ) } - return p2pModules + return busMocks, p2pModules } // TODO_THIS_TEST: need this? @@ -122,6 +138,7 @@ func NewBusesAndP2PModuleWithHost( return busMock, NewP2PModuleWithHost(t, busMock, host) } +// TODO_THIS_COMMIT: rename; consider returning *p2p.P2PModule instead func NewP2PModuleWithHost( t gocuke.TestingT, busMock *mock_modules.MockBus, diff --git a/internal/testutil/module.go b/internal/testutil/module.go new file mode 100644 index 0000000000..a59710b028 --- /dev/null +++ b/internal/testutil/module.go @@ -0,0 +1,41 @@ +package testutil + +import ( + "github.com/foxcpp/go-mockdns" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/pokt-network/pocket/runtime/genesis" + "github.com/pokt-network/pocket/shared/modules" + "github.com/pokt-network/pocket/shared/modules/base_modules" +) + +// TODO_THIS_COMMIT: is this helpful? +const TestModuleName = "testModule" + +var ( + _ modules.Module = &TestModule{} + _ modules.ModuleFactoryWithOptions = &TestModule{} +) + +type TestModule struct { + base_modules.IntegratableModule + base_modules.InterruptableModule + + DNS *mockdns.Server + Genesis *genesis.GenesisState + Libp2pNetworkMock mocknet.Mocknet +} + +func (m *TestModule) GetModuleName() string { + return TestModuleName +} + +func (m *TestModule) Create( + bus modules.Bus, + opts ...modules.ModuleOption, +) (modules.Module, error) { + panic("implement me") +} + +func (m *TestModule) GetDNS() *mockdns.Server { + return m.DNS +} diff --git a/internal/testutil/network.go b/internal/testutil/network.go new file mode 100644 index 0000000000..1403dca464 --- /dev/null +++ b/internal/testutil/network.go @@ -0,0 +1,73 @@ +package testutil + +import ( + "fmt" + + crypto2 "github.com/libp2p/go-libp2p/core/crypto" + "github.com/libp2p/go-libp2p/core/host" + "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/multiformats/go-multiaddr" + "github.com/regen-network/gocuke" + "github.com/stretchr/testify/require" + + "github.com/pokt-network/pocket/runtime/defaults" + "github.com/pokt-network/pocket/shared/crypto" +) + +const ServiceURLFormat = "node%d.consensus:42069" + +func NewMocknetHost( + t gocuke.TestingT, + libp2pNetworkMock mocknet.Mocknet, + privKey crypto.PrivateKey, +) host.Host { + t.Helper() + + // TODO_THIS_COMMIT: move to const + addrMock, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/10.0.0.1/tcp/%d", defaults.DefaultP2PPort)) + require.NoError(t, err) + + libp2pPrivKey, err := crypto2.UnmarshalEd25519PrivateKey(privKey.Bytes()) + require.NoError(t, err) + + host, err := libp2pNetworkMock.AddPeer(libp2pPrivKey, addrMock) + require.NoError(t, err) + + return host +} + +func SequentialServiceURLPrivKeyMap(t gocuke.TestingT, count int) map[string]crypto.PrivateKey { + t.Helper() + + // CONSIDERATION: using an iterator/generator would prevent unintentional + // ID collisions + privKeys := LoadLocalnetPrivateKeys(t, count) + // CONSIDERATION: using an iterator/generator would prevent unintentional + // serviceURL collisions + serviceURLs := SequentialServiceURLs(t, count) + + require.GreaterOrEqualf(t, len(privKeys), len(serviceURLs), "not enough private keys for service URLs") + + serviceURLKeysMap := make(map[string]crypto.PrivateKey, len(serviceURLs)) + + for i, serviceURL := range serviceURLs { + serviceURLKeysMap[serviceURL] = privKeys[i] + } + return serviceURLKeysMap +} + +// CONSIDERATION: serviceURLs are only unique within their respective slice; +// consider building an iterator/generator instead. +func SequentialServiceURLs(t gocuke.TestingT, count int) (serviceURLs []string) { + t.Helper() + + for i := 0; i < count; i++ { + serviceURLs = append(serviceURLs, NewServiceURL(i+1)) + } + return serviceURLs +} + +// TECHDEBT: rename `validatorId()` to `serviceURL()` +func NewServiceURL(i int) string { + return fmt.Sprintf(ServiceURLFormat, i) +} diff --git a/internal/testutil/p2p/network.go b/internal/testutil/p2p/network.go index 77fdb9edb1..23196a6c89 100644 --- a/internal/testutil/p2p/network.go +++ b/internal/testutil/p2p/network.go @@ -1,14 +1,10 @@ package p2p_testutil import ( - "fmt" "github.com/libp2p/go-libp2p/core/crypto" - libp2pHost "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/peer" libp2pPeer "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/p2p/net/mock" - "github.com/multiformats/go-multiaddr" - "github.com/pokt-network/pocket/runtime/defaults" "github.com/regen-network/gocuke" "github.com/stretchr/testify/require" @@ -25,30 +21,23 @@ func NewMocknetWithNPeers(t gocuke.TestingT, peerCount int) (mocknet.Mocknet, [] // load pre-generated validator keypairs libp2pNetworkMock := mocknet.New() privKeys := testutil.LoadLocalnetPrivateKeys(t, peerCount) - serviceURLs := SequentialServiceURLs(t, peerCount) + serviceURLs := testutil.SequentialServiceURLs(t, peerCount) _ = SetupMockNetPeers(t, libp2pNetworkMock, privKeys, serviceURLs) return libp2pNetworkMock, serviceURLs } -func NewMocknetHost( - t gocuke.TestingT, - libp2pNetworkMock mocknet.Mocknet, - privKey cryptoPocket.PrivateKey, -) libp2pHost.Host { +func NewLibp2pNetworkMock(t gocuke.TestingT) mocknet.Mocknet { t.Helper() - // TODO_THIS_COMMIT: move to const - addrMock, err := multiaddr.NewMultiaddr(fmt.Sprintf("/ip4/10.0.0.1/tcp/%d", defaults.DefaultP2PPort)) - require.NoError(t, err) - - libp2pPrivKey, err := crypto.UnmarshalEd25519PrivateKey(privKey.Bytes()) - require.NoError(t, err) - - host, err := libp2pNetworkMock.AddPeer(libp2pPrivKey, addrMock) - require.NoError(t, err) + libp2pNetworkMock := mocknet.New() + // destroy mocknet on test cleanup + t.Cleanup(func() { + err := libp2pNetworkMock.Close() + require.NoError(t, err) + }) - return host + return libp2pNetworkMock } func SetupMockNetPeers( @@ -85,17 +74,6 @@ func SetupMockNetPeers( return peerIDs } -// CONSIDERATION: serviceURLs are only unique within their respective slice; -// consider building an iterator/generator instead. -func SequentialServiceURLs(t gocuke.TestingT, count int) (serviceURLs []string) { - t.Helper() - - for i := 0; i < count; i++ { - serviceURLs = append(serviceURLs, NewServiceURL(i+1)) - } - return serviceURLs -} - func PeersFromPrivKeysAndServiceURLs( t gocuke.TestingT, privKeys []cryptoPocket.PrivateKey, @@ -110,7 +88,7 @@ func PeersFromPrivKeysAndServiceURLs( } for i, privKey := range privKeys[:maxCount] { - peerInfo := peerFromPrivKeyAndServiceURL(t, privKey, NewServiceURL(i+1)) + peerInfo := peerFromPrivKeyAndServiceURL(t, privKey, testutil.NewServiceURL(i+1)) peersInfo = append(peersInfo, peerInfo) } return peersInfo @@ -132,10 +110,3 @@ func peerFromPrivKeyAndServiceURL( return peerInfo } - -const ServiceURLFormat = "node%d.consensus:42069" - -// TECHDEBT: rename `validatorId()` to `serviceURL()` -func NewServiceURL(i int) string { - return fmt.Sprintf(ServiceURLFormat, i) -} diff --git a/internal/testutil/runtime/genesis.go b/internal/testutil/runtime/genesis.go index b14aac47dd..47da6caed6 100644 --- a/internal/testutil/runtime/genesis.go +++ b/internal/testutil/runtime/genesis.go @@ -1,7 +1,7 @@ package runtime_testutil import ( - "github.com/pokt-network/pocket/internal/testutil/p2p" + "github.com/pokt-network/pocket/internal/testutil" "github.com/pokt-network/pocket/runtime/genesis" "github.com/pokt-network/pocket/runtime/test_artifacts" "github.com/pokt-network/pocket/shared/core/types" @@ -33,12 +33,36 @@ func BaseGenesisStateMock(t gocuke.TestingT, valKeys []cryptoPocket.PublicKey, s return genesisState } +func BaseGenesisStateMockFromServiceURLKeyMap(t gocuke.TestingT, serviceURLKeyMap map[string]cryptoPocket.PrivateKey) *genesis.GenesisState { + t.Helper() + + var validators []*types.Actor + genesisState := new(genesis.GenesisState) + for serviceURL, privKey := range serviceURLKeyMap { + addr := privKey.Address().String() + mockValidator := &types.Actor{ + ActorType: types.ActorType_ACTOR_TYPE_VAL, + Address: addr, + PublicKey: privKey.PublicKey().String(), + ServiceUrl: serviceURL, + StakedAmount: test_artifacts.DefaultStakeAmountString, + PausedHeight: int64(0), + UnstakingHeight: int64(0), + Output: addr, + } + validators = append(validators, mockValidator) + } + genesisState.Validators = validators + + return genesisState +} + func GenesisWithSequentialServiceURLs(t gocuke.TestingT, valKeys []cryptoPocket.PublicKey) *genesis.GenesisState { t.Helper() serviceURLs := make([]string, len(valKeys)) for i := range valKeys { - serviceURLs[i] = p2p_testutil.NewServiceURL(i + 1) + serviceURLs[i] = testutil.NewServiceURL(i + 1) } return BaseGenesisStateMock(t, valKeys, serviceURLs) } diff --git a/p2p/integration/background_gossip_test.go b/p2p/integration/background_gossip_test.go index 47382a5186..9549375bca 100644 --- a/p2p/integration/background_gossip_test.go +++ b/p2p/integration/background_gossip_test.go @@ -41,10 +41,10 @@ func TestMinimal(t *testing.T) { t.Parallel() // a new step definition suite is constructed for every scenario - gocuke.NewRunner(t, &suite{}).Path(backgroundGossipFeaturePath).Run() + gocuke.NewRunner(t, new(backgroundGossipSuite)).Path(backgroundGossipFeaturePath).Run() } -type suite struct { +type backgroundGossipSuite struct { // special arguments like TestingT are injected automatically into exported fields gocuke.TestingT @@ -71,7 +71,7 @@ type suite struct { sender *p2p.P2PModule } -func (s *suite) Before(scenario gocuke.Scenario) { +func (s *backgroundGossipSuite) Before(scenario gocuke.Scenario) { s.mu.Lock() defer s.mu.Unlock() @@ -79,23 +79,23 @@ func (s *suite) Before(scenario gocuke.Scenario) { s.receivedFromServiceURLMap = make(map[string]struct{}) } -func (s *suite) AFaultyNetworkOfPeers(a int64) { +func (s *backgroundGossipSuite) AFaultyNetworkOfPeers(a int64) { panic("PENDING") } -func (s *suite) NumberOfFaultyPeers(a int64) { +func (s *backgroundGossipSuite) NumberOfFaultyPeers(a int64) { panic("PENDING") } -func (s *suite) NumberOfNodesJoinTheNetwork(a int64) { +func (s *backgroundGossipSuite) NumberOfNodesJoinTheNetwork(a int64) { panic("PENDING") } -func (s *suite) NumberOfNodesLeaveTheNetwork(a int64) { +func (s *backgroundGossipSuite) NumberOfNodesLeaveTheNetwork(a int64) { panic("PENDING") } -func (s *suite) AFullyConnectedNetworkOfPeers(count int64) { +func (s *backgroundGossipSuite) AFullyConnectedNetworkOfPeers(count int64) { var ( peerCount = int(count) pubKeys = make([]cryptoPocket.PublicKey, peerCount) @@ -277,7 +277,7 @@ func (s *suite) AFullyConnectedNetworkOfPeers(count int64) { } } -func (s *suite) ANodeBroadcastsATestMessageViaItsBackgroundRouter() { +func (s *backgroundGossipSuite) ANodeBroadcastsATestMessageViaItsBackgroundRouter() { // TODO_THIS_COMMIT: refactor s.timeoutDuration = broadcastTimeoutDuration @@ -295,7 +295,7 @@ func (s *suite) ANodeBroadcastsATestMessageViaItsBackgroundRouter() { require.NoError(s, err) } -func (s *suite) MinusOneNumberOfNodesShouldReceiveTheTestMessage(receivedCountPlus1 int64) { +func (s *backgroundGossipSuite) MinusOneNumberOfNodesShouldReceiveTheTestMessage(receivedCountPlus1 int64) { done := make(chan struct{}, 1) go func() { @@ -323,7 +323,7 @@ func (s *suite) MinusOneNumberOfNodesShouldReceiveTheTestMessage(receivedCountPl } } -func (s *suite) initBootstrapPeerIDChMap(p2pModule *p2p.P2PModule) { +func (s *backgroundGossipSuite) initBootstrapPeerIDChMap(p2pModule *p2p.P2PModule) { selfID := p2pModule.GetHost().ID() // initialize `s.bootstrapPeerIDChMap` for each p2pModule if _, ok := s.bootstrapPeerIDChMap[selfID]; !ok { @@ -331,7 +331,7 @@ func (s *suite) initBootstrapPeerIDChMap(p2pModule *p2p.P2PModule) { } } -func (s *suite) initBootstrapPeerIDsMap(p2pModule *p2p.P2PModule) { +func (s *backgroundGossipSuite) initBootstrapPeerIDsMap(p2pModule *p2p.P2PModule) { selfID := p2pModule.GetHost().ID() // initialize `s.bootstrapPeerIDsMap` if s.bootstrapPeerIDsMap == nil { @@ -344,7 +344,7 @@ func (s *suite) initBootstrapPeerIDsMap(p2pModule *p2p.P2PModule) { } } -func (s *suite) trackBootstrapProgress(p2pModule *p2p.P2PModule, peerCount int) { +func (s *backgroundGossipSuite) trackBootstrapProgress(p2pModule *p2p.P2PModule, peerCount int) { s.initBootstrapPeerIDsMap(p2pModule) selfID := p2pModule.GetHost().ID() diff --git a/p2p/integration/peer_discovery.feature b/p2p/integration/peer_discovery.feature index 0f06ed36d7..c968ca3ca1 100644 --- a/p2p/integration/peer_discovery.feature +++ b/p2p/integration/peer_discovery.feature @@ -7,57 +7,55 @@ Feature: Background Router Peer Discovery # Scenario: Inactive nodes are removed from the peerstore Scenario Outline: Fully connected network bootstrapping - Given a "bootstrap" node - When number of nodes join the network - Then the "bootstrap" node should have number of peers in its peerstore - And the "bootstrap" node should not be included in its own peerstore - And other nodes should have number of peers in their peerstores - And other nodes should not be included in their respective peerstores + Given a network containing a "bootstrap" node + When number of "other" nodes join the network + Then the "bootstrap" node should have plus one number of peers in its peerstore + And other nodes should have plus one number of peers in their peerstores Examples: - | size | - | 4 | - | 6 | - | 12 | + | count | + | 4 | +# | 6 | +# | 12 | # | 100 | # | 1024 | - Scenario Outline: Fully connected network churning - Given a "bootstrap" node - When number of nodes join the network - And the "bootstrap" node leaves the network - And number of nodes leave the network - And number of nodes join the network - Then the network should contain number of nodes - And each node should have number of peers in their respective peerstores - And each node should not have any leavers in their peerstores - - Examples: - | initial | leavers | joiners | final | - | 4 | 2 | 2 | 4 | - | 4 | 3 | 4 | 5 | - | 12 | 6 | 6 | 12 | -# | 100 | 50 | 55 | 105 | -# | 1024 | 1000 | 1200 | 1224 | - -# TODO_THIS_COMMIT: very similar test will exercise libp2p relaying.. - Scenario Outline: Discovery across pre-bootstrap network partitions - Given a "bootstrap_A" node in partition "A" - And a "bootstrap_B" node in partition "B" - And a "bootstrap_C" node in partition "C" - And number of nodes bootstrap in partition "A" - And number of nodes bootstrap in partition "B" - And number of nodes bootstrap in partition "C" - When a "bridge_AB" node joins partitions "A" and "B" - Then all nodes in partition "A" should discover all nodes in partition "B" - And all nodes in partition "B" should discover all nodes in partition "A" - When a "bridge_BC" node joins partitions "B" and "C" - Then all nodes in partition "A" should discover all nodes in partition "C" - And all nodes in partition "B" should discover all nodes in partition "C" - And all nodes in partition "C" should discover all nodes in partition "A" - And all nodes in partition "C" should discover all nodes in partition "B" - - Examples: - | size_a | size_b | size_c | - | 2 | 2 | 3 | - | 10 | 5 | 12 | +# Scenario Outline: Fully connected network churning +# Given a "bootstrap" node +# When number of nodes join the network +# And the "bootstrap" node leaves the network +# And number of nodes leave the network +# And number of nodes join the network +# Then the network should contain number of nodes +# And each node should have number of peers in their respective peerstores +# And each node should not have any leavers in their peerstores +# +# Examples: +# | initial | leavers | joiners | final | +# | 4 | 2 | 2 | 4 | +# | 4 | 3 | 4 | 5 | +# | 12 | 6 | 6 | 12 | +## | 100 | 50 | 55 | 105 | +## | 1024 | 1000 | 1200 | 1224 | +# +## TODO_THIS_COMMIT: very similar test will exercise libp2p relaying.. +# Scenario Outline: Discovery across pre-bootstrap network partitions +# Given a "bootstrap_A" node in partition "A" +# And a "bootstrap_B" node in partition "B" +# And a "bootstrap_C" node in partition "C" +# And number of nodes bootstrap in partition "A" +# And number of nodes bootstrap in partition "B" +# And number of nodes bootstrap in partition "C" +# When a "bridge_AB" node joins partitions "A" and "B" +# Then all nodes in partition "A" should discover all nodes in partition "B" +# And all nodes in partition "B" should discover all nodes in partition "A" +# When a "bridge_BC" node joins partitions "B" and "C" +# Then all nodes in partition "A" should discover all nodes in partition "C" +# And all nodes in partition "B" should discover all nodes in partition "C" +# And all nodes in partition "C" should discover all nodes in partition "A" +# And all nodes in partition "C" should discover all nodes in partition "B" +# +# Examples: +# | size_a | size_b | size_c | +# | 2 | 2 | 3 | +# | 10 | 5 | 12 | diff --git a/p2p/integration/peer_discovery_test.go b/p2p/integration/peer_discovery_test.go index c84d2d4ac8..5641800965 100644 --- a/p2p/integration/peer_discovery_test.go +++ b/p2p/integration/peer_discovery_test.go @@ -1,79 +1,235 @@ +//go:build test + package integration import ( + "github.com/foxcpp/go-mockdns" + mocknet "github.com/libp2p/go-libp2p/p2p/net/mock" + "github.com/pokt-network/pocket/internal/testutil" + "github.com/pokt-network/pocket/internal/testutil/constructors" + generics_testutil "github.com/pokt-network/pocket/internal/testutil/generics" + runtime_testutil "github.com/pokt-network/pocket/internal/testutil/runtime" + "github.com/pokt-network/pocket/p2p" + cryptoPocket "github.com/pokt-network/pocket/shared/crypto" "github.com/pokt-network/pocket/shared/modules" + mock_modules "github.com/pokt-network/pocket/shared/modules/mocks" + "github.com/regen-network/gocuke" + "github.com/stretchr/testify/require" "testing" + "time" ) const ( peerDiscoveryFeaturePath = "peer_discovery.feature" - bootstrapNodePrefix = "bootstrap" -) - -var ( - testNodes map[string]modules.P2PModule + bootstrapNodeLabelPrefix = "bootstrap" + otherNodeLabelPrefix = "other" ) func TestPeerDiscoveryIntegration(t *testing.T) { t.Parallel() - //testutil.RunGherkinFeature(t, peerDiscoveryFeaturePath, initPeerDiscoveryScenarios) + gocuke.NewRunner(t, new(backgroundPeerDiscoverySuite)).Path(peerDiscoveryFeaturePath).Run() } -//func aNode(nodeName string) error { -// if strings.HasPrefix(bootstrapNodePrefix, nodeName) { -// // -- -// } -// -// return godog.ErrPending -//} -// -//func allNodesInPartitionShouldDiscoverAllNodesInPartition(partitionA, partitionB string) error { -// return godog.ErrPending -//} -// -//func eachNodeShouldHaveNumberOfPeersInTheirRespectivePeerstores(expectedPeerCount int) error { -// return godog.ErrPending -//} -// -//func eachNodeShouldNotHaveAnyLeaversInTheirPeerstores() error { -// return godog.ErrPending +type backgroundPeerDiscoverySuite struct { + gocuke.TestingT + + dnsSrv *mockdns.Server + busMocks map[string]*mock_modules.MockBus + libp2pNetworkMock mocknet.Mocknet + p2pModules map[string]modules.P2PModule + + // TODO: something more sophisticated.. + // - what about a list of nodes sharing a label? + // + // labelServiceURLMap a list of serviceURLs to a set of labels + labelServiceURLMap map[string][]string +} + +func (s *backgroundPeerDiscoverySuite) Before(_ gocuke.Scenario) { + s.labelServiceURLMap = make(map[string][]string) +} + +func (s *backgroundPeerDiscoverySuite) ANetworkContainingANode(nodeLabel string) { + s.dnsSrv = testutil.MinimalDNSMock(s) + + s.busMocks, s.libp2pNetworkMock, s.p2pModules = constructors.NewBusesMocknetAndP2PModules( + s, 1, s.dnsSrv, nil, nil, + ) + + // i.e. "only" serviceURL as this step definition initializes the network + firstServiceURL := generics_testutil.GetKeys(s.busMocks)[0] + s.addServiceURLWithLabel(nodeLabel, firstServiceURL) + + err := s.p2pModules[firstServiceURL].Start() + require.NoError(s, err) + + // TODO_THIS_COMMIT: revisit... + time.Sleep(time.Second * 1) +} + +func (s *backgroundPeerDiscoverySuite) NumberOfNodesJoinTheNetwork(nodeCount int64, nodeLabel string) { + // TECHDEBT: use an iterator instead.. + // plus 1 to account for the bootstrap node serviceURL which we used earlier + serviceURLKeyMap := testutil.SequentialServiceURLPrivKeyMap(s, int(nodeCount+1)) + + // TODO_THIS_COMMIT: clarify how to use `bootstrapNodeLabelPrefix` / what it is for + bootstrapNodeServiceURLs := s.getServiceURLsWithLabel(bootstrapNodeLabelPrefix) + require.Equalf(s, 1, len(bootstrapNodeServiceURLs), "expected exactly one bootstrap node") + + bootstrapNodeServiceURL := bootstrapNodeServiceURLs[0] + + // bootstrap node is the only validator in genesis + genesisState := runtime_testutil.BaseGenesisStateMockFromServiceURLKeyMap( + s, map[string]cryptoPocket.PrivateKey{ + bootstrapNodeServiceURL: serviceURLKeyMap[bootstrapNodeServiceURL], + }, + ) + + // remove the bootstrap node from the map + delete(serviceURLKeyMap, bootstrapNodeServiceURL) + + for serviceURL := range serviceURLKeyMap { + s.addServiceURLWithLabel(otherNodeLabelPrefix, serviceURL) + } + + joinersBusMocks, joinersP2PModules := constructors.NewBusesAndP2PModules( + s, nil, + s.dnsSrv, + genesisState, + s.libp2pNetworkMock, + serviceURLKeyMap, + ) + + err := s.libp2pNetworkMock.LinkAll() + require.NoError(s, err) + + for _, p2pModule := range joinersP2PModules { + err := p2pModule.Start() + require.NoError(s, err) + } + + s.addBusMocks(joinersBusMocks) + s.addP2PModules(joinersP2PModules) + + // TODO_THIS_COMMIT: wait for bootstrapping + time.Sleep(time.Second * 1) +} + +// TODO_THIS_COMMIT: move below exported methods +func (s *backgroundPeerDiscoverySuite) addServiceURLWithLabel(nodeLabel, serviceURL string) { + serviceURLs := s.labelServiceURLMap[nodeLabel] + if serviceURLs == nil { + serviceURLs = make([]string, 0) + } + s.labelServiceURLMap[nodeLabel] = append(serviceURLs, serviceURL) +} +func (s *backgroundPeerDiscoverySuite) getServiceURLsWithLabel(nodeLabel string) []string { + serviceURLs, ok := s.labelServiceURLMap[nodeLabel] + if !ok { + return nil + } + + if len(serviceURLs) < 1 { + return nil + } + return serviceURLs +} + +func (s *backgroundPeerDiscoverySuite) TheNodeShouldHavePlusOneNumberOfPeersInItsPeerstore(nodeLabel string, peerCountMinus1 int64) { + labelServiceURLs := s.getServiceURLsWithLabel(nodeLabel) + //serviceURL, ok := s.labelServiceURLMap[nodeLabel] + require.NotEmptyf(s, labelServiceURLs, "node label %q not found", nodeLabel) + require.Equalf(s, 1, len(labelServiceURLs), "node label %q has more than one service url", nodeLabel) + + serviceURL := labelServiceURLs[0] + p2pModule, ok := s.p2pModules[serviceURL] + require.Truef(s, ok, "p2p module for service url %q not found", serviceURL) + + host := p2pModule.(*p2p.P2PModule).GetHost() + peers := host.Peerstore().Peers() + + require.Equalf(s, int(peerCountMinus1+1), len(peers), "unexpected number of peers in peerstore: %s", peers) +} + +func (s *backgroundPeerDiscoverySuite) OtherNodesShouldHavePlusOneNumberOfPeersInTheirPeerstores(peerCountMinus1 int64) { + // TODO_THIS_COMMIT: clarify how to use `bootstrapNodeLabelPrefix` / what it is for + otherNodeServiceURLs := s.getServiceURLsWithoutLabel(bootstrapNodeLabelPrefix) + + require.NotEmpty(s, otherNodeServiceURLs, "other nodes not found") + require.Equal(s, int(peerCountMinus1), len(otherNodeServiceURLs)) + + for _, serviceURL := range otherNodeServiceURLs { + p2pModule, ok := s.p2pModules[serviceURL] + require.Truef(s, ok, "p2p module for service url %q not found", serviceURL) + + host := p2pModule.(*p2p.P2PModule).GetHost() + peers := host.Peerstore().Peers() + + require.Equalf(s, int(peerCountMinus1+1), len(peers), "unexpected number of peers in peerstore: %s", peers) + } +} + +//func (s *backgroundPeerDiscoverySuite) EachNodeShouldNotHaveAnyLeaversInTheirPeerstores() { +// panic("PENDING") //} // -//func otherNodesShouldHaveNumberOfPeersInTheirPeerstores(arg1 int) error { -// return godog.ErrPending +//func (s *backgroundPeerDiscoverySuite) LeaverNumberOfNodesLeaveTheNetwork() { +// panic("PENDING") //} -// -//func otherNodesShouldNotBeIncludedInTheirRespectivePeerstores() error { -// return godog.ErrPending + +func (s *backgroundPeerDiscoverySuite) EachNodeShouldHaveNumberOfPeersInTheirRespectivePeerstores(peerCount int64) { + panic("PENDING") +} + +//func (s *backgroundPeerDiscoverySuite) NumberOfNodesBootstrapInPartition(a int64, b string) { +// panic("PENDING") //} -// -//func theNetworkShouldContainNumberOfNodes(arg1 int) error { -// return godog.ErrPending + +func (s *backgroundPeerDiscoverySuite) TheNetworkShouldContainNumberOfNodes(nodeCount int64) { + panic("PENDING") +} + +//func (s *backgroundPeerDiscoverySuite) ANodeInPartition(a string, b string) { +// panic("PENDING") //} // -//func theNodeShouldHaveNumberOfPeersInItsPeerstore(arg1 string, arg2 int) error { -// return godog.ErrPending +//func (s *backgroundPeerDiscoverySuite) ANodeJoinsPartitionsAnd(a string, b string, c string) { +// panic("PENDING") //} // -//func theNodeShouldNotBeIncludedInItsOwnPeerstore(arg1 string) error { -// return godog.ErrPending +//func (s *backgroundPeerDiscoverySuite) AllNodesInPartitionShouldDiscoverAllNodesInPartition(a string, b string) { +// panic("PENDING") //} -// -//func initPeerDiscoveryScenarios(ctx *godog.ScenarioContext) { -// ctx.Step(`^a "([^"]*)" node$`, aNode) -// ctx.Step(`^a "([^"]*)" node in partition "([^"]*)"$`, aNodeInPartition) -// ctx.Step(`^a "([^"]*)" node joins partitions "([^"]*)" and "([^"]*)"$`, aNodeJoinsPartitionsAnd) -// ctx.Step(`^all nodes in partition "([^"]*)" should discover all nodes in partition "([^"]*)"$`, allNodesInPartitionShouldDiscoverAllNodesInPartition) -// ctx.Step(`^each node should have (\d+) number of peers in their respective peerstores$`, eachNodeShouldHaveNumberOfPeersInTheirRespectivePeerstores) -// ctx.Step(`^each node should not have any leavers in their peerstores$`, eachNodeShouldNotHaveAnyLeaversInTheirPeerstores) -// ctx.Step(`^(\d+) number of nodes bootstrap in partition "([^"]*)"$`, numberOfNodesBootstrapInPartition) -// ctx.Step(`^(\d+) number of nodes join the network$`, numberOfNodesJoinTheNetwork) -// ctx.Step(`^(\d+) number of nodes leave the network$`, numberOfNodesLeaveTheNetwork) -// ctx.Step(`^other nodes should have (\d+) number of peers in their peerstores$`, otherNodesShouldHaveNumberOfPeersInTheirPeerstores) -// ctx.Step(`^other nodes should not be included in their respective peerstores$`, otherNodesShouldNotBeIncludedInTheirRespectivePeerstores) -// ctx.Step(`^the network should contain (\d+) number of nodes$`, theNetworkShouldContainNumberOfNodes) -// ctx.Step(`^the "([^"]*)" node leaves the network$`, theNodeLeavesTheNetwork) -// ctx.Step(`^the "([^"]*)" node should have (\d+) number of peers in its peerstore$`, theNodeShouldHaveNumberOfPeersInItsPeerstore) -// ctx.Step(`^the "([^"]*)" node should not be included in its own peerstore$`, theNodeShouldNotBeIncludedInItsOwnPeerstore) + +//func (s *backgroundPeerDiscoverySuite) TheNodeLeavesTheNetwork(a string) { +// panic("PENDING") //} + +func (s *backgroundPeerDiscoverySuite) addBusMocks(busMocks map[string]*mock_modules.MockBus) { + s.Helper() + + for serviceURL, busMock := range busMocks { + require.Nilf(s, s.busMocks[serviceURL], "busMock for serviceURL %s already exists", serviceURL) + s.busMocks[serviceURL] = busMock + } +} + +func (s *backgroundPeerDiscoverySuite) addP2PModules(p2pModules map[string]modules.P2PModule) { + s.Helper() + + for serviceURL, p2pModule := range p2pModules { + require.Nilf(s, s.p2pModules[serviceURL], "p2pModule for serviceURL %s already exists", serviceURL) + s.p2pModules[serviceURL] = p2pModule + } +} + +func (s *backgroundPeerDiscoverySuite) getServiceURLsWithoutLabel(nodeLabel string) (serviceURLs []string) { + for label, urls := range s.labelServiceURLMap { + if label == nodeLabel { + continue + } + serviceURLs = append(serviceURLs, urls...) + } + return serviceURLs +} diff --git a/p2p/module.go b/p2p/module.go index 616237569e..89f712ef26 100644 --- a/p2p/module.go +++ b/p2p/module.go @@ -331,7 +331,7 @@ func (m *p2pModule) setupRouters() (err error) { CurrentHeightProvider: m.currentHeightProvider, PeerstoreProvider: m.pstoreProvider, Host: m.host, - Handler: m.handleAppData, + Handler: m.handlePocketEnvelope, }, ) if err != nil { diff --git a/p2p/module_raintree_test.go b/p2p/module_raintree_test.go index 20596913e6..6d0f895c88 100644 --- a/p2p/module_raintree_test.go +++ b/p2p/module_raintree_test.go @@ -22,7 +22,6 @@ import ( "github.com/pokt-network/pocket/internal/testutil" "github.com/pokt-network/pocket/internal/testutil/constructors" - "github.com/pokt-network/pocket/internal/testutil/p2p" persistence_testutil "github.com/pokt-network/pocket/internal/testutil/persistence" "github.com/pokt-network/pocket/shared/messaging" "github.com/regen-network/gocuke" @@ -46,7 +45,7 @@ func TestMain(m *testing.M) { // ### RainTree Unit Tests ### func TestRainTreeNetworkCompleteOneNodes(t *testing.T) { // val_1 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ originatorNode: {0, 0}, // val_1, the originator, does 0 network reads or writes } @@ -57,13 +56,13 @@ func TestRainTreeNetworkCompleteTwoNodes(t *testing.T) { // val_1 // └───────┐ // val_2 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) // Per the diagram above, in the case of a 2 node network, the originator node (val_1) does a // single write to another node (val_2), also the // originator node and never performs any reads or writes during a RainTree broadcast. expectedCalls := TestNetworkSimulationConfig{ // Attempt: I think Validator 1 is sending a message in a 2 (including self) node network originatorNode: {0, 1}, // val_1 does a single network write (to val_2) - p2p_testutil.NewServiceURL(2): {1, 0}, // val_2 does a single network read (from val_1) + testutil.NewServiceURL(2): {1, 0}, // val_2 does a single network read (from val_1) } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -72,11 +71,11 @@ func TestRainTreeNetworkCompleteThreeNodes(t *testing.T) { // val_1 // ┌───────┴────┬─────────┐ // val_2 val_1 val_3 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {0, 2}, // val_1 does two network writes (to val_2 and val_3) - p2p_testutil.NewServiceURL(2): {1, 0}, // val_2 does a single network read (from val_1) - p2p_testutil.NewServiceURL(3): {1, 0}, // val_2 does a single network read (from val_3) + originatorNode: {0, 2}, // val_1 does two network writes (to val_2 and val_3) + testutil.NewServiceURL(2): {1, 0}, // val_2 does a single network read (from val_1) + testutil.NewServiceURL(3): {1, 0}, // val_2 does a single network read (from val_3) } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -88,12 +87,12 @@ func TestRainTreeNetworkCompleteFourNodes(t *testing.T) { // val_2 val_1 val_3 // └───────┐ └───────┐ └───────┐ // val_3 val_2 val_4 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {0, 3}, // val_1 does 3 network writes (two to val_2 and 1 to val_3) - p2p_testutil.NewServiceURL(2): {2, 1}, // val_2 does 2 network reads (both from val_1) and 1 network write (to val_3) - p2p_testutil.NewServiceURL(3): {2, 1}, // val_2 does 2 network reads (from val_1 and val_2) and 1 network write (to val_4) - p2p_testutil.NewServiceURL(4): {1, 0}, // val_2 does 1 network read (from val_3) + originatorNode: {0, 3}, // val_1 does 3 network writes (two to val_2 and 1 to val_3) + testutil.NewServiceURL(2): {2, 1}, // val_2 does 2 network reads (both from val_1) and 1 network write (to val_3) + testutil.NewServiceURL(3): {2, 1}, // val_2 does 2 network reads (from val_1 and val_2) and 1 network write (to val_4) + testutil.NewServiceURL(4): {1, 0}, // val_2 does 1 network read (from val_3) } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -104,17 +103,17 @@ func TestRainTreeNetworkCompleteNineNodes(t *testing.T) { // val_4 val_1 val_7 // ┌───────┴────┬─────────┐ ┌───────┴────┬─────────┐ ┌───────┴────┬─────────┐ // val_6 val_4 val_8 val_3 val_1 val_5 val_9 val_7 val_2 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {0, 4}, - p2p_testutil.NewServiceURL(2): {1, 0}, - p2p_testutil.NewServiceURL(3): {1, 0}, - p2p_testutil.NewServiceURL(4): {1, 2}, - p2p_testutil.NewServiceURL(5): {1, 0}, - p2p_testutil.NewServiceURL(6): {1, 0}, - p2p_testutil.NewServiceURL(7): {1, 2}, - p2p_testutil.NewServiceURL(8): {1, 0}, - p2p_testutil.NewServiceURL(9): {1, 0}, + originatorNode: {0, 4}, + testutil.NewServiceURL(2): {1, 0}, + testutil.NewServiceURL(3): {1, 0}, + testutil.NewServiceURL(4): {1, 2}, + testutil.NewServiceURL(5): {1, 0}, + testutil.NewServiceURL(6): {1, 0}, + testutil.NewServiceURL(7): {1, 2}, + testutil.NewServiceURL(8): {1, 0}, + testutil.NewServiceURL(9): {1, 0}, } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -128,20 +127,20 @@ func TestRainTreeNetworkCompleteNineNodes(t *testing.T) { // val_8 val_7 val_10 val_6 val_5 val_8 val_11 val_10 val_5 val_4 val_3 val_6 val_2 val_1 val_4 val_7 val_6 val_1 val_12 val_11 val_2 val_10 val_9 val_12 val_3 val_2 val_9 func TestRainTreeCompleteTwelveNodes(t *testing.T) { - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {1, 6}, - p2p_testutil.NewServiceURL(2): {3, 2}, - p2p_testutil.NewServiceURL(3): {2, 2}, - p2p_testutil.NewServiceURL(4): {2, 0}, - p2p_testutil.NewServiceURL(5): {2, 4}, - p2p_testutil.NewServiceURL(6): {3, 2}, - p2p_testutil.NewServiceURL(7): {2, 2}, - p2p_testutil.NewServiceURL(8): {2, 0}, - p2p_testutil.NewServiceURL(9): {2, 4}, - p2p_testutil.NewServiceURL(10): {3, 2}, - p2p_testutil.NewServiceURL(11): {2, 2}, - p2p_testutil.NewServiceURL(12): {2, 0}, + originatorNode: {1, 6}, + testutil.NewServiceURL(2): {3, 2}, + testutil.NewServiceURL(3): {2, 2}, + testutil.NewServiceURL(4): {2, 0}, + testutil.NewServiceURL(5): {2, 4}, + testutil.NewServiceURL(6): {3, 2}, + testutil.NewServiceURL(7): {2, 2}, + testutil.NewServiceURL(8): {2, 0}, + testutil.NewServiceURL(9): {2, 4}, + testutil.NewServiceURL(10): {3, 2}, + testutil.NewServiceURL(11): {2, 2}, + testutil.NewServiceURL(12): {2, 0}, } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -154,26 +153,26 @@ func TestRainTreeNetworkCompleteEighteenNodes(t *testing.T) { // val_11 val_7 val_15 val_5 val_1 val_9 val_17 val_13 val_3 // ┌────────┴─────┬───────────┐ ┌───────┴────┬──────────┐ ┌────────┴─────┬──────────┐ ┌───────┴────┬──────────┐ ┌───────┴────┬─────────┐ ┌────────┴────┬─────────┐ ┌───────┴─────┬──────────┐ ┌────────┴─────┬───────────┐ ┌───────┴────┬──────────┐ // val_13 val_11 val_16 val_9 val_7 val_12 val_17 val_15 val_8 val_7 val_5 val_10 val_3 val_1 val_6 val_11 val_9 val_2 val_1 val_17 val_4 val_15 val_13 val_18 val_5 val_3 val_14 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {1, 6}, - p2p_testutil.NewServiceURL(2): {1, 0}, - p2p_testutil.NewServiceURL(3): {2, 2}, - p2p_testutil.NewServiceURL(4): {1, 0}, - p2p_testutil.NewServiceURL(5): {2, 2}, - p2p_testutil.NewServiceURL(6): {1, 0}, - p2p_testutil.NewServiceURL(7): {2, 4}, - p2p_testutil.NewServiceURL(8): {1, 0}, - p2p_testutil.NewServiceURL(9): {2, 2}, - p2p_testutil.NewServiceURL(10): {1, 0}, - p2p_testutil.NewServiceURL(11): {2, 2}, - p2p_testutil.NewServiceURL(12): {1, 0}, - p2p_testutil.NewServiceURL(13): {2, 4}, - p2p_testutil.NewServiceURL(14): {1, 0}, - p2p_testutil.NewServiceURL(15): {2, 2}, - p2p_testutil.NewServiceURL(16): {1, 0}, - p2p_testutil.NewServiceURL(17): {2, 2}, - p2p_testutil.NewServiceURL(18): {1, 0}, + originatorNode: {1, 6}, + testutil.NewServiceURL(2): {1, 0}, + testutil.NewServiceURL(3): {2, 2}, + testutil.NewServiceURL(4): {1, 0}, + testutil.NewServiceURL(5): {2, 2}, + testutil.NewServiceURL(6): {1, 0}, + testutil.NewServiceURL(7): {2, 4}, + testutil.NewServiceURL(8): {1, 0}, + testutil.NewServiceURL(9): {2, 2}, + testutil.NewServiceURL(10): {1, 0}, + testutil.NewServiceURL(11): {2, 2}, + testutil.NewServiceURL(12): {1, 0}, + testutil.NewServiceURL(13): {2, 4}, + testutil.NewServiceURL(14): {1, 0}, + testutil.NewServiceURL(15): {2, 2}, + testutil.NewServiceURL(16): {1, 0}, + testutil.NewServiceURL(17): {2, 2}, + testutil.NewServiceURL(18): {1, 0}, } testRainTreeCalls(t, originatorNode, expectedCalls) } @@ -186,35 +185,35 @@ func TestRainTreeNetworkCompleteTwentySevenNodes(t *testing.T) { // val_16 val_10 val_22 val_7 val_1 val_13 val_25 val_19 val_4 // ┌────────┴─────┬───────────┐ ┌────────┴─────┬───────────┐ ┌────────┴─────┬───────────┐ ┌────────┴────┬──────────┐ ┌───────┴────┬─────────┐ ┌────────┴─────┬──────────┐ ┌───────┴─────┬──────────┐ ┌────────┴─────┬───────────┐ ┌───────┴────┬──────────┐ // val_20 val_16 val_24 val_14 val_10 val_18 val_26 val_22 val_12 val_11 val_7 val_15 val_5 val_1 val_9 val_17 val_13 val_3 val_2 val_25 val_6 val_23 val_19 val_27 val_8 val_4 val_21 - originatorNode := p2p_testutil.NewServiceURL(1) + originatorNode := testutil.NewServiceURL(1) expectedCalls := TestNetworkSimulationConfig{ - originatorNode: {0, 6}, - p2p_testutil.NewServiceURL(2): {1, 0}, - p2p_testutil.NewServiceURL(3): {1, 0}, - p2p_testutil.NewServiceURL(4): {1, 2}, - p2p_testutil.NewServiceURL(5): {1, 0}, - p2p_testutil.NewServiceURL(6): {1, 0}, - p2p_testutil.NewServiceURL(7): {1, 2}, - p2p_testutil.NewServiceURL(8): {1, 0}, - p2p_testutil.NewServiceURL(9): {1, 0}, - p2p_testutil.NewServiceURL(10): {1, 4}, - p2p_testutil.NewServiceURL(11): {1, 0}, - p2p_testutil.NewServiceURL(12): {1, 0}, - p2p_testutil.NewServiceURL(13): {1, 2}, - p2p_testutil.NewServiceURL(14): {1, 0}, - p2p_testutil.NewServiceURL(15): {1, 0}, - p2p_testutil.NewServiceURL(16): {1, 2}, - p2p_testutil.NewServiceURL(17): {1, 0}, - p2p_testutil.NewServiceURL(18): {1, 0}, - p2p_testutil.NewServiceURL(19): {1, 4}, - p2p_testutil.NewServiceURL(20): {1, 0}, - p2p_testutil.NewServiceURL(21): {1, 0}, - p2p_testutil.NewServiceURL(22): {1, 2}, - p2p_testutil.NewServiceURL(23): {1, 0}, - p2p_testutil.NewServiceURL(24): {1, 0}, - p2p_testutil.NewServiceURL(25): {1, 2}, - p2p_testutil.NewServiceURL(26): {1, 0}, - p2p_testutil.NewServiceURL(27): {1, 0}, + originatorNode: {0, 6}, + testutil.NewServiceURL(2): {1, 0}, + testutil.NewServiceURL(3): {1, 0}, + testutil.NewServiceURL(4): {1, 2}, + testutil.NewServiceURL(5): {1, 0}, + testutil.NewServiceURL(6): {1, 0}, + testutil.NewServiceURL(7): {1, 2}, + testutil.NewServiceURL(8): {1, 0}, + testutil.NewServiceURL(9): {1, 0}, + testutil.NewServiceURL(10): {1, 4}, + testutil.NewServiceURL(11): {1, 0}, + testutil.NewServiceURL(12): {1, 0}, + testutil.NewServiceURL(13): {1, 2}, + testutil.NewServiceURL(14): {1, 0}, + testutil.NewServiceURL(15): {1, 0}, + testutil.NewServiceURL(16): {1, 2}, + testutil.NewServiceURL(17): {1, 0}, + testutil.NewServiceURL(18): {1, 0}, + testutil.NewServiceURL(19): {1, 4}, + testutil.NewServiceURL(20): {1, 0}, + testutil.NewServiceURL(21): {1, 0}, + testutil.NewServiceURL(22): {1, 2}, + testutil.NewServiceURL(23): {1, 0}, + testutil.NewServiceURL(24): {1, 0}, + testutil.NewServiceURL(25): {1, 2}, + testutil.NewServiceURL(26): {1, 0}, + testutil.NewServiceURL(27): {1, 0}, } testRainTreeCalls(t, originatorNode, expectedCalls) } diff --git a/p2p/module_test.go b/p2p/module_test.go index c2503f6990..d39c9f0976 100644 --- a/p2p/module_test.go +++ b/p2p/module_test.go @@ -12,7 +12,6 @@ import ( "github.com/stretchr/testify/require" "github.com/pokt-network/pocket/internal/testutil" - p2p_testutil "github.com/pokt-network/pocket/internal/testutil/p2p" "github.com/pokt-network/pocket/internal/testutil/persistence" "github.com/pokt-network/pocket/internal/testutil/runtime" typesP2P "github.com/pokt-network/pocket/p2p/types" @@ -126,7 +125,7 @@ func Test_Create_configureBootstrapNodes(t *testing.T) { pubKeys[i] = privKey.PublicKey() } - serviceURLs := p2p_testutil.SequentialServiceURLs(t, len(pubKeys)) + serviceURLs := testutil.SequentialServiceURLs(t, len(pubKeys)) genesisStateMock := runtime_testutil.BaseGenesisStateMock(t, pubKeys, serviceURLs) persistenceMock := persistence_testutil.BasePersistenceMock(t, mockBus, genesisStateMock) mockBus.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes() diff --git a/p2p/transport_encryption_test.go b/p2p/transport_encryption_test.go index bc140144fb..86e3c0f1d7 100644 --- a/p2p/transport_encryption_test.go +++ b/p2p/transport_encryption_test.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "github.com/pokt-network/pocket/internal/testutil" - p2p_testutil "github.com/pokt-network/pocket/internal/testutil/p2p" "github.com/pokt-network/pocket/internal/testutil/persistence" "github.com/pokt-network/pocket/internal/testutil/runtime" "github.com/pokt-network/pocket/internal/testutil/telemetry" @@ -62,7 +61,7 @@ func TestP2pModule_Insecure_Error(t *testing.T) { for i, privKey := range keys { pubKeys[i] = privKey.PublicKey() } - serviceURLs := p2p_testutil.SequentialServiceURLs(t, len(pubKeys)) + serviceURLs := testutil.SequentialServiceURLs(t, len(pubKeys)) genesisStateMock := runtime_testutil.BaseGenesisStateMock(t, pubKeys, serviceURLs) persistenceMock := persistence_testutil.BasePersistenceMock(t, busMock, genesisStateMock) busMock.EXPECT().GetPersistenceModule().Return(persistenceMock).AnyTimes()