-
Notifications
You must be signed in to change notification settings - Fork 378
feat(outcalls): add flexible outcalls endpoint #7615
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 13 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
531c07d
quick
mihailjianu1 f5afe3a
add api
mihailjianu1 89ce91e
add more things
mihailjianu1 3ffe811
add test too
mihailjianu1 1d63c34
lint
mihailjianu1 c8ad104
add ic.did test
mihailjianu1 eeceec9
change to record opt
mihailjianu1 022269d
space
mihailjianu1 5e5a93e
Merge branch 'master' into mihailjianu1/outcalls-flexible-endpoint
mihailjianu1 04774bc
ic.did
mihailjianu1 39e46da
Merge branch 'master' into mihailjianu1/outcalls-flexible-endpoint
mihailjianu1 94a1ade
remove ic.did
mihailjianu1 bec081a
fix test
mihailjianu1 37344bc
change
mihailjianu1 3bd411f
fix build
mihailjianu1 9c7f446
u64
mihailjianu1 abdeaf0
remove guard
mihailjianu1 c073451
requested_counts -> replication
mihailjianu1 9a28db2
nat64 -> nat43
mihailjianu1 5b3a52f
Merge branch 'master' into mihailjianu1/outcalls-flexible-endpoint
mihailjianu1 f88f1f6
Automatically fixing code for linting and formatting issues
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
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
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
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,132 @@ | ||
| /* tag::catalog[] | ||
| Title:: Basic HTTP requests from canisters | ||
|
|
||
| Goal:: Ensure simple HTTP requests can be made from canisters. | ||
|
|
||
| Runbook:: | ||
| 0. Instantiate a universal VM with a webserver | ||
| 1. Instantiate an IC with one application subnet with the HTTP feature enabled. | ||
| 2. Install NNS canisters | ||
| 3. Install the proxy canister | ||
| 4. Make an update call to the proxy canister. | ||
|
|
||
| Success:: | ||
| 1. Received http response with status 200. | ||
|
|
||
| end::catalog[] */ | ||
| #![allow(deprecated)] | ||
|
|
||
| use anyhow::Result; | ||
| use anyhow::bail; | ||
| use canister_http::*; | ||
| use canister_test::Canister; | ||
| use dfn_candid::candid_one; | ||
| use ic_cdk::api::call::RejectionCode; | ||
| use ic_management_canister_types_private::{ | ||
| BoundedHttpHeaders, FlexibleCanisterHttpRequestArgs, HttpMethod, TransformContext, | ||
| TransformFunc, | ||
| }; | ||
| use ic_system_test_driver::driver::group::SystemTestGroup; | ||
| use ic_system_test_driver::driver::{ | ||
| test_env::TestEnv, | ||
| test_env_api::{READY_WAIT_TIMEOUT, RETRY_BACKOFF}, | ||
| }; | ||
| use ic_system_test_driver::systest; | ||
| use ic_system_test_driver::util::block_on; | ||
| use proxy_canister::FlexibleRemoteHttpRequest; | ||
| use slog::{Logger, info}; | ||
|
|
||
| fn main() -> Result<()> { | ||
| SystemTestGroup::new() | ||
| .with_setup(canister_http::setup) | ||
| .add_test(systest!(test)) | ||
| .execute_from_args()?; | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| pub fn test(env: TestEnv) { | ||
| let logger = env.logger(); | ||
| let mut nodes = get_node_snapshots(&env); | ||
| let node = nodes.next().expect("there is no application node"); | ||
| let runtime = get_runtime_from_node(&node); | ||
| let proxy_canister = create_proxy_canister(&env, &runtime, &node); | ||
| let webserver_ipv6 = get_universal_vm_address(&env); | ||
|
|
||
| block_on(async { | ||
| test_proxy_canister( | ||
| &proxy_canister, | ||
| format!("https://[{webserver_ipv6}]"), | ||
| logger, | ||
| ) | ||
| .await; | ||
| }); | ||
| } | ||
|
|
||
| async fn test_proxy_canister(proxy_canister: &Canister<'_>, url: String, logger: Logger) { | ||
| ic_system_test_driver::retry_with_msg_async!( | ||
| format!( | ||
| "calling send_request of proxy canister {} with URL {}", | ||
| proxy_canister.canister_id(), | ||
| url | ||
| ), | ||
| &logger, | ||
| READY_WAIT_TIMEOUT, | ||
| RETRY_BACKOFF, | ||
| || async { | ||
| let context = "There is context to be appended in body"; | ||
| let res = proxy_canister | ||
| .update_( | ||
| "send_flexible_request", | ||
| candid_one::< | ||
| Result<Vec<u8>, (RejectionCode, String)>, | ||
| FlexibleRemoteHttpRequest, | ||
| >, | ||
| FlexibleRemoteHttpRequest { | ||
| request: FlexibleCanisterHttpRequestArgs { | ||
| url: url.clone(), | ||
| headers: BoundedHttpHeaders::new(vec![]), | ||
| body: None, | ||
| transform: Some(TransformContext { | ||
| function: TransformFunc(candid::Func { | ||
| principal: proxy_canister.canister_id().get().0, | ||
| method: "transform_with_context".to_string(), | ||
| }), | ||
| context: context.as_bytes().to_vec(), | ||
| }), | ||
| method: HttpMethod::GET, | ||
| requested_counts: None, | ||
| }, | ||
| cycles: 500_000_000_000, | ||
| }, | ||
| ) | ||
| .await | ||
| .expect("Update call to proxy canister failed"); | ||
|
|
||
| let expected_error_msg = "FlexibleHttpRequest is not yet implemented"; | ||
|
|
||
| match res { | ||
| Ok(_) => { | ||
| bail!("Update call succeeded unexpectedly."); | ||
| } | ||
| Err((code, message)) => { | ||
| if message == expected_error_msg { | ||
| info!( | ||
| &logger, | ||
| "Http request failed with expected error. Code: {:?}, Message: {}", | ||
| code, message | ||
| ); | ||
| Ok(()) | ||
| } else { | ||
| bail!( | ||
| "Http request failed with unexpected error. Code: {:?}, Message: '{}'. Expected: '{}'", | ||
| code, message, expected_error_msg | ||
| ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ) | ||
| .await | ||
| .expect("Timeout waiting for http call to fail with the correct error"); | ||
| } |
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.