-
Notifications
You must be signed in to change notification settings - Fork 3
[Chore] Sui gRPC client migration #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f20f69e
initial draft
faisal-chainlink e26b8cd
initial draft
faisal-chainlink 5a75e9a
Merge branch 'main' into chore/sui-grpc-client-migration
faisal-chainlink 3fd4b96
Merge branch 'main' into chore/sui-grpc-client-migration
faisal-chainlink 1a74ee3
update deps
faisal-chainlink f2a4d03
update Sui mocks and deps
faisal-chainlink e08b190
update deps in /deployment
faisal-chainlink 0f4bdb0
update Sui balance check test
faisal-chainlink d550dc8
merge main
faisal-chainlink 7431cbe
update chainlink-sui dep ref
faisal-chainlink e3d6291
update mcms dep ref
faisal-chainlink cd72a9e
update mcms and chainlink-sui deps
faisal-chainlink 944da42
Merge branch 'main' into chore/sui-grpc-client-migration
faisal-chainlink a392659
tidy
faisal-chainlink 3f627a3
update MCMS ref
faisal-chainlink d2a5c25
lint fixes
faisal-chainlink b143dda
add sui client test to address code cov
faisal-chainlink 3ad0d1b
Potential fix for pull request finding
faisal-chainlink ef0b7f8
lint fixes
faisal-chainlink 0865474
Merge branch 'main' into chore/sui-grpc-client-migration
faisal-chainlink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package sui | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/url" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
|
|
||
| cslclient "github.com/smartcontractkit/chainlink-sui/relayer/client" | ||
| ) | ||
|
|
||
| const defaultGrpcToken = "test" | ||
|
|
||
| // NewPTBClientFromNodeURL creates a gRPC-backed Sui PTB client from an HTTP RPC URL. | ||
| func NewPTBClientFromNodeURL(log logger.Logger, nodeURL string, grpcToken string) (cslclient.SuiPTBClient, error) { | ||
| grpcTarget, err := grpcTargetFromNodeURL(nodeURL) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| if grpcToken == "" { | ||
| grpcToken = defaultGrpcToken | ||
| } | ||
|
faisal-chainlink marked this conversation as resolved.
|
||
|
|
||
| return cslclient.NewPTBClient(log, cslclient.PTBClientConfig{ | ||
| GrpcTarget: grpcTarget, | ||
| GrpcToken: grpcToken, | ||
| TransactionTimeout: 30 * time.Second, | ||
| MaxConcurrentRequests: 50, | ||
| DefaultRequestType: cslclient.WaitForEffectsCert, | ||
| }) | ||
| } | ||
|
|
||
| func grpcTargetFromNodeURL(nodeURL string) (string, error) { | ||
| u, err := url.Parse(nodeURL) | ||
| if err != nil { | ||
| return "", fmt.Errorf("parse node URL %q: %w", nodeURL, err) | ||
| } | ||
| host := u.Hostname() | ||
| port := u.Port() | ||
| if host == "" { | ||
| return "", fmt.Errorf("node URL %q has no host", nodeURL) | ||
| } | ||
| if port == "" { | ||
| switch u.Scheme { | ||
| case "https": | ||
| port = "443" | ||
| default: | ||
| port = "9000" | ||
| } | ||
| } | ||
| if strings.Contains(host, ":") && !strings.HasPrefix(host, "[") { | ||
| return fmt.Sprintf("[%s]:%s", host, port), nil | ||
| } | ||
|
|
||
| return fmt.Sprintf("%s:%s", host, port), nil | ||
| } | ||
|
faisal-chainlink marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| package sui | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGrpcTargetFromNodeURL(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| nodeURL string | ||
| want string | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "host with explicit port", | ||
| nodeURL: "http://127.0.0.1:9000", | ||
| want: "127.0.0.1:9000", | ||
| }, | ||
| { | ||
| name: "http scheme defaults to port 9000", | ||
| nodeURL: "http://example.com", | ||
| want: "example.com:9000", | ||
| }, | ||
| { | ||
| name: "https scheme defaults to port 443", | ||
| nodeURL: "https://example.com", | ||
| want: "example.com:443", | ||
| }, | ||
| { | ||
| name: "ipv6 host with port gets bracketed", | ||
| nodeURL: "http://[::1]:9000", | ||
| want: "[::1]:9000", | ||
| }, | ||
| { | ||
| name: "ipv6 host without port gets bracketed and defaulted", | ||
| nodeURL: "http://[::1]", | ||
| want: "[::1]:9000", | ||
| }, | ||
| { | ||
| name: "invalid URL returns error", | ||
| nodeURL: "http://\x7f", | ||
| wantErr: "parse node URL", | ||
| }, | ||
| { | ||
| name: "missing host returns error", | ||
| nodeURL: "http:///path", | ||
| wantErr: "has no host", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| got, err := grpcTargetFromNodeURL(tt.nodeURL) | ||
| if tt.wantErr != "" { | ||
| require.Error(t, err) | ||
| assert.Contains(t, err.Error(), tt.wantErr) | ||
|
|
||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestNewPTBClientFromNodeURL(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| log, err := logger.New() | ||
| require.NoError(t, err) | ||
|
|
||
| t.Run("valid URL with empty token uses default", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| client, err := NewPTBClientFromNodeURL(log, "http://127.0.0.1:9000", "") | ||
| require.NoError(t, err) | ||
| require.NotNil(t, client) | ||
| }) | ||
|
|
||
| t.Run("valid URL with explicit token", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| client, err := NewPTBClientFromNodeURL(log, "http://127.0.0.1:9000", "my-token") | ||
| require.NoError(t, err) | ||
| require.NotNil(t, client) | ||
| }) | ||
|
|
||
| t.Run("invalid URL returns error", func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| client, err := NewPTBClientFromNodeURL(log, "http://\x7f", "") | ||
| require.Error(t, err) | ||
| require.Nil(t, client) | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.