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

chore: create PocketIC instance via PocketIC library #4007

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions src/dfx-core/src/config/model/dfinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,17 @@ impl ReplicaLogLevel {
Self::Trace => "trace".to_string(),
}
}

pub fn to_level(&self) -> slog::Level {
match self {
Self::Critical => slog::Level::Critical,
Self::Error => slog::Level::Error,
Self::Warning => slog::Level::Warning,
Self::Info => slog::Level::Info,
Self::Debug => slog::Level::Debug,
Self::Trace => slog::Level::Trace,
}
}
}

/// # Local Replica Configuration
Expand Down
16 changes: 2 additions & 14 deletions src/dfx-core/src/config/model/replica_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::config::model::dfinity::{ReplicaLogLevel, ReplicaSubnetType};
use candid::Principal;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::default::Default;
Expand Down Expand Up @@ -193,7 +192,6 @@ pub enum CachedReplicaConfig<'a> {
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
pub struct CachedConfig<'a> {
pub replica_rev: String,
pub effective_canister_id: Option<Principal>,
#[serde(flatten)]
pub config: CachedReplicaConfig<'a>,
}
Expand All @@ -202,30 +200,20 @@ impl<'a> CachedConfig<'a> {
pub fn replica(config: &'a ReplicaConfig, replica_rev: String) -> Self {
Self {
replica_rev,
effective_canister_id: None,
config: CachedReplicaConfig::Replica {
config: Cow::Borrowed(config),
},
}
}
pub fn pocketic(
config: &'a ReplicaConfig,
replica_rev: String,
effective_canister_id: Option<Principal>,
) -> Self {
pub fn pocketic(config: &'a ReplicaConfig, replica_rev: String) -> Self {
Self {
replica_rev,
effective_canister_id,
config: CachedReplicaConfig::PocketIc {
config: Cow::Borrowed(config),
},
}
}
pub fn can_share_state(&self, other: &Self) -> bool {
// effective canister id does not matter for ability to share state
self.replica_rev == other.replica_rev && self.config == other.config
}
pub fn get_effective_canister_id(&self) -> Option<Principal> {
self.effective_canister_id
self == other
}
}
4 changes: 1 addition & 3 deletions src/dfx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ os_str_bytes = { version = "6.3.0", features = ["conversions"] }
patch = "0.7.0"
pem.workspace = true
petgraph = "0.6.0"
pocket-ic = { git = "https://github.com/dfinity/ic", rev = "a62848817cec7ae50618a87a526c85d020283fd9" }
rand = "0.8.5"
regex = "1.5.5"
reqwest = { workspace = true, features = ["blocking", "json"] }
Expand Down Expand Up @@ -126,9 +127,6 @@ ci_info = "0.14"
[target.'cfg(windows)'.dependencies]
junction = "1.0.0"

[target.'cfg(unix)'.dependencies]
pocket-ic = { git = "https://github.com/dfinity/ic", rev = "a62848817cec7ae50618a87a526c85d020283fd9" }

[dev-dependencies]
env_logger = "0.10"
proptest = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/actors/btc_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ fn btc_adapter_start_thread(
// This waits for the child to stop, or the receiver to receive a message.
// We don't restart the adapter if done = true.
match wait_for_child_or_receiver(&mut child, &receiver) {
ChildOrReceiver::Receiver => {
ChildOrReceiver::Receiver(()) => {
debug!(logger, "Got signal to stop. Killing btc-adapter process...");
let _ = child.kill();
let _ = child.wait();
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/actors/canister_http_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn canister_http_adapter_start_thread(
// This waits for the child to stop, or the receiver to receive a message.
// We don't restart the adapter if done = true.
match wait_for_child_or_receiver(&mut child, &receiver) {
ChildOrReceiver::Receiver => {
ChildOrReceiver::Receiver(()) => {
debug!(
logger,
"Got signal to stop. Killing ic-https-outcalls-adapter process..."
Expand Down
3 changes: 1 addition & 2 deletions src/dfx/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ pub fn start_pocketic_actor(
};
let actor_config = pocketic::Config {
pocketic_path,
effective_config_path: local_server_descriptor.effective_config_path(),
replica_config,
bitcoind_addr: local_server_descriptor.bitcoin.nodes.clone(),
bitcoin_integration_config,
Expand All @@ -223,7 +222,7 @@ pub fn start_pocketic_actor(
logger: Some(env.get_logger().clone()),
verbose: env.get_verbose_level() > 0,
};
Ok(pocketic::PocketIc::new(actor_config).start())
Ok(pocketic::PocketIc::new(actor_config, env.get_pocketic_handle()).start())
}

#[context("Failed to start PostStart actor.")]
Expand Down
Loading
Loading