Skip to content

Commit

Permalink
fix: Node.close() should check if channel has been initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
janaakhterov committed Dec 30, 2020
1 parent 5461af2 commit 2a57b35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 18 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ func TestClientFromConfig(t *testing.T) {
assert.Nil(t, client.operator)
}

func TestClientSetNetwork(t *testing.T) {
client := ClientForPreviewnet()

assert.NotNil(t, client)
assert.Equal(t, 4, len(client.network.network))
assert.Nil(t, client.operator)

network := make(map[string]AccountID)
network["35.237.200.180:50211"] = AccountID{0, 0, 3}
network["35.186.191.247:50211"] = AccountID{0, 0, 4}
network["35.192.2.25:50211"] = AccountID{0, 0, 5}
network["35.199.161.108:50211"] = AccountID{0, 0, 6}
network["35.203.82.240:50211"] = AccountID{0, 0, 7}

client.SetNetwork(network)
assert.Equal(t, 5, len(client.network.network))
}

func TestClientFromConfigWithOperator(t *testing.T) {
client, err := ClientFromConfig([]byte(testClientJSONWithOperator))
assert.NoError(t, err)
Expand Down
6 changes: 5 additions & 1 deletion node.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ func (node *node) getChannel() (*channel, error) {
}

func (node *node) close() error {
return node.channel.client.Close()
if node.channel != nil {
return node.channel.client.Close()
}

return nil
}

func (nodes nodes) Len() int {
Expand Down

0 comments on commit 2a57b35

Please sign in to comment.