diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 652575a4ce..f48cb84411 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -5,7 +5,7 @@ import { UpdateMethod } from './canister_methods/update_method_arb'; export type Canister = { sourceCode: string; - tests: Test[]; + tests: Test[][]; }; export type CanisterConfig = { @@ -26,8 +26,28 @@ export function CanisterArb(configArb: fc.Arbitrary) { config.globalDeclarations ?? [], canisterMethods ); - const tests = canisterMethods.flatMap( - (canisterMethod) => canisterMethod.tests + + const tests = canisterMethods.reduce( + (acc: Test[][], canisterMethod): Test[][] => { + if (canisterMethod.tests.length < acc.length) { + return acc.map((accTests, index) => { + return [ + ...accTests, + ...(canisterMethod.tests[index] ?? []) + ]; + }); + } else { + return canisterMethod.tests.map( + (canisterMethodTests, index) => { + return [ + ...(acc[index] ?? []), + ...canisterMethodTests + ]; + } + ); + } + }, + [] ); return { diff --git a/property_tests/arbitraries/canister_methods/index.ts b/property_tests/arbitraries/canister_methods/index.ts index 5a63af1dee..4a716fde25 100644 --- a/property_tests/arbitraries/canister_methods/index.ts +++ b/property_tests/arbitraries/canister_methods/index.ts @@ -33,7 +33,7 @@ export type TestsGenerator< ReturnTypeAgentArgumentValue, ReturnTypeAgentResponseValue > -) => Test[]; +) => Test[][]; export type CallbackLocation = 'INLINE' | 'STANDALONE'; diff --git a/property_tests/arbitraries/canister_methods/query_method_arb.ts b/property_tests/arbitraries/canister_methods/query_method_arb.ts index bd7ce045c2..e8fd209dd0 100644 --- a/property_tests/arbitraries/canister_methods/query_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/query_method_arb.ts @@ -18,7 +18,7 @@ export type QueryMethod = { imports: Set; globalDeclarations: string[]; sourceCode: string; - tests: Test[]; + tests: Test[][]; }; export function QueryMethodArb< diff --git a/property_tests/arbitraries/canister_methods/update_method_arb.ts b/property_tests/arbitraries/canister_methods/update_method_arb.ts index 09bbb97d3c..f9a8b5e670 100644 --- a/property_tests/arbitraries/canister_methods/update_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/update_method_arb.ts @@ -19,7 +19,7 @@ export type UpdateMethod = { imports: Set; globalDeclarations: string[]; sourceCode: string; - tests: Test[]; + tests: Test[][]; }; export function UpdateMethodArb< diff --git a/property_tests/arbitraries/stable_b_tree_map_arb.ts b/property_tests/arbitraries/stable_b_tree_map_arb.ts index b0836fa5ed..b7b72157a7 100644 --- a/property_tests/arbitraries/stable_b_tree_map_arb.ts +++ b/property_tests/arbitraries/stable_b_tree_map_arb.ts @@ -17,11 +17,19 @@ export const StableBTreeMapArb = fc .map(([keySample, valueSample, uniqueIdentifier, memoryId]) => { const name = `stableBTreeMap${uniqueIdentifier}`; + const imports = new Set([ + ...keySample.src.imports, + ...valueSample.src.imports, + 'stableJson', + 'StableBTreeMap' + ]); + return { name, - body: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(stableJson, stableJson, ${memoryId});`, - param0: keySample, - param1: valueSample + imports, + definition: `let ${name} = StableBTreeMap<${keySample.src.candidTypeAnnotation}, ${valueSample.src.candidTypeAnnotation}>(stableJson, stableJson, ${memoryId});`, + keySample, + valueSample }; }); diff --git a/property_tests/index.ts b/property_tests/index.ts index 57a9b58df9..5e896d5901 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -29,29 +29,37 @@ export function runPropTests(canisterArb: fc.Arbitrary) { stdio: 'inherit' }); - execSync(`dfx deploy canister`, { - stdio: 'inherit' - }); + for (let i = 0; i < canister.tests.length; i++) { + execSync(`dfx deploy canister`, { + stdio: 'inherit' + }); - execSync(`dfx generate canister`, { - stdio: 'inherit' - }); + execSync(`dfx generate canister`, { + stdio: 'inherit' + }); - const result = await runTests( - canister.tests, - process.env.AZLE_PROPTEST_VERBOSE !== 'true' - ); + const tests = canister.tests[i]; - execSync( - `node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`, - { - stdio: 'inherit' - } - ); + const result = await runTests( + tests, + process.env.AZLE_PROPTEST_VERBOSE !== 'true' + ); + + execSync( + `node_modules/.bin/tsc --noEmit --skipLibCheck --target es2020 --strict --moduleResolution node --allowJs`, + { + stdio: 'inherit' + } + ); - clearUniquePrimitiveArb(); + clearUniquePrimitiveArb(); + + if (result === false) { + return false; + } + } - return result; + return true; }), { numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1), diff --git a/property_tests/tests/blob/test/generate_tests.ts b/property_tests/tests/blob/test/generate_tests.ts index 4b01823c76..c17cc88366 100644 --- a/property_tests/tests/blob/test/generate_tests.ts +++ b/property_tests/tests/blob/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, paramBlobs: Named>[], returnBlob: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = Uint8Array.from( paramBlobs .map((blob) => blob.el.agentResponseValue) @@ -19,19 +19,21 @@ export function generateTests( ); return [ - { - name: `blob ${functionName}`, - test: async () => { - const actor = getActor('./tests/blob/test'); + [ + { + name: `blob ${functionName}`, + test: async () => { + const actor = getActor('./tests/blob/test'); - const result = await actor[functionName]( - ...paramBlobs.map((blob) => blob.el.agentArgumentValue) - ); + const result = await actor[functionName]( + ...paramBlobs.map((blob) => blob.el.agentArgumentValue) + ); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/bool/test/generate_tests.ts b/property_tests/tests/bool/test/generate_tests.ts index 06fade587b..7c177ceed9 100644 --- a/property_tests/tests/bool/test/generate_tests.ts +++ b/property_tests/tests/bool/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamBools: Named>[], returnBool: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamBools.reduce( (acc, param) => acc && param.el.agentResponseValue, returnBool.agentResponseValue @@ -18,17 +18,19 @@ export function generateTests( ); return [ - { - name: `bool ${functionName}`, - test: async () => { - const actor = getActor('./tests/bool/test'); + [ + { + name: `bool ${functionName}`, + test: async () => { + const actor = getActor('./tests/bool/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/float32/test/generate_tests.ts b/property_tests/tests/float32/test/generate_tests.ts index e2e891e2b7..039658f13e 100644 --- a/property_tests/tests/float32/test/generate_tests.ts +++ b/property_tests/tests/float32/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamFloat32s: Named>[], returnFloat32: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamFloat32s.length === 0 ? returnFloat32.agentResponseValue @@ -17,17 +17,19 @@ export function generateTests( (paramFloats) => paramFloats.el.agentArgumentValue ); return [ - { - name: `float32 ${functionName}`, - test: async () => { - const actor = getActor('./tests/float32/test'); + [ + { + name: `float32 ${functionName}`, + test: async () => { + const actor = getActor('./tests/float32/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/float64/test/generate_tests.ts b/property_tests/tests/float64/test/generate_tests.ts index 9f1429ac9e..082d6ffa97 100644 --- a/property_tests/tests/float64/test/generate_tests.ts +++ b/property_tests/tests/float64/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamFloat64s: Named>[], returnFloat64: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamFloat64s.length + 1; const expectedResult = namedParamFloat64s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `float64 ${functionName}`, - test: async () => { - const actor = getActor('./tests/float64/test'); + [ + { + name: `float64 ${functionName}`, + test: async () => { + const actor = getActor('./tests/float64/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/func/test/generate_tests.ts b/property_tests/tests/func/test/generate_tests.ts index ee6e49c55f..78ee387a4f 100644 --- a/property_tests/tests/func/test/generate_tests.ts +++ b/property_tests/tests/func/test/generate_tests.ts @@ -9,23 +9,25 @@ export function generateTests( functionName: string, namedParamFuncs: Named>[], returnFunc: CandidValueAndMeta -): Test[] { +): Test[][] { return [ - { - name: `func ${functionName}`, - test: async () => { - const actor = getActor('./tests/func/test'); + [ + { + name: `func ${functionName}`, + test: async () => { + const actor = getActor('./tests/func/test'); - const result = await actor[functionName]( - ...namedParamFuncs.map( - (param) => param.el.agentArgumentValue - ) - ); + const result = await actor[functionName]( + ...namedParamFuncs.map( + (param) => param.el.agentArgumentValue + ) + ); - return { - Ok: deepEqual(result, returnFunc.agentResponseValue) - }; + return { + Ok: deepEqual(result, returnFunc.agentResponseValue) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/int/test/generate_tests.ts b/property_tests/tests/int/test/generate_tests.ts index 1b01b2a30b..9130aa7e56 100644 --- a/property_tests/tests/int/test/generate_tests.ts +++ b/property_tests/tests/int/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamInts: Named>[], returnInt: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamInts.reduce( (acc, param) => acc + param.el.agentResponseValue, returnInt.agentResponseValue @@ -18,17 +18,19 @@ export function generateTests( ); return [ - { - name: `int ${functionName}`, - test: async () => { - const actor = getActor('./tests/int/test'); + [ + { + name: `int ${functionName}`, + test: async () => { + const actor = getActor('./tests/int/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/int16/test/generate_tests.ts b/property_tests/tests/int16/test/generate_tests.ts index 1372b4352e..7200340249 100644 --- a/property_tests/tests/int16/test/generate_tests.ts +++ b/property_tests/tests/int16/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamInt16s: Named>[], returnInt16: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamInt16s.length + 1; const expectedResult = Math.floor( namedParamInt16s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `int16 ${functionName}`, - test: async () => { - const actor = getActor('./tests/int16/test'); + [ + { + name: `int16 ${functionName}`, + test: async () => { + const actor = getActor('./tests/int16/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/int32/test/generate_tests.ts b/property_tests/tests/int32/test/generate_tests.ts index 748ebae928..873d51b758 100644 --- a/property_tests/tests/int32/test/generate_tests.ts +++ b/property_tests/tests/int32/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamInt32s: Named>[], returnInt32: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamInt32s.length + 1; const expectedResult = Math.floor( namedParamInt32s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `int32 ${functionName}`, - test: async () => { - const actor = getActor('./tests/int32/test'); + [ + { + name: `int32 ${functionName}`, + test: async () => { + const actor = getActor('./tests/int32/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/int64/test/generate_tests.ts b/property_tests/tests/int64/test/generate_tests.ts index 958bd40c94..f5c4e8cd91 100644 --- a/property_tests/tests/int64/test/generate_tests.ts +++ b/property_tests/tests/int64/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamInt64s: Named>[], returnInt64: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamInt64s.length + 1; const expectedResult = namedParamInt64s.reduce( @@ -20,17 +20,19 @@ export function generateTests( (param) => param.el.agentArgumentValue ); return [ - { - name: `int64 ${functionName}`, - test: async () => { - const actor = getActor('./tests/int64/test'); + [ + { + name: `int64 ${functionName}`, + test: async () => { + const actor = getActor('./tests/int64/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/int8/test/generate_tests.ts b/property_tests/tests/int8/test/generate_tests.ts index 43f5c8fc3b..6b7a31f4c3 100644 --- a/property_tests/tests/int8/test/generate_tests.ts +++ b/property_tests/tests/int8/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamInt8s: Named>[], returnInt8: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamInt8s.length + 1; const expectedResult = Math.floor( namedParamInt8s.reduce( @@ -20,17 +20,19 @@ export function generateTests( (param) => param.el.agentArgumentValue ); return [ - { - name: `test ${functionName}`, - test: async () => { - const actor = getActor('./tests/int8/test'); + [ + { + name: `test ${functionName}`, + test: async () => { + const actor = getActor('./tests/int8/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/nat/test/generate_tests.ts b/property_tests/tests/nat/test/generate_tests.ts index 31a0047d76..7861644296 100644 --- a/property_tests/tests/nat/test/generate_tests.ts +++ b/property_tests/tests/nat/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamNats: Named>[], returnNat: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamNats.reduce( (acc, param) => acc + param.el.agentResponseValue, returnNat.agentResponseValue @@ -18,17 +18,19 @@ export function generateTests( ); return [ - { - name: `nat ${functionName}`, - test: async () => { - const actor = getActor('./tests/nat/test'); + [ + { + name: `nat ${functionName}`, + test: async () => { + const actor = getActor('./tests/nat/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/nat16/test/generate_tests.ts b/property_tests/tests/nat16/test/generate_tests.ts index 6adc8ebffe..2202e87b8a 100644 --- a/property_tests/tests/nat16/test/generate_tests.ts +++ b/property_tests/tests/nat16/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamNat16s: Named>[], returnNat16: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamNat16s.length + 1; const expectedResult = Math.floor( namedParamNat16s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `nat16 ${functionName}`, - test: async () => { - const actor = getActor('./tests/nat16/test'); + [ + { + name: `nat16 ${functionName}`, + test: async () => { + const actor = getActor('./tests/nat16/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/nat32/test/generate_tests.ts b/property_tests/tests/nat32/test/generate_tests.ts index c1f484d48c..6fad821fb8 100644 --- a/property_tests/tests/nat32/test/generate_tests.ts +++ b/property_tests/tests/nat32/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamNat32s: Named>[], returnNat32: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamNat32s.length + 1; const expectedResult = Math.floor( namedParamNat32s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `nat32 ${functionName}`, - test: async () => { - const actor = getActor('./tests/nat32/test'); + [ + { + name: `nat32 ${functionName}`, + test: async () => { + const actor = getActor('./tests/nat32/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/nat64/test/generate_tests.ts b/property_tests/tests/nat64/test/generate_tests.ts index e6cb87ca50..6d6f1294b6 100644 --- a/property_tests/tests/nat64/test/generate_tests.ts +++ b/property_tests/tests/nat64/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamNat64s: Named>[], returnNat64: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamNat64s.length + 1; const expectedResult = namedParamNat64s.reduce( @@ -20,17 +20,19 @@ export function generateTests( ); return [ - { - name: `nat64 ${functionName}`, - test: async () => { - const actor = getActor('./tests/nat64/test'); + [ + { + name: `nat64 ${functionName}`, + test: async () => { + const actor = getActor('./tests/nat64/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/nat8/test/generate_tests.ts b/property_tests/tests/nat8/test/generate_tests.ts index 60f29c0a2e..c354d973a3 100644 --- a/property_tests/tests/nat8/test/generate_tests.ts +++ b/property_tests/tests/nat8/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamNat8s: Named>[], returnNat8: CandidValueAndMeta -): Test[] { +): Test[][] { const count = namedParamNat8s.length + 1; const expectedResult = Math.floor( namedParamNat8s.reduce( @@ -21,17 +21,19 @@ export function generateTests( ); return [ - { - name: `nat8 ${functionName}`, - test: async () => { - const actor = getActor('./tests/nat8/test'); + [ + { + name: `nat8 ${functionName}`, + test: async () => { + const actor = getActor('./tests/nat8/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/null/test/generate_tests.ts b/property_tests/tests/null/test/generate_tests.ts index 0c19d354d3..1d920da949 100644 --- a/property_tests/tests/null/test/generate_tests.ts +++ b/property_tests/tests/null/test/generate_tests.ts @@ -8,23 +8,25 @@ export function generateTests( functionName: string, namedParamNulls: Named>[], _returnNull: CandidValueAndMeta -): Test[] { +): Test[][] { return [ - { - name: `test ${functionName}`, - test: async () => { - const actor = getActor('./tests/null/test'); + [ + { + name: `test ${functionName}`, + test: async () => { + const actor = getActor('./tests/null/test'); - const result = await actor[functionName]( - ...namedParamNulls.map( - (param) => param.el.agentArgumentValue - ) - ); + const result = await actor[functionName]( + ...namedParamNulls.map( + (param) => param.el.agentArgumentValue + ) + ); - return { - Ok: deepEqual(result, null) - }; + return { + Ok: deepEqual(result, null) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/opt/test/generate_tests.ts b/property_tests/tests/opt/test/generate_tests.ts index 772d58eca0..3ec3692e6f 100644 --- a/property_tests/tests/opt/test/generate_tests.ts +++ b/property_tests/tests/opt/test/generate_tests.ts @@ -9,25 +9,27 @@ export function generateTests( functionName: string, namedParamOpts: Named>[], returnOpt: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = returnOpt.agentResponseValue; return [ - { - name: `opt ${functionName}`, - test: async () => { - const actor = getActor('./tests/opt/test'); + [ + { + name: `opt ${functionName}`, + test: async () => { + const actor = getActor('./tests/opt/test'); - const params = namedParamOpts.map( - (param) => param.el.agentArgumentValue - ); + const params = namedParamOpts.map( + (param) => param.el.agentArgumentValue + ); - const result = await actor[functionName](...params); + const result = await actor[functionName](...params); - return { - Ok: deepEqual(expectedResult, result) - }; + return { + Ok: deepEqual(expectedResult, result) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/principal/test/generate_tests.ts b/property_tests/tests/principal/test/generate_tests.ts index 5433012364..2e80abbfd0 100644 --- a/property_tests/tests/principal/test/generate_tests.ts +++ b/property_tests/tests/principal/test/generate_tests.ts @@ -9,25 +9,27 @@ export function generateTests( functionName: string, namedParamPrincipals: Named>[], returnPrincipal: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamPrincipals.length > 0 ? namedParamPrincipals[0].el.agentResponseValue : returnPrincipal.agentResponseValue; return [ - { - name: `principal ${functionName}`, - test: async () => { - const actor = getActor('./tests/principal/test'); - const result = await actor[functionName]( - ...namedParamPrincipals.map( - (param) => param.el.agentArgumentValue - ) - ); + [ + { + name: `principal ${functionName}`, + test: async () => { + const actor = getActor('./tests/principal/test'); + const result = await actor[functionName]( + ...namedParamPrincipals.map( + (param) => param.el.agentArgumentValue + ) + ); - return { Ok: deepEqual(result, expectedResult) }; + return { Ok: deepEqual(result, expectedResult) }; + } } - } + ] ]; } diff --git a/property_tests/tests/query_methods/test/generate_tests.ts b/property_tests/tests/query_methods/test/generate_tests.ts index a2b0f1ccf3..62f689c9ee 100644 --- a/property_tests/tests/query_methods/test/generate_tests.ts +++ b/property_tests/tests/query_methods/test/generate_tests.ts @@ -10,24 +10,26 @@ export function generateTests( functionName: string, params: Named>[], returnType: CandidValueAndMeta -): Test[] { +): Test[][] { const paramValues = params.map((param) => param.el.agentArgumentValue); const expectedResult = returnType.agentResponseValue; return [ - { - name: `query method "${functionName}"`, - test: async () => { - const actor = getActor('./tests/query_methods/test'); - const result = await actor[functionName](...paramValues); - const valuesAreEqual = deepEqual(result, expectedResult); + [ + { + name: `query method "${functionName}"`, + test: async () => { + const actor = getActor('./tests/query_methods/test'); + const result = await actor[functionName](...paramValues); + const valuesAreEqual = deepEqual(result, expectedResult); - return valuesAreEqual - ? { Ok: true } - : { - Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}` - }; + return valuesAreEqual + ? { Ok: true } + : { + Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}` + }; + } } - } + ] ]; } diff --git a/property_tests/tests/record/test/generate_tests.ts b/property_tests/tests/record/test/generate_tests.ts index 803eceb80a..0e2dadfe87 100644 --- a/property_tests/tests/record/test/generate_tests.ts +++ b/property_tests/tests/record/test/generate_tests.ts @@ -9,23 +9,25 @@ export function generateTests( functionName: string, namedParamRecords: Named>[], returnRecord: CandidValueAndMeta -): Test[] { +): Test[][] { return [ - { - name: `record ${functionName}`, - test: async () => { - const actor = getActor('./tests/record/test'); + [ + { + name: `record ${functionName}`, + test: async () => { + const actor = getActor('./tests/record/test'); - const result = await actor[functionName]( - ...namedParamRecords.map( - (param) => param.el.agentArgumentValue - ) - ); + const result = await actor[functionName]( + ...namedParamRecords.map( + (param) => param.el.agentArgumentValue + ) + ); - return { - Ok: deepEqual(result, returnRecord.agentResponseValue) - }; + return { + Ok: deepEqual(result, returnRecord.agentResponseValue) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/service/test/generate_tests.ts b/property_tests/tests/service/test/generate_tests.ts index d3590a364f..38f55f4e23 100644 --- a/property_tests/tests/service/test/generate_tests.ts +++ b/property_tests/tests/service/test/generate_tests.ts @@ -9,34 +9,36 @@ export function generateTests( functionName: string, namedParamServices: Named>[], returnService: CandidValueAndMeta -): Test[] { +): Test[][] { return [ - { - name: `service ${functionName}`, - test: async () => { - // Using execSync because the JS Agent has a bug expecting services - // to be ordered by hash or something. - // See https://forum.dfinity.org/t/topic/20885/14 + [ + { + name: `service ${functionName}`, + test: async () => { + // Using execSync because the JS Agent has a bug expecting services + // to be ordered by hash or something. + // See https://forum.dfinity.org/t/topic/20885/14 - const paramsString = namedParamServices - .map( - (param) => - `service "${param.el.agentArgumentValue.toText()}"` - ) - .join(); + const paramsString = namedParamServices + .map( + (param) => + `service "${param.el.agentArgumentValue.toText()}"` + ) + .join(); - const result = execSync( - `dfx canister call canister ${functionName} '(${paramsString})'` - ) - .toString() - .trim(); + const result = execSync( + `dfx canister call canister ${functionName} '(${paramsString})'` + ) + .toString() + .trim(); - return { - Ok: - result === - `(service "${returnService.agentArgumentValue.toText()}")` - }; + return { + Ok: + result === + `(service "${returnService.agentArgumentValue.toText()}")` + }; + } } - } + ] ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/contains_key.ts b/property_tests/tests/stable_b_tree_map/test/contains_key.ts index f488595f48..665bc29f23 100644 --- a/property_tests/tests/stable_b_tree_map/test/contains_key.ts +++ b/property_tests/tests/stable_b_tree_map/test/contains_key.ts @@ -11,32 +11,26 @@ export function ContainsKeyTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'bool', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'bool']); const paramCandidTypeObjects = [ - stableBTreeMap.param0.src.candidTypeObject + stableBTreeMap.keySample.src.candidTypeObject ].join(', '); - const returnCandidType = `bool`; + const returnCandidTypeObject = `bool`; const body = generateBody(stableBTreeMap.name); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0.agentArgumentValue + stableBTreeMap.keySample.agentArgumentValue ); return { imports, globalDeclarations: [], - sourceCode: `${functionName}: query([${paramCandidTypeObjects}], ${returnCandidType}, (param0) => { + sourceCode: `${functionName}: query([${paramCandidTypeObjects}], ${returnCandidTypeObject}, (param0) => { ${body} })`, - tests: [test] + tests }; }); } @@ -47,17 +41,49 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest(functionName: string, param0Value: any): Test { - return { - name: `containsKey ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +function generateTests(functionName: string, param0Value: any): Test[][] { + return [ + [ + { + name: `containsKey after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](param0Value); + const result = await actor[functionName](param0Value); - return { - Ok: deepEqual(result, true) - }; - } - }; + return { + Ok: deepEqual(result, true) + }; + } + } + ], + [ + { + name: `containsKey after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](param0Value); + + return { + Ok: deepEqual(result, true) + }; + } + } + ], + [ + { + name: `containsKey after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](param0Value); + + return { + Ok: deepEqual(result, false) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/get.ts b/property_tests/tests/stable_b_tree_map/test/get.ts index e8463eba74..652b1ac030 100644 --- a/property_tests/tests/stable_b_tree_map/test/get.ts +++ b/property_tests/tests/stable_b_tree_map/test/get.ts @@ -11,25 +11,19 @@ export function GetTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'Opt', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'Opt']); const paramCandidTypeObjects = [ - stableBTreeMap.param0.src.candidTypeObject + stableBTreeMap.keySample.src.candidTypeObject ].join(', '); - const returnCandidTypeObject = `Opt(${stableBTreeMap.param1.src.candidTypeObject})`; + const returnCandidTypeObject = `Opt(${stableBTreeMap.valueSample.src.candidTypeObject})`; const body = generateBody(stableBTreeMap.name); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0.agentArgumentValue, - stableBTreeMap.param1.agentArgumentValue + stableBTreeMap.keySample.agentArgumentValue, + stableBTreeMap.valueSample.agentArgumentValue ); return { @@ -38,7 +32,7 @@ export function GetTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([${paramCandidTypeObjects}], ${returnCandidTypeObject}, (param0) => { ${body} })`, - tests: [test] + tests }; }); } @@ -49,21 +43,53 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest( +function generateTests( functionName: string, param0Value: any, param1Value: any -): Test { - return { - name: `get ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [ + { + name: `get after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](param0Value); + const result = await actor[functionName](param0Value); - return { - Ok: deepEqual(result, [param1Value]) - }; - } - }; + return { + Ok: deepEqual(result, [param1Value]) + }; + } + } + ], + [ + { + name: `get after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](param0Value); + + return { + Ok: deepEqual(result, [param1Value]) + }; + } + } + ], + [ + { + name: `get after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](param0Value); + + return { + Ok: deepEqual(result, []) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/insert.ts b/property_tests/tests/stable_b_tree_map/test/insert.ts index bfcab355eb..4e66e9d458 100644 --- a/property_tests/tests/stable_b_tree_map/test/insert.ts +++ b/property_tests/tests/stable_b_tree_map/test/insert.ts @@ -11,26 +11,20 @@ export function InsertTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'Opt', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'Opt']); const paramCandidTypeObjects = [ - stableBTreeMap.param0.src.candidTypeObject, - stableBTreeMap.param1.src.candidTypeObject + stableBTreeMap.keySample.src.candidTypeObject, + stableBTreeMap.valueSample.src.candidTypeObject ].join(', '); - const returnCandidTypeObject = `Opt(${stableBTreeMap.param1.src.candidTypeObject})`; + const returnCandidTypeObject = `Opt(${stableBTreeMap.valueSample.src.candidTypeObject})`; const body = generateBody(stableBTreeMap.name); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0.agentArgumentValue, - stableBTreeMap.param1.agentArgumentValue + stableBTreeMap.keySample.agentArgumentValue, + stableBTreeMap.valueSample.agentArgumentValue ); return { @@ -39,7 +33,7 @@ export function InsertTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: update([${paramCandidTypeObjects}], ${returnCandidTypeObject}, (param0, param1) => { ${body} })`, - tests: [test] + tests }; }); } @@ -50,21 +44,28 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest( +function generateTests( functionName: string, param0Value: any, param1Value: any -): Test { - return { - name: `insert ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [ + { + name: `insert after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](param0Value, param1Value); + const result = await actor[functionName]( + param0Value, + param1Value + ); - return { - Ok: deepEqual(result, []) - }; - } - }; + return { + Ok: deepEqual(result, []) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/is_empty.ts b/property_tests/tests/stable_b_tree_map/test/is_empty.ts index 1cac2be778..9e12c8d8e2 100644 --- a/property_tests/tests/stable_b_tree_map/test/is_empty.ts +++ b/property_tests/tests/stable_b_tree_map/test/is_empty.ts @@ -11,17 +11,11 @@ export function IsEmptyTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'bool', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'bool']); const body = generateBody(stableBTreeMap.name); - const test = generateTest(functionName); + const tests = generateTests(functionName); return { imports, @@ -29,7 +23,7 @@ export function IsEmptyTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([], bool, () => { ${body} })`, - tests: [test] + tests }; }); } @@ -40,17 +34,49 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest(functionName: string): Test { - return { - name: `isEmpty ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +function generateTests(functionName: string): Test[][] { + return [ + [ + { + name: `isEmpty after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](); + const result = await actor[functionName](); - return { - Ok: deepEqual(result, false) - }; - } - }; + return { + Ok: deepEqual(result, true) + }; + } + } + ], + [ + { + name: `isEmpty after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, false) + }; + } + } + ], + [ + { + name: `isEmpty after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, true) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/items.ts b/property_tests/tests/stable_b_tree_map/test/items.ts index fee398fe0e..c3e82aa345 100644 --- a/property_tests/tests/stable_b_tree_map/test/items.ts +++ b/property_tests/tests/stable_b_tree_map/test/items.ts @@ -12,21 +12,18 @@ export function ItemsTestArb(stableBTreeMap: StableBTreeMap) { .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, + ...stableBTreeMap.imports, 'Vec', - 'Tuple', - 'stableJson', - 'StableBTreeMap' + 'Tuple' ]); - const returnCandidTypeObject = `Vec(Tuple(${stableBTreeMap.param0.src.candidTypeObject}, ${stableBTreeMap.param1.src.candidTypeObject}))`; + const returnCandidTypeObject = `Vec(Tuple(${stableBTreeMap.keySample.src.candidTypeObject}, ${stableBTreeMap.valueSample.src.candidTypeObject}))`; const body = generateBody(stableBTreeMap.name); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0.agentArgumentValue, - stableBTreeMap.param1.agentArgumentValue + stableBTreeMap.keySample.agentArgumentValue, + stableBTreeMap.valueSample.agentArgumentValue ); return { @@ -35,7 +32,7 @@ export function ItemsTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([], ${returnCandidTypeObject}, () => { ${body} })`, - tests: [test] + tests }; }); } @@ -46,21 +43,53 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest( +function generateTests( functionName: string, param0Value: any, param1Value: any -): Test { - return { - name: `items ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [ + { + name: `items after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](); + const result = await actor[functionName](); - return { - Ok: deepEqual(result, [[param0Value, param1Value]]) - }; - } - }; + return { + Ok: deepEqual(result, [[param0Value, param1Value]]) + }; + } + } + ], + [ + { + name: `items after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, [[param0Value, param1Value]]) + }; + } + } + ], + [ + { + name: `items after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, []) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/keys.ts b/property_tests/tests/stable_b_tree_map/test/keys.ts index d97cda5dbb..0fee90545f 100644 --- a/property_tests/tests/stable_b_tree_map/test/keys.ts +++ b/property_tests/tests/stable_b_tree_map/test/keys.ts @@ -14,21 +14,15 @@ export function KeysTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'Vec', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'Vec']); - const returnCandidTypeObject = `Vec(${stableBTreeMap.param0.src.candidTypeObject})`; + const returnCandidTypeObject = `Vec(${stableBTreeMap.keySample.src.candidTypeObject})`; const body = generateBody( stableBTreeMap.name, - stableBTreeMap.param0.src.candidTypeAnnotation + stableBTreeMap.keySample.src.candidTypeAnnotation ); - const test = generateTest(functionName, stableBTreeMap.param0); + const tests = generateTests(functionName, stableBTreeMap.keySample); return { imports, @@ -36,7 +30,7 @@ export function KeysTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([], ${returnCandidTypeObject}, () => { ${body} })`, - tests: [test] + tests }; }); } @@ -52,27 +46,73 @@ function generateBody( `; } -function generateTest( +function generateTests( functionName: string, param0: CandidValueAndMeta -): Test { - return { - name: `keys ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [ + { + name: `keys after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](); + const result = await actor[functionName](); - return { - Ok: deepEqual( - getArrayForCandidType(param0.src.candidTypeAnnotation).from( - result - ), - getArrayForCandidType(param0.src.candidTypeAnnotation).from( - [param0.agentArgumentValue] - ) - ) - }; - } - }; + return { + Ok: deepEqual( + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from([param0.agentArgumentValue]) + ) + }; + } + } + ], + [ + { + name: `keys after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual( + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from([param0.agentArgumentValue]) + ) + }; + } + } + ], + [ + { + name: `keys after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual( + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param0.src.candidTypeAnnotation + ).from([]) + ) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/len.ts b/property_tests/tests/stable_b_tree_map/test/len.ts index f8fb5d1cd4..4522f1d3f0 100644 --- a/property_tests/tests/stable_b_tree_map/test/len.ts +++ b/property_tests/tests/stable_b_tree_map/test/len.ts @@ -11,18 +11,12 @@ export function LenTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'nat64', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'nat64']); const returnCandidTypeObject = `nat64`; const body = generateBody(stableBTreeMap.name); - const test = generateTest(functionName); + const tests = generateTests(functionName); return { imports, @@ -30,7 +24,7 @@ export function LenTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([], ${returnCandidTypeObject}, () => { ${body} })`, - tests: [test] + tests }; }); } @@ -41,17 +35,49 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest(functionName: string): Test { - return { - name: `len ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +function generateTests(functionName: string): Test[][] { + return [ + [ + { + name: `len after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](); + const result = await actor[functionName](); - return { - Ok: deepEqual(result, 1n) - }; - } - }; + return { + Ok: deepEqual(result, 1n) + }; + } + } + ], + [ + { + name: `len after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, 1n) + }; + } + } + ], + [ + { + name: `len after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual(result, 0n) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/remove.ts b/property_tests/tests/stable_b_tree_map/test/remove.ts index 35506bb2f4..05816efe25 100644 --- a/property_tests/tests/stable_b_tree_map/test/remove.ts +++ b/property_tests/tests/stable_b_tree_map/test/remove.ts @@ -14,25 +14,19 @@ export function RemoveTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'Opt', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'Opt']); const paramCandidTypeObjects = [ - stableBTreeMap.param0.src.candidTypeObject + stableBTreeMap.keySample.src.candidTypeObject ].join(', '); - const returnCandidTypeObject = `Opt(${stableBTreeMap.param1.src.candidTypeObject})`; + const returnCandidTypeObject = `Opt(${stableBTreeMap.valueSample.src.candidTypeObject})`; const body = generateBody(stableBTreeMap.name); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0.agentArgumentValue, - stableBTreeMap.param1.agentArgumentValue + stableBTreeMap.keySample.agentArgumentValue, + stableBTreeMap.valueSample.agentArgumentValue ); return { @@ -41,7 +35,7 @@ export function RemoveTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: update([${paramCandidTypeObjects}], ${returnCandidTypeObject}, (param0) => { ${body} })`, - tests: [test] + tests }; }); } @@ -52,21 +46,26 @@ function generateBody(stableBTreeMapName: string): string { `; } -function generateTest( +function generateTests( functionName: string, param0Value: any, param1Value: any -): Test { - return { - name: `remove ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [], + [ + { + name: `remove after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName](param0Value); + const result = await actor[functionName](param0Value); - return { - Ok: deepEqual(result, [param1Value]) - }; - } - }; + return { + Ok: deepEqual(result, [param1Value]) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/stable_b_tree_map/test/test.ts b/property_tests/tests/stable_b_tree_map/test/test.ts index 297698bb32..433870c307 100644 --- a/property_tests/tests/stable_b_tree_map/test/test.ts +++ b/property_tests/tests/stable_b_tree_map/test/test.ts @@ -22,45 +22,47 @@ const StableBTreeMapTestArb = fc StableBTreeMapArb.chain((stableBTreeMap) => { return fc .tuple( + IsEmptyTestArb(stableBTreeMap), InsertTestArb(stableBTreeMap), ContainsKeyTestArb(stableBTreeMap), GetTestArb(stableBTreeMap), - IsEmptyTestArb(stableBTreeMap), ItemsTestArb(stableBTreeMap), KeysTestArb(stableBTreeMap), LenTestArb(stableBTreeMap), - RemoveTestArb(stableBTreeMap), - ValuesTestArb(stableBTreeMap) + ValuesTestArb(stableBTreeMap), + RemoveTestArb(stableBTreeMap) ) .map( ([ + isEmptyTestQueryMethod, + insertTestQueryMethod, containsKeyTestQueryMethod, getTestQueryMethod, - isEmptyTestQueryMethod, itemsTestQueryMethod, keysTestQueryMethod, lenTestQueryMethod, - removeTestQueryMethod, - valuesTestQueryMethod + valuesTestQueryMethod, + removeTestQueryMethod ]) => { return { globalDeclarations: [ - stableBTreeMap.body, - ...stableBTreeMap.param0.src + stableBTreeMap.definition, + ...stableBTreeMap.keySample.src .variableAliasDeclarations, - ...stableBTreeMap.param1.src + ...stableBTreeMap.valueSample.src .variableAliasDeclarations ], queryMethods: [], updateMethods: [ + isEmptyTestQueryMethod, + insertTestQueryMethod, containsKeyTestQueryMethod, getTestQueryMethod, - isEmptyTestQueryMethod, itemsTestQueryMethod, keysTestQueryMethod, lenTestQueryMethod, - removeTestQueryMethod, - valuesTestQueryMethod + valuesTestQueryMethod, + removeTestQueryMethod ] }; } diff --git a/property_tests/tests/stable_b_tree_map/test/values.ts b/property_tests/tests/stable_b_tree_map/test/values.ts index 6f99c86004..660a87aa1a 100644 --- a/property_tests/tests/stable_b_tree_map/test/values.ts +++ b/property_tests/tests/stable_b_tree_map/test/values.ts @@ -14,24 +14,17 @@ export function ValuesTestArb(stableBTreeMap: StableBTreeMap) { return fc .tuple(UniqueIdentifierArb('stableBTreeMap')) .map(([functionName]): QueryMethod => { - const imports = new Set([ - ...stableBTreeMap.param0.src.imports, - ...stableBTreeMap.param1.src.imports, - 'Vec', - 'stableJson', - 'StableBTreeMap' - ]); + const imports = new Set([...stableBTreeMap.imports, 'Vec']); - const returnCandidTypeObject = `Vec(${stableBTreeMap.param1.src.candidTypeObject})`; + const returnCandidTypeObject = `Vec(${stableBTreeMap.valueSample.src.candidTypeObject})`; const body = generateBody( stableBTreeMap.name, - stableBTreeMap.param1.src.candidTypeAnnotation + stableBTreeMap.valueSample.src.candidTypeAnnotation ); - const test = generateTest( + const tests = generateTests( functionName, - stableBTreeMap.param0, - stableBTreeMap.param1 + stableBTreeMap.valueSample ); return { @@ -40,7 +33,7 @@ export function ValuesTestArb(stableBTreeMap: StableBTreeMap) { sourceCode: `${functionName}: query([], ${returnCandidTypeObject}, () => { ${body} })`, - tests: [test] + tests }; }); } @@ -56,31 +49,73 @@ function generateBody( `; } -function generateTest( +function generateTests( functionName: string, - param0: CandidValueAndMeta, param1: CandidValueAndMeta -): Test { - return { - name: `values ${functionName}`, - test: async () => { - const actor = getActor('./tests/stable_b_tree_map/test'); +): Test[][] { + return [ + [ + { + name: `values after first deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); - const result = await actor[functionName]( - param0.agentArgumentValue, - param1.agentArgumentValue - ); + const result = await actor[functionName](); - return { - Ok: deepEqual( - getArrayForCandidType(param1.src.candidTypeAnnotation).from( - result - ), - getArrayForCandidType(param1.src.candidTypeAnnotation).from( - [param1.agentArgumentValue] - ) - ) - }; - } - }; + return { + Ok: deepEqual( + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from([param1.agentArgumentValue]) + ) + }; + } + } + ], + [ + { + name: `values after second deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual( + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from([param1.agentArgumentValue]) + ) + }; + } + } + ], + [ + { + name: `values after third deploy ${functionName}`, + test: async () => { + const actor = getActor('./tests/stable_b_tree_map/test'); + + const result = await actor[functionName](); + + return { + Ok: deepEqual( + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from(result), + getArrayForCandidType( + param1.src.candidTypeAnnotation + ).from([]) + ) + }; + } + } + ] + ]; } diff --git a/property_tests/tests/text/test/generate_tests.ts b/property_tests/tests/text/test/generate_tests.ts index 5b603660c7..df609bfa41 100644 --- a/property_tests/tests/text/test/generate_tests.ts +++ b/property_tests/tests/text/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( functionName: string, namedParamTexts: Named>[], returnTexts: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = namedParamTexts.reduce( (acc, param) => acc + param.el.agentResponseValue, returnTexts.agentResponseValue @@ -18,17 +18,19 @@ export function generateTests( ); return [ - { - name: `text ${functionName}`, - test: async () => { - const actor = getActor('./tests/text/test'); + [ + { + name: `text ${functionName}`, + test: async () => { + const actor = getActor('./tests/text/test'); - const result = await actor[functionName](...paramValues); + const result = await actor[functionName](...paramValues); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/tuple/test/generate_tests.ts b/property_tests/tests/tuple/test/generate_tests.ts index b26960de6b..a88bdb4e90 100644 --- a/property_tests/tests/tuple/test/generate_tests.ts +++ b/property_tests/tests/tuple/test/generate_tests.ts @@ -12,23 +12,25 @@ export function generateTests( functionName: string, namedParamTuples: Named>[], returnTuple: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = returnTuple.agentResponseValue; return [ - { - name: `tuple ${functionName}`, - test: async () => { - const actor = getActor('./tests/tuple/test'); + [ + { + name: `tuple ${functionName}`, + test: async () => { + const actor = getActor('./tests/tuple/test'); - const result = await actor[functionName]( - ...namedParamTuples.map( - (param) => param.el.agentArgumentValue - ) - ); + const result = await actor[functionName]( + ...namedParamTuples.map( + (param) => param.el.agentArgumentValue + ) + ); - return { Ok: deepEqual(result, expectedResult) }; + return { Ok: deepEqual(result, expectedResult) }; + } } - } + ] ]; } diff --git a/property_tests/tests/update_methods/test/generate_tests.ts b/property_tests/tests/update_methods/test/generate_tests.ts index 18f069bf60..1d64ee7e17 100644 --- a/property_tests/tests/update_methods/test/generate_tests.ts +++ b/property_tests/tests/update_methods/test/generate_tests.ts @@ -10,24 +10,26 @@ export function generateTests( functionName: string, params: Named>[], returnType: CandidValueAndMeta -): Test[] { +): Test[][] { const paramValues = params.map((param) => param.el.agentArgumentValue); const expectedResult = returnType.agentResponseValue; return [ - { - name: `update method "${functionName}"`, - test: async () => { - const actor = getActor('./tests/update_methods/test'); - const result = await actor[functionName](...paramValues); - const valuesAreEqual = deepEqual(result, expectedResult); + [ + { + name: `update method "${functionName}"`, + test: async () => { + const actor = getActor('./tests/update_methods/test'); + const result = await actor[functionName](...paramValues); + const valuesAreEqual = deepEqual(result, expectedResult); - return valuesAreEqual - ? { Ok: true } - : { - Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}` - }; + return valuesAreEqual + ? { Ok: true } + : { + Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}` + }; + } } - } + ] ]; } diff --git a/property_tests/tests/variant/test/generate_tests.ts b/property_tests/tests/variant/test/generate_tests.ts index 4bf5262aa4..270f08a078 100644 --- a/property_tests/tests/variant/test/generate_tests.ts +++ b/property_tests/tests/variant/test/generate_tests.ts @@ -9,25 +9,27 @@ export function generateTests( functionName: string, namedParamVariants: Named>[], returnVariant: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = returnVariant.agentResponseValue; return [ - { - name: `variant ${functionName}`, - test: async () => { - const actor = getActor('./tests/variant/test'); + [ + { + name: `variant ${functionName}`, + test: async () => { + const actor = getActor('./tests/variant/test'); - const result = await actor[functionName]( - ...namedParamVariants.map( - (param) => param.el.agentArgumentValue - ) - ); + const result = await actor[functionName]( + ...namedParamVariants.map( + (param) => param.el.agentArgumentValue + ) + ); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; } diff --git a/property_tests/tests/vec/test/generate_tests.ts b/property_tests/tests/vec/test/generate_tests.ts index 1c0e7400a4..0ba77a672d 100644 --- a/property_tests/tests/vec/test/generate_tests.ts +++ b/property_tests/tests/vec/test/generate_tests.ts @@ -8,24 +8,26 @@ export function generateTests( functionName: string, namedParamVecs: Named>[], returnVec: CandidValueAndMeta -): Test[] { +): Test[][] { const expectedResult = returnVec.agentResponseValue; return [ - { - name: `vec ${functionName}`, - test: async () => { - const actor = getActor('./tests/vec/test'); + [ + { + name: `vec ${functionName}`, + test: async () => { + const actor = getActor('./tests/vec/test'); - const params = namedParamVecs.map( - (param) => param.el.agentArgumentValue - ); - const result = await actor[functionName](...params); + const params = namedParamVecs.map( + (param) => param.el.agentArgumentValue + ); + const result = await actor[functionName](...params); - return { - Ok: deepEqual(result, expectedResult) - }; + return { + Ok: deepEqual(result, expectedResult) + }; + } } - } + ] ]; }