From 74b110a10d194bee1db2c801ea44802815fd9862 Mon Sep 17 00:00:00 2001 From: mraszyk <31483726+mraszyk@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:43:07 +0100 Subject: [PATCH] feat: PocketIC supports force and shared network (#4002) --- CHANGELOG.md | 4 ++++ .../src/config/model/settings_digest.rs | 17 +++++++---------- src/dfx/src/commands/start.rs | 4 ++-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d76bb09abb..8ecc8f39df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/src/dfx-core/src/config/model/settings_digest.rs b/src/dfx-core/src/config/model/settings_digest.rs index bdbfda9280..7daceed3ae 100644 --- a/src/dfx-core/src/config/model/settings_digest.rs +++ b/src/dfx-core/src/config/model/settings_digest.rs @@ -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)] @@ -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, @@ -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 { @@ -105,7 +101,8 @@ fn get_replica_backend_settings( .unwrap_or_default(), artificial_delay, }; - BackendSettings::Replica { + BackendSettings { settings: Cow::Owned(replica_settings), + pocketic, } } diff --git a/src/dfx/src/commands/start.rs b/src/dfx/src/commands/start.rs index 9ba08000d9..ea9270e9b3 100644 --- a/src/dfx/src/commands/start.rs +++ b/src/dfx/src/commands/start.rs @@ -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] @@ -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,