diff --git a/property_tests/arbitraries/candid/constructed/vec_arb.ts b/property_tests/arbitraries/candid/constructed/vec_arb.ts index fff832c1d3..f57ac8ed0a 100644 --- a/property_tests/arbitraries/candid/constructed/vec_arb.ts +++ b/property_tests/arbitraries/candid/constructed/vec_arb.ts @@ -36,7 +36,10 @@ const VecInnerArb = ( return fc .tuple(fc.array(arb), arb) .map(([sample, src]): CandidMeta> => { - const valueLiteral = generateValueLiteral(sample); + const valueLiteral = generateValueLiteral( + sample, + src.src.candidType + ); return { value: generateValue(sample, src.src.candidType), @@ -49,20 +52,6 @@ const VecInnerArb = ( }); }; -function toNumberArray(array: T[]): number[] { - if (array.every((item) => typeof item === 'number')) { - return array as number[]; - } - throw new Error('array is not a number array'); -} - -function toBigintArray(array: T[]): bigint[] { - if (array.every((item) => typeof item === 'bigint')) { - return array as bigint[]; - } - throw new Error('array is not a bigint array'); -} - function generateValue( array: CandidMeta[], candidType: string @@ -70,16 +59,16 @@ function generateValue( const value = array.map((sample) => sample.value); if (candidType === 'int8') { - return new Int8Array(toNumberArray(value)); + return new Int8Array(value as number[]); } if (candidType === 'int16') { - return new Int16Array(toNumberArray(value)); + return new Int16Array(value as number[]); } if (candidType === 'int32') { - return new Int32Array(toNumberArray(value)); + return new Int32Array(value as number[]); } if (candidType === 'int64') { - return new BigInt64Array(toBigintArray(value)); + return new BigInt64Array(value as bigint[]); } if (candidType === 'nat8') { return new Uint8Array(value as number[]); @@ -97,11 +86,41 @@ function generateValue( return value; } -function generateValueLiteral(sample: CandidMeta[]) { +function generateValueLiteral( + sample: CandidMeta[], + candidType: string +) { const valueLiterals = sample .map((sample) => sample.src.valueLiteral) .join(','); - return `[${valueLiterals}]`; + + const valueLiteral = `[${valueLiterals}]`; + + if (candidType === 'int32') { + return `Int32Array.from(${valueLiteral})`; + } + + if (candidType === 'int16') { + return `Int16Array.from(${valueLiteral})`; + } + + if (candidType === 'int8') { + return `Int8Array.from(${valueLiteral})`; + } + + if (candidType === 'nat32') { + return `Uint32Array.from(${valueLiteral})`; + } + + if (candidType === 'nat16') { + return `Uint16Array.from(${valueLiteral})`; + } + + if (candidType === 'nat8') { + return `Uint8Array.from(${valueLiteral})`; + } + + return valueLiteral; } export const VecArb = fc.oneof( diff --git a/property_tests/arbitraries/candid/to_src_literal/principal.ts b/property_tests/arbitraries/candid/to_src_literal/principal.ts index 2cc2cc61b4..b1663d2146 100644 --- a/property_tests/arbitraries/candid/to_src_literal/principal.ts +++ b/property_tests/arbitraries/candid/to_src_literal/principal.ts @@ -1,5 +1,5 @@ import { Principal } from '@dfinity/principal'; export function principalToSrcLiteral(value: Principal): string { - return `Principal.fromText('${value.toText()}')`; + return `DfinityPrincipal.fromText('${value.toText()}')`; } diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index a2ed2814d2..efcdeef17d 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -37,6 +37,7 @@ export function CanisterArb(testArb: fc.Arbitrary) { sourceCode: ` import { Canister, query, ${imports.join(', ')} } from 'azle'; import { deepEqual } from 'fast-equals'; + import { Principal as DfinityPrincipal } from '@dfinity/principal'; ${candidTypeDeclarations} diff --git a/property_tests/tests/func/test/test.ts b/property_tests/tests/func/test/test.ts index 5b863f8014..9c3dd74f8e 100644 --- a/property_tests/tests/func/test/test.ts +++ b/property_tests/tests/func/test/test.ts @@ -92,14 +92,9 @@ function generateBody( .map((func, paramIndex): string => { const paramName = `param${paramIndex}`; - const [principal, methodName] = func.value; - - const principalValueIsCorrect = `${paramName}[0].toText() === '${principal.toText()}'`; - const methodNameIsCorrect = `${paramName}[1] === '${methodName}'`; const throwError = `throw new Error('${paramName} is incorrectly ordered')`; - const debug = `console.log(${paramName})\nconsole.log(${func.src.valueLiteral})\n`; - return `${debug}if (!deepEqual(${paramName}[0].toText(), ${func.src.valueLiteral}[0].toText())) ${throwError}`; + return `if (!deepEqual(${paramName}, ${func.src.valueLiteral})) ${throwError}`; }) .join('\n'); diff --git a/property_tests/tests/opt/test/test.ts b/property_tests/tests/opt/test/test.ts index c7f13ebf0d..e7b4cb01c0 100644 --- a/property_tests/tests/opt/test/test.ts +++ b/property_tests/tests/opt/test/test.ts @@ -70,7 +70,7 @@ function generateBody( const areParamsCorrectlyOrdered = paramNames .map((paramName, index) => { - return `if (false && !deepEqual(${paramName}, ${paramLiterals[index]})) throw new Error('${paramName} is incorrectly ordered')`; + return `if (!deepEqual(${paramName}, ${paramLiterals[index]})) throw new Error('${paramName} is incorrectly ordered')`; }) .join('\n'); diff --git a/property_tests/tests/principal/test/test.ts b/property_tests/tests/principal/test/test.ts index 8d5990d443..065878b835 100644 --- a/property_tests/tests/principal/test/test.ts +++ b/property_tests/tests/principal/test/test.ts @@ -78,8 +78,8 @@ function generateBody( const paramsCorrectlyOrdered = paramNames .map((paramName, index) => { const areEqual = `deepEqual( - ${paramName}.toText(), - ${paramPrincipals[index].src.valueLiteral}.toText() + ${paramName}, + ${paramPrincipals[index].src.valueLiteral} )`; return `if (!${areEqual}) throw new Error('${paramName} is incorrectly ordered')`; diff --git a/property_tests/tests/vec/test/test.ts b/property_tests/tests/vec/test/test.ts index 4c4e3571e5..49f1efc0df 100644 --- a/property_tests/tests/vec/test/test.ts +++ b/property_tests/tests/vec/test/test.ts @@ -88,7 +88,7 @@ function generateTest( test: async () => { const actor = getActor('./tests/vec/test'); - const params = paramVecs.map((vec) => [...vec.value]); + const params = paramVecs.map((vec) => vec.value); const result = await actor[functionName](...params); return {