Skip to content

Commit

Permalink
Stylistic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dansteren committed Nov 1, 2023
1 parent 9842a63 commit 26be737
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions property_tests/tests/blob/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@ const BlobTestArb = fc
BlobArb
)
.map(([functionName, paramBlobs, defaultReturnBlob]): TestSample => {
const imports = defaultReturnBlob.src.imports;

const imports = new Set(['blob', 'nat8', 'Vec']);
const paramNames = paramBlobs.map((_, index) => `param${index}`);
const paramCandidTypes = paramBlobs
.map((blob) => blob.src.candidType)
.join(', ');

const returnCandidType = defaultReturnBlob.src.candidType;

const body = generateBody(paramNames, paramBlobs, defaultReturnBlob);

const test = generateTest(functionName, paramBlobs, defaultReturnBlob);

return {
Expand Down Expand Up @@ -58,13 +54,18 @@ function generateBody(
// TODO maybe a global variable that we can write into and call would work
const paramsCorrectlyOrdered = paramNames
.map((paramName, index) => {
return `if (${paramName}.length !== ${paramBlobs[index].value.length}) throw new Error('${paramName} is incorrectly ordered')`;
const paramIsCorrectLength = `${paramName}.length === ${paramBlobs[index].value.length}`;

const throwError = `throw new Error('${paramName} is incorrectly ordered')`;

return `if (!(${paramIsCorrectLength})) ${throwError};`;
})
.join('\n');

const returnStatement = `Uint8Array.from([${[...returnBlob.value]} ${
returnBlob.value.length > 0 ? ',' : ''
} ${paramNames.map((paramName) => `...${paramName}`).join(', ')}])`;

return `
${paramsAreUint8Arrays}
Expand Down
2 changes: 1 addition & 1 deletion property_tests/tests/bool/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const BoolTestArb = fc
return {
imports,
functionName,
paramNames,
paramCandidTypes,
returnCandidType,
paramNames,
body,
test
};
Expand Down

0 comments on commit 26be737

Please sign in to comment.