Skip to content

Commit

Permalink
Fixup QueryMethodArb type arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Nov 22, 2023
1 parent a3fca1c commit 851104b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 18 deletions.
12 changes: 7 additions & 5 deletions property_tests/arbitraries/candid/constructed/blob_arb.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import fc from 'fast-check';
import { CandidMetaArb } from '../candid_arb';
import { CandidMeta, CandidMetaArb } from '../candid_arb';
import { blobToSrcLiteral } from '../to_src_literal/blob';

export const BlobArb = fc
.oneof(
CandidMetaArb(fc.uint8Array(), 'Vec(nat8)', blobToSrcLiteral),
CandidMetaArb(fc.uint8Array(), 'blob', blobToSrcLiteral)
)
.map((sample) => ({
...sample,
src: { ...sample.src, imports: new Set(['blob', 'nat8', 'Vec']) }
}));
.map(
(sample): CandidMeta<Uint8Array> => ({
...sample,
src: { ...sample.src, imports: new Set(['blob', 'nat8', 'Vec']) }
})
);
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function TupleArb(candidTypeArb: fc.Arbitrary<CandidMeta<CandidType>>) {

const agentArgumentValue = generateVale(fields);

const agentResponseValue = generateExpectedVale(fields);
const agentResponseValue = generateExpectedValue(fields);

return {
src: {
Expand All @@ -53,7 +53,7 @@ function generateVale(fields: CandidMeta<CandidType>[]) {
return fields.map((field) => field.agentArgumentValue);
}

function generateExpectedVale(fields: CandidMeta<CandidType>[]): Tuple | {} {
function generateExpectedValue(fields: CandidMeta<CandidType>[]): ReturnTuple {
if (fields.length === 0) {
return {};
}
Expand Down
38 changes: 27 additions & 11 deletions property_tests/arbitraries/query_method_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,46 @@ export type QueryMethod = {

export type BodyGenerator<
ParamType extends CandidType,
ReturnType extends CandidType
ParamAgentType,
ReturnType extends CandidType,
ReturnAgentType
> = (
namedParams: Named<CandidMeta<ParamType>>[],
returnType: CandidMeta<ReturnType>
namedParams: Named<CandidMeta<ParamType, ParamAgentType>>[],
returnType: CandidMeta<ReturnType, ReturnAgentType>
) => string;

export type TestsGenerator<
ParamType extends CandidType,
ReturnType extends CandidType
ParamAgentType,
ReturnType extends CandidType,
ReturnAgentType
> = (
methodName: string,
namedParams: Named<CandidMeta<ParamType>>[],
returnType: CandidMeta<ReturnType>
namedParams: Named<CandidMeta<ParamType, ParamAgentType>>[],
returnType: CandidMeta<ReturnType, ReturnAgentType>
) => Test[];

export function QueryMethodArb<
ParamType extends CandidType,
ReturnType extends CandidType
ParamAgentType,
ReturnType extends CandidType,
ReturnAgentType
>(
paramTypeArrayArb: fc.Arbitrary<CandidMeta<ParamType>[]>,
returnTypeArb: fc.Arbitrary<CandidMeta<ReturnType>>,
paramTypeArrayArb: fc.Arbitrary<CandidMeta<ParamType, ParamAgentType>[]>,
returnTypeArb: fc.Arbitrary<CandidMeta<ReturnType, ReturnAgentType>>,
constraints: {
generateBody: BodyGenerator<ParamType, ReturnType>;
generateTests: TestsGenerator<ParamType, ReturnType>;
generateBody: BodyGenerator<
ParamType,
ParamAgentType,
ReturnType,
ReturnAgentType
>;
generateTests: TestsGenerator<
ParamType,
ParamAgentType,
ReturnType,
ReturnAgentType
>;
// TODO: Consider adding a callback to determine the returnType
// i.e. instead of using the first one if the params array isn't empty.
}
Expand Down

0 comments on commit 851104b

Please sign in to comment.