feat(PocketIC): support for specifying subnet cost schedule#9419
Open
feat(PocketIC): support for specifying subnet cost schedule#9419
Conversation
adambratschikaye
approved these changes
Mar 17, 2026
Comment on lines
+3321
to
+3342
| async fn rental_subnet_with_subnet_admins() { | ||
| // Create a PocketIC instance with a single rental subnet. | ||
| let admin = Principal::anonymous(); | ||
| let subnet_spec = SubnetSpec::default() | ||
| .with_subnet_admins(vec![admin]) | ||
| .with_cost_schedule(CanisterCyclesCostSchedule::Free); | ||
| let config = ExtendedSubnetConfigSet { | ||
| application: vec![subnet_spec], | ||
| ..Default::default() | ||
| }; | ||
| let mut pic = PocketIcBuilder::new_with_config(config).build_async().await; | ||
|
|
||
| // Derive the rental subnet's subnet ID. | ||
| let topology = pic.topology().await; | ||
| let rental_subnet = topology.get_app_subnets()[0]; | ||
|
|
||
| // Run the test. | ||
| rental_subnet_or_cloud_engine_test(&mut pic, rental_subnet).await; | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn cloud_engine_with_subnet_admins() { |
Contributor
There was a problem hiding this comment.
These two tests still are almost entirely duplicated. Maybe rental_subnet_or_cloud_engine_test can take a closure SubnetSpec -> ExtendedSubnetConfigSet or something and have that be the only difference?
Contributor
Author
There was a problem hiding this comment.
The reusable test function would also need to take a closure Topology -> Principal abstracting over
let rental_subnet = topology.get_app_subnets()[0];
and
let cloud_engine = topology.get_cloud_engines()[0];
respectively (we should test that the PocketIC builder created the appropriate subnet kind and thus enumerating all subnets and taking the first one would reduce test coverage).
If we want to make the test more compact, I'd suggest to introduce a private enum:
enum FreeSubnet {
RentalSubnet,
CloudEngine,
}
and do stuff like
let subnet_id = match free_subnet {
FreeSubnet::RentalSubnet => topology.get_app_subnets()[0],
FreeSubnet::CloudEngine => topology.get_cloud_engines()[0],
};
What do you think?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for specifying subnet cost schedule in PocketIC.
Note: backward-compatibility is ensured by using
#[serde(default)](commit).