Skip to content

Commit 36a1507

Browse files
authored
fix: PocketIcBuilder::with_nns_state and PocketIcBuilder::with_subnet_state on Windows (#8628)
This PR makes the PocketIC library perform the conversion of the state directory path from its Windows-native form to the WSL-native form. This way, users of the PocketIC library (e.g., tests) do not have to perform the conversion repeatedly at all call sites.
1 parent e338b43 commit 36a1507

File tree

3 files changed

+5
-25
lines changed

3 files changed

+5
-25
lines changed

packages/pocket-ic/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ impl PocketIcBuilder {
347347
/// `-- tmp
348348
pub fn with_subnet_state(mut self, subnet_kind: SubnetKind, path_to_state: PathBuf) -> Self {
349349
let mut config = self.config.unwrap_or_default();
350-
let subnet_spec = SubnetSpec::default().with_state_dir(path_to_state);
350+
#[cfg(not(windows))]
351+
let state_dir = path_to_state;
352+
#[cfg(windows)]
353+
let state_dir = wsl_path(&path_to_state, "subnet state").into();
354+
let subnet_spec = SubnetSpec::default().with_state_dir(state_dir);
351355
match subnet_kind {
352356
SubnetKind::NNS => config.nns = Some(subnet_spec),
353357
SubnetKind::SNS => config.sns = Some(subnet_spec),

packages/pocket-ic/tests/icp_features.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ use std::collections::BTreeMap;
3434
use std::io::Read;
3535
use std::time::Duration;
3636
use tempfile::TempDir;
37-
#[cfg(windows)]
38-
use wslpath::windows_to_wsl;
3937

4038
mod common;
4139

@@ -1020,12 +1018,7 @@ fn read_registry() {
10201018
)]
10211019
fn with_all_icp_features_and_nns_state() {
10221020
let state_dir = TempDir::new().unwrap();
1023-
#[cfg(not(windows))]
10241021
let state_dir_path_buf = state_dir.path().to_path_buf();
1025-
#[cfg(windows)]
1026-
let state_dir_path_buf = windows_to_wsl(state_dir.path().as_os_str().to_str().unwrap())
1027-
.unwrap()
1028-
.into();
10291022

10301023
let _pic = PocketIcBuilder::new()
10311024
.with_icp_features(all_icp_features())
@@ -1036,12 +1029,7 @@ fn with_all_icp_features_and_nns_state() {
10361029
#[tokio::test]
10371030
async fn with_all_icp_features_and_nns_subnet_state() {
10381031
let state_dir = TempDir::new().unwrap();
1039-
#[cfg(not(windows))]
10401032
let state_dir_path_buf = state_dir.path().to_path_buf();
1041-
#[cfg(windows)]
1042-
let state_dir_path_buf = windows_to_wsl(state_dir.path().as_os_str().to_str().unwrap())
1043-
.unwrap()
1044-
.into();
10451033

10461034
let (_, url) = start_server(StartServerParams::default()).await;
10471035
let client = reqwest::Client::new();

packages/pocket-ic/tests/tests.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use std::{
3030
time::{Duration, SystemTime},
3131
};
3232
use tempfile::{NamedTempFile, TempDir};
33-
#[cfg(windows)]
34-
use wslpath::windows_to_wsl;
3533

3634
mod common;
3735

@@ -2783,12 +2781,7 @@ fn test_specified_id_on_resumed_state() {
27832781
#[should_panic(expected = "is not a (subnet state) directory")]
27842782
fn with_subnet_state_file() {
27852783
let state_file = NamedTempFile::new().unwrap();
2786-
#[cfg(not(windows))]
27872784
let state_file_path_buf = state_file.path().to_path_buf();
2788-
#[cfg(windows)]
2789-
let state_file_path_buf = windows_to_wsl(state_file.path().as_os_str().to_str().unwrap())
2790-
.unwrap()
2791-
.into();
27922785

27932786
let _pic = PocketIcBuilder::new()
27942787
.with_subnet_state(SubnetKind::Application, state_file_path_buf)
@@ -2799,12 +2792,7 @@ fn with_subnet_state_file() {
27992792
#[should_panic(expected = "Provided an empty state directory at path")]
28002793
fn with_empty_subnet_state() {
28012794
let state_dir = TempDir::new().unwrap();
2802-
#[cfg(not(windows))]
28032795
let state_dir_path_buf = state_dir.path().to_path_buf();
2804-
#[cfg(windows)]
2805-
let state_dir_path_buf = windows_to_wsl(state_dir.path().as_os_str().to_str().unwrap())
2806-
.unwrap()
2807-
.into();
28082796

28092797
let _pic = PocketIcBuilder::new()
28102798
.with_subnet_state(SubnetKind::Application, state_dir_path_buf)

0 commit comments

Comments
 (0)