-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* make assertions * pin btc-canister * gitignore * comment * asset_storage * fix management * chess * counter * print * simplify profile * edition 2021 & resolver 2
- Loading branch information
Showing
21 changed files
with
114 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,66 @@ | ||
load ../../bats/bats-assert/load.bash | ||
|
||
# Executed before each test. | ||
setup() { | ||
cd examples/asset_storage | ||
# Make sure the directory is clean. | ||
dfx start --clean --background | ||
dfx start --clean --background | ||
|
||
run dfx identity new alice --disable-encryption | ||
run dfx identity new bob --disable-encryption | ||
run dfx identity new charlie --disable-encryption | ||
x=$(mktemp -d -t cdk-XXXXXXXX) | ||
export DFX_CONFIG_ROOT="$x" | ||
dfx identity new alice --storage-mode=plaintext | ||
dfx identity new bob --storage-mode=plaintext | ||
dfx identity new charlie --storage-mode=plaintext | ||
} | ||
|
||
# executed after each test | ||
teardown() { | ||
dfx stop | ||
rm -rf "$DFX_CONFIG_ROOT" | ||
} | ||
|
||
@test "Can store and restore assets" { | ||
dfx deploy | ||
dfx canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
dfx canister call asset_storage retrieve '("asset_name")' | ||
run dfx canister call asset_storage retrieve '("unknown")' | ||
# As of dfx 0.8.1, above command results in following error message: | ||
# > The Replica returned an error: code 5, message: "IC0502: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped: unreachable" | ||
[ "$status" != 0 ] | ||
} | ||
|
||
@test "Will fails on invalid identities" { | ||
dfx identity use alice | ||
dfx deploy | ||
dfx canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
dfx canister call asset_storage retrieve '("asset_name")' | ||
|
||
dfx canister call asset_storage add_user "(principal \"$(dfx --identity charlie identity get-principal)\")" | ||
|
||
dfx identity use bob | ||
dfx canister call asset_storage retrieve '("asset_name")' | ||
dfx --identity alice deploy | ||
run dfx --identity alice canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
assert_success | ||
run dfx --identity alice canister call asset_storage retrieve '("asset_name")' | ||
assert_success | ||
|
||
# Test that an unknown asset fails. | ||
run dfx canister call asset_storage retrieve '("unknown")' | ||
[ "$status" != 0 ] | ||
run dfx --identity alice canister call asset_storage retrieve '("unknown")' | ||
assert_failure | ||
} | ||
|
||
# Test that cannot upload assets as bob. | ||
run dfx canister call asset_storage store '("asset_name", vec { 1; })' | ||
[ "$status" != 0 ] | ||
@test "Unauthorized identity cannot store" { | ||
dfx --identity alice deploy | ||
dfx --identity alice canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
dfx --identity alice canister call asset_storage retrieve '("asset_name")' | ||
|
||
# Test we can upload assets as charlie. | ||
dfx identity use charlie | ||
run dfx canister call asset_storage store '("asset_name_2", vec { 1; 2; 3; })' | ||
[ "$status" == 0 ] | ||
} | ||
# add charlie | ||
run dfx --identity alice canister call asset_storage add_user "(principal \"$(dfx --identity charlie identity get-principal)\")" | ||
assert_success | ||
|
||
@test "Can upgrade and keep ACLs" { | ||
dfx identity use alice | ||
dfx deploy | ||
# bob cannot upload assets | ||
run dfx --identity bob canister call asset_storage store '("asset_name", vec { 1; })' | ||
assert_failure | ||
|
||
dfx canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
dfx identity use bob | ||
run dfx canister call asset_storage retrieve '("unknown")' | ||
[ "$status" != 0 ] | ||
# charlie can upload assets | ||
run dfx --identity charlie canister call asset_storage store '("asset_name_2", vec { 1; 2; 3; })' | ||
assert_success | ||
} | ||
|
||
dfx identity use alice | ||
dfx canister call asset_storage add_user "(principal \"$(dfx --identity charlie identity get-principal)\")" | ||
@test "Can upgrade and keep the access control list" { | ||
dfx --identity alice deploy | ||
dfx --identity alice canister call asset_storage store '("asset_name", vec { 1; 2; 3; })' | ||
dfx --identity alice canister call asset_storage add_user "(principal \"$(dfx --identity charlie identity get-principal)\")" | ||
|
||
dfx build | ||
dfx canister install --all --mode=upgrade | ||
|
||
dfx identity use charlie | ||
run dfx canister call asset_storage store '("asset_name_2", vec { 1; 2; 3; })' | ||
[ "$status" == 0 ] | ||
# bob still cannot upload assets | ||
run dfx --identity bob canister call asset_storage store '("asset_name", vec { 1; })' | ||
assert_failure | ||
|
||
# charlie still can upload assets | ||
run dfx --identity charlie canister call asset_storage store '("asset_name_2", vec { 1; 2; 3; })' | ||
assert_success | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ic-btc-canister.wasm.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
[workspace] | ||
members = [ | ||
"src/caller", | ||
] | ||
members = ["src/caller"] | ||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.