-
Notifications
You must be signed in to change notification settings - Fork 110
Add TestNewSwarm and simplify NewSwarm constructor #557
Conversation
common.FromHex(config.BzzKey), | ||
kp, | ||
) | ||
|
||
config.HiveParams.Discovery = true |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine by me :)
There was a problem hiding this 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) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") | ||
} | ||
}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Objects states are mostly private and not accessible from the |
dir, err := ioutil.TempDir("", "swarm") | ||
if err != nil { | ||
t.Fatal(err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer os.RemoveAll(dir)
There was a problem hiding this comment.
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.
This PR: