Skip to content

Commit b143dda

Browse files
add sui client test to address code cov
1 parent d2a5c25 commit b143dda

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

chain/sui/client_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package sui
2+
3+
import (
4+
"testing"
5+
6+
"github.com/smartcontractkit/chainlink-common/pkg/logger"
7+
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestGrpcTargetFromNodeURL(t *testing.T) {
12+
t.Parallel()
13+
14+
tests := []struct {
15+
name string
16+
nodeURL string
17+
want string
18+
wantErr string
19+
}{
20+
{
21+
name: "host with explicit port",
22+
nodeURL: "http://127.0.0.1:9000",
23+
want: "127.0.0.1:9000",
24+
},
25+
{
26+
name: "http scheme defaults to port 9000",
27+
nodeURL: "http://example.com",
28+
want: "example.com:9000",
29+
},
30+
{
31+
name: "https scheme defaults to port 443",
32+
nodeURL: "https://example.com",
33+
want: "example.com:443",
34+
},
35+
{
36+
name: "ipv6 host with port gets bracketed",
37+
nodeURL: "http://[::1]:9000",
38+
want: "[::1]:9000",
39+
},
40+
{
41+
name: "ipv6 host without port gets bracketed and defaulted",
42+
nodeURL: "http://[::1]",
43+
want: "[::1]:9000",
44+
},
45+
{
46+
name: "invalid URL returns error",
47+
nodeURL: "http://\x7f",
48+
wantErr: "parse node URL",
49+
},
50+
{
51+
name: "missing host returns error",
52+
nodeURL: "http:///path",
53+
wantErr: "has no host",
54+
},
55+
}
56+
57+
for _, tt := range tests {
58+
t.Run(tt.name, func(t *testing.T) {
59+
t.Parallel()
60+
61+
got, err := grpcTargetFromNodeURL(tt.nodeURL)
62+
if tt.wantErr != "" {
63+
require.Error(t, err)
64+
assert.Contains(t, err.Error(), tt.wantErr)
65+
return
66+
}
67+
require.NoError(t, err)
68+
assert.Equal(t, tt.want, got)
69+
})
70+
}
71+
}
72+
73+
func TestNewPTBClientFromNodeURL(t *testing.T) {
74+
t.Parallel()
75+
76+
log, err := logger.New()
77+
require.NoError(t, err)
78+
79+
t.Run("valid URL with empty token uses default", func(t *testing.T) {
80+
t.Parallel()
81+
82+
client, err := NewPTBClientFromNodeURL(log, "http://127.0.0.1:9000", "")
83+
require.NoError(t, err)
84+
require.NotNil(t, client)
85+
})
86+
87+
t.Run("valid URL with explicit token", func(t *testing.T) {
88+
t.Parallel()
89+
90+
client, err := NewPTBClientFromNodeURL(log, "http://127.0.0.1:9000", "my-token")
91+
require.NoError(t, err)
92+
require.NotNil(t, client)
93+
})
94+
95+
t.Run("invalid URL returns error", func(t *testing.T) {
96+
t.Parallel()
97+
98+
client, err := NewPTBClientFromNodeURL(log, "http://\x7f", "")
99+
require.Error(t, err)
100+
require.Nil(t, client)
101+
})
102+
}

0 commit comments

Comments
 (0)