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

chore: support dfx start --pocketic #143

Merged
merged 21 commits into from
Nov 7, 2024
Merged
5 changes: 4 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
matrix:
os: [ macos-12, ubuntu-20.04 ]
extension: [ nns, sns ]
pocketic: [ "", "pocketic" ]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -44,7 +45,7 @@ jobs:
- name: Install IC SDK (dfx)
uses: dfinity/setup-dfx@main
with:
dfx-version: "0.23.0"
dfx-version: "0.24.1"
- name: Set prebuilt extensions directory
run: echo "PREBUILT_EXTENSIONS_DIR=$HOME/prebuilt-extensions" >> $GITHUB_ENV
- name: Build extension manually
Expand All @@ -54,6 +55,8 @@ jobs:
if: matrix.extension == 'sns'
- name: run test
run: timeout 2400 e2e/bats/bin/bats extensions/${{ matrix.extension }}/e2e/tests/*.bash
env:
USE_POCKET_IC: ${{ matrix.pocketic }}

aggregate:
name: e2e:required
Expand Down
121 changes: 8 additions & 113 deletions e2e/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,52 +146,6 @@ determine_network_directory() {
fi
}

# Start the replica in the background.
dfx_start() {
local port dfx_config_root webserver_port
dfx_patchelf

# Start on random port for parallel test execution
FRONTEND_HOST="127.0.0.1:0"

determine_network_directory
if [ "$USE_IC_REF" ]
then
if [[ $# -eq 0 ]]; then
dfx start --emulator --background --host "$FRONTEND_HOST" 3>&-
else
batslib_decorate "no arguments to dfx start --emulator supported yet"
fail
fi

test -f "$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port"
port=$(cat "$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port")
else
# Bats creates a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves child processes running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
if [[ $# -eq 0 ]]; then
dfx start --background --host "$FRONTEND_HOST" --artificial-delay 100 3>&- # Start on random port for parallel test execution
else
dfx start --background --artificial-delay 100 "$@" 3>&-
fi

dfx_config_root="$E2E_NETWORK_DATA_DIRECTORY/replica-configuration"
printf "Configuration Root for DFX: %s\n" "${dfx_config_root}"
test -f "${dfx_config_root}/replica-1.port"
port=$(cat "${dfx_config_root}/replica-1.port")
fi

webserver_port=$(cat "$E2E_NETWORK_DATA_DIRECTORY/webserver-port")

printf "Replica Configured Port: %s\n" "${port}"
printf "Webserver Configured Port: %s\n" "${webserver_port}"

timeout 5 sh -c \
"until nc -z localhost ${port}; do echo waiting for replica; sleep 1; done" \
|| (echo "could not connect to replica on port ${port}" && exit 1)
}

# Tries to start dfx on the default port, repeating until it succeeds or times out.
#
# Motivation: dfx nns install works only on port 8080, as URLs are compiled into the wasms. This means that multiple
Expand All @@ -201,9 +155,16 @@ dfx_start() {
# - It may also be that ic-nns-install, if used on a non-standard port, installs only the core canisters not the UI.
# - However until we have implemented good solutions, all tests on ic-nns-install must run on port 8080.
dfx_start_for_nns_install() {
if [ "$USE_POCKET_IC" ]
then
DFX_START="dfx start --pocketic"
else
DFX_START="dfx start"
fi

# TODO: When nns-dapp supports dynamic ports, this wait can be removed.
timeout 300 sh -c \
"until dfx start --clean --background --host 127.0.0.1:8080 --verbose ; do echo waiting for port 8080 to become free; sleep 3; done" \
"until $DFX_START --clean --background --host 127.0.0.1:8080 --verbose ; do echo waiting for port 8080 to become free; sleep 3; done" \
|| (echo "could not connect to replica on port 8080" && exit 1)
# TODO: figure out how to plug bats' "run" into above statement,
# so that below asserts will work as expected
Expand All @@ -218,54 +179,6 @@ wait_until_replica_healthy() {
echo "replica became healthy"
}

# Start the replica in the background.
dfx_replica() {
local replica_port dfx_config_root
dfx_patchelf
determine_network_directory
if [ "$USE_IC_REF" ]
then
# Bats creates a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves child processes running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx replica --emulator --port 0 "$@" 3>&- &
export DFX_REPLICA_PID=$!

timeout 60 sh -c \
"until test -s \"$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port\"; do echo waiting for ic-ref port; sleep 1; done" \
|| (echo "replica did not write to \"$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port\" file" && exit 1)

test -f "$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port"
replica_port=$(cat "$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port")

else
# Bats creates a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves child processes running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx replica --port 0 "$@" 3>&- &
export DFX_REPLICA_PID=$!

timeout 60 sh -c \
"until test -s \"$E2E_NETWORK_DATA_DIRECTORY/replica-configuration/replica-1.port\"; do echo waiting for replica port; sleep 1; done" \
|| (echo "replica did not write to port file" && exit 1)

dfx_config_root="$E2E_NETWORK_DATA_DIRECTORY/replica-configuration"
test -f "${dfx_config_root}/replica-1.port"
replica_port=$(cat "${dfx_config_root}/replica-1.port")

fi

printf "Replica Configured Port: %s\n" "${replica_port}"

timeout 5 sh -c \
"until nc -z localhost ${replica_port}; do echo waiting for replica; sleep 1; done" \
|| (echo "could not connect to replica on port ${replica_port}" && exit 1)

# ping the replica directly, because the bootstrap (that launches icx-proxy, which dfx ping usually connects to)
# is not running yet
dfx ping --wait-healthy "http://127.0.0.1:${replica_port}"
}

dfx_bootstrap() {
# This only works because we use the network by name
# (implicitly: --network local)
Expand Down Expand Up @@ -332,20 +245,6 @@ setup_actuallylocal_shared_network() {
jq '.actuallylocal.providers=["http://127.0.0.1:'"$webserver_port"'"]' "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"
}

setup_local_shared_network() {
local replica_port
if [ "$USE_IC_REF" ]
then
replica_port=$(get_ic_ref_port)
else
replica_port=$(get_replica_port)
fi

[ ! -f "$E2E_NETWORKS_JSON" ] && echo "{}" >"$E2E_NETWORKS_JSON"

jq ".local.bind=\"127.0.0.1:${replica_port}\"" "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON"
}

use_wallet_wasm() {
# shellcheck disable=SC2154
export DFX_WALLET_WASM="${archive}/wallet/$1/wallet.wasm"
Expand Down Expand Up @@ -379,10 +278,6 @@ get_replica_pid() {
cat "$E2E_NETWORK_DATA_DIRECTORY/replica-configuration/replica-pid"
}

get_ic_ref_port() {
cat "$E2E_NETWORK_DATA_DIRECTORY/ic-ref.port"

}
get_replica_port() {
cat "$E2E_NETWORK_DATA_DIRECTORY/replica-configuration/replica-1.port"
}
Expand Down
7 changes: 6 additions & 1 deletion extensions/nns/e2e/tests/nns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ assert_nns_canister_id_matches() {
run dfx --identity ident-1 canister call rkp4c-7iaaa-aaaaa-aaaca-cai notify_mint_cycles '(record { block_index = 5 : nat64; })'
# If cycles ledger is configured correctly, then notify_mint_cycles will try to call the cycles ledger (and fail because the canister is not even created).
# If it is not configured correctly, then this will complain about the cycles ledger canister id not being configured.
assert_output --partial "Canister um5iw-rqaaa-aaaaq-qaaba-cai not found"
if [ "$USE_POCKET_IC" ]
then
assert_output --partial "No route to canister um5iw-rqaaa-aaaaq-qaaba-cai"
else
assert_output --partial "Canister um5iw-rqaaa-aaaaq-qaaba-cai not found"
fi
}

2 changes: 1 addition & 1 deletion extensions/nns/src/install_nns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub async fn install_nns(
verify_local_replica_type_is_system(network, networks_config)?;
verify_nns_canister_ids_are_available(agent).await?;
let provider_url = get_and_check_provider(network)?;
let nns_url = get_and_check_replica_url(network, logger)?;
let nns_url = provider_url.clone();
let subnet_id = get_subnet_id(agent).await?.to_text();

eprintln!("Installing the core backend wasm canisters...");
Expand Down
8 changes: 4 additions & 4 deletions extensions/sns/e2e/tests/sns.bash
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SNS_CONFIG_FILE_NAME="sns_init.yaml"
echo "===== 3 ====="
install_shared_asset subnet_type/shared_network_settings/system
echo "===== 4 ====="
dfx start --clean --background --host 127.0.0.1:8080
dfx_start_for_nns_install
echo "===== 5 ====="
wait_until_replica_healthy
echo "===== 6 ====="
Expand Down Expand Up @@ -107,7 +107,7 @@ SNS_CONFIG_FILE_NAME="sns_init.yaml"
@test "sns prepare-canisters adds NNS Root" {
dfx_extension_install_manually nns
install_shared_asset subnet_type/shared_network_settings/system
dfx start --clean --background --host 127.0.0.1:8080
dfx_start_for_nns_install
wait_until_replica_healthy

dfx_new_frontend && dfx deploy
Expand All @@ -132,7 +132,7 @@ SNS_CONFIG_FILE_NAME="sns_init.yaml"
@test "sns prepare-canisters removes NNS Root" {
dfx_extension_install_manually nns
install_shared_asset subnet_type/shared_network_settings/system
dfx start --clean --background --host 127.0.0.1:8080
dfx_start_for_nns_install
wait_until_replica_healthy

dfx_new_frontend && dfx deploy
Expand Down Expand Up @@ -233,4 +233,4 @@ SNS_CONFIG_FILE_NAME="sns_init.yaml"
@test "sns neuron-id-to-candid-subaccount --escaped has a reasonable output" {
run dfx sns neuron-id-to-candid-subaccount 9f5f9fda77a03e7177126d0be8c99e931a5381731d00da53ede363140e1be5d6 --escaped
assert_output 'blob \"\\9f\\5f\\9f\\da\\77\\a0\\3e\\71\\77\\12\\6d\\0b\\e8\\c9\\9e\\93\\1a\\53\\81\\73\\1d\\00\\da\\53\\ed\\e3\\63\\14\\0e\\1b\\e5\\d6\"'
}
}
Loading