pub fn inter_canister_query_first_canister_multiple_request(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    let mut rng = ctx.rng.clone();
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    rt.block_on({
        async move {
            let endpoint = get_random_node_endpoint(&handle, &mut rng);
endpoint.assert_ready(ctx).await;
            let agent = assert_create_agent(endpoint.url.as_str()).await;

            let canister_b_wasm = wabt::wat2wasm(
                r#"(module
              (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
              (import "ic0" "msg_reply" (func $msg_reply))
              (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
              (func $hi
                (call $ic0_msg_arg_data_copy (i32.const 0) (i32.const 0) (i32.const 1))
                (call $msg_reply_data_append (i32.const 0) (i32.const 1))
                (call $msg_reply))
              (data (i32.const 0) "0")
              (memory $memory 1)
              (export "memory" (memory $memory))
              (export "canister_query hi" (func $hi)))"#,
            )
                .unwrap();
            let canister_b = create_and_install(&agent, &canister_b_wasm).await;

            let canister_a_wasm = wabt::wat2wasm(format!(
                r#"(module
                    (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
                    (import "ic0" "msg_reply" (func $msg_reply))
                    (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
                    (import "ic0" "debug_print" (func $debug_print (param i32) (param i32)))
                    (import "ic0" "call_new"
                        (func $ic0_call_new
                        (param i32 i32)
                        (param $method_name_src i32)    (param $method_name_len i32)
                        (param $reply_fun i32)          (param $reply_env i32)
                        (param $reject_fun i32)         (param $reject_env i32)
                    ))
                    (import "ic0" "call_data_append" (func $ic0_call_data_append (param $src i32) (param $size i32)))
                    (import "ic0" "call_perform" (func $ic0_call_perform (result i32)))
                    (func $hi
                      ;; heap[10] = payload[0]
                      (call $ic0_msg_arg_data_copy (i32.const 10) (i32.const 0) (i32.const 1))
                      ;; Call B
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                      ;; Call B again
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                    )
                    (func $on_reply (param $env i32)
                      ;; Increment that we saw a reply
                      (i32.store (i32.const 20) (i32.add (i32.const 1) (i32.load (i32.const 20))))
                      ;; if two replies seen, then reply
                      (if (i32.eq (i32.load (i32.const 20)) (i32.const 2))
                        (then
                          (call $msg_reply_data_append (i32.const 10) (i32.const 1))
                          (call $msg_reply)
                        )
                      )
                    )
                    (func $on_reject (param $env i32)
                      unreachable
                    )
                    (table funcref (elem $on_reply $on_reject))
                    (memory $memory 1)
                    (data (i32.const 0) "hi")
                    (data (i32.const 100) "{}")
                    (export "canister_query hi" (func $hi))
                    (export "memory" (memory $memory)))"#,
                canister_b.as_slice().len(),
                canister_b.as_slice().len(),
                escape_for_wat(&canister_b))).unwrap();
            let canister_a = create_and_install(&agent, &canister_a_wasm).await;
            let result = agent.query(&canister_a, "hi").with_arg(vec![5]).call().await.unwrap();
            assert_eq!(result, vec![5]);
        }
    });
}
/// End user sends a query msg to canisterA; canisterA sends two queries to
/// canisterB; canisterB replies to both; canisterA replies when it sees the
/// second reply from canisterB.
End user sends a query msg to canisterA; canisterA sends two queries to
canisterB; canisterB replies to both; canisterA replies when it sees the
second reply from canisterB.
End user sends a query msg to canisterA ; canisterA sends two queries to canisterB ; canisterB replies to both ; canisterA replies when it sees the second reply from canisterB .
pub fn inter_canister_query_first_canister_multiple_request(
    handle: IcHandle,
    ctx: &ic_fondue::pot::Context,
) {
    let mut rng = ctx.rng.clone();
    let rt = tokio::runtime::Runtime::new().expect("Could not create tokio runtime.");
    rt.block_on({
        async move {
            let endpoint = get_random_node_endpoint(&handle, &mut rng);
endpoint.assert_ready(ctx).await;
            let agent = assert_create_agent(endpoint.url.as_str()).await;
            let canister_b_wasm = wabt::wat2wasm(
                r#"(module
              (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
              (import "ic0" "msg_reply" (func $msg_reply))
              (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
              (func $hi
                (call $ic0_msg_arg_data_copy (i32.const 0) (i32.const 0) (i32.const 1))
                (call $msg_reply_data_append (i32.const 0) (i32.const 1))
                (call $msg_reply))
              (data (i32.const 0) "0")
              (memory $memory 1)
              (export "memory" (memory $memory))
              (export "canister_query hi" (func $hi)))"#,
            )
                .unwrap();
            let canister_b = create_and_install(&agent, &canister_b_wasm).await;
            let canister_a_wasm = wabt::wat2wasm(format!(
                r#"(module
                    (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
                    (import "ic0" "msg_reply" (func $msg_reply))
                    (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
                    (import "ic0" "debug_print" (func $debug_print (param i32) (param i32)))
                    (import "ic0" "call_new"
                        (func $ic0_call_new
                        (param i32 i32)
                        (param $method_name_src i32)    (param $method_name_len i32)
                        (param $reply_fun i32)          (param $reply_env i32)
                        (param $reject_fun i32)         (param $reject_env i32)
                    ))
                    (import "ic0" "call_data_append" (func $ic0_call_data_append (param $src i32) (param $size i32)))
                    (import "ic0" "call_perform" (func $ic0_call_perform (result i32)))
                    (func $hi
                      ;; heap[10] = payload[0]
                      (call $ic0_msg_arg_data_copy (i32.const 10) (i32.const 0) (i32.const 1))
                      ;; Call B
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                      ;; Call B again
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                    )
                    (func $on_reply (param $env i32)
                      ;; Increment that we saw a reply
                      (i32.store (i32.const 20) (i32.add (i32.const 1) (i32.load (i32.const 20))))
                      ;; if two replies seen, then reply
                      (if (i32.eq (i32.load (i32.const 20)) (i32.const 2))
                        (then
                          (call $msg_reply_data_append (i32.const 10) (i32.const 1))
                          (call $msg_reply)
                        )
                      )
                    )
                    (func $on_reject (param $env i32)
                      unreachable
                    )
                    (table funcref (elem $on_reply $on_reject))
                    (memory $memory 1)
                    (data (i32.const 0) "hi")
                    (data (i32.const 100) "{}")
                    (export "canister_query hi" (func $hi))
                    (export "memory" (memory $memory)))"#,
                canister_b.as_slice().len(),
                canister_b.as_slice().len(),
                escape_for_wat(&canister_b))).unwrap();
            let canister_a = create_and_install(&agent, &canister_a_wasm).await;
            let result = agent.query(&canister_a, "hi").with_arg(vec![5]).call().await.unwrap();
            assert_eq!(result, vec![5]);
        }
    });
}
pub fn inter_canister_query_first_canister_multiple_request ( handle : IcHandle , ctx : & ic_fondue :: pot :: Context , ) { let mut rng = ctx . rng . clone ( ) ; let rt = tokio :: runtime :: Runtime :: new ( ) . expect ( " " ) ; rt . block_on ( { async move { let endpoint = get_random_node_endpoint ( & handle , & mut rng ) ; endpoint . assert_ready ( ctx ) . await ; let agent = assert_create_agent ( endpoint . url . as_str ( ) ) . await ; let canister_b_wasm = wabt :: wat2wasm ( r#"(module
              (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
              (import "ic0" "msg_reply" (func $msg_reply))
              (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
              (func $hi
                (call $ic0_msg_arg_data_copy (i32.const 0) (i32.const 0) (i32.const 1))
                (call $msg_reply_data_append (i32.const 0) (i32.const 1))
                (call $msg_reply))
              (data (i32.const 0) "0")
              (memory $memory 1)
              (export "memory" (memory $memory))
              (export "canister_query hi" (func $hi)))"# , ) . unwrap ( ) ; let canister_b = create_and_install ( & agent , & canister_b_wasm ) . await ; let canister_a_wasm = wabt :: wat2wasm ( format ! ( r#"(module
                    (import "ic0" "msg_arg_data_copy" (func $ic0_msg_arg_data_copy (param i32) (param i32) (param i32)))
                    (import "ic0" "msg_reply" (func $msg_reply))
                    (import "ic0" "msg_reply_data_append" (func $msg_reply_data_append (param i32 i32)))
                    (import "ic0" "debug_print" (func $debug_print (param i32) (param i32)))
                    (import "ic0" "call_new"
                        (func $ic0_call_new
                        (param i32 i32)
                        (param $method_name_src i32)    (param $method_name_len i32)
                        (param $reply_fun i32)          (param $reply_env i32)
                        (param $reject_fun i32)         (param $reject_env i32)
                    ))
                    (import "ic0" "call_data_append" (func $ic0_call_data_append (param $src i32) (param $size i32)))
                    (import "ic0" "call_perform" (func $ic0_call_perform (result i32)))
                    (func $hi
                      ;; heap[10] = payload[0]
                      (call $ic0_msg_arg_data_copy (i32.const 10) (i32.const 0) (i32.const 1))
                      ;; Call B
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                      ;; Call B again
                      (i32.store
                        (i32.const 30)
                        (call $ic0_call_new
                          (i32.const 100) (i32.const {})  ;; reflector canister id
                          (i32.const 0) (i32.const 2)     ;; refers to "hi" on the heap
                          (i32.const 0) (i32.const 0)     ;; on_reply closure
                          (i32.const 0) (i32.const 0)     ;; on_reject closure
                        )
                        (call $ic0_call_data_append
                          (i32.const 10) (i32.const 1)    ;; refers to byte copied from the payload
                        )
                        (call $ic0_call_perform)
                      )
                    )
                    (func $on_reply (param $env i32)
                      ;; Increment that we saw a reply
                      (i32.store (i32.const 20) (i32.add (i32.const 1) (i32.load (i32.const 20))))
                      ;; if two replies seen, then reply
                      (if (i32.eq (i32.load (i32.const 20)) (i32.const 2))
                        (then
                          (call $msg_reply_data_append (i32.const 10) (i32.const 1))
                          (call $msg_reply)
                        )
                      )
                    )
                    (func $on_reject (param $env i32)
                      unreachable
                    )
                    (table funcref (elem $on_reply $on_reject))
                    (memory $memory 1)
                    (data (i32.const 0) "hi")
                    (data (i32.const 100) "{}")
                    (export "canister_query hi" (func $hi))
                    (export "memory" (memory $memory)))"# canister_b as_slice ( ) len ( ) canister_b as_slice ( ) len ( ) escape_for_wat ( canister_b ) ) ) . unwrap ( ) ; let canister_a = create_and_install ( & agent , & canister_a_wasm ) . await ; let result = agent . query ( & canister_a , " " ) . with_arg ( vec ! [ 5 ] ) . call ( ) . await . unwrap ( ) ; assert_eq ! ( result vec [ 5 ] ) ; } } ) ; }
End user sends a query msg to canisterA; canisterA sends two queries to
canisterB; canisterB replies to both; canisterA replies when it sees the
second reply from canisterB.
End user sends a query msg to canisterA ; canisterA sends two queries to canisterB ; canisterB replies to both ; canisterA replies when it sees the second reply from canisterB .
handle
IcHandle
ctx
&ic_fondue::pot::Context
handle
IcHandle
ctx
&ic_fondue::pot::Context