Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 0 additions & 21 deletions e2e/assets/counter_as/dfx.json

This file was deleted.

1 change: 1 addition & 0 deletions e2e/assets/counter_as/patch.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dfx config canisters/hello/main counter.as
21 changes: 0 additions & 21 deletions e2e/assets/counter_wat/dfx.json

This file was deleted.

21 changes: 0 additions & 21 deletions e2e/assets/greet_as/dfx.json

This file was deleted.

1 change: 1 addition & 0 deletions e2e/assets/greet_as/patch.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dfx config canisters/hello/main greet.as
4 changes: 4 additions & 0 deletions e2e/assets/invalid_as/invalid.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Some Invalid Code
No way this is valid ActorScript, right?

// Who knows...
3 changes: 3 additions & 0 deletions e2e/assets/invalid_as/patch.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/dev/null

dfx config canisters/hello/main invalid.as
87 changes: 31 additions & 56 deletions e2e/basic-project.bash
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
#!/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)
export RUST_BACKTRACE=1

dfx new e2e-project
test -d e2e-project
test -f e2e-project/dfx.json
cd e2e-project

echo PWD: $(pwd) >&2
dfx_new
}

teardown() {
Expand All @@ -19,45 +16,25 @@ teardown() {
killall dfx nodemanager client || true
}

# Create a new project and starts its client in the background.
dfx_start() {
# Bats create a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leave a child process running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx start --background 3>&-
}

# Takes a name of the asset folder, and copy those files to the current project.
install_asset() {
ASSET_ROOT=${BATS_TEST_DIRNAME}/assets/$1/
cp -R $ASSET_ROOT/* .
}

@test "build + install + call + request-status -- greet_as" {
install_asset greet_as
dfx_start
dfx build
INSTALL_REQUEST_ID=$(dfx canister install 1 build/greet.wasm)
INSTALL_REQUEST_ID=$(dfx canister install 1 canisters/greet.wasm)
dfx canister request-status $INSTALL_REQUEST_ID

run dfx canister query 1 greet --type=string Banzai
[[ $status == 0 ]]
[[ "$output" == "Hello, Banzai!" ]]
assert_command dfx canister query 1 greet --type=string Banzai
assert_eq "Hello, Banzai!"

# Using call --wait.
run dfx canister call --wait 1 greet --type=string Bongalo
echo $output
[[ $status == 0 ]]
[[ "$output" == "Hello, Bongalo!" ]]
assert_command dfx canister call --wait 1 greet --type=string Bongalo
assert_eq "Hello, Bongalo!"

# Using call and request-status.
run dfx canister call 1 greet --type=string Blueberry
[[ $status == 0 ]]

assert_command dfx canister call 1 greet --type=string Blueberry
# At this point $output is the request ID.
run dfx canister request-status $output
[[ $status == 0 ]]
[[ "$output" == "Hello, Blueberry!" ]]
assert_command dfx canister request-status $output
assert_eq "Hello, Blueberry!"
}

@test "build + install + call + request-status -- counter_wat" {
Expand Down Expand Up @@ -105,36 +82,34 @@ install_asset() {
install_asset counter_as
dfx_start
dfx build
dfx canister install 1 build/counter.wasm
dfx canister install 1 canisters/counter.wasm --wait

assert_command dfx canister call 1 read --wait
assert_eq "0"

assert_command dfx canister call 1 inc --wait
assert_eq ""

run dfx canister call 1 read --wait
[[ "$output" == "0" ]]
run dfx canister call 1 inc --wait
[[ "$output" == "" ]]
run dfx canister query 1 read
[[ "$output" == "1" ]]
assert_command dfx canister query 1 read
assert_eq "1"

dfx canister call --wait 1 inc
run dfx canister query 1 read
[[ "$output" == "2" ]]
assert_command dfx canister query 1 read
assert_eq "2"

dfx canister call --wait 1 inc
run dfx canister query 1 read
[[ "$output" == "3" ]]
assert_command dfx canister query 1 read
assert_eq "3"

run dfx canister call 1 inc
[[ $status == 0 ]]
dfx canister request-status $output
[[ $status == 0 ]]
assert_command dfx canister call 1 inc
assert_command dfx canister request-status $output

# Call write.
run dfx canister call 1 write --type=number 1337 --wait
[[ $status == 0 ]]
assert_command dfx canister call 1 write --type=number 1337 --wait
assert_eq ""

# Write has no return value. But we can _call_ read too.
run dfx canister call 1 read
[[ $status == 0 ]]
run dfx canister request-status $output
[[ $status == 0 ]]
[[ "$output" == "1337" ]]
assert_command dfx canister call 1 read
assert_command dfx canister request-status $output
assert_eq "1337"
}
32 changes: 14 additions & 18 deletions e2e/config.bash
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
#!/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
}

@test "dfx config -- read/write" {
dfx new e2e-project
cd e2e-project

run dfx config defaults/build/output
[[ $status == 0 ]]
[[ "$output" == "\"canisters/\"" ]]
assert_command dfx config defaults/build/output
assert_eq '"canisters/"'

run dfx config defaults.build.output
[[ $status == 0 ]]
[[ "$output" == "\"canisters/\"" ]]
assert_command dfx config defaults.build.output
assert_eq '"canisters/"'

run dfx config defaults/build/output "other/"
[[ $status == 0 ]]
assert_command dfx config defaults/build/output "other/"
assert_eq ""

run dfx config defaults/build/output
[[ $status == 0 ]]
[[ "$output" == "\"other/\"" ]]
assert_command dfx config defaults/build/output
assert_eq '"other/"'

run dfx config non_existent
[[ $status == 255 ]]
assert_command_fail dfx config non_existent

# We don't allow to change values that are non existent.
run dfx config non_existent 123
[[ $status != 0 ]]
assert_command_fail dfx config non_existent 123
}
33 changes: 9 additions & 24 deletions e2e/frontend.bash
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/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 e2e-project
cd e2e-project
dfx_new
}

teardown() {
Expand All @@ -14,35 +15,19 @@ teardown() {
killall dfx nodemanager client || true
}

# Creates a new project and starts its client in the background.
dfx_start() {
# Bats create a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves a child process running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx start --background $* 3>&-
}

# Takes a name of the asset folder, and copy those files to the current project.
install_asset() {
ASSET_ROOT=${BATS_TEST_DIRNAME}/assets/$1/
cp -R $ASSET_ROOT/* .
}

@test "dfx start serves a frontend" {
dfx_start

run curl http://localhost:8000 # 8000 = default port.
[[ $status == 0 ]]
grep -i "<html>" <(echo $output)
assert_command curl http://localhost:8000 # 8000 = default port.
assert_match "<html>"
}

@test "dfx start serves a frontend on a port" {
dfx_start --host 127.0.0.1:12345

run curl http://localhost:12345 # 8000 = default port.
[[ $status == 0 ]]
grep -i "<html>" <(echo $output)
assert_command curl http://localhost:12345 # 8000 = default port.
assert_match "<html>"

run curl http://localhost:8000
[[ $status != 0 ]] # This should have failed (no frontend on 8000).
assert_command_fail curl http://localhost:8000
assert_match "Connection refused"
}
28 changes: 28 additions & 0 deletions e2e/utils/_.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
source ${BATSLIB}/load.bash
load utils/assertions

# Takes a name of the asset folder, and copy those files to the current project.
install_asset() {
ASSET_ROOT=${BATS_TEST_DIRNAME}/assets/$1/
cp -R $ASSET_ROOT/* .

[ -f ./patch.bash ] && source ./patch.bash
}

dfx_new() {
dfx new e2e-project
test -d e2e-project
test -f e2e-project/dfx.json
cd e2e-project

echo PWD: $(pwd) >&2
}

# Start the client in the background.
dfx_start() {
# Bats create a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leave a child process running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx start --background "$@" 3>&-
}

Loading