Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Add TestNewSwarm and simplify NewSwarm constructor#557

Merged
zelig merged 2 commits into
swarm-network-rewritefrom
test-newswarm
May 23, 2018
Merged

Add TestNewSwarm and simplify NewSwarm constructor#557
zelig merged 2 commits into
swarm-network-rewritefrom
test-newswarm

Conversation

@janos
Copy link
Copy Markdown
Member

@janos janos commented May 18, 2018

This PR:

  • adds TestNewSwarm test for validating the constructed Swarm fields
  • simplifies NewSwarm constructor
  • moves Swap dialer to NewSwarm
  • fixes a lint error in api/client

@janos janos requested review from gbalint and nolash May 18, 2018 10:52
Comment thread swarm/swarm.go
kp,
)

config.HiveParams.Discovery = true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we overriding the configuration param here?

Comment thread swarm/swarm.go
self.bzz = network.NewBzz(bzzconfig, to, stateStore, stream.Spec, self.streamer.Run)

// Pss = postal service over swarm (devp2p over bzz)
config.Pss = config.Pss.WithPrivateKey(self.privateKey)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that config should bot be mutated in constructor, so I moved this line to api.Config.Init function. @nolash is that ok?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine by me :)

Copy link
Copy Markdown
Contributor

@nolash nolash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good beginning, but should we have deeper tests of some of the objects' states aswell?

Comment thread swarm/swarm.go
return nil, fmt.Errorf("error connecting to SWAP API %s: %s", config.SwapApi, err)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there a reason why this was initialized outside before?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have ipcEndpoint available in all test cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I guess now we don't need that anymore?

Comment thread swarm/swarm_test.go
t.Error("private key is not set")
}
if !s.config.HiveParams.Discovery {
t.Error("config.HiveParams.Discovery is false, must be true regardless the configuration")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have configuration parameters if it always has to be true?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly my question in this PR #557 (diff). That is the case that we have now.

Comment thread swarm/swarm_test.go
if s.dns == nil {
t.Error("dns is not initialized")
}
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should check mutable resources here aswell, their validation depends on ens.

Copy link
Copy Markdown
Member Author

@janos janos May 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceHandler has ensClient and ethClient as unexported fields. How would you suggest to do the check?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's not so easy, also because ResourceHandler isn't even a member of the Swarm object. But it got me thinking that there should probably be some way of querying certain parts of the state of it. I'll keep it in mind for later.

Comment thread swarm/swarm_test.go
},
check: func(t *testing.T, s *Swarm, _ *api.Config) {
if s.backend != nil {
t.Error("backend is not nil")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this configuration mean in practice? Should it actually do something?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backend is related to swap, it is just unfortunately called.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the answer, but it doesn't seem important in any case.

@janos
Copy link
Copy Markdown
Member Author

janos commented May 18, 2018

This is a good beginning, but should we have deeper tests of some of the objects' states aswell?

Objects states are mostly private and not accessible from the swarm package where this test is. This test is covering only what can be reached.

Comment thread swarm/swarm_test.go
dir, err := ioutil.TempDir("", "swarm")
if err != nil {
t.Fatal(err)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer os.RemoveAll(dir)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ups, thanks Lewis. It is fixed now.

@zelig zelig merged commit d68fa66 into swarm-network-rewrite May 23, 2018
@zelig zelig deleted the test-newswarm branch May 23, 2018 09:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants