Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PocketIC): Support for new server version 2.0.1 #52

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## 2.0.1 - 2023-11-23

### Added
- Support for PocketIC server version 2.0.1


### Changed
- When the PocketIC binary is not found, the error now points to the PocketIC repo instead of the download link



## 2.0.0 - 2023-11-21

### Added
Expand Down
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
pocket-ic-darwin-gz = {
url = "https://download.dfinity.systems/ic/29ec86dc9f9ca4691d4d4386c8b2aa41e14d9d16/openssl-static-binaries/x86_64-darwin/pocket-ic.gz";
url = "https://download.dfinity.systems/ic/69e1408347723dbaa7a6cd2faa9b65c42abbe861/openssl-static-binaries/x86_64-darwin/pocket-ic.gz";
flake = false;
};
pocket-ic-linux-gz = {
url = "https://download.dfinity.systems/ic/29ec86dc9f9ca4691d4d4386c8b2aa41e14d9d16/openssl-static-binaries/x86_64-linux/pocket-ic.gz";
url = "https://download.dfinity.systems/ic/69e1408347723dbaa7a6cd2faa9b65c42abbe861/openssl-static-binaries/x86_64-linux/pocket-ic.gz";
flake = false;
};
};
Expand Down
16 changes: 0 additions & 16 deletions pocket_ic/pocket_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,6 @@ def create_canister(
Returns:
ic.Principal: the ID of the created canister
"""

if canister_id:
subnet_id = self.get_subnet(canister_id)
if not subnet_id:
raise ValueError("Canister ID not contained in any subnet")

topology = {k.to_str(): v for k, v in self.topology.items()}
subnet_kind = topology[subnet_id.to_str()]
if (
subnet_kind == SubnetKind.APPLICATION
or subnet_kind == SubnetKind.SYSTEM
):
raise ValueError(
"Creating a canister with ID is only supported on Bitcoin, Fiduciary, II, SNS and NNS subnets"
)

record = Types.Record(
{
"settings": Types.Opt(
Expand Down
6 changes: 1 addition & 5 deletions pocket_ic/pocket_ic_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@ def __init__(self) -> None:
The PocketIC binary could not be found at "{bin_path}". Please specify the path to the binary with the POCKET_IC_BIN environment variable, \
or place it in your current working directory (you are running PocketIC from {os.getcwd()}).

Run the following commands to get the binary:
curl -sLO https://download.dfinity.systems/ic/29ec86dc9f9ca4691d4d4386c8b2aa41e14d9d16/openssl-static-binaries/x86_64-$platform/pocket-ic.gz
gzip -d pocket-ic.gz
chmod +x pocket-ic
where $platform is 'linux' for Linux and 'darwin' for Intel/rosetta-enabled Darwin.
To download the binary, please visit https://github.com/dfinity/pocketic.
"""
)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pocket_ic"
version = "2.0.0"
version = "2.0.1"
description = "PocketIC: A Canister Smart Contract Testing Platform"
authors = [
"The Internet Computer Project Developers <dept-testing_&_verification@dfinity.org>",
Expand Down
24 changes: 6 additions & 18 deletions tests/pocket_ic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,6 @@


class PocketICTests(unittest.TestCase):
def test_create_canister_with_id_failures(self):
pic = PocketIC(SubnetConfig(application=1))
existing_canister_id = pic.create_canister()
with self.assertRaises(ValueError) as ex:
pic.create_canister(canister_id=existing_canister_id)
self.assertEqual(
ex.exception.args[0],
"Creating a canister with ID is only supported on Bitcoin, Fiduciary, II, SNS and NNS subnets",
)

pic = PocketIC(SubnetConfig(nns=True))
canister_id = ic.Principal.anonymous()
with self.assertRaises(ValueError) as ex:
pic.create_canister(canister_id=canister_id)
self.assertEqual(
ex.exception.args[0], "Canister ID not contained in any subnet"
)

def test_create_canister_with_id(self):
pic = PocketIC(SubnetConfig(nns=True))
canister_id = ic.Principal.from_str("rwlgt-iiaaa-aaaaa-aaaaa-cai")
Expand All @@ -49,6 +31,12 @@ def test_create_canister_with_id(self):
new_canister_id = pic.create_canister()
self.assertNotEqual(new_canister_id.bytes, canister_id.bytes)

# Creating a canister with an ID that is not hosted by any subnet fails.
canister_id = ic.Principal.anonymous()
with self.assertRaises(ValueError) as ex:
pic.create_canister(canister_id=canister_id)
self.assertIn("CanisterNotHostedBySubnet", ex.exception.args[0])

def test_large_config_and_deduplication(self):
pic = PocketIC(
SubnetConfig(
Expand Down