From f9ac446b37916a52b470279ca6ba495d4790e778 Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Thu, 3 Aug 2023 17:52:11 +0200 Subject: [PATCH 1/5] test(e2e): test tip of the branch --- .github/workflows/e2e.yml | 2 ++ e2e/utils.sh | 31 ++++++++++++++++++++++++++ extensions-utils/src/project/import.rs | 10 +-------- extensions/nns/e2e/tests/nns.bash | 5 +++-- extensions/sns/e2e/tests/sns.bash | 11 ++++----- 5 files changed, 43 insertions(+), 16 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index be5005c..97774ef 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -27,6 +27,8 @@ jobs: if: contains(matrix.os, 'macos-12') == false - name: Install sponge and timeout run: brew install coreutils sponge + - name: Install cargo-dist + run: cargo install cargo-dist - name: Install IC SDK (dfx) run: sh -ci "$(curl -sSL https://internetcomputer.org/install.sh)" - name: run test diff --git a/e2e/utils.sh b/e2e/utils.sh index ab994c9..8d26c9e 100644 --- a/e2e/utils.sh +++ b/e2e/utils.sh @@ -22,6 +22,19 @@ install_shared_asset() { cp -R "$ASSET_ROOT"/* "$(dirname "$E2E_NETWORKS_JSON")" } +dfx_extension_install_manually() ( + cd "$GIT_ROOT_DIR" + local extension_name="$1" + package_version=$(HOME="$CARGO_HOME" cargo metadata --format-version=1 | jq -r '.workspace_members[]' | rg "$extension_name" | cut -d" " -f2) + HOME="$CARGO_HOME" cargo dist build --tag="$extension_name-v$package_version" # cargo-dist needs git tag only metadata-related stuff; it won't do git checkout, it will build from HEAD + extensions_dir="$(dfx cache show)/extensions" + arch_platform="$(get_arch_and_platform)" + rm -rf "$extensions_dir/$extension_name-$arch_platform" "${extensions_dir:?}/$extension_name" # remove old versions + mkdir -p "$extensions_dir" + tar xfJ "target/distrib/$extension_name-$arch_platform.tar.xz" -C "$extensions_dir" + mv "$extensions_dir/$extension_name-$arch_platform" "$extensions_dir/$extension_name" +) + standard_setup() { # We want to work from a temporary directory, different for every test. x=$(mktemp -d -t dfx-e2e-XXXXXXXX) @@ -446,3 +459,21 @@ assert_no_dfx_start_or_replica_processes() { fi } +get_arch_and_platform() { + ARCH=$(uname -m) + SYS=$(uname -s) + + if [[ "$ARCH" == "x86_64" ]]; then + if [[ "$SYS" == "Darwin" ]]; then + echo "$ARCH-apple-darwin" + elif [[ "$SYS" == "Linux" ]]; then + echo "$ARCH-unknown-linux-gnu" + else + echo "System not recognized" + fi + elif [[ "$ARCH" == "arm64" && "$SYS" == "Darwin" ]]; then + echo "aarch64-apple-darwin" + else + echo "Architecture not recognized" + fi +} diff --git a/extensions-utils/src/project/import.rs b/extensions-utils/src/project/import.rs index af5ce35..32dca31 100644 --- a/extensions-utils/src/project/import.rs +++ b/extensions-utils/src/project/import.rs @@ -239,16 +239,8 @@ impl Loader { fn client(&mut self) -> Result<&Client, ProjectError> { if self.client.is_none() { - let tls_config = rustls::ClientConfig::builder() - .with_safe_defaults() - .with_webpki_roots() - .with_no_client_auth(); - - // Advertise support for HTTP/2 - //tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; - let client = reqwest::Client::builder() - .use_preconfigured_tls(tls_config) + .use_rustls_tls() .build() .map_err(ProjectError::CouldNotCreateHttpClient)?; self.client = Some(client); diff --git a/extensions/nns/e2e/tests/nns.bash b/extensions/nns/e2e/tests/nns.bash index 6515d5d..8fb1cb1 100755 --- a/extensions/nns/e2e/tests/nns.bash +++ b/extensions/nns/e2e/tests/nns.bash @@ -1,6 +1,7 @@ #!/usr/bin/env bats -GIT_ROOT_DIR=$(git rev-parse --show-toplevel) +export GIT_ROOT_DIR=$(git rev-parse --show-toplevel) +export CARGO_HOME="$HOME" load "$GIT_ROOT_DIR"/e2e/utils.sh @@ -9,7 +10,7 @@ assets="$(dirname "$BATS_TEST_FILENAME")"/../assets setup() { standard_setup - dfx extension install nns + dfx_extension_install_manually nns dfx_new } diff --git a/extensions/sns/e2e/tests/sns.bash b/extensions/sns/e2e/tests/sns.bash index f004a1c..48ce6d8 100755 --- a/extensions/sns/e2e/tests/sns.bash +++ b/extensions/sns/e2e/tests/sns.bash @@ -1,13 +1,14 @@ #!/usr/bin/env bats -GIT_ROOT_DIR=$(git rev-parse --show-toplevel) +export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" +export CARGO_HOME="$HOME" load "$GIT_ROOT_DIR"/e2e/utils.sh setup() { standard_setup - dfx extension install sns + dfx_extension_install_manually sns } teardown() { @@ -60,21 +61,21 @@ SNS_CONFIG_FILE_NAME="sns.yml" } @test "sns deploy fails without config file" { + dfx_extension_install_manually nns dfx_new - dfx extension install nns dfx nns import rm -f sns.yml # Is not expected to be present anyway run dfx sns deploy assert_failure - assert_output --partial "Error encountered when generating the SnsInitPayload: Couldn't open initial parameters file" + assert_output --regexp "Error encountered when generating the SnsInitPayload.* Unable to read .*sns.yml.* No such file or directory" } @test "sns deploy succeeds" { + dfx_extension_install_manually nns dfx_new install_shared_asset subnet_type/shared_network_settings/system dfx start --clean --background --host 127.0.0.1:8080 sleep 1 - dfx extension install nns dfx nns install dfx nns import dfx sns import From 3413ee5d70a2275bcd5bc40aab19e012ad290d7a Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Thu, 3 Aug 2023 20:01:26 +0200 Subject: [PATCH 2/5] shellcheck lints --- e2e/utils.sh | 2 +- extensions/nns/e2e/tests/nns.bash | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/utils.sh b/e2e/utils.sh index 8d26c9e..6c32fae 100644 --- a/e2e/utils.sh +++ b/e2e/utils.sh @@ -1,6 +1,6 @@ set -e -GIT_ROOT_DIR=$(git rev-parse --show-toplevel) +GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" load "$GIT_ROOT_DIR"/e2e/bats-support/load load "$GIT_ROOT_DIR"/e2e/bats-assert/load diff --git a/extensions/nns/e2e/tests/nns.bash b/extensions/nns/e2e/tests/nns.bash index 8fb1cb1..78a68d5 100755 --- a/extensions/nns/e2e/tests/nns.bash +++ b/extensions/nns/e2e/tests/nns.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bats -export GIT_ROOT_DIR=$(git rev-parse --show-toplevel) +export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" export CARGO_HOME="$HOME" load "$GIT_ROOT_DIR"/e2e/utils.sh From 996cb49f84d3a622703512df10e5154aba140b35 Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Thu, 3 Aug 2023 21:20:03 +0200 Subject: [PATCH 3/5] Update e2e/utils.sh Co-authored-by: Eric Swanson <64809312+ericswanson-dfinity@users.noreply.github.com> --- e2e/utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/utils.sh b/e2e/utils.sh index 6c32fae..4fe62d2 100644 --- a/e2e/utils.sh +++ b/e2e/utils.sh @@ -25,7 +25,7 @@ install_shared_asset() { dfx_extension_install_manually() ( cd "$GIT_ROOT_DIR" local extension_name="$1" - package_version=$(HOME="$CARGO_HOME" cargo metadata --format-version=1 | jq -r '.workspace_members[]' | rg "$extension_name" | cut -d" " -f2) + package_version=$(HOME="$CARGO_HOME" cargo metadata --format-version=1 | jq -r '.workspace_members[]' | grep "$extension_name" | cut -d" " -f2) HOME="$CARGO_HOME" cargo dist build --tag="$extension_name-v$package_version" # cargo-dist needs git tag only metadata-related stuff; it won't do git checkout, it will build from HEAD extensions_dir="$(dfx cache show)/extensions" arch_platform="$(get_arch_and_platform)" From 6c9591e15ca5e2b2c66db3760196bd987b958d1b Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Thu, 3 Aug 2023 22:43:05 +0200 Subject: [PATCH 4/5] fix e2e err msg assert --- extensions/sns/e2e/tests/sns.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/sns/e2e/tests/sns.bash b/extensions/sns/e2e/tests/sns.bash index 48ce6d8..33fd3c0 100755 --- a/extensions/sns/e2e/tests/sns.bash +++ b/extensions/sns/e2e/tests/sns.bash @@ -67,7 +67,7 @@ SNS_CONFIG_FILE_NAME="sns.yml" rm -f sns.yml # Is not expected to be present anyway run dfx sns deploy assert_failure - assert_output --regexp "Error encountered when generating the SnsInitPayload.* Unable to read .*sns.yml.* No such file or directory" + assert_output --regexp "Error encountered when generating the SnsInitPayload.* Couldn't open initial parameters file .*sns.yml.* No such file or directory" } @test "sns deploy succeeds" { From 178a865c0643f87b755d495c74789c0fa67929db Mon Sep 17 00:00:00 2001 From: Marcin Nowak-Liebiediew Date: Fri, 4 Aug 2023 14:43:25 +0200 Subject: [PATCH 5/5] revert some changes --- e2e/utils.sh | 3 +-- extensions-utils/src/project/import.rs | 10 +++++++++- extensions/nns/e2e/tests/nns.bash | 2 -- extensions/sns/e2e/tests/sns.bash | 3 +-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/e2e/utils.sh b/e2e/utils.sh index 4fe62d2..8a0d4f3 100644 --- a/e2e/utils.sh +++ b/e2e/utils.sh @@ -1,7 +1,6 @@ set -e -GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" - +export CARGO_HOME="$HOME" load "$GIT_ROOT_DIR"/e2e/bats-support/load load "$GIT_ROOT_DIR"/e2e/bats-assert/load diff --git a/extensions-utils/src/project/import.rs b/extensions-utils/src/project/import.rs index 32dca31..af5ce35 100644 --- a/extensions-utils/src/project/import.rs +++ b/extensions-utils/src/project/import.rs @@ -239,8 +239,16 @@ impl Loader { fn client(&mut self) -> Result<&Client, ProjectError> { if self.client.is_none() { + let tls_config = rustls::ClientConfig::builder() + .with_safe_defaults() + .with_webpki_roots() + .with_no_client_auth(); + + // Advertise support for HTTP/2 + //tls_config.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()]; + let client = reqwest::Client::builder() - .use_rustls_tls() + .use_preconfigured_tls(tls_config) .build() .map_err(ProjectError::CouldNotCreateHttpClient)?; self.client = Some(client); diff --git a/extensions/nns/e2e/tests/nns.bash b/extensions/nns/e2e/tests/nns.bash index 78a68d5..428b4ce 100755 --- a/extensions/nns/e2e/tests/nns.bash +++ b/extensions/nns/e2e/tests/nns.bash @@ -1,8 +1,6 @@ #!/usr/bin/env bats export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" -export CARGO_HOME="$HOME" - load "$GIT_ROOT_DIR"/e2e/utils.sh assets="$(dirname "$BATS_TEST_FILENAME")"/../assets diff --git a/extensions/sns/e2e/tests/sns.bash b/extensions/sns/e2e/tests/sns.bash index 33fd3c0..fe10352 100755 --- a/extensions/sns/e2e/tests/sns.bash +++ b/extensions/sns/e2e/tests/sns.bash @@ -1,7 +1,6 @@ #!/usr/bin/env bats export GIT_ROOT_DIR="$(git rev-parse --show-toplevel)" -export CARGO_HOME="$HOME" load "$GIT_ROOT_DIR"/e2e/utils.sh @@ -67,7 +66,7 @@ SNS_CONFIG_FILE_NAME="sns.yml" rm -f sns.yml # Is not expected to be present anyway run dfx sns deploy assert_failure - assert_output --regexp "Error encountered when generating the SnsInitPayload.* Couldn't open initial parameters file .*sns.yml.* No such file or directory" + assert_output --partial "Error encountered when generating the SnsInitPayload: Couldn't open initial parameters file" } @test "sns deploy succeeds" {