Skip to content

test(sns): Porting sns-testing to the ICP mono repo, Part II - prototype - #4067

Closed
aterga wants to merge 22 commits into
dfinity:masterfrom
serokell:serokell/sns-testing
Closed

aterga wants to merge 22 commits into
dfinity:masterfrom
serokell:serokell/sns-testing

Conversation

@aterga

@aterga aterga commented Feb 23, 2025 •

Copy link
Copy Markdown
Contributor

This is the second PR for implementing the next-gen sns-testing tool. It can now be written in Rust and continuously tested against the latest SNS features.

At the core of this tool lies the PocketIC framework, the testing framework capable of creating a fully deterministic environment for testing complex ICP dapp scenarios.

This PR is authored by Serokell and reviewed by the DFINITY Foundation. Please refer to the reviews here: #3654

< Previous PR |

@aterga aterga left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a pass over rs/nervous_system/agent and
rs/nervous_system/integration_tests/src/nervous_system_agent_helpers.rs

Look very promising!

Some high-level suggestions:

  • Code organization. Let's have a clear separation between code that's test-only vs. production-ready code. How to best do that? Ideally, we'd have the separation on the level of crates. So there could be rs/nervous_system/helpers for the production-ready helpers (e.g., submitting a proposal makes sense to put there) while testing-related helpers could go to rs/nervous_system/integration_tests/helpers.
  • Safety Since any code that's production-ready can be used (at least in theory) from a system that's supposed to be fault tolerant, such code must not panic. Conversely, it's fine to panic in test-only code, unless handing or propagating the errors has clear advantages.
  • Restrict which types are exposed in the agent API. Clients who want to call a canister endpoint already need to know the basics, e.g., what is a principal, a canister ID, or a subaccount. But currently, calling agent function also requires them to import (and know about) some more specialized types, often only used in as a single function's request or response payload. We should aim to handle specialized types in the agent's implementation, while keeping the function signatures with basic types whenever possible. This is not necessarily a general rule, as sometimes avoiding too many parameters is worth keeping an argument of a specialized type (e.g., TransferArgs). But we do have an opportunity to prettify some canister APIs this way, which could simplify the client code and dependency graph.

Comment thread rs/nervous_system/agent/src/nns/cmc.rs Resolved
Comment thread rs/sns/testing/dfx.json Resolved
@rvem
rvem force-pushed the serokell/sns-testing branch from 8082975 to 72347e0 Compare February 27, 2025 10:52
@rvem
rvem force-pushed the serokell/sns-testing branch from 8b2a285 to bad90ea Compare March 10, 2025 13:22
@rvem

rvem commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

Code organization
Safety

Agree to both suggestions. The code from the nervous_system_agent_helpers module was refactored to avoid panicking in runtime and return Result instead. However, I didn't spend much time on providing decent error reporting, and in most cases, a plain String is used to report an error. This should be fine for now since these helpers will either panic in tests returning the message or in sns-testing CLI runtime.

Restrict which types are exposed in the agent API

I don't think it's a good idea always to avoid exposing internal APIs in agent helpers since internal API types may be quite nontrivial (e.g. ListProposals), so keeping the reference to the internal API type (and its documentation) might be a good idea. Additionally, some of these types have the Default trait implementation that might be suitable for the majority of use cases.

OTOH, for internal API types like GetProposal I believe it's worth hiding the wrapper and providing functions that operate on "primitive" types.

So I think the overall approach should be the following: if the internal API type is simple enough (i.e. wraps a couple "primitive" types whose purpose is straightforward), then we should avoid exposing the internal API, otherwise, it's better to depend on it. What do you think?

Comment thread rs/sns/testing/README.md Resolved
Comment thread rs/sns/testing/README.md Resolved
Comment thread rs/sns/testing/src/main.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/sns.rs Resolved
Comment thread rs/sns/testing/src/utils.rs Resolved
Comment thread rs/sns/testing/src/utils.rs Resolved
Comment thread rs/sns/testing/src/utils.rs Resolved
Comment thread rs/sns/testing/src/utils.rs Resolved
Comment thread rs/sns/testing/tests/sns_testing_ci.rs Resolved
Comment thread rs/sns/testing/tests/sns_testing_ci.rs Resolved
Comment thread rs/sns/testing/src/main.rs Resolved
@rvem
rvem force-pushed the serokell/sns-testing branch 2 times, most recently from 0493412 to ea79fec Compare March 17, 2025 12:59
@aterga
aterga marked this pull request as ready for review March 17, 2025 17:22
@aterga
aterga requested a review from a team as a code owner March 17, 2025 17:22
@rvem
rvem force-pushed the serokell/sns-testing branch from 3c8c66a to ee3a1fd Compare March 20, 2025 10:25
@rvem
rvem requested a review from a team as a code owner March 21, 2025 10:07
rvem added 20 commits March 27, 2025 09:13
We want to reuse some of the helpers from 'pocket_ic_helpers' module in
non PocketIC-specific environment. To achieve this, these helpers were
abtracted out to use generic 'CallCanisters' interface to interact with
the network.

'pocket_ic_helpers' interface remains the same and uses
'nervous_agent_helpers' implementation for those helpers that we
re-implemented.
We want to be able SNS-specific parts of sns-testing scenario on the
network provided either via PocketIC or via 'ic-agent' clients.

The following parts of sns-testing scenario were reimplemented to use
nervous-agent-based implementation:
* NNS proposal creation and adoption to create the new SNS.
* SNS swap completion.
* SNS proposal creation and adoption to upgrade the test canister.
Currently the CLI from sns-testing runs the basic scenario using
PocketIC API. However, we'd like to be able to run the scenario on
artibrary network available via ic-agent-compatible HTTP endpoint.

To achieve this, the CLI was split into two subcommands:
* 'nns-init'
  This subcommand bootstraps the NNS on a fresh PocketIC instance using
  PocketIC API.
* 'run-basic-scenario'
  This subcommand runs the basic scenario (create and adopt the new SNS
  via NNS proposal, complete SNS swap, upgrade SNS-controlled canister via SNS proposal)
  on a network provided by HTTP endpoint using 'ic-agent' as a backend.
…ning the basic scenario

If the network setup is invalid or the target canister doesn't have the
correct state (e.g. doesn't have the NNS Root canister as a controller),
the scenario may fail during the execution throwing potentially
confusing errors from NNS/SNS canisters and leaving the SNS in 'failed' state.
Moreover, these errors may not be thrown instantly and the user may have
to wait before actually knowing that something is off.

Add steps to validate the target IC network and the target test
canister.

Network validation checks the following:
1) All "backend" NNS canisters are installed.
2) The network has SNS subnet.
3) The SNS WASM canister has SNS canisters' WASM modules.

Test canister validation checks the following:
1) Canister was created and installed.
2) The NNS Root canister is controller of the canister.
Using user-provided identity as ICP treasury is error-prone since the
user may accidentally provide wrong identity name as an argument.

Use hardcoded identity instead. Since it's deterministically generated,
it's guaranteed to always be the same over 'sns-testing' invocations.
PocketIC now exposes a dedicated method to determine whether the
instance is running in 'auto_progress' mode.
@rvem
rvem force-pushed the serokell/sns-testing branch from 4368c53 to 03add34 Compare March 27, 2025 08:13
@aterga aterga changed the title test(sns): Porting sns-testing to the ICP mono repo, Part II test(sns): Porting sns-testing to the ICP mono repo, Part II - proto Mar 27, 2025
@aterga aterga changed the title test(sns): Porting sns-testing to the ICP mono repo, Part II - proto test(sns): Porting sns-testing to the ICP mono repo, Part II - prototype Mar 27, 2025
@aterga

aterga commented Mar 27, 2025

Copy link
Copy Markdown
Contributor Author

This branch has been copied over, and the PR was reopened here: #4548

@aterga aterga closed this Mar 27, 2025
github-merge-queue Bot pushed a commit that referenced this pull request Apr 1, 2025
This is the second PR for implementing the next-gen
[sns-testing](https://github.com/dfinity/sns-testing) tool. It can now
be written in Rust and continuously tested against the latest SNS
features.

At the core of this tool lies the [PocketIC
framework](https://crates.io/crates/pocket-ic/6.0.0), the testing
framework capable of creating a fully deterministic environment for
testing complex ICP dapp scenarios.

This PR is authored by Serokell and reviewed by the DFINITY Foundation.
Please refer to the reviews here:
#4067

< [Previous PR](#3979) |

---------

Co-authored-by: Roman Melnikov <[email protected]>
sasa-tomic pushed a commit that referenced this pull request Apr 7, 2025
This is the second PR for implementing the next-gen
[sns-testing](https://github.com/dfinity/sns-testing) tool. It can now
be written in Rust and continuously tested against the latest SNS
features.

At the core of this tool lies the [PocketIC
framework](https://crates.io/crates/pocket-ic/6.0.0), the testing
framework capable of creating a fully deterministic environment for
testing complex ICP dapp scenarios.

This PR is authored by Serokell and reviewed by the DFINITY Foundation.
Please refer to the reviews here:
#4067

< [Previous PR](#3979) |

---------

Co-authored-by: Roman Melnikov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants