diff --git a/p2p/simulations/network_test.go b/p2p/simulations/network_test.go index b27757c732..2c280432c7 100644 --- a/p2p/simulations/network_test.go +++ b/p2p/simulations/network_test.go @@ -25,21 +25,20 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" - "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/simulations/adapters" - "github.com/ethereum/go-ethereum/rpc" ) func init() { - log.Root().SetHandler(log.LvlFilterHandler(4, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) + log.Root().SetHandler(log.LvlFilterHandler(*loglevel, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) } +//TestSnapshotExplicit tests that nodes connect and disconnect properly +//and that the exposed services are as perscribed func TestSnapshotExplicit(t *testing.T) { - // create simulation network with 20 testService nodes adapter := adapters.NewSimAdapter(adapters.Services{ - "dummy": newDummyService, - "dummy2": newDummy2Service, + "dummy": node.NewNoopServiceA, + "dummy2": node.NewNoopServiceB, }) network := NewNetwork(adapter, &NetworkConfig{ DefaultService: "dummy", @@ -121,12 +120,12 @@ func TestSnapshotExplicit(t *testing.T) { } } - snap, err = network.SnapshotWithServices([]string{"bzz"}, []string{"test"}) + snap, err = network.SnapshotWithServices([]string{"bzz"}, []string{"dummy2"}) if err != nil { t.Fatal(err) } for _, svc := range snap.Nodes[0].Node.Config.Services { - if svc != "dummy" && svc != "dummy2" && svc != "bzz" { + if svc != "dummy" && svc != "bzz" { t.Fatalf("unexpected service %s", svc) } } @@ -246,36 +245,6 @@ func TestNetworkSimulation(t *testing.T) { } } -type dummyService struct { -} - -type dummy2Service struct { - dummyService -} - -func newDummyService(ctx *adapters.ServiceContext) (node.Service, error) { - return &dummyService{}, nil -} -func newDummy2Service(ctx *adapters.ServiceContext) (node.Service, error) { - return &dummy2Service{}, nil -} - -func (p *dummyService) APIs() []rpc.API { - return []rpc.API{} -} - -func (p *dummyService) Protocols() []p2p.Protocol { - return []p2p.Protocol{} -} - -func (p *dummyService) Start(server *p2p.Server) error { - return nil -} - -func (p *dummyService) Stop() error { - return nil -} - func triggerChecks(ctx context.Context, ids []enode.ID, trigger chan enode.ID, interval time.Duration) { tick := time.NewTicker(interval) defer tick.Stop() diff --git a/swarm/network/simulations/discovery/discovery_test.go b/swarm/network/simulations/discovery/discovery_test.go index ed68bbc623..cd5456b73e 100644 --- a/swarm/network/simulations/discovery/discovery_test.go +++ b/swarm/network/simulations/discovery/discovery_test.go @@ -87,7 +87,7 @@ func getDbStore(nodeID string) (*state.DBStore, error) { var ( nodeCount = flag.Int("nodes", 10, "number of nodes to create (default 10)") initCount = flag.Int("conns", 1, "number of originally connected peers (default 1)") - snapshotFile = flag.String("snapshot", "", "create snapshot") + snapshotFile = flag.String("snapshot", "", "path to create snapshot file in") loglevel = flag.Int("loglevel", 3, "verbosity of logs") rawlog = flag.Bool("rawlog", false, "remove terminal formatting from logs") serviceOverride = flag.String("services", "", "remove or add services to the node snapshot; prefix with \"+\" to add, \"-\" to remove; example: +pss,-discovery") @@ -317,6 +317,8 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul addServices = append(addServices, osvc[1:]) } else if strings.Index(osvc, "-") == 0 { removeServices = append(removeServices, osvc[1:]) + } else { + panic("stick to the rules, you know what they are") } } snap, err = net.SnapshotWithServices(addServices, removeServices)