Skip to content

Commit

Permalink
update to limit size instead of forcing it to be empty
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Jan 18, 2024
1 parent 4ff3dc4 commit 554b7ce
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fc from 'fast-check';
import fc, { ArrayConstraints } from 'fast-check';
import { Vec } from '.';
import { CandidType } from '../../candid_type';
import { CorrespondingJSType } from '../../corresponding_js_type';
Expand All @@ -13,6 +13,14 @@ import {
import { CandidValues, CandidValueArb } from '../../candid_values_arb';
import { RecursiveShapes } from '../../recursive';

/*
https://github.com/dfinity/candid/blob/491969f34dd791e51f69c5f8d3c6192ae405b839/spec/Candid.md#memory
Set size limit to follow candid spec
const NULL_VEC_SIZE_LIMIT = 2_000_000;
*/
// TODO set to zero until the limit is unified on both the canister and client side as per https://github.com/demergent-labs/azle/issues/1538
const EMPTYISH_VEC_SIZE_LIMIT = 0;

export function VecValuesArb(
vecDefinition: VecCandidDefinition,
recursiveShapes: RecursiveShapes,
Expand All @@ -23,14 +31,9 @@ export function VecValuesArb(
generateEmptyVec(vecDefinition.innerType.candidMeta.candidType)
);
}
if (isEmptyInnerType(vecDefinition.innerType)) {
return fc.constant(
generateEmptyVec(vecDefinition.innerType.candidMeta.candidType)
);
}
const arbitraryMemberValues = fc
.tuple(
fc.array(fc.constant(null)),
fc.array(fc.constant(null), determineVecConstraints(vecDefinition)),
fc.constant(vecDefinition.innerType)
)
.chain(([arrayTemplate, innerType]) =>
Expand Down Expand Up @@ -59,6 +62,15 @@ export function VecValuesArb(
});
}

function determineVecConstraints(
vecDefinition: VecCandidDefinition
): ArrayConstraints | undefined {
if (isEmptyInnerType(vecDefinition.innerType)) {
return { maxLength: EMPTYISH_VEC_SIZE_LIMIT };
}
return;
}

function generateEmptyVec(innerCandidType: CandidType): CandidValues<Vec> {
return {
valueLiteral: typeValueLiteral('[]', innerCandidType),
Expand Down

0 comments on commit 554b7ce

Please sign in to comment.