-
Notifications
You must be signed in to change notification settings - Fork 863
Backport release/v6.3: Adjusted RPC http requests to use POST instead of GET
#2687
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
5 commits
Select commit
Hold shift + click to select a range
a27d511
Adjusted RPC http requests to use POST instead of GET (#2675)
monty-sei c594bc1
Merge branch 'release/v6.3' into backport-2675-to-release/v6.3
masih 885b7f2
Merge branch 'release/v6.3' into backport-2675-to-release/v6.3
masih 10cb469
Merge branch 'release/v6.3' into backport-2675-to-release/v6.3
masih ec294f3
Merge branch 'release/v6.3' into backport-2675-to-release/v6.3
masih 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package cli | ||
|
|
||
| import ( | ||
| "crypto/ecdsa" | ||
| "crypto/rand" | ||
| "encoding/json" | ||
| "math/big" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/ethereum/go-ethereum/crypto" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetChainId(t *testing.T) { | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| chainIdHex string | ||
| chainId int64 | ||
| hasURL bool | ||
| }{ | ||
| {"mainnet chain id", "0x531", 1329, true}, | ||
| {"testnet chain id", "0x530", 1328, true}, | ||
| {"url error chain id", "", 0, false}, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
|
|
||
| //Setup RPC Server with result and get URL | ||
| rpcServer := getRPCServer(t, test.chainIdHex) | ||
| defer rpcServer.Close() | ||
|
|
||
| if test.hasURL { | ||
| chainId, err := getChainId(rpcServer.URL) | ||
| require.NoError(t, err) | ||
| require.Equal(t, *big.NewInt(test.chainId), *chainId) | ||
| } else { | ||
| _, err := getChainId("") | ||
| require.Error(t, err) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestGetNonce(t *testing.T) { | ||
| //Test nonce is zero for a new wallet | ||
| //Generate a new privateKey from secp256k1 and get public key | ||
| privateKey, err := ecdsa.GenerateKey(crypto.S256(), rand.Reader) | ||
| require.NoError(t, err) | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| publicKey ecdsa.PublicKey | ||
| nonceHex string | ||
| nonce uint64 | ||
| }{ | ||
| {"new address", privateKey.PublicKey, "0x0", uint64(0)}, | ||
| {"active address", privateKey.PublicKey, "0x5", uint64(5)}, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
|
|
||
| //Setup RPC Server with result and get URL | ||
| rpcServer := getRPCServer(t, test.nonceHex) | ||
| defer rpcServer.Close() | ||
|
|
||
| nonce, err := getNonce(rpcServer.URL, test.publicKey) | ||
| require.NoError(t, err) | ||
| require.Equal(t, nonce, test.nonce) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func getRPCServer(t *testing.T, result string) *httptest.Server { | ||
| return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| //Standard method call response from POST request to RPC | ||
| response := map[string]any{ | ||
| "jsonrpc": "2.0", | ||
| "id": "send-cli", | ||
| "result": result, | ||
| } | ||
|
|
||
| //Adjust to default GET response if not POST | ||
| if r.Method != http.MethodPost { | ||
| response = map[string]any{ | ||
| "sei": []map[string]any{ | ||
| { | ||
| "id": "evm:local", | ||
| "alias": "sei", | ||
| "state": "OK", | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| w.Header().Set("Content-Type", "application/json") | ||
| err := json.NewEncoder(w).Encode(response) | ||
| require.NoError(t, err) | ||
| })) | ||
| } |
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.