Skip to content
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

EPROD 1082 migrate all dfx and state machine tests to pocket ic #238

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,5 @@ ic-cdk = "0.17"
ic-cdk-macros = "0.17"
ic-cdk-timers = "0.11"
ic-ledger-types = "0.14"
ic-test-state-machine-client = "3"
icrc-ledger-types = "0.1.0"
pocket-ic = "6"
1 change: 0 additions & 1 deletion ic-canister-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = "Client for interacting with an IC Canister"
default = []
ic-agent-client = ["dep:ic-agent"]
pocket-ic-client = ["dep:tokio", "ic-exports/pocket-ic-tests"]
state-machine-tests-client = ["dep:tokio", "ic-exports/ic-test-state-machine"]

[dependencies]
async-trait = { workspace = true }
Expand Down
11 changes: 0 additions & 11 deletions ic-canister-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ pub enum CanisterClientError {
#[error("ic agent error: {0}")]
IcAgentError(#[from] ic_agent::agent::AgentError),

#[cfg(feature = "state-machine-tests-client")]
#[error("state machine test error: {0}")]
StateMachineTestError(ic_exports::ic_test_state_machine::UserError),

#[cfg(feature = "pocket-ic-client")]
#[error("pocket-ic test error: {0:?}")]
PocketIcTestError(ic_exports::pocket_ic::CallError),
Expand All @@ -36,13 +32,6 @@ impl From<ic_exports::pocket_ic::UserError> for CanisterClientError {
}
}

#[cfg(feature = "state-machine-tests-client")]
impl From<ic_exports::ic_test_state_machine::UserError> for CanisterClientError {
fn from(error: ic_exports::ic_test_state_machine::UserError) -> Self {
CanisterClientError::StateMachineTestError(error)
}
}

pub type CanisterClientResult<T> = Result<T, CanisterClientError>;

/// This tuple is returned incase of IC errors such as Network, canister error.
Expand Down
5 changes: 0 additions & 5 deletions ic-canister-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ pub mod client;
pub mod error;
pub mod ic_client;

#[cfg(feature = "state-machine-tests-client")]
pub mod state_machine_tests;

#[cfg(feature = "pocket-ic-client")]
pub mod pocket_ic;

Expand All @@ -20,5 +17,3 @@ pub use ic_agent;
pub use ic_client::IcCanisterClient;
#[cfg(feature = "pocket-ic-client")]
pub use pocket_ic::PocketIcClient;
#[cfg(feature = "state-machine-tests-client")]
pub use state_machine_tests::StateMachineCanisterClient;
24 changes: 0 additions & 24 deletions ic-canister-client/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,6 @@ pub struct PocketIcClient {
pub caller: Principal,
}

impl Drop for PocketIcClient {
fn drop(&mut self) {
if let Some(client) = self.client.take() {
if let Ok(client) = Arc::try_unwrap(client) {
// Spawns a tokio task to drop the client.
// This workaround is necessary because Rust does not support async drop.
//
// This has some main drawbacks:
//
// 1. It panics if not executed in a tokio runtime.
// 2. As the spawn is executed in background, there's no guarantee that it will actually run.
//
// Not dropping the client will cause a memory leak in the PocketIc Server,
// however, this is not a big deal since the server will automatically clean
// the resources after 60 seconds of inactivity.
//
tokio::spawn(async move {
client.drop().await;
});
}
}
}
}

impl PocketIcClient {
/// Creates a new instance of a PocketIcClient.
/// The new instance is independent and have no access to canisters of other instances.
Expand Down
157 changes: 0 additions & 157 deletions ic-canister-client/src/state_machine_tests.rs

This file was deleted.

2 changes: 0 additions & 2 deletions ic-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ edition.workspace = true
default = []
ledger = ["ic-ledger-types"]
icrc = ["icrc-ledger-types"]
ic-test-state-machine = ["flate2", "ic-test-state-machine-client", "log", "reqwest", "tokio"]
pocket-ic-tests = ["flate2", "pocket-ic", "log", "reqwest", "tokio"]

[dependencies]
Expand All @@ -22,7 +21,6 @@ ic-cdk-timers = { workspace = true }
ic-crypto-getrandom-for-wasm = { path = "../ic-crypto-getrandom-for-wasm" }
ic-kit = { path = "../ic-kit" }
ic-ledger-types = { workspace = true, optional = true }
ic-test-state-machine-client = { workspace = true, optional = true }
icrc-ledger-types = { workspace = true, optional = true }
pocket-ic = { workspace = true, optional = true }
serde = { workspace = true }
Expand Down
111 changes: 0 additions & 111 deletions ic-exports/src/ic_test_state_machine.rs

This file was deleted.

3 changes: 0 additions & 3 deletions ic-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ pub mod icrc_types {

#[cfg(feature = "pocket-ic-tests")]
pub mod pocket_ic;

#[cfg(feature = "ic-test-state-machine")]
pub mod ic_test_state_machine;
2 changes: 1 addition & 1 deletion ic-exports/src/pocket_ic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{env, fs};
use flate2::read::GzDecoder;
use log::*;
pub use pocket_ic::nonblocking::*;
use pocket_ic::PocketIcBuilder;
pub use pocket_ic::PocketIcBuilder;
pub use pocket_ic::{common, CallError, ErrorCode, UserError, WasmResult};
use tokio::sync::OnceCell;

Expand Down
2 changes: 1 addition & 1 deletion ic-task-scheduler/tests/pocket_ic_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl PocketIcTestContext {
}
}

async fn deploy_dummy_scheduler_canister() -> anyhow::Result<PocketIcTestContext> {
async fn deploy_dummy_scheduler_canister<'a>() -> anyhow::Result<PocketIcTestContext> {
let client = init_pocket_ic().await.build_async().await;
println!("Creating dummy canister");

Expand Down
Loading