-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support
wasm_memory_persistence
for canister upgrades (#3890)
- Loading branch information
1 parent
e80551c
commit c6aab05
Showing
10 changed files
with
108 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
`classical-actor.wasm` is built from `actor.mo` with `moc -o classical-actor.wasm actor.mo`. | ||
`enhanced-actor.wasm` is built from `actor.mo` with `moc -o enhanced-actor.wasm --enhanced-orthogonal-persistence actor.mo`. | ||
`actor.did` is obtained by `moc --idl actor.mo`. |
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,3 @@ | ||
service : { | ||
getVersion: () -> (nat) query; | ||
} |
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,12 @@ | ||
import Prim "mo:prim"; | ||
|
||
actor { | ||
stable var version = 0; | ||
|
||
version += 1; | ||
Prim.debugPrint("Deployed actor version " # debug_show (version)); | ||
|
||
public query func getVersion() : async Nat { | ||
return version; | ||
}; | ||
}; |
Binary file not shown.
Binary file not shown.
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,9 @@ | ||
{ | ||
"canisters": { | ||
"test": { | ||
"type": "custom", | ||
"candid": "actor.did", | ||
"wasm": "classical-actor.wasm" | ||
} | ||
} | ||
} |
Binary file not shown.
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,66 @@ | ||
#!/usr/bin/env bats | ||
|
||
load ../utils/_ | ||
|
||
setup() { | ||
standard_setup | ||
|
||
dfx_new test | ||
} | ||
|
||
teardown() { | ||
dfx_stop | ||
|
||
standard_teardown | ||
} | ||
|
||
@test "migrate Motoko from classical persistence to classical persistence" { | ||
install_asset wasm_memory_persistence | ||
dfx_start | ||
dfx deploy | ||
dfx deploy --upgrade-unchanged | ||
assert_command dfx canister call test getVersion '()' | ||
assert_match "(2 : nat)" | ||
} | ||
|
||
@test "migrate Motoko from classical persistence to enhanced orthogonal persistence" { | ||
install_asset wasm_memory_persistence | ||
dfx_start | ||
dfx deploy | ||
jq '.canisters.test.wasm="enhanced-actor.wasm"' dfx.json | sponge dfx.json | ||
dfx deploy | ||
assert_command dfx canister call test getVersion '()' | ||
assert_match "(2 : nat)" | ||
} | ||
|
||
@test "migrate Motoko from enhanced orthogonal persistence to enhanced orthogonal persistence" { | ||
install_asset wasm_memory_persistence | ||
dfx_start | ||
jq '.canisters.test.wasm="enhanced-actor.wasm"' dfx.json | sponge dfx.json | ||
dfx deploy | ||
jq '.canisters.test.wasm="enhanced-actor.wasm"' dfx.json | sponge dfx.json | ||
dfx deploy --upgrade-unchanged | ||
assert_command dfx canister call test getVersion '()' | ||
assert_match "(2 : nat)" | ||
} | ||
|
||
@test "failing Motoko downgrade from enhanced orthogonal persistence to classical persistence" { | ||
install_asset wasm_memory_persistence | ||
dfx_start | ||
jq '.canisters.test.wasm="enhanced-actor.wasm"' dfx.json | sponge dfx.json | ||
dfx deploy | ||
jq '.canisters.test.wasm="classical-actor.wasm"' dfx.json | sponge dfx.json | ||
assert_command_fail dfx deploy | ||
assert_match "The \`wasm_memory_persistence: opt Keep\` upgrade option requires that the new canister module supports enhanced orthogonal persistence." | ||
} | ||
|
||
@test "re-install Motoko enhanced orthogonal persistence with classical persistence" { | ||
install_asset wasm_memory_persistence | ||
dfx_start | ||
jq '.canisters.test.wasm="enhanced-actor.wasm"' dfx.json | sponge dfx.json | ||
dfx deploy | ||
jq '.canisters.test.wasm="classical-actor.wasm"' dfx.json | sponge dfx.json | ||
echo yes | dfx canister install test --mode=reinstall | ||
assert_command dfx canister call test getVersion '()' | ||
assert_match "(1 : nat)" | ||
} |
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