Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolas Haimerl committed Feb 6, 2024
1 parent 1576d73 commit 51ae5f0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
57 changes: 30 additions & 27 deletions ic-agent/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,35 +675,38 @@ impl Agent {
) -> Result<Vec<u8>, AgentError> {
let mut retry_policy = get_retry_policy();

Check failure on line 676 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (linux)

cannot find function `get_retry_policy` in this scope

Check failure on line 676 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (macos)

cannot find function `get_retry_policy` in this scope

let mut request_accepted = false;
loop {
match self.request_status_signed(&request_id,effective_canister_id,signed_request_status).await? {
RequestStatusResponse::Unknown => {},

RequestStatusResponse::Received | RequestStatusResponse::Processing => {
if !request_accepted {
retry_policy.reset();
request_accepted = true;
}
}

RequestStatusResponse::Replied(ReplyResponse { arg, .. }) => {
return Ok(arg)
}

RequestStatusResponse::Rejected(response) => Err(AgentError::ReplicaError(response)),

RequestStatusResponse::Done => Err(AgentError::RequestStatusDoneNoReply(String::from(
*request_id,
))),
};

match retry_policy.next_backoff() {
#[cfg(not(target_family = "wasm"))]
Some(duration) => tokio::time::sleep(duration).await,
None => return Err(AgentError::TimeoutWaitingForResponse()),
let mut request_accepted = false;
loop {
match self
.request_status_signed(&request_id, effective_canister_id, signed_request_status)
.await?
{
RequestStatusResponse::Unknown => {}

RequestStatusResponse::Received | RequestStatusResponse::Processing => {
if !request_accepted {
retry_policy.reset();
request_accepted = true;
}
}

RequestStatusResponse::Replied(ReplyResponse { arg, .. }) => return Ok(arg),

RequestStatusResponse::Rejected(response) => {
Err(AgentError::ReplicaError(response))

Check failure on line 696 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (linux)

`match` arms have incompatible types

Check failure on line 696 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (macos)

`match` arms have incompatible types
}

RequestStatusResponse::Done => Err(AgentError::RequestStatusDoneNoReply(
String::from(*request_id),

Check failure on line 700 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (linux)

the trait bound `std::string::String: From<[u8; 32]>` is not satisfied

Check failure on line 700 in ic-agent/src/agent/mod.rs

View workflow job for this annotation

GitHub Actions / build (macos)

the trait bound `std::string::String: From<[u8; 32]>` is not satisfied
)),
};

match retry_policy.next_backoff() {
#[cfg(not(target_family = "wasm"))]
Some(duration) => tokio::time::sleep(duration).await,
None => return Err(AgentError::TimeoutWaitingForResponse()),
}
}
}

/// Call request_status on the RequestId in a loop and return the response as a byte vector.
Expand Down
31 changes: 18 additions & 13 deletions ref-tests/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! Contrary to ic-ref.rs, these tests are not meant to match any other tests. They're
//! integration tests with a running IC-Ref.
use std::{alloc::System, sync::Arc};
use candid::CandidType;
use ic_agent::{
agent::{agent_error::HttpErrorPayload, RejectCode, RejectResponse},
Expand All @@ -22,6 +21,7 @@ use ref_tests::{
get_wallet_wasm_from_env, universal_canister::payload, with_universal_canister,
with_wallet_canister,
};
use std::{alloc::System, sync::Arc};

#[ignore]
#[test]
Expand Down Expand Up @@ -69,7 +69,7 @@ fn basic_expiry() {
#[test]
fn wait_signed() {
with_universal_canister(|agent, canister_id| async move {
fn serialized_bytes(envelope:Envelope) -> Vec<u8>{
fn serialized_bytes(envelope: Envelope) -> Vec<u8> {
let mut serialized_bytes = Vec::new();
let mut serializer = serde_cbor::Serializer::new(&mut serialized_bytes);
serializer.self_describe().unwrap();
Expand All @@ -79,10 +79,9 @@ fn wait_signed() {
let arg = payload().reply_data(b"hello").build();
let ingress_expiry = (SystemTime::now() + Duration::from_secs(120)).as_nanos() as u64;

let agent_identity = Arc:new(create_basic_identity().unwrap());
let agent_identity = create_basic_identity().unwrap().into();
agent.set_arc_identity(agent_identity);


let call_envelope_content = EnvelopeContent::Call {
sender: agent.get_principal().unwrap(),
arg: arg.clone(),
Expand All @@ -101,15 +100,19 @@ fn wait_signed() {

let call_envelope_serialized = serialized_bytes(call_envelope);

agent.update_signed(canister_id,call_envelope_serialized).unwrap();

agent
.update_signed(canister_id, call_envelope_serialized)
.unwrap();

let paths: Vec<Vec<Label>> = vec![vec!["request_status".into(), call_request_id.to_vec().into()]];
let paths: Vec<Vec<Label>> = vec![vec![
"request_status".into(),
call_request_id.to_vec().into(),
]];
let read_state_envelope_content = EnvelopeContent::ReadState {
sender: agent.get_principal().unwrap(),
paths,
ingress_expiry,
};
sender: agent.get_principal().unwrap(),
paths,
ingress_expiry,
};

let read_signature = agent_identity.sign(read_state_envelope_content).unwrap();

Expand All @@ -122,8 +125,10 @@ fn wait_signed() {

let read_envelope_serialized = serialized_bytes(read_state_envelope);


let result = agent.wait_signed(call_request_id, canister_id, read_envelope_serialized).await.unwrap();
let result = agent
.wait_signed(call_request_id, canister_id, read_envelope_serialized)
.await
.unwrap();

assert_eq!(result.as_slice(), b"hello");

Expand Down

0 comments on commit 51ae5f0

Please sign in to comment.