Skip to content

Commit

Permalink
install canister on subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
fxgst committed Nov 8, 2023
1 parent 3a8fef4 commit 2d9322f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
7 changes: 5 additions & 2 deletions pocket_ic/pocket_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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})
)
Expand Down
13 changes: 10 additions & 3 deletions tests/pocket_ic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 2d9322f

Please sign in to comment.