Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions e2e/bats/assets/transitive_deps_canisters/a/main.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor {
public func greet(name : Text) : async Text {
return "Namaste, " # name # "!";
};
};
5 changes: 5 additions & 0 deletions e2e/bats/assets/transitive_deps_canisters/b/main.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor {
public func greet(name : Text) : async Text {
return "Hola, " # name # "!";
};
};
5 changes: 5 additions & 0 deletions e2e/bats/assets/transitive_deps_canisters/c/main.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
actor {
public func greet(name : Text) : async Text {
return "Hello, " # name # "!";
};
};
28 changes: 28 additions & 0 deletions e2e/bats/assets/transitive_deps_canisters/dfx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"canisters": {
"canister_a": {
"main": "./a/main.mo",
"type": "motoko"
},
"canister_b": {
"dependencies": ["canister_a"],
"main": "./b/main.mo",
"type": "motoko"
},
"canister_c": {
"dependencies": ["canister_b"],
"main": "./c/main.mo",
"type": "motoko"
}
},
"defaults": {
"build": {
"packtool": ""
}
},
"networks": {
"local": {
"bind": "127.0.0.1:8000"
}
}
}
1 change: 1 addition & 0 deletions e2e/bats/assets/transitive_deps_canisters/patch.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Do nothing
2 changes: 1 addition & 1 deletion e2e/bats/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ teardown() {

dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install e2e_project_assets

assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")'
Expand Down
4 changes: 2 additions & 2 deletions e2e/bats/base.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ teardown() {

dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install e2e_project

assert_command dfx canister call --query e2e_project is_digit '("5")'
Expand All @@ -34,6 +34,6 @@ teardown() {

dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_command_fail dfx build --all
assert_match 'import error, package "base" not defined'
}
8 changes: 4 additions & 4 deletions e2e/bats/basic-project.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ teardown() {
install_asset greet
dfx_start
dfx canister create --all
dfx build
dfx build --all
# INSTALL_REQUEST_ID=$(dfx canister install hello --async)
# dfx canister request-status $INSTALL_REQUEST_ID
dfx canister install hello
Expand All @@ -43,7 +43,7 @@ teardown() {
install_asset counter
dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install hello

assert_command dfx canister call hello read
Expand Down Expand Up @@ -87,7 +87,7 @@ teardown() {
install_asset counter_idl
dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install --all

assert_command dfx canister call hello inc '(42,false,"testzZ",vec{1;2;3},opt record{head=42; tail=opt record{head=+43; tail=null}}, variant { cons=record{ 42; variant { cons=record{43; variant { nil }} } } })'
Expand All @@ -98,7 +98,7 @@ teardown() {
install_asset matrix_multiply
dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install --all

assert_command dfx canister call hello multiply '(vec{vec{1;2};vec{3;4};vec{5;6}},vec{vec{1;2;3};vec{4;5;6}})'
Expand Down
2 changes: 1 addition & 1 deletion e2e/bats/bootstrap.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ teardown() {
@test "bootstrap fetches candid file" {
dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install hello
ID=$(dfx canister id hello)

Expand Down
26 changes: 13 additions & 13 deletions e2e/bats/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ teardown() {
install_asset invalid
dfx_start
dfx canister create --all
assert_command_fail dfx build
assert_command_fail dfx build --all
assert_match "syntax error"
}

@test "build supports relative imports" {
install_asset import
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
dfx canister install --all
assert_command dfx canister call e2e_project greet World
assert_match "10World"
Expand All @@ -35,49 +35,49 @@ teardown() {
@test "build succeeds on default project" {
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
}

# TODO: Before Tungsten, we need to update this test for code with inter-canister calls.
# Currently due to new canister ids, the wasm binary will be different for inter-canister calls.
@test "build twice produces the same wasm binary" {
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
cp .dfx/local/canisters/e2e_project/e2e_project.wasm ./old.wasm
assert_command dfx build
assert_command dfx build --all
assert_command diff .dfx/local/canisters/e2e_project/e2e_project.wasm ./old.wasm
}

@test "build outputs warning" {
install_asset warning
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
assert_match "warning, this pattern consuming type"
}

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

@test "build fails if canister type is not supported" {
dfx_start
dfx config canisters.e2e_project.type unknown_canister_type
dfx canister create --all
assert_command_fail dfx build
assert_command_fail dfx build --all
assert_match "CouldNotFindBuilderForCanister"
}

@test "can build a custom canister type" {
dfx_start
install_asset custom_canister
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
assert_match "CUSTOM_CANISTER_BUILD_DONE"

dfx canister install --all
Expand All @@ -87,21 +87,21 @@ teardown() {
@test "build succeeds with network parameter" {
dfx_start
dfx canister --network local create --all
assert_command dfx build --network local
assert_command dfx build --network local --all
}

@test "build succeeds when requested network is configured" {
dfx_start

assert_command dfx config networks.tungsten.providers '[ "http://127.0.0.1:8000" ]'
assert_command dfx canister --network tungsten create --all
assert_command dfx build --network tungsten
assert_command dfx build --network tungsten --all
}

@test "build output for local network is in expected directory" {
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
assert_command ls .dfx/local/canisters/e2e_project/
assert_command ls .dfx/local/canisters/e2e_project/e2e_project.wasm
}
Expand All @@ -110,7 +110,7 @@ teardown() {
dfx_start
assert_command dfx config networks.tungsten.providers '[ "http://127.0.0.1:8000" ]'
dfx canister --network tungsten create --all
assert_command dfx build --network tungsten
assert_command dfx build --network tungsten --all
assert_command ls .dfx/tungsten/canisters/e2e_project/
assert_command ls .dfx/tungsten/canisters/e2e_project/e2e_project.wasm
}
Expand Down
74 changes: 74 additions & 0 deletions e2e/bats/build_granular.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env bats

load utils/_

setup() {
# We want to work from a temporary directory, different for every test.
cd $(mktemp -d -t dfx-e2e-XXXXXXXX)

dfx_new
}

teardown() {
dfx_stop
}

@test "direct dependencies are built" {
dfx_start
dfx canister create --all
#specify build for only assets_canister
dfx build e2e_project_assets

#validate direct dependency built and is callable
assert_command dfx canister install e2e_project
assert_command dfx canister call e2e_project greet World
}

@test "transitive dependencies are built" {
install_asset transitive_deps_canisters
dfx_start
dfx canister create --all
#install of tertiary dependency canister will fail since its not built
assert_command_fail dfx canister install canister_a
#specify build for primary canister
dfx build canister_c

#validate tertiary transitive dependency is built and callable
assert_command dfx canister install canister_a
assert_command dfx canister call canister_a greet World
assert_match '("Namaste, World!")'
}

@test "unspecified dependencies are not built" {
dfx_start
dfx canister create --all
# only build motoko canister
dfx build e2e_project
# validate assets canister wasn't built and can't be installed
assert_command_fail dfx canister install e2e_project_assets
assert_match "No such file or directory"
}


@test "manual build of specified canisters succeeds" {
install_asset assetscanister

dfx_start
dfx canister create e2e_project
dfx build e2e_project
assert_command dfx canister install e2e_project
assert_command dfx canister call e2e_project greet World

assert_command_fail dfx canister install e2e_project_assets
assert_match "Cannot find canister id. Please issue 'dfx canister create e2e_project_assets'."
dfx canister create e2e_project_assets
dfx build e2e_project_assets
dfx canister install e2e_project_assets

assert_command dfx canister call --query e2e_project_assets retrieve '("binary/noise.txt")'
assert_eq '(vec { 184; 1; 32; 128; 10; 119; 49; 50; 32; 0; 120; 121; 10; 75; 76; 11; 10; 106; 107; })'

assert_command dfx canister call --query e2e_project_assets retrieve '("text-with-newlines.txt")'
assert_eq '(vec { 99; 104; 101; 114; 114; 105; 101; 115; 10; 105; 116; 39; 115; 32; 99; 104; 101; 114; 114; 121; 32; 115; 101; 97; 115; 111; 110; 10; 67; 72; 69; 82; 82; 73; 69; 83; })'

}
2 changes: 1 addition & 1 deletion e2e/bats/call.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ teardown() {
install_asset greet
dfx_start
dfx canister create --all
dfx build
dfx build --all
dfx canister install hello
assert_command dfx canister call $(dfx canister id hello) greet '("Names are difficult")'
assert_match '("Hello, Names are difficult!")'
Expand Down
6 changes: 3 additions & 3 deletions e2e/bats/create.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ teardown() {

@test "build fails without create" {
dfx_start
assert_command_fail dfx build
assert_match "Cannot find canister id. Please issue 'dfx canister create e2e_project'"
assert_command_fail dfx build --all
assert_match "Cannot find canister id."
}

@test "build fails if all canisters in project are not created" {
dfx_start
assert_command dfx canister create e2e_project
assert_command_fail dfx build
assert_command_fail dfx build --all
assert_match "Cannot find canister id. Please issue 'dfx canister create e2e_project_assets'"
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/bats/frontend.bash
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ teardown() {
@test "dfx start serves a frontend" {
dfx_start
dfx canister create --all
dfx build --skip-frontend
dfx build e2e_project

sleep 1
assert_command curl http://localhost:8000 # 8000 = default port.
Expand All @@ -31,7 +31,7 @@ teardown() {
cat <<<$(jq '.networks.local.bind="127.0.0.1:12345"' dfx.json) >dfx.json

dfx canister create --all
dfx build --skip-frontend
dfx build e2e_project

assert_command curl http://localhost:12345 # 8000 = default port.
assert_match "<html>"
Expand Down
2 changes: 1 addition & 1 deletion e2e/bats/id.bash
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ teardown() {
install_asset id
dfx_start
dfx canister create --all
dfx build
dfx build --all
assert_command dfx canister id e2e_project
assert_match $(cat .dfx/local/canister_ids.json | jq -r .e2e_project.local)
}
2 changes: 1 addition & 1 deletion e2e/bats/identity.bash
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ teardown() {
install_asset identity
dfx_start
dfx canister create --all
assert_command dfx build
assert_command dfx build --all
assert_command dfx canister install --all

ID_CALL=$(dfx canister call e2e_project fromCall)
Expand Down
6 changes: 3 additions & 3 deletions e2e/bats/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ teardown() {
@test "install succeeds when --all is provided" {
dfx_start
dfx canister create --all
dfx build
dfx build --all

assert_command dfx canister install --all

Expand All @@ -36,7 +36,7 @@ teardown() {
@test "install succeeds with network name" {
dfx_start
dfx canister create --all
dfx build
dfx build --all

assert_command dfx canister --network local install --all

Expand All @@ -46,7 +46,7 @@ teardown() {
@test "install fails with network name that is not in dfx.json" {
dfx_start
dfx canister create --all
dfx build
dfx build --all

assert_command_fail dfx canister --network nosuch install --all

Expand Down
Loading