Skip to content

Commit

Permalink
feat: PocketIC supports force and shared network (#4002)
Browse files Browse the repository at this point in the history
  • Loading branch information
mraszyk authored Nov 22, 2024
1 parent 8cb62ce commit 74b110a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# UNRELEASED

### feat: `dfx start --pocketic` supports `--force` and shared networks.

`dfx start --pocketic` is now compatible with `--force` and shared networks.

### feat: error when using insecure identity on mainnet

This used to be a warning. A hard error can abort the command so that no insecure state will be on the mainnet.
Expand Down
17 changes: 7 additions & 10 deletions src/dfx-core/src/config/model/settings_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ struct ReplicaSettings {
}

#[derive(Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
enum BackendSettings<'a> {
Replica { settings: Cow<'a, ReplicaSettings> },
PocketIc,
struct BackendSettings<'a> {
settings: Cow<'a, ReplicaSettings>,
pocketic: bool,
}

#[derive(Serialize, Deserialize, PartialEq, Eq)]
Expand All @@ -60,11 +59,7 @@ pub fn get_settings_digest(
artificial_delay: u32,
pocketic: bool,
) -> String {
let backend = if pocketic {
BackendSettings::PocketIc
} else {
get_replica_backend_settings(local_server_descriptor, artificial_delay)
};
let backend = get_replica_backend_settings(local_server_descriptor, artificial_delay, pocketic);
let settings = Settings {
ic_repo_commit: ic_repo_commit.into(),
backend,
Expand All @@ -77,6 +72,7 @@ pub fn get_settings_digest(
fn get_replica_backend_settings(
local_server_descriptor: &LocalServerDescriptor,
artificial_delay: u32,
pocketic: bool,
) -> BackendSettings {
let http_handler = HttpHandlerSettings {
port: if let Some(port) = local_server_descriptor.replica.port {
Expand Down Expand Up @@ -105,7 +101,8 @@ fn get_replica_backend_settings(
.unwrap_or_default(),
artificial_delay,
};
BackendSettings::Replica {
BackendSettings {
settings: Cow::Owned(replica_settings),
pocketic,
}
}
4 changes: 2 additions & 2 deletions src/dfx/src/commands/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct StartOpts {
artificial_delay: u32,

/// Start even if the network config was modified.
#[arg(long, conflicts_with = "pocketic")]
#[arg(long)]
force: bool,

/// A list of domains that can be served. These are used for canister resolution [default: localhost]
Expand Down Expand Up @@ -338,7 +338,7 @@ pub fn exec(
&local_server_descriptor.scope,
LocalNetworkScopeDescriptor::Shared { .. }
);
if is_shared_network && !pocketic {
if is_shared_network {
save_json_file(
&local_server_descriptor.effective_config_path_by_settings_digest(),
&effective_config,
Expand Down

0 comments on commit 74b110a

Please sign in to comment.