Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

final StableBTreeMap tests #1475

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions property_tests/arbitraries/canister_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UpdateMethod } from './canister_methods/update_method_arb';

export type Canister = {
sourceCode: string;
tests: Test[];
tests: Test[][];
};

export type CanisterConfig = {
Expand All @@ -26,8 +26,28 @@ export function CanisterArb(configArb: fc.Arbitrary<CanisterConfig>) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion property_tests/arbitraries/canister_methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export type TestsGenerator<
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
>
) => Test[];
) => Test[][];

export type CallbackLocation = 'INLINE' | 'STANDALONE';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type QueryMethod = {
imports: Set<string>;
globalDeclarations: string[];
sourceCode: string;
tests: Test[];
tests: Test[][];
};

export function QueryMethodArb<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type UpdateMethod = {
imports: Set<string>;
globalDeclarations: string[];
sourceCode: string;
tests: Test[];
tests: Test[][];
};

export function UpdateMethodArb<
Expand Down
14 changes: 11 additions & 3 deletions property_tests/arbitraries/stable_b_tree_map_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
});

Expand Down
44 changes: 26 additions & 18 deletions property_tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,37 @@ export function runPropTests(canisterArb: fc.Arbitrary<Canister>) {
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),
Expand Down
26 changes: 14 additions & 12 deletions property_tests/tests/blob/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateTests(
functionName: string,
paramBlobs: Named<CandidValueAndMeta<Uint8Array>>[],
returnBlob: CandidValueAndMeta<Uint8Array>
): Test[] {
): Test[][] {
const expectedResult = Uint8Array.from(
paramBlobs
.map((blob) => blob.el.agentResponseValue)
Expand All @@ -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)
};
}
}
}
]
];
}
22 changes: 12 additions & 10 deletions property_tests/tests/bool/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateTests(
functionName: string,
namedParamBools: Named<CandidValueAndMeta<boolean>>[],
returnBool: CandidValueAndMeta<boolean>
): Test[] {
): Test[][] {
const expectedResult = namedParamBools.reduce(
(acc, param) => acc && param.el.agentResponseValue,
returnBool.agentResponseValue
Expand All @@ -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)
};
}
}
}
]
];
}
22 changes: 12 additions & 10 deletions property_tests/tests/float32/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateTests(
functionName: string,
namedParamFloat32s: Named<CandidValueAndMeta<number>>[],
returnFloat32: CandidValueAndMeta<number>
): Test[] {
): Test[][] {
const expectedResult =
namedParamFloat32s.length === 0
? returnFloat32.agentResponseValue
Expand All @@ -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)
};
}
}
}
]
];
}
22 changes: 12 additions & 10 deletions property_tests/tests/float64/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateTests(
functionName: string,
namedParamFloat64s: Named<CandidValueAndMeta<number>>[],
returnFloat64: CandidValueAndMeta<number>
): Test[] {
): Test[][] {
const count = namedParamFloat64s.length + 1;
const expectedResult =
namedParamFloat64s.reduce(
Expand All @@ -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)
};
}
}
}
]
];
}
30 changes: 16 additions & 14 deletions property_tests/tests/func/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@ export function generateTests(
functionName: string,
namedParamFuncs: Named<CandidValueAndMeta<Func>>[],
returnFunc: CandidValueAndMeta<Func>
): 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)
};
}
}
}
]
];
}
22 changes: 12 additions & 10 deletions property_tests/tests/int/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function generateTests(
functionName: string,
namedParamInts: Named<CandidValueAndMeta<bigint>>[],
returnInt: CandidValueAndMeta<bigint>
): Test[] {
): Test[][] {
const expectedResult = namedParamInts.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt.agentResponseValue
Expand All @@ -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)
};
}
}
}
]
];
}
Loading