Skip to content

Commit

Permalink
fix tests that require redeploy, ensure that they actually redeploy e…
Browse files Browse the repository at this point in the history
…ven if the wasm binary does not change
  • Loading branch information
lastmjs committed Sep 27, 2023
1 parent 1cf54d9 commit fda3245
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 15 deletions.
1 change: 1 addition & 0 deletions examples/motoko_examples/persistent-storage/src/index.did
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
service: () -> {
getRedeployed: () -> (bool) query;
increment: () -> (nat);
get: () -> (nat) query;
reset: () -> (nat);
Expand Down
9 changes: 9 additions & 0 deletions examples/motoko_examples/persistent-storage/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
bool,
ic,
init,
nat,
postUpgrade,
query,
Service,
StableBTreeMap,
Expand All @@ -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 =
Expand Down
11 changes: 10 additions & 1 deletion examples/motoko_examples/persistent-storage/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
1 change: 1 addition & 0 deletions examples/randomness/src/index.did
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
service: () -> {
getRedeployed: () -> (bool) query;
randomNumber: () -> (float64);
}
10 changes: 9 additions & 1 deletion examples/randomness/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();
})
Expand Down
11 changes: 10 additions & 1 deletion examples/randomness/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
},
{
Expand Down
1 change: 1 addition & 0 deletions examples/stable_structures/src/canister1/index.did
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion examples/stable_structures/src/canister1/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/stable_structures/src/canister2/index.did
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
10 changes: 9 additions & 1 deletion examples/stable_structures/src/canister2/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions examples/stable_structures/src/canister3/index.did
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 9 additions & 1 deletion examples/stable_structures/src/canister3/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
34 changes: 25 additions & 9 deletions examples/stable_structures/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const STABLE_MAP_KEYS: [
nat8,
nat16,
nat32,
Reaction,
User,
typeof Reaction,
typeof User,
string[], //Opt?
BigUint64Array,
null,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -110,8 +110,8 @@ const STABLEMAPVALUES: [
null,
string[],
boolean[],
User,
Reaction,
typeof User,
typeof Reaction,
Principal
] = [
'hello',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit fda3245

Please sign in to comment.