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

Add TestNewSwarm and simplify NewSwarm constructor #557

Merged
merged 2 commits into from
May 23, 2018

Conversation

janos
Copy link
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

common.FromHex(config.BzzKey),
kp,
)

config.HiveParams.Discovery = true
Copy link
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?

@@ -228,7 +225,6 @@ func NewSwarm(ctx *node.ServiceContext, backend chequebook.Backend, config *api.
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
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
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
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?

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

Copy link
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
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
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?

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
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
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.

if s.dns == nil {
t.Error("dns is not initialized")
}
},
Copy link
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
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
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.

},
check: func(t *testing.T, s *Swarm, _ *api.Config) {
if s.backend != nil {
t.Error("backend is not nil")
Copy link
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
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
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
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.

dir, err := ioutil.TempDir("", "swarm")
if err != nil {
t.Fatal(err)
}
Copy link

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