Skip to content

Commit

Permalink
Use monorepo SNS CLI dependency instead of having an embedded binary …
Browse files Browse the repository at this point in the history
…& unify the behavior with the monorepo's SNS CLI (#91)

* Add sns-cli dependency

* Use the SNS CLI directly instead of calling an embedded binary

* Address MR feedback

* address feedback 2

* Address MR feeback 3

* MR feedback 4
  • Loading branch information
anchpop authored Mar 27, 2024
1 parent 9faea90 commit e931915
Show file tree
Hide file tree
Showing 23 changed files with 3,070 additions and 696 deletions.
3,062 changes: 2,948 additions & 114 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ slog = "^2.7.0"
tempfile = "3.5.0"
tokio = "^1.36.0"
url = "^2.4.1"
ic-sns-cli = { git = "https://github.com/dfinity/ic", rev = "5fe907da2193c6051634b29133280f53f2490d52" }

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
6 changes: 0 additions & 6 deletions extensions/nns/e2e/tests/nns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ teardown() {
assert_output --partial 'Common command-line options for `ic-admin`'
}

@test "sns binary exists and is executable" {
run "$(dfx cache show)/extensions/nns/sns-cli" --help
assert_failure
assert_output --partial "Initialize, deploy and interact with an SNS."
}

@test "dfx nns install command exists" {
run dfx nns install --help
assert_success
Expand Down
7 changes: 7 additions & 0 deletions extensions/sns/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Unreleased] - ReleaseDate

- The behavior of the `dfx sns` extension has been updated to match the `sns-cli` tool.
The main effect of this is that many deprecated commands have been removed, and the remaining commands have been renamed.
- Renamed `dfx sns config` to `dfx sns init-config-file`
- Removed `dfx sns config create`. Instead, check the [sns-testing repo](https://github.com/dfinity/sns-testing/blob/main/example_sns_init.yaml) for an example template you can base your `sns_init.yaml` on.
- Removed `dfx sns deploy`
- Introduced `dfx sns deploy-testflight`, which can be used to create a test deployment of the SNS on mainnet or on a local replica.

## [0.3.1] - 2024-02-09
- Same functionality as version `0.3.0`.

Expand Down
3 changes: 2 additions & 1 deletion extensions/sns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dfx-extensions-utils.workspace = true
[dependencies]
dfx-core.workspace = true
dfx-extensions-utils.workspace = true
ic-sns-cli.workspace = true

anyhow.workspace = true
clap.workspace = true
Expand All @@ -29,4 +30,4 @@ publish = false
# list of replacements to be made after issuing `cargo release -p nns SEMVER`

[package.metadata.dist]
include = ["extension.json", "sns-cli"]
include = ["extension.json"]
76 changes: 12 additions & 64 deletions extensions/sns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,90 +9,38 @@ dfx sns [subcommand] [flag]

Depending on the `dfx sns` subcommand you specify, additional arguments, options, and flags might apply. For reference information and examples that illustrate using `dfx sns` commands, select an appropriate command.

| Command | Description |
|----------------------------------------------------|----------------------------------------------------------------|
| [`create`](#_dfx_sns_create) | Creates an SNS configuration template. |
| [`validate`](#_dfx_sns_validate) | Checks whether the sns config file is valid. |
| [`deploy`](#_dfx_sns_deploy) | Deploys SNS canisters according to the local config. |
| [`prepare-canisters`](#_dfx_sns_prepare-canisters) | Prepares dapp canister(s) for SNS decentralization. |
| [`propose`](#_dfx_sns_propose) | Submits a CreateServiceNervousSystem NNS Proposal. |
| `help` | Displays usage information message for a specified subcommand. |
| Command | Description |
| ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
| [`init-config-file validate`](#_dfx_sns_init-config-file_validate) | Checks whether the sns config file is valid. |
| [`deploy-testflight`](#_dfx_sns_deploy-testflight) | Creates a test deployment of the SNS canisters according to the local config. |
| [`prepare-canisters`](#_dfx_sns_prepare-canisters) | Prepares dapp canister(s) for SNS decentralization by adding NNS root as one of their controllers. |
| [`propose`](#_dfx_sns_propose) | Submits a CreateServiceNervousSystem NNS Proposal. |
| `help` | Displays usage information message for a specified subcommand. |

To view usage information for a specific subcommand, specify the subcommand and the `--help` flag. For example, to see usage information for `dfx sns validate`, you can run the following command:

``` bash
dfx sns validate --help
```


## dfx sns create

Use the `dfx sns create` command to create an SNS configuration file. The configuration file specifies important, legally and financially relevant details about dapp decentralization. The file leaves blank parameters such as token name; you will need to fill these in.

### Basic usage

``` bash
dfx sns create
```

### Examples

You can use the `dfx sns create` command to create and view a configuration file:

``` bash
dfx sns create
less sns.yml
```

## dfx sns validate
## dfx sns init-config-file validate

Use the `dfx sns validate` command to verify that an SNS configuration file is well formed.

### Basic usage

``` bash
dfx sns validate
```

### Examples

You can use the `dfx sns validate` command to verify that a configuration template is valid. It is not; it needs details such as token name:

``` bash
dfx sns config create
```
Fill in the blank fields, then:
``` bash
dfx sns config validate
dfx sns init-config-file validate
```

## dfx sns deploy
## dfx sns deploy-testflight

Use the `dfx sns deploy` command to create SNS canisters according to the local configuration file.

Note: Deploying SNS canisters does not require a proposal, however there is a hefty fee. Please don't create canisters on mainnet until you have tested your configuration locally and are sure that you are happy with it.
Use the `dfx sns deploy-testflight` command to create a testflight deployment of the SNS canisters according to the local configuration file. A testflight is an sns deployed directly to a local replica or the Internet Computer, skipping the proposal, token swap, and sns-wasm canister. The SNS canisters remain controlled by the developer after deployment. See [the testflight documentation](https://internetcomputer.org/docs/current/developer-docs/daos/sns/testing/testing-on-mainnet) for more details.

### Basic usage

``` bash
dfx sns deploy
```

### Examples

Create an SNS on the local testnet:
``` bash
dfx sns config create
```
Fill in the blank fields, then:
``` bash
dfx sns config validate
dfx sns deploy
```
You can now verify that the sns canisters have been created. E.g.:
```
dfx canister info sns_root
dfx canister info sns_ledger
dfx sns deploy-testflight --init-config-file /path/to/sns_init.yaml
```

## dfx sns prepare-canisters
Expand Down
46 changes: 0 additions & 46 deletions extensions/sns/e2e/assets/sns/valid/sns.yml

This file was deleted.

98 changes: 25 additions & 73 deletions extensions/sns/e2e/tests/sns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,65 +17,44 @@ teardown() {
}

# The location of the SNS init config.
SNS_CONFIG_FILE_NAME="sns.yml"
SNS_CONFIG_FILE_V2_NAME="sns_v2.yml"
SNS_CONFIG_FILE_NAME="sns_init.yaml"

@test "sns-cli binary exists and is executable" {
run "$(dfx cache show)"/extensions/sns/sns-cli --help
assert_output --partial "Initialize, deploy and interact with an SNS"
}

@test "sns config create and validate fail outside of a project" {
run dfx sns config create
assert_failure
assert_output --partial 'Error: Cannot find dfx configuration file in the current working directory. Did you forget to create one?'
run dfx sns config validate
assert_failure
assert_output --partial 'Error: Cannot find dfx configuration file in the current working directory. Did you forget to create one?'
}

@test "sns config create creates a default configuration" {
dfx_new
run dfx sns config create
assert_success
assert_output --regexp "Created SNS configuration at: .*/sns.yml"
: "Check that the file exists..."
test -e sns.yml
}

@test "sns config validate approves a valid configuration" {
@test "sns init-config-file validate approves a valid configuration" {
dfx_new
install_asset sns/valid
run dfx sns config validate
run dfx sns init-config-file validate
assert_success
assert_output --partial 'SNS config file is valid'
assert_output '' # no output if the file is valid
}

@test "sns config validate identifies a missing key" {
@test "sns init-config-file validate identifies a missing key" {
dfx_new
install_asset sns/valid
grep -v token_name "${SNS_CONFIG_FILE_NAME}" | sponge "$SNS_CONFIG_FILE_NAME"
run dfx sns config validate
# make the config file invalid by removing lines that contain "transaction_fee"
# every test is run in a unique temporary directory, so we aren't modifying
# anything that will be used by other tests by doing this.
grep -v transaction_fee "${SNS_CONFIG_FILE_NAME}" | sponge "$SNS_CONFIG_FILE_NAME"
run dfx sns init-config-file validate
assert_failure
assert_output --partial "Error: token-name must be specified"

assert_output --partial "transaction_fee"
}

@test "sns deploy exists" {
dfx sns deploy --help
@test "sns propose exists" {
run dfx sns propose --help
assert_output --partial "Subcommand for submitting a CreateServiceNervousSystem NNS Proposal"
}

@test "sns deploy fails without config file" {
@test "sns propose fails without config file" {
dfx_extension_install_manually nns
dfx_new
dfx nns import
rm -f sns.yml # Is not expected to be present anyway
run dfx sns deploy
run dfx sns propose --neuron-id 1
assert_failure
assert_output --regexp "Error encountered when generating the SnsInitPayload: Unable to read .*sns.yml.* No such file or directory"
assert_output --partial "Unable to read the SNS configuration file"
}

@test "sns deploy succeeds" {
@test "sns propose succeeds" {
dfx_extension_install_manually nns
dfx_new
install_shared_asset subnet_type/shared_network_settings/system
Expand All @@ -88,9 +67,9 @@ SNS_CONFIG_FILE_V2_NAME="sns_v2.yml"
cat dfx.json
# Deploy the SNS
install_asset sns/valid
dfx sns config validate
# The remaining steps don't work any more as a pre-launch whitelist has been added.
#dfx sns deploy
dfx sns init-config-file validate
# The remaining steps don't work any more as the steps required have changed due to one-proposal
#dfx sns propose
# SNS canister IDs should be saved
#dfx canister id sns_governance
#dfx canister id sns_index
Expand Down Expand Up @@ -171,36 +150,9 @@ SNS_CONFIG_FILE_V2_NAME="sns_v2.yml"
}

# This test asserts that the `propose` subcommand exist in the current extension version.
@test "sns propose exists" {
run dfx sns propose --help
assert_output --partial "dfx sns propose"
}

# This test asserts that at least one neuron flag must be specified to succeed
@test "sns propose must use a neuron flag" {
install_asset sns/valid

run dfx sns propose sns_v2.yml
assert_failure
assert_output --partial "sns propose --dfx-cache-path <DFX_CACHE_PATH> <--neuron-id <NEURON_ID>|--neuron-memo <NEURON_MEMO>|--test-neuron-proposer> <INIT_CONFIG_FILE>"
}

# This test asserts that a local dfx server with the NNS installed can submit a
# CreateServiceNervousSystem NNS Proposal with the test neuron
@test "sns propose can submit a proposal with the test neuron" {
dfx_new

dfx_extension_install_manually nns
install_shared_asset subnet_type/shared_network_settings/system
install_asset sns/valid

dfx_start_for_nns_install
dfx nns install

run dfx sns propose --test-neuron-proposer "${SNS_CONFIG_FILE_V2_NAME}"
assert_success
assert_output --partial "🚀 Success!"
assert_output --partial "Proposal ID"
@test "sns deploy-testflight exists" {
run dfx sns deploy-testflight --help
assert_output --partial "Deploy an sns directly to a local replica or the Internet Computer"
}

# This test asserts that a local dfx server wih the NNS installed can a
Expand Down Expand Up @@ -249,7 +201,7 @@ SNS_CONFIG_FILE_V2_NAME="sns_v2.yml"
assert_success

# Actually submit the proposal
run dfx sns propose --neuron-id "${NEURON_ID}" "valid/${SNS_CONFIG_FILE_V2_NAME}"
run dfx sns propose --neuron-id "${NEURON_ID}" "valid/${SNS_CONFIG_FILE_NAME}"
assert_success
assert_output --partial "🚀 Success!"
assert_output --partial "Proposal ID"
Expand Down
Loading

0 comments on commit e931915

Please sign in to comment.