Skip to content

Commit

Permalink
825 invalid fallback mirror node insecure port (#829)
Browse files Browse the repository at this point in the history
* Removed port 5600 from toInsecure and refactored tests

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Removed all references to port 5600

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Changed old url references to mirror node with the actual one

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

* Deleted unnecessary print

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>

---------

Signed-off-by: NikolaMirchev <nikola.mirchev@limechain.tech>
  • Loading branch information
NicolaMirchev authored Nov 13, 2023
1 parent 639c8e6 commit 745eeed
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 50 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func ClientForName(name string) (*Client, error) {
case "local", "localhost":
network := make(map[string]AccountID)
network["127.0.0.1:50213"] = AccountID{Account: 3}
mirror := []string{"127.0.0.1:5600"}
mirror := []string{"127.0.0.1:433"}
client := ClientForNetwork(network)
client.SetMirrorNetwork(mirror)
return client, nil
Expand Down
4 changes: 2 additions & 2 deletions client_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const testClientJSONWrongTypeNetwork string = `{
"accountId": "0.0.3",
"privateKey": "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"
},
"mirrorNetwork": ["hcs.testnet.mirrornode.hedera.com:5600"]
"mirrorNetwork": ["testnet.mirrornode.hedera.com:443"]
}`

const testClientJSONWrongAccountIDNetwork string = `{
Expand All @@ -86,5 +86,5 @@ const testClientJSONWrongAccountIDNetwork string = `{
"accountId": "wrong",
"privateKey": "302e020100300506032b657004220420db484b828e64b2d8f12ce3c0a0e93a0b8cce7af1bb8f39c97732394482538e10"
},
"mirrorNetwork": ["hcs.testnet.mirrornode.hedera.com:5600"]
"mirrorNetwork": ["testnet.mirrornode.hedera.com:443"]
}`
26 changes: 14 additions & 12 deletions client_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,47 +175,49 @@ func TestUnitClientSetNetworkExtensive(t *testing.T) {

func TestUnitClientSetMirrorNetwork(t *testing.T) {
t.Parallel()


mirrorNetworkString := "testnet.mirrornode.hedera.com:443"
mirrorNetwork1String := "testnet1.mirrornode.hedera.com:443"
defaultNetwork := make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetworkString)
client, err := _NewMockClient()
require.NoError(t, err)
client.SetMirrorNetwork(defaultNetwork)

mirrorNetwork := client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

defaultNetworkWithExtraNode := make([]string, 0)
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, "hcs.testnet1.mirrornode.hedera.com:5600")
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, mirrorNetworkString)
defaultNetworkWithExtraNode = append(defaultNetworkWithExtraNode, mirrorNetwork1String)

client.SetMirrorNetwork(defaultNetworkWithExtraNode)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 2, len(mirrorNetwork))
require.True(t, contains(mirrorNetwork, "hcs.testnet.mirrornode.hedera.com:5600"))
require.True(t, contains(mirrorNetwork, "hcs.testnet1.mirrornode.hedera.com:5600"))
require.True(t, contains(mirrorNetwork, mirrorNetworkString))
require.True(t, contains(mirrorNetwork, mirrorNetwork1String))

defaultNetwork = make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet1.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetwork1String)

client.SetMirrorNetwork(defaultNetwork)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet1.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetwork1String, mirrorNetwork[0])

defaultNetwork = make([]string, 0)
defaultNetwork = append(defaultNetwork, "hcs.testnet.mirrornode.hedera.com:5600")
defaultNetwork = append(defaultNetwork, mirrorNetworkString)

client.SetMirrorNetwork(defaultNetwork)
mirrorNetwork = client.GetMirrorNetwork()
assert.Equal(t, 1, len(mirrorNetwork))
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

client.SetTransportSecurity(true)
mirrorNetwork = client.GetMirrorNetwork()
// SetTransportSecurity is deprecated, so the mirror node should not be updated
assert.Equal(t, "hcs.testnet.mirrornode.hedera.com:5600", mirrorNetwork[0])
assert.Equal(t, mirrorNetworkString, mirrorNetwork[0])

err = client.Close()
require.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go 1.21.3

use .
35 changes: 6 additions & 29 deletions managed_node_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,18 @@ func (address *_ManagedNodeAddress) _IsTransportSecurity() bool {
}

func (address *_ManagedNodeAddress) _ToInsecure() *_ManagedNodeAddress {
port := address.port

switch address.port {
case 50212:
port = 50211
case 443:
port = 5600
if address.port == 50212 {
address.port = uint32(50211)
}

return &_ManagedNodeAddress{
address: address.address,
port: port,
}
return address
}

func (address *_ManagedNodeAddress) _ToSecure() *_ManagedNodeAddress {
port := address.port

switch port {
case 50211:
return &_ManagedNodeAddress{
address: address.address,
port: 50212,
}
case 5600:
return &_ManagedNodeAddress{
address: address.address,
port: 443,
}
}

return &_ManagedNodeAddress{
address: address.address,
port: port,
if address.port == 50211 {
address.port = uint32(50212)
}
return address
}

func (address *_ManagedNodeAddress) _Equals(comp _ManagedNodeAddress) bool { //nolint
Expand Down
10 changes: 5 additions & 5 deletions managed_node_address_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func TestUnitManagedNodeAddressTest(t *testing.T) {
require.True(t, urlAddressInsecure.port == 50211)
require.True(t, urlAddressInsecure._String() == "0.testnet.hedera.com:50211")

mirrorNodeAddress, err := _ManagedNodeAddressFromString("hcs.mainnet.mirrornode.hedera.com:5600")
mirrorNodeAddress, err := _ManagedNodeAddressFromString("hcs.mainnet.mirrornode.hedera.com:50211")
require.NoError(t, err)
require.True(t, *mirrorNodeAddress.address == "hcs.mainnet.mirrornode.hedera.com")
require.True(t, mirrorNodeAddress.port == 5600)
require.True(t, mirrorNodeAddress._String() == "hcs.mainnet.mirrornode.hedera.com:5600")
require.True(t, mirrorNodeAddress.port == 50211)
require.True(t, mirrorNodeAddress._String() == "hcs.mainnet.mirrornode.hedera.com:50211")

mirrorNodeAddressSecure := mirrorNodeAddress._ToSecure()
require.True(t, *mirrorNodeAddressSecure.address == "hcs.mainnet.mirrornode.hedera.com")
Expand All @@ -77,8 +77,8 @@ func TestUnitManagedNodeAddressTest(t *testing.T) {

mirrorNodeAddressInsecure := mirrorNodeAddressSecure._ToInsecure()
require.True(t, *mirrorNodeAddressInsecure.address == "hcs.mainnet.mirrornode.hedera.com")
require.True(t, mirrorNodeAddressInsecure.port == 5600)
require.True(t, mirrorNodeAddressInsecure._String() == "hcs.mainnet.mirrornode.hedera.com:5600")
require.True(t, mirrorNodeAddressInsecure.port == 50211)
require.True(t, mirrorNodeAddressInsecure._String() == "hcs.mainnet.mirrornode.hedera.com:50211")

_, err = _ManagedNodeAddressFromString("this is a random string with spaces:443")
require.Error(t, err)
Expand Down
2 changes: 1 addition & 1 deletion utilities_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewIntegrationTestEnv(t *testing.T) IntegrationTestEnv {
} else if os.Getenv("HEDERA_NETWORK") == "localhost" {
network := make(map[string]AccountID)
network["127.0.0.1:50213"] = AccountID{Account: 3}
mirror := []string{"127.0.0.1:5600"}
mirror := []string{"127.0.0.1:443"}
env.Client = ClientForNetwork(network)
env.Client.SetMirrorNetwork(mirror)
} else if os.Getenv("HEDERA_NETWORK") == "testnet" {
Expand Down

0 comments on commit 745eeed

Please sign in to comment.