diff --git a/pocket_ic/pocket_ic.py b/pocket_ic/pocket_ic.py index b0f7544..128279c 100644 --- a/pocket_ic/pocket_ic.py +++ b/pocket_ic/pocket_ic.py @@ -82,7 +82,10 @@ def get_subnet_of_canister(self, canister_id: ic.Principal) -> Optional[ic.Princ "canister_id": base64.b64encode(canister_id.bytes).decode() } res = self._instance_post("read/canister_exists", payload) - return ic.Principal.from_str(res["subnet_id"]) if res is not None else None + if res: + b = base64.b64decode(res["canister_id"]) + return ic.Principal(b) + return None def check_canister_exists(self, canister_id: ic.Principal) -> bool: """Check whether the provided canister exists. @@ -240,7 +243,7 @@ def create_canister(self, settings: Optional[list] = None, subnet: Optional[ic.P {"type": record, "value": {"settings": settings if settings else []}} ] - request_result = self._canister_call("update/execute_ingress_message", None, {"SubnetId": subnet.to_str()} if subnet else None, "provisional_create_canister_with_cycles", ic.encode(payload)) + request_result = self._canister_call("update/execute_ingress_message", None, {"SubnetId": list(bytes(subnet.bytes))} if subnet else None, "provisional_create_canister_with_cycles", ic.encode(payload)) candid = ic.decode( bytes(request_result), Types.Record({"canister_id": Types.Principal}) ) diff --git a/tests/pocket_ic_test.py b/tests/pocket_ic_test.py index 5c14d23..4c2c830 100644 --- a/tests/pocket_ic_test.py +++ b/tests/pocket_ic_test.py @@ -24,10 +24,17 @@ def tearDown(self) -> None: del self.pic return super().tearDown() - def test_basic_multi_subnet(self): + def test_install_canister_on_subnet(self): config = [NNS, STANDARD] pic = PocketIC(config) - id = pic.create_canister() + + canister_1 = pic.create_canister(subnet=ic.Principal.from_str("fscpm-uiaaa-aaaaa-aaaap-yai")) + canister_2 = pic.create_canister(subnet=ic.Principal.from_str("yndj2-3ybaa-aaaaa-aaaap-yai")) + + subnet_1 = pic.get_subnet_of_canister(canister_1) + print(subnet_1) + subnet_2 = pic.get_subnet_of_canister(canister_2) + print(subnet_2) def test_set_get_stable_memory_no_compression(self): canister_id = self.pic.create_canister() @@ -76,7 +83,7 @@ def test_canister_exists(self): self.assertEqual(self.pic.check_canister_exists(canister_id), True) def test_canister_exists_negative(self): - canister_id = ic.Principal.from_str("rwlgt-iiaaa-aaaaa-aaaaa-cai") + canister_id = ic.Principal.anonymous() self.assertEqual(self.pic.check_canister_exists(canister_id), False) def test_cycles_balance(self):