-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use network.rpc_client() to get a contract's spec this will make sure that we're adding the necessary rpc provider headers, if they are required for the given provider * Use self.rpc_client() in network for creating a new rpc client * Refactor TestEnv to have a network field * Test that rpc_headers are being passed on rpc provider requests * Fix operations int test * Clippy * Add CC-1.0 to allowed licenses in deny.toml https://stellarfoundation.slack.com/archives/C92PPVBPT/p1734657921992129 * fix * Use workspace httpmock dep also - move soroban-test httpmock dep to dev-dependencies - use workspace dep for stellar-ledger test --------- Co-authored-by: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com>
- Loading branch information
1 parent
a5f0259
commit 1c0d4e6
Showing
13 changed files
with
155 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -6,5 +6,6 @@ mod init; | |
// #[cfg(feature = "it")] | ||
mod integration; | ||
mod plugin; | ||
mod rpc_provider; | ||
mod util; | ||
mod version; |
This file contains 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,97 @@ | ||
use httpmock::{prelude::*, Mock}; | ||
use serde_json::json; | ||
use soroban_rpc::{GetEventsResponse, GetNetworkResponse}; | ||
use soroban_test::{TestEnv, LOCAL_NETWORK_PASSPHRASE}; | ||
|
||
#[tokio::test] | ||
async fn test_use_rpc_provider_with_auth_header() { | ||
// mock out http request to rpc provider | ||
let server = MockServer::start(); | ||
let generate_account_mock = mock_generate_account(&server); | ||
let get_network_mock = mock_get_network(&server); | ||
let get_events_mock = mock_get_events(&server); | ||
|
||
// create a new test environment with the mock server | ||
let rpc_url = server.url(""); | ||
let rpc_headers = vec![("Authorization".to_string(), "Bearer test-token".to_string())]; | ||
let sandbox = &TestEnv::with_rpc_provider(&rpc_url, rpc_headers); | ||
|
||
sandbox | ||
.new_assert_cmd("events") | ||
.arg("--start-ledger") | ||
.arg("1000") | ||
.assert() | ||
.success(); | ||
|
||
// generate account is being called in `with_rpc_provider` | ||
generate_account_mock.assert(); | ||
// get_network and get_events are being called in the `stellar events` command | ||
get_network_mock.assert(); | ||
get_events_mock.assert(); | ||
} | ||
|
||
fn mock_generate_account(server: &MockServer) -> Mock { | ||
server.mock(|when, then| { | ||
when.method(GET) | ||
.path("/friendbot") | ||
.header("accept", "*/*") | ||
.header("user-agent", "soroban-cli/22.0.1"); //update this to be future proof | ||
then.status(200); | ||
}) | ||
} | ||
|
||
fn mock_get_network(server: &MockServer) -> Mock { | ||
server.mock(|when, then| { | ||
when.method(POST) | ||
.path("/") | ||
.header("authorization", "Bearer test-token") | ||
.json_body(json!({ | ||
"jsonrpc": "2.0", | ||
"id": 0, | ||
"method": "getNetwork" | ||
})); | ||
|
||
then.status(200).json_body(json!({ | ||
"jsonrpc": "2.0", | ||
"id": 0, | ||
"result": GetNetworkResponse { | ||
friendbot_url: None, | ||
passphrase: LOCAL_NETWORK_PASSPHRASE.to_string(), | ||
protocol_version: 22} | ||
})); | ||
}) | ||
} | ||
|
||
fn mock_get_events(server: &MockServer) -> Mock { | ||
server.mock(|when, then| { | ||
when.method(POST) | ||
.path("/") | ||
.header("authorization", "Bearer test-token") | ||
.json_body(json!({ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"method": "getEvents", | ||
"params": { | ||
"startLedger": 1000, | ||
"filters": [ | ||
{ | ||
"contractIds": [], | ||
"topics": [] | ||
} | ||
], | ||
"pagination": { | ||
"limit": 10 | ||
} | ||
} | ||
})); | ||
|
||
then.status(200).json_body(json!({ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": GetEventsResponse { | ||
events: vec![], | ||
latest_ledger: 1000 | ||
} | ||
})); | ||
}) | ||
} |
This file contains 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 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
Oops, something went wrong.