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

test(e2e): test tip of the branch #40

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions e2e/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
smallstepman marked this conversation as resolved.
Show resolved Hide resolved
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)
Expand Down Expand Up @@ -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
}
10 changes: 1 addition & 9 deletions extensions-utils/src/project/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions extensions/nns/e2e/tests/nns.bash
Original file line number Diff line number Diff line change
@@ -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)
smallstepman marked this conversation as resolved.
Show resolved Hide resolved
export CARGO_HOME="$HOME"

load "$GIT_ROOT_DIR"/e2e/utils.sh

Expand All @@ -9,7 +10,7 @@ assets="$(dirname "$BATS_TEST_FILENAME")"/../assets
setup() {
standard_setup

dfx extension install nns
dfx_extension_install_manually nns

dfx_new
}
Expand Down
11 changes: 6 additions & 5 deletions extensions/sns/e2e/tests/sns.bash
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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
Expand Down