diff --git a/examples/motoko_examples/persistent-storage/src/index.did b/examples/motoko_examples/persistent-storage/src/index.did index 0233802ba2..de7d56cbc4 100644 --- a/examples/motoko_examples/persistent-storage/src/index.did +++ b/examples/motoko_examples/persistent-storage/src/index.did @@ -1,4 +1,5 @@ service: () -> { + getRedeployed: () -> (bool) query; increment: () -> (nat); get: () -> (nat) query; reset: () -> (nat); diff --git a/examples/motoko_examples/persistent-storage/src/index.ts b/examples/motoko_examples/persistent-storage/src/index.ts index a80c4e4b15..88cab41e04 100644 --- a/examples/motoko_examples/persistent-storage/src/index.ts +++ b/examples/motoko_examples/persistent-storage/src/index.ts @@ -1,7 +1,9 @@ import { + bool, ic, init, nat, + postUpgrade, query, Service, StableBTreeMap, @@ -10,11 +12,18 @@ import { } from 'azle'; let stableStorage = StableBTreeMap(text, nat, 0); +let redeployed = false; export default Service({ init: init([], () => { stableStorage.insert('counter', 0n); }), + postUpgrade: postUpgrade([], () => { + redeployed = true; + }), + getRedeployed: query([], bool, () => { + return redeployed; + }), increment: update([], nat, () => { const counterOpt = stableStorage.get('counter'); const counter = diff --git a/examples/motoko_examples/persistent-storage/test/tests.ts b/examples/motoko_examples/persistent-storage/test/tests.ts index 7c31ec7ba7..95c65a953e 100644 --- a/examples/motoko_examples/persistent-storage/test/tests.ts +++ b/examples/motoko_examples/persistent-storage/test/tests.ts @@ -37,11 +37,20 @@ export function getTests( { name: 'deploy', prep: async () => { - execSync(`dfx deploy`, { + execSync(`dfx deploy --upgrade-unchanged`, { stdio: 'inherit' }); } }, + { + name: 'getRedeployed', + test: async () => { + const result = await persistentStorageCanister.getRedeployed(); + return { + Ok: result === true + }; + } + }, { name: 'get', test: async () => { diff --git a/examples/randomness/src/index.did b/examples/randomness/src/index.did index a0b06380d2..85dd1aa82a 100644 --- a/examples/randomness/src/index.did +++ b/examples/randomness/src/index.did @@ -1,3 +1,4 @@ service: () -> { + getRedeployed: () -> (bool) query; randomNumber: () -> (float64); } diff --git a/examples/randomness/src/index.ts b/examples/randomness/src/index.ts index dc8e94e417..1d0144ac75 100644 --- a/examples/randomness/src/index.ts +++ b/examples/randomness/src/index.ts @@ -1,6 +1,14 @@ -import { float64, Service, update } from 'azle'; +import { bool, float64, postUpgrade, query, Service, update } from 'azle'; + +let redeployed = false; export default Service({ + postUpgrade: postUpgrade([], () => { + redeployed = true; + }), + getRedeployed: query([], bool, () => { + return redeployed; + }), randomNumber: update([], float64, () => { return Math.random(); }) diff --git a/examples/randomness/test/tests.ts b/examples/randomness/test/tests.ts index 10ad7afaa6..0fa8e36afb 100644 --- a/examples/randomness/test/tests.ts +++ b/examples/randomness/test/tests.ts @@ -41,7 +41,16 @@ export function getTests(randomnessCanister: ActorSubclass<_SERVICE>): Test[] { { name: 'dfx deploy', prep: async () => { - execSync('dfx deploy'); + execSync('dfx deploy --upgrade-unchanged'); + } + }, + { + name: 'getRedeployed', + test: async () => { + const result = await randomnessCanister.getRedeployed(); + return { + Ok: result === true + }; } }, { diff --git a/examples/stable_structures/src/canister1/index.did b/examples/stable_structures/src/canister1/index.did index 2c1ee4d027..bc224a4700 100644 --- a/examples/stable_structures/src/canister1/index.did +++ b/examples/stable_structures/src/canister1/index.did @@ -17,6 +17,7 @@ type rec_17 = record {username:text; posts:vec rec_18}; type rec_20 = record {title:text}; type rec_19 = record {username:text; posts:vec rec_20}; service: () -> { + getRedeployed: () -> (bool) query; stableMap0ContainsKey: (nat8) -> (bool) query; stableMap0Get: (nat8) -> (opt text) query; stableMap0Insert: (nat8, text) -> (opt text); diff --git a/examples/stable_structures/src/canister1/index.ts b/examples/stable_structures/src/canister1/index.ts index 800502beab..f02334b584 100644 --- a/examples/stable_structures/src/canister1/index.ts +++ b/examples/stable_structures/src/canister1/index.ts @@ -1,11 +1,19 @@ -import { Service } from 'azle'; +import { Service, bool, postUpgrade, query } from 'azle'; import { stableMap0Methods } from './stable_map_0'; import { stableMap1Methods } from './stable_map_1'; import { stableMap2Methods } from './stable_map_2'; import { stableMap3Methods } from './stable_map_3'; import { stableMap4Methods } from './stable_map_4'; +let redeployed = false; + export default Service({ + postUpgrade: postUpgrade([], () => { + redeployed = true; + }), + getRedeployed: query([], bool, () => { + return redeployed; + }), ...stableMap0Methods, ...stableMap1Methods, ...stableMap2Methods, diff --git a/examples/stable_structures/src/canister2/index.did b/examples/stable_structures/src/canister2/index.did index f5e72a536a..40409a17d5 100644 --- a/examples/stable_structures/src/canister2/index.did +++ b/examples/stable_structures/src/canister2/index.did @@ -1,4 +1,5 @@ service: () -> { + getRedeployed: () -> (bool) query; stableMap5ContainsKey: (opt text) -> (bool) query; stableMap5Get: (opt text) -> (opt float64) query; stableMap5Insert: (opt text, float64) -> (opt float64); diff --git a/examples/stable_structures/src/canister2/index.ts b/examples/stable_structures/src/canister2/index.ts index e6acec7c10..3e55a41f3d 100644 --- a/examples/stable_structures/src/canister2/index.ts +++ b/examples/stable_structures/src/canister2/index.ts @@ -1,11 +1,19 @@ -import { Service } from 'azle'; +import { Service, bool, postUpgrade, query } from 'azle'; import { stableMap5Methods } from './stable_map_5'; import { stableMap6Methods } from './stable_map_6'; import { stableMap7Methods } from './stable_map_7'; import { stableMap8Methods } from './stable_map_8'; import { stableMap9Methods } from './stable_map_9'; +let redeployed = false; + export default Service({ + postUpgrade: postUpgrade([], () => { + redeployed = true; + }), + getRedeployed: query([], bool, () => { + return redeployed; + }), ...stableMap5Methods, ...stableMap6Methods, ...stableMap7Methods, diff --git a/examples/stable_structures/src/canister3/index.did b/examples/stable_structures/src/canister3/index.did index 4599327e85..f54e153fc3 100644 --- a/examples/stable_structures/src/canister3/index.did +++ b/examples/stable_structures/src/canister3/index.did @@ -17,6 +17,7 @@ type rec_18 = variant {Sad; Happy}; type rec_19 = variant {Sad; Happy}; type rec_20 = variant {Sad; Happy}; service: () -> { + getRedeployed: () -> (bool) query; stableMap10ContainsKey: (float32) -> (bool) query; stableMap10Get: (float32) -> (opt opt bool) query; stableMap10Insert: (float32, opt bool) -> (opt opt bool); diff --git a/examples/stable_structures/src/canister3/index.ts b/examples/stable_structures/src/canister3/index.ts index 665387ca75..609149a9b9 100644 --- a/examples/stable_structures/src/canister3/index.ts +++ b/examples/stable_structures/src/canister3/index.ts @@ -1,11 +1,19 @@ -import { Service } from 'azle'; +import { Service, bool, postUpgrade, query } from 'azle'; import { stableMap10Methods } from './stable_map_10'; import { stableMap11Methods } from './stable_map_11'; import { stableMap12Methods } from './stable_map_12'; import { stableMap13Methods } from './stable_map_13'; +let redeployed = false; + export default Service({ + postUpgrade: postUpgrade([], () => { + redeployed = true; + }), + getRedeployed: query([], bool, () => { + return redeployed; + }), ...stableMap10Methods, ...stableMap11Methods, ...stableMap12Methods, diff --git a/examples/stable_structures/test/tests.ts b/examples/stable_structures/test/tests.ts index 59c9c5f934..35cf4000d7 100644 --- a/examples/stable_structures/test/tests.ts +++ b/examples/stable_structures/test/tests.ts @@ -25,8 +25,8 @@ const STABLE_MAP_KEYS: [ nat8, nat16, nat32, - Reaction, - User, + typeof Reaction, + typeof User, string[], //Opt? BigUint64Array, null, @@ -66,8 +66,8 @@ const STABLE_MAP_KEYSCOMPS: [ (a: nat8 | undefined, b: nat8) => boolean, (a: nat16 | undefined, b: nat16) => boolean, (a: nat32 | undefined, b: nat32) => boolean, - (a: Reaction | undefined, b: Reaction) => boolean, - (a: User | undefined, b: User) => boolean, + (a: typeof Reaction | undefined, b: typeof Reaction) => boolean, + (a: typeof User | undefined, b: typeof User) => boolean, (a: string[] | undefined, b: string[]) => boolean, (a: BigUint64Array | undefined, b: BigInt64Array) => boolean, (a: null | undefined, b: null) => boolean, @@ -110,8 +110,8 @@ const STABLEMAPVALUES: [ null, string[], boolean[], - User, - Reaction, + typeof User, + typeof Reaction, Principal ] = [ 'hello', @@ -149,8 +149,8 @@ const STABLEMAPVALUECOMPS: [ (a: null | undefined, b: null) => boolean, (a: string[] | undefined, b: string[]) => boolean, (a: boolean[] | undefined, b: boolean[]) => boolean, - (a: User | undefined, b: User) => boolean, - (a: Reaction | undefined, b: Reaction) => boolean, + (a: typeof User | undefined, b: typeof User) => boolean, + (a: typeof Reaction | undefined, b: typeof Reaction) => boolean, (a: Principal | undefined, b: Principal) => boolean ] = [ simpleEquals, @@ -186,7 +186,23 @@ export function getTests( { name: 'redeploy canisters', prep: async () => { - execSync('dfx deploy', { stdio: 'inherit' }); + execSync('dfx deploy --upgrade-unchanged', { + stdio: 'inherit' + }); + } + }, + { + name: 'getRedeployed', + test: async () => { + const result1 = + await stableStructuresCanister_1.getRedeployed(); + const result2 = + await stableStructuresCanister_2.getRedeployed(); + const result3 = + await stableStructuresCanister_3.getRedeployed(); + return { + Ok: result1 === true && result2 === true && result3 === true + }; } }, ...postRedeployTests(stableStructuresCanister_1, 0, 4),