Skip to content

Commit 24a3df2

Browse files
committed
feat: make the library and tests compatible with server v10.0.0
1 parent 645f7a0 commit 24a3df2

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

pocket_ic/subnet_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _json(self) -> dict:
130130
"verified_application": self.verified_application,
131131
},
132132
"state_dir": self.state_dir,
133-
"nonmainnet_features": False,
133+
"nonmainnet_features": {},
134134
"log_level": None,
135135
"bitcoind_addr": None,
136136
}

tests/pocket_ic_test.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,32 +202,51 @@ def test_store_restore_state(self):
202202
self.assertEqual(stable_mem2, stable_mem)
203203
self.assertEqual(len(pic2.topology()), 2)
204204

205+
# delete the PocketIC instance
205206
del pic2
206207

207-
# create a new PocketIC instance with only the app subnet copied over
208-
config3 = SubnetConfig()
208+
# clean up
209+
shutil.rmtree(tmp_dir)
209210

210-
# get the app subnet's folder from the state directory
211-
with open(os.path.join(tmp_dir, "topology.json"), "r") as f:
212-
dirs = json.load(f)["subnet_configs"].items()
211+
def test_add_subnet_with_state(self):
212+
# create a PocketIC instance with a state directory
213+
tmp_dir = tempfile.mkdtemp()
214+
config = SubnetConfig(application=1, state_dir=tmp_dir)
215+
pic = PocketIC(config)
213216

214-
# find the app subnet's folder
215-
app_subnet_key = [
216-
k
217-
for k, v in dirs
218-
if v["subnet_config"]["subnet_kind"] == SubnetKind.APPLICATION.value
219-
][0]
217+
# create a canister on app subnet
218+
canister_id = pic.create_canister()
219+
pic.add_cycles(canister_id, 20_000_000_000_000)
220+
pic.install_code(canister_id, b"\x00\x61\x73\x6d\x01\x00\x00\x00", [])
220221

221-
config3.add_subnet_with_state(
222+
# set stable memory of the canister
223+
pic.set_stable_memory(canister_id, b"Hello world!")
224+
stable_mem = pic.get_stable_memory(canister_id)
225+
self.assertTrue(stable_mem.startswith(b"Hello world!"))
226+
227+
# delete the PocketIC instance
228+
del pic
229+
230+
# create a new PocketIC instance with only the app subnet restored from state
231+
config2 = SubnetConfig()
232+
233+
# get the app subnet's folder from the state directory
234+
# (the app subnet's folder is the only subfolder in the state directory)
235+
subfolders = [d for d in os.listdir(tmp_dir) if os.path.isdir(os.path.join(tmp_dir, d))]
236+
self.assertEqual(len(subfolders), 1)
237+
app_subnet_key = subfolders[0]
238+
239+
# add the app subnet with its state
240+
config2.add_subnet_with_state(
222241
SubnetKind.APPLICATION,
223242
os.path.join(tmp_dir, app_subnet_key),
224243
)
225244

226245
# app subnet canister stays, NNS subnet is not there
227-
pic3 = PocketIC(config3)
228-
stable_mem3 = pic3.get_stable_memory(canister_id)
229-
self.assertEqual(stable_mem3, stable_mem2)
230-
self.assertEqual(len(pic3.topology()), 1)
246+
pic2 = PocketIC(config2)
247+
stable_mem2 = pic2.get_stable_memory(canister_id)
248+
self.assertEqual(stable_mem2, stable_mem)
249+
self.assertEqual(len(pic2.topology()), 1)
231250

232251
# clean up
233252
shutil.rmtree(tmp_dir)

0 commit comments

Comments
 (0)