Skip to content
1 change: 1 addition & 0 deletions .shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
external-sources=true
454 changes: 227 additions & 227 deletions e2e/tests-dfx/assetscanister.bash

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e/tests-dfx/base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ teardown() {
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'import error \[M0010\], package "base" not defined'
assert_match 'import error \[M0010\], package "base" not defined' "$output"
}
8 changes: 4 additions & 4 deletions e2e/tests-dfx/basic-project.bash
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ teardown() {
assert_eq "4449444c00017d02"

assert_command_fail dfx canister call --query hello_backend inc
assert_match "inc is an update method, not a query method."
assert_match "Run the command without '--query'."
assert_match "inc is an update method, not a query method." "$output"
assert_match "Run the command without '--query'." "$output"


dfx canister call hello_backend inc
Expand Down Expand Up @@ -151,7 +151,7 @@ teardown() {
assert_command dfx canister call hello_backend always_accepted

assert_command_fail dfx canister call hello_backend always_rejected
assert_contains "canister_inspect_message explicitly refused message"
assert_contains "canister_inspect_message explicitly refused message" "$output"
}

@test "inspect message - rust" {
Expand All @@ -165,5 +165,5 @@ teardown() {
assert_command dfx canister call hello_backend always_accepted

assert_command_fail dfx canister call hello_backend always_rejected
assert_contains "Canister rejected the message"
assert_contains "Canister rejected the message" "$output"
}
4 changes: 2 additions & 2 deletions e2e/tests-dfx/bitcoin.bash
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ set_local_network_bitcoin_enabled() {
address = "bcrt1qu58aj62urda83c00eylc6w34yl2s6e5rkzqet7";
}
)'
assert_contains "tip_height = 0 : nat32;"
assert_contains "tip_height = 0 : nat32;" "$output"

# bitcoin_get_current_fee_percentiles
assert_command dfx canister call --with-cycles 100000000 --wallet default aaaaa-aa --candid bitcoin.did bitcoin_get_current_fee_percentiles '(record { network = variant { regtest } })'
Expand All @@ -101,5 +101,5 @@ set_local_network_bitcoin_enabled() {
# It's hard to test this without a real transaction, but we can at least check that the call fails.
# The error message indicates that the argument is in correct format, only the inner transaction is malformed.
assert_command_fail dfx canister call --with-cycles 5020000000 --wallet default aaaaa-aa --candid bitcoin.did bitcoin_send_transaction '(record { transaction = vec {0:nat8}; network = variant { regtest } })'
assert_contains "send_transaction failed: MalformedTransaction"
assert_contains "send_transaction failed: MalformedTransaction" "$output"
}
44 changes: 22 additions & 22 deletions e2e/tests-dfx/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -70,52 +70,52 @@ teardown() {
jq '.canisters.e2e_project.build="echo nope"' dfx.json | sponge dfx.json

assert_command_fail dfx deploy
assert_contains "Canister 'e2e_project' defines its wasm field as a URL, and has a build step."
assert_contains "Canister 'e2e_project' defines its wasm field as a URL, and has a build step." "$output"
}

@test "build uses default build args" {
install_asset default_args
assert_command_fail dfx build --check
assert_match "unknown option"
assert_match "compacting-gcX"
assert_match "unknown option" "$output"
assert_match "compacting-gcX" "$output"
}

@test "build uses canister build args" {
install_asset canister_args
assert_command_fail dfx build --check
assert_match "unknown option"
assert_match "compacting-gcY"
assert_not_match "compacting-gcX"
assert_match "unknown option" "$output"
assert_match "compacting-gcY" "$output"
assert_not_match "compacting-gcX" "$output"
}

@test "empty canister build args don't shadow default" {
install_asset empty_canister_args
assert_command_fail dfx build --check
assert_match '"--error-detail" "5"'
assert_match "unknown option"
assert_match "compacting-gcX"
assert_match '"--error-detail" "5"' "$output"
assert_match "unknown option" "$output"
assert_match "compacting-gcX" "$output"
}

@test "build fails on invalid motoko" {
install_asset invalid
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match "syntax error"
assert_match "syntax error" "$output"
}

@test "build --check fails on build error when there are no canister ids" {
install_asset invalid
assert_command_fail dfx build --check
assert_match "syntax error"
assert_match "syntax error" "$output"
}

@test "build --check fails on build error when there are canister ids" {
dfx_start
dfx canister create --all
install_asset invalid
assert_command_fail dfx build --check
assert_match "syntax error"
assert_match "syntax error" "$output"
}

@test "build supports relative imports" {
Expand Down Expand Up @@ -150,8 +150,8 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build
assert_contains "Building canister 'e2e_project_backend'"
assert_contains "Finished building canisters."
assert_contains "Building canister 'e2e_project_backend'" "$output"
assert_contains "Finished building canisters." "$output"
}

@test "build succeeds if enable optimize" {
Expand All @@ -168,11 +168,11 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build custom -vvv
assert_not_match "Shrinking Wasm"
assert_not_match "Shrinking Wasm" "$output"

jq '.canisters.custom.shrink=true' dfx.json | sponge dfx.json
assert_command dfx build custom -vvv
assert_match "Shrinking Wasm"
assert_match "Shrinking Wasm" "$output"
}

@test "build custom canister default no optimize" {
Expand All @@ -182,11 +182,11 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build custom -vvv
assert_not_match "Optimizing"
assert_not_match "Optimizing" "$output"

jq '.canisters.custom.optimize="size"' dfx.json | sponge dfx.json
assert_command dfx build custom -vvv
assert_match "Optimizing Wasm at level"
assert_match "Optimizing Wasm at level" "$output"
}

@test "build succeeds if enable gzip" {
Expand Down Expand Up @@ -222,15 +222,15 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build
assert_match "warning \[M0145\], this pattern of type"
assert_match "warning \[M0145\], this pattern of type" "$output"
}

@test "build fails on unknown imports" {
install_asset import_error
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_match 'import error \[M0011\], canister alias "random" not defined'
assert_match 'import error \[M0011\], canister alias "random" not defined' "$output"
}

@test "build fails if canister type is not supported" {
Expand All @@ -239,7 +239,7 @@ teardown() {
jq '.canisters.e2e_project_backend.type="unknown_canister_type"' dfx.json | sponge dfx.json
assert_command_fail dfx build
# shellcheck disable=SC2016
assert_match "canister 'e2e_project_backend' has unknown type 'unknown_canister_type' and there is no installed extension by that name which could define it"
assert_match "canister 'e2e_project_backend' has unknown type 'unknown_canister_type' and there is no installed extension by that name which could define it" "$output"

# If canister type is invalid, `dfx stop` fails
jq '.canisters.e2e_project_backend.type="motoko"' dfx.json | sponge dfx.json
Expand Down Expand Up @@ -372,5 +372,5 @@ teardown() {
assert_command dfx build --check
# the module contains table64 which is not supported by ic_wasm::optimize
# optimization failure doesn't fail the build, but a warning is issued
assert_contains "WARNING: Failed to optimize the Wasm module:"
assert_contains "WARNING: Failed to optimize the Wasm module:" "$output"
}
10 changes: 5 additions & 5 deletions e2e/tests-dfx/build_granular.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ teardown() {
dfx build e2e_project_backend
# validate assets canister wasn't built and can't be installed
assert_command_fail dfx canister install e2e_project_frontend
assert_match "The canister must be built before install. Please run \`dfx build\`."
assert_match "The canister must be built before install. Please run \`dfx build\`." "$output"
}


Expand All @@ -61,26 +61,26 @@ teardown() {
assert_command dfx canister call e2e_project_backend greet World

assert_command_fail dfx canister install e2e_project_frontend
assert_match "Cannot find canister id. Please issue 'dfx canister create e2e_project_frontend'."
assert_match "Cannot find canister id. Please issue 'dfx canister create e2e_project_frontend'." "$output"
dfx canister create e2e_project_frontend
dfx build e2e_project_frontend
dfx canister install e2e_project_frontend

assert_command dfx canister call --query e2e_project_frontend retrieve '("/binary/noise.txt")' --output idl
# shellcheck disable=SC2154
assert_eq '(blob "\b8\01\20\80\0a\77\31\32\20\00\78\79\0a\4b\4c\0b\0a\6a\6b")' "$stdout"
assert_eq '(blob "\b8\01\20\80\0a\77\31\32\20\00\78\79\0a\4b\4c\0b\0a\6a\6b")'

assert_command dfx canister call --query e2e_project_frontend retrieve '("/text-with-newlines.txt")' --output idl
# shellcheck disable=SC2154
assert_eq '(blob "cherries\0ait\27s cherry season\0aCHERRIES")' "$stdout"
assert_eq '(blob "cherries\0ait\27s cherry season\0aCHERRIES")'
}

@test "cyclic dependencies are detected" {
install_asset transitive_deps_canisters
dfx_start
dfx canister create --all
assert_command_fail dfx build canister_e
assert_match "Circular canister dependencies: canister_e -> canister_d -> canister_e"
assert_match "Circular canister dependencies: canister_e -> canister_d -> canister_e" "$output"
}

@test "multiple non-cyclic dependency paths to the same canister are ok" {
Expand Down
6 changes: 3 additions & 3 deletions e2e/tests-dfx/build_rust.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build
assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed."
assert_match "Cannot check for vulnerabilities in rust canisters because cargo-audit is not installed." "$output"
}

@test "build with vulnerabilities in rust dependencies emits a warning" {
Expand All @@ -33,8 +33,8 @@ teardown() {
dfx_start
dfx canister create --all
assert_command dfx build
assert_match "Audit found vulnerabilities"
assert_match "Audit found vulnerabilities" "$output"
jq '.canisters.hello.skip_cargo_audit=true' dfx.json | sponge dfx.json
assert_command dfx build
assert_not_match "Audit found vulnerabilities"
assert_not_match "Audit found vulnerabilities" "$output"
}
28 changes: 15 additions & 13 deletions e2e/tests-dfx/call.bash
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ teardown() {
# if no candid method known, then no field names
assert_command dfx canister call "$CANISTER_ID" make_struct2 '("A", "B")'
# shellcheck disable=SC2154
assert_eq '(record { 99 = "A"; 100 = "B" })' "$stdout"
assert_eq '(record { 99 = "A"; 100 = "B" })'

# if passing the candid file, field names available
assert_command dfx canister call --candid full.did "$CANISTER_ID" make_struct2 '("A", "B")'
Expand Down Expand Up @@ -249,6 +249,7 @@ teardown() {
assert_match '("Hello, you!")'
}

# shellcheck disable=SC2030
@test "inter-canister calls" {
dfx_new_rust inter
install_asset inter
Expand Down Expand Up @@ -299,6 +300,7 @@ teardown() {
assert_match '(8 : nat)'
}

# shellcheck disable=SC2031
function impersonate_sender() {
IDENTITY_PRINCIPAL="${1}"

Expand All @@ -311,57 +313,57 @@ function impersonate_sender() {

# updating settings now fails because the default identity does not control the canister anymore
assert_command_fail dfx canister update-settings hello_backend --freezing-threshold 0 --confirm-very-short-freezing-threshold
assert_contains "The principal you are using to call a management function is not part of the controllers."
assert_contains "The principal you are using to call a management function is not part of the controllers." "$output"

# updating settings succeeds when impersonating the management canister as the sender
assert_command dfx canister update-settings hello_backend --freezing-threshold 0 --confirm-very-short-freezing-threshold --impersonate "${IDENTITY_PRINCIPAL}"

# canister status fails because the default identity does not control the canister anymore
assert_command_fail dfx canister status hello_backend
assert_contains "The principal you are using to call a management function is not part of the controllers."
assert_contains "The principal you are using to call a management function is not part of the controllers." "$output"

# canister status succeeds when impersonating the management canister as the sender
assert_command dfx canister status hello_backend --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Controllers: ${IDENTITY_PRINCIPAL}"
assert_contains "Freezing threshold: 0"
assert_contains "Controllers: ${IDENTITY_PRINCIPAL}" "$output"
assert_contains "Freezing threshold: 0" "$output"

# freeze the canister
assert_command dfx canister update-settings hello_backend --freezing-threshold 9223372036854775808 --confirm-very-long-freezing-threshold --impersonate "${IDENTITY_PRINCIPAL}"

# test management canister call submission failure
assert_command_fail dfx canister status hello_backend --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit management canister call: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit management canister call: Canister $CANISTER_ID is out of cycles" "$output"

# test update call submission failure
assert_command_fail dfx canister call aaaaa-aa canister_status "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles" "$output"

# test async call submission failure
assert_command_fail dfx canister call aaaaa-aa canister_status "(record { canister_id=principal\"$CANISTER_ID\" })" --async --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles"
assert_contains "Failed to submit canister call: Canister $CANISTER_ID is out of cycles" "$output"

# unfreeze the canister
assert_command dfx canister update-settings hello_backend --freezing-threshold 0 --confirm-very-short-freezing-threshold --impersonate "${IDENTITY_PRINCIPAL}"

# test update call failure
assert_command_fail dfx canister call aaaaa-aa delete_canister "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Canister call failed: Canister $CANISTER_ID must be stopped before it is deleted."
assert_contains "Canister call failed: Canister $CANISTER_ID must be stopped before it is deleted." "$output"

# test update call
assert_command dfx canister call aaaaa-aa start_canister "(record { canister_id=principal\"$CANISTER_ID\" })" --update --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "()"
assert_contains "()" "$output"

# test async call
assert_command dfx canister call aaaaa-aa canister_status "(record { canister_id=principal\"$CANISTER_ID\" })" --async --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "Request ID:"
assert_contains "Request ID:" "$output"

# test query call failure
assert_command_fail dfx canister call aaaaa-aa fetch_canister_logs "(record { canister_id=principal\"$CANISTER_ID\" })" --query --impersonate "$CANISTER_ID"
assert_contains "Failed to perform query call: Caller $CANISTER_ID is not allowed to access canister logs (IC0406)"
assert_contains "Failed to perform query call: Caller $CANISTER_ID is not allowed to access canister logs (IC0406)" "$output"

# test query call
assert_command dfx canister call aaaaa-aa fetch_canister_logs "(record { canister_id=principal\"$CANISTER_ID\" })" --query --impersonate "${IDENTITY_PRINCIPAL}"
assert_contains "(record { 1_754_302_831 = vec {} })"
assert_contains "(record { 1_754_302_831 = vec {} })" "$output"
}

@test "impersonate management canister as sender" {
Expand Down
Loading
Loading