Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Dec 12, 2023
1 parent 45837a2 commit 74859ad
Show file tree
Hide file tree
Showing 33 changed files with 109 additions and 96 deletions.
22 changes: 9 additions & 13 deletions property_tests/arbitraries/canister_methods/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ export type BodyGenerator<
namedParams: Named<
CandidValueAndMeta<ParamAgentArgumentValue, ParamAgentResponseValue>
>[],
returnType:
| CandidValueAndMeta<
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
>
| undefined
returnType: CandidValueAndMeta<
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
>
) => string;

export type TestsGenerator<
Expand All @@ -31,12 +29,10 @@ export type TestsGenerator<
namedParams: Named<
CandidValueAndMeta<ParamAgentArgumentValue, ParamAgentResponseValue>
>[],
returnType:
| CandidValueAndMeta<
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
>
| undefined
returnType: CandidValueAndMeta<
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
>
) => Test[][];

export type CallbackLocation = 'INLINE' | 'STANDALONE';
Expand All @@ -52,7 +48,7 @@ export function generateCallback<
ReturnAgentType
>(
namedParams: Named<CandidValueAndMeta<ParamType, ParamAgentType>>[],
returnType: CandidValueAndMeta<ReturnType, ReturnAgentType> | undefined,
returnType: CandidValueAndMeta<ReturnType, ReturnAgentType>,
generateBody: BodyGenerator<
ParamType,
ParamAgentType,
Expand Down
15 changes: 9 additions & 6 deletions property_tests/arbitraries/canister_methods/init_method_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
generateCallback
} from '.';
import { Test } from '../../../test';
import { VoidArb } from '../candid/primitive/void';

export type InitMethod<
ParamAgentArgumentValue extends CorrespondingJSType,
Expand Down Expand Up @@ -39,14 +40,14 @@ export function InitMethodArb<
generateBody: BodyGenerator<
ParamAgentArgumentValue,
ParamAgentResponseValue,
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
ReturnTypeAgentArgumentValue | undefined,
ReturnTypeAgentResponseValue | undefined
>;
generateTests: TestsGenerator<
ParamAgentArgumentValue,
ParamAgentResponseValue,
ReturnTypeAgentArgumentValue,
ReturnTypeAgentResponseValue
ReturnTypeAgentArgumentValue | undefined,
ReturnTypeAgentResponseValue | undefined
>;
callbackLocation?: CallbackLocation;
}
Expand All @@ -55,6 +56,7 @@ export function InitMethodArb<
.tuple(
UniqueIdentifierArb('canisterMethod'),
paramTypeArrayArb,
VoidArb(),
fc.constantFrom(
'INLINE',
'STANDALONE'
Expand All @@ -68,6 +70,7 @@ export function InitMethodArb<
([
functionName,
paramTypes,
returnType,
defaultCallbackLocation,
callbackName
]) => {
Expand All @@ -90,7 +93,7 @@ export function InitMethodArb<

const callback = generateCallback(
namedParams,
undefined,
returnType,
constraints.generateBody,
callbackLocation,
callbackName
Expand All @@ -114,7 +117,7 @@ export function InitMethodArb<
const tests = constraints.generateTests(
functionName,
namedParams,
undefined
returnType
);

return {
Expand Down
10 changes: 5 additions & 5 deletions property_tests/tests/blob/test/generate_body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function generateBody(

const paramsCorrectlyOrdered = areParamsCorrectlyOrdered(namedParamBlobs);

const returnStatement = `Uint8Array.from([${[
...returnBlob.agentArgumentValue
]} ${returnBlob.agentArgumentValue.length > 0 ? ',' : ''} ${namedParamBlobs
.map((param) => `...${param.name}`)
.join(', ')}])`;
const returnValue = returnBlob.value.agentArgumentValue;

const returnStatement = `Uint8Array.from([${[...returnValue]} ${
returnValue.length > 0 ? ',' : ''
} ${namedParamBlobs.map((param) => `...${param.name}`).join(', ')}])`;

return `
${paramsAreUint8Arrays}
Expand Down
8 changes: 5 additions & 3 deletions property_tests/tests/blob/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export function generateTests(
): Test[][] {
const expectedResult = Uint8Array.from(
paramBlobs
.map((blob) => blob.el.agentResponseValue)
.map((blob) => blob.el.value.agentResponseValue)
.reduce(
(acc, blob) => [...acc, ...blob],
[...returnBlob.agentResponseValue]
[...returnBlob.value.agentResponseValue]
)
);

Expand All @@ -26,7 +26,9 @@ export function generateTests(
const actor = getActor(__dirname);

const result = await actor[functionName](
...paramBlobs.map((blob) => blob.el.agentArgumentValue)
...paramBlobs.map(
(blob) => blob.el.value.agentArgumentValue
)
);

return {
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/bool/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function generateTests(
returnBool: CandidValueAndMeta<boolean>
): Test[][] {
const expectedResult = namedParamBools.reduce(
(acc, param) => acc && param.el.agentResponseValue,
returnBool.agentResponseValue
(acc, param) => acc && param.el.value.agentResponseValue,
returnBool.value.agentResponseValue
);
const paramValues = namedParamBools.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/float32/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ export function generateTests(
): Test[][] {
const expectedResult =
namedParamFloat32s.length === 0
? returnFloat32.agentResponseValue
: namedParamFloat32s[0].el.agentResponseValue;
? returnFloat32.value.agentResponseValue
: namedParamFloat32s[0].el.value.agentResponseValue;
const paramValues = namedParamFloat32s.map(
(paramFloats) => paramFloats.el.agentArgumentValue
(paramFloats) => paramFloats.el.value.agentArgumentValue
);
return [
[
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/float64/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamFloat64s.length + 1;
const expectedResult =
namedParamFloat64s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnFloat64.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnFloat64.value.agentResponseValue
) / count;

const paramValues = namedParamFloat64s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
7 changes: 5 additions & 2 deletions property_tests/tests/func/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ export function generateTests(

const result = await actor[functionName](
...namedParamFuncs.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
)
);

return {
Ok: deepEqual(result, returnFunc.agentResponseValue)
Ok: deepEqual(
result,
returnFunc.value.agentResponseValue
)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candi

export function generateBody(
_namedParams: Named<CandidValueAndMeta<CorrespondingJSType>>[],
returnType: CandidValueAndMeta<CorrespondingJSType> | undefined
returnType: CandidValueAndMeta<CorrespondingJSType>
) {
return `return ${returnType?.src.valueLiteral}`;
return `return ${returnType.src.valueLiteral}`;
}
6 changes: 3 additions & 3 deletions property_tests/tests/int/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function generateTests(
returnInt: CandidValueAndMeta<bigint>
): Test[][] {
const expectedResult = namedParamInts.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnInt.value.agentResponseValue
);
const paramValues = namedParamInts.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/int16/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamInt16s.length + 1;
const expectedResult = Math.floor(
namedParamInt16s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt16.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnInt16.value.agentResponseValue
) / count
);
const paramValues = namedParamInt16s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/int32/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamInt32s.length + 1;
const expectedResult = Math.floor(
namedParamInt32s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt32.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnInt32.value.agentResponseValue
) / count
);
const paramValues = namedParamInt32s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/int64/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamInt64s.length + 1;
const expectedResult =
namedParamInt64s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt64.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnInt64.value.agentResponseValue
) / BigInt(count);

const paramValues = namedParamInt64s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);
return [
[
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/int8/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamInt8s.length + 1;
const expectedResult = Math.floor(
namedParamInt8s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnInt8.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnInt8.value.agentResponseValue
) / count
);
const paramValues = namedParamInt8s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);
return [
[
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/nat/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export function generateTests(
returnNat: CandidValueAndMeta<bigint>
): Test[][] {
const expectedResult = namedParamNats.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnNat.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnNat.value.agentResponseValue
);
const paramValues = namedParamNats.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/nat16/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamNat16s.length + 1;
const expectedResult = Math.floor(
namedParamNat16s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnNat16.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnNat16.value.agentResponseValue
) / count
);
const paramValues = namedParamNat16s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/nat32/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamNat32s.length + 1;
const expectedResult = Math.floor(
namedParamNat32s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnNat32.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnNat32.value.agentResponseValue
) / count
);
const paramValues = namedParamNat32s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/nat64/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export function generateTests(
const count = namedParamNat64s.length + 1;
const expectedResult =
namedParamNat64s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnNat64.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnNat64.value.agentResponseValue
) / BigInt(count);
const paramValues = namedParamNat64s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
6 changes: 3 additions & 3 deletions property_tests/tests/nat8/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function generateTests(
const count = namedParamNat8s.length + 1;
const expectedResult = Math.floor(
namedParamNat8s.reduce(
(acc, param) => acc + param.el.agentResponseValue,
returnNat8.agentResponseValue
(acc, param) => acc + param.el.value.agentResponseValue,
returnNat8.value.agentResponseValue
) / count
);
const paramValues = namedParamNat8s.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
);

return [
Expand Down
2 changes: 1 addition & 1 deletion property_tests/tests/null/test/generate_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function generateTests(

const result = await actor[functionName](
...namedParamNulls.map(
(param) => param.el.agentArgumentValue
(param) => param.el.value.agentArgumentValue
)
);

Expand Down
Loading

0 comments on commit 74859ad

Please sign in to comment.