Rust-based SNS-testing

Project highlights

This project is dedicated to porting the old sns-testing to the ICP monorepo.

The new implementation is written in Rust to ensure the code is always tested to be compatible with the latest SNS feature.

It uses PocketIC to launch the local IC network on which users can test their SNSes.

Features

sns-testing allows users to easily bootstrap the local PocketIC-based IC network with pre-installed NNS-related canisters, including NNS dapp and Internet Identity.

Users can interact with canisters that expose a web UI through their browsers.

The local network is compatible with existing IC tooling, such as dfx and quill.

Community-driven activities (such as NNS voting to create the new SNS, SNS swap completion, and SNS voting) can be automated via the sns-testing CLI.

How to install

Clone the ICP monorepo and follow the sns-testing README.

Usage Example

The sns-testing README provides a more detailed step-by-step guide on how to deploy a user-defined SNS and interact with it during its lifecycle.

Set up the environment

  1. Create a dedicated dfx identity that will be used with sns-testing:

    dfx identity new sns-testing --storage-mode=plaintext
    
  2. Add all required binaries to PATH

    cd rs/sns/testing
    . scripts/env.sh
    

Bootstrap the local IC network

  1. Launch pocket-ic-server instance. The binary will remain running in the foregound, so this step has to be run in a separate terminal session.

    pocket-ic-server --ttl 600 --port 8888 # Feel free to use a different TTL
    
  2. Bootstrap the IC network

    bazel run //rs/sns/testing:sns-testing-init -- --server-url "http://127.0.0.1:8888" \
        --dev-identity sns-testing \
        --deciding-nns-neuron-id 1
    

These steps will launch the local IC network with a dfx-compatible HTTP endpoint exposed at http://127.0.0.1:8080.

The NNS on this network will have a neuron with ID 1 that has the majority of the voting power and is controlled by the sns-testing identity principal.

Get ICP tokens

Go to http://qoctq-giaaa-aaaaa-aaaea-cai.localhost:8080/tokens/ and click “Sign in with Internet Identity”. Follow the instructions to create the new identity (typically with ID 10000).

Click the “Receive” button on the NNS dapp web UI to get the ICP Address you can receive tokens to.

To receive tokens:

sns-testing --network http://127.0.0.1:8080 transfer-icp --amount 1000 \
	--to <ICP Address>

Received ICP tokens can be used to create an NNS neuron or to participate in the SNS swap.

Create the new SNS

The suggested way to create proposals to launch the new SNS is to use sns propose command from the sns CLI.

Note that to be able to make the SNS swap start directly after SNS creation, you’ll need to set start_time: null in the swap parameters in the SNS YAML config.

sns propose --network http://127.0.0.1:8080 --neuron-id 1 sns_init.yaml

Note that we’re using the same NNS neuron ID as in the sns-testing-init invocation above.

The NNS dapp web UI will show that the proposal to create the new SNS was adopted and executed:

Complete SNS swap

Open the NNS dapp launchpad (http://qoctq-giaaa-aaaaa-aaaea-cai.localhost:8080/launchpad/) to check the SNS swap state.

You can now participate in the swap using your identity (NNS dapp web UI or quill).

To complete the SNS swap by providing the maximum direct ICP commitment run:

sns-testing --network http://127.0.0.1:8080 swap-complete --sns-name "Daniel"

Identities that participated in the swap will increase their dissolve delay to participate in the SNS voting in the future.

Check the swap state in the NNS dapp once again to ensure that it was completed.

Perform SNS-controlled canister upgrade

The suggested way to submit SNS proposals is to use quill. For more info, please refer to the official documentation.

Once the SNS proposal is created, you can upvote it using the identities that participated in the SNS swap previously within sns-testing swap-complete command:

sns-testing --network http://127.0.0.1:8080 sns-proposal-upvote --sns-name "Daniel" --proposal-id "1" --wait

Check the NNS dapp to see the state of the SNS proposal.

Documentation

Please refer to the sns-testing README.

Future Plans

One possible improvement step is to remove the runtime dependency on bazel for sns-testing-init. This will allow the distribution of SNS testing binaries separately through a CDN.

Another direction is to provide PocketIC-based Rust helpers to develop and run testing scenarios in CI using the deterministic mode of PocketIC.

6 Likes