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

Add CI test that checks an SNS can be launched using dfx nns / dfx sns #131

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ jobs:
uses: dfinity/setup-dfx@main
- name: Set prebuilt extensions directory
run: echo "PREBUILT_EXTENSIONS_DIR=$HOME/prebuilt-extensions" >> $GITHUB_ENV
- name: Build extension manually
run: .github/workflows/build-extension-manually.sh ${{ matrix.extension }}
- name: Build nns manually
run: .github/workflows/build-extension-manually.sh nns
if: matrix.extension == 'sns'
- name: run test
run: timeout 2400 e2e/bats/bin/bats extensions/${{ matrix.extension }}/e2e/tests/*.bash
# - name: Build extension manually
# run: .github/workflows/build-extension-manually.sh ${{ matrix.extension }}
# - name: Build nns manually
# run: .github/workflows/build-extension-manually.sh nns
# if: matrix.extension == 'sns'
# - name: run test
# run: timeout 2400 e2e/bats/bin/bats extensions/${{ matrix.extension }}/e2e/tests/*.bash
- name: run sns tests
run: timeout 2400 bash e2e/launch-simple-sns.sh

aggregate:
name: e2e:required
Expand Down
96 changes: 96 additions & 0 deletions e2e/launch-simple-sns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
#
# Tested with dfx 0.20.1

set -euo pipefail

# This ID corresponds to TEST_NEURON_1
NEURON_ID="449479075714955186"

dfx start --clean --background

dfx identity use default
cargo run --bin nns install --dfx-cache-path="$(dfx cache show)"

# Ensure we have a powerful neuron
cat <<EOF >ident-1.pem
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEICJxApEbuZznKFpV+VKACRK30i6+7u5Z13/DOl18cIC+oAcGBSuBBAAK
oUQDQgAEPas6Iag4TUx+Uop+3NhE6s3FlayFtbwdhRVjvOar0kPTfE/N8N6btRnd
74ly5xXEBNSXiENyxhEuzOZrIWMCNQ==
-----END EC PRIVATE KEY-----
EOF
dfx identity import --force --storage-mode=plaintext ident-1 ident-1.pem
dfx identity use ident-1
PRINCIPAL_ID=$(dfx identity get-principal)

# Hack

Choose a reason for hiding this comment

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

Can you say more about why this hack is needed?

sleep 15s

# Top-up the SNS-W canister
dfx ledger fabricate-cycles --canister qaa6y-5yaaa-aaaaa-aaafa-cai --t 2345

Choose a reason for hiding this comment

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

How about using variables for the canister IDs? Also below.


dfx canister call "rrkah-fqaaa-aaaaa-aaaaq-cai" update_neuron '(
record {
id = opt record { id = '${NEURON_ID}' : nat64 };

Choose a reason for hiding this comment

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

I was super confused about why the variable expansion works with the single quotes. But then I realized you actually end the single quote string, concatenate the variable and then open a new string. Is that intentional or did it work by accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was intentional, but I'm no Bash expert — maybe there's a better way.

staked_maturity_e8s_equivalent = null;
controller = opt principal "'${PRINCIPAL_ID}'";
recent_ballots = vec {};
kyc_verified = true;
neuron_type = null;
not_for_profit = false;
maturity_e8s_equivalent = 1_000_000 : nat64;
cached_neuron_stake_e8s = 1_000_000_000_000_000 : nat64;
created_timestamp_seconds = 123 : nat64;
auto_stake_maturity = opt true;
aging_since_timestamp_seconds = 456 : nat64;
hot_keys = vec {};
account = blob "3\8fZ\9fn\af]\a9\17\be\ea\14yA\f3\b3\00\16\af[\ae\1cq\c0\a0\dd\1d?\d8\e7\a96";

Choose a reason for hiding this comment

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

Where does this blob come from?

joined_community_fund_timestamp_seconds = opt (1 : nat64);
dissolve_state = opt variant {
DissolveDelaySeconds = 252_460_800 : nat64
};
followees = vec {};
neuron_fees_e8s = 0 : nat64;
transfer = null;
known_neuron_data = null;
spawn_at_timestamp_seconds = null;
},
)'

curl https://raw.githubusercontent.com/dfinity/sns-testing/main/example_sns_init.yaml \
| sed "s/YOUR_PRINCIPAL_ID/${PRINCIPAL_ID}/" \
| sed "s/- YOUR_CANISTER_ID//" > sns_init.yaml

touch logo.png

cargo run --bin sns propose --neuron-id "${NEURON_ID}" sns_init.yaml

# Check that the CreateServiceNervousSystem propsoal was executed
PROPOSAL_DATA=$(dfx canister \

Choose a reason for hiding this comment

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

NCR: shellcheck would require double quotes around the $() so I guess this repo doesn't run a linter on the shell scripts?
Might be worth doing.

call "rrkah-fqaaa-aaaaa-aaaaq-cai" \
list_proposals '(
record {
include_reward_status = vec {};
before_proposal = null;
limit = 1;
exclude_topic = vec {};
include_status = vec {};
}
)' | idl2json)

while [ "$(echo "${PROPOSAL_DATA}" | jq -r '.proposal_info[0].executed_timestamp_seconds')" == "0" ]
do
FAILURE_REASON=$(echo "${PROPOSAL_DATA}" | jq -c -r '.proposal_info[0].failure_reason?')
if [ "$FAILURE_REASON" = "null" ]; then
printf "."
sleep 1
else
echo "CreateServiceNervousSystem proposal FAILED: ${FAILURE_REASON}"
dfx stop
exit 1
fi
done

echo "CreateServiceNervousSystem proposal SUCCEEDED!"
echo "Run `dfx stop` when you're done testing."
Loading