From 1f7adbd2cfd8ad78093791fad8846b93929219dd Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Fri, 8 Dec 2023 16:12:39 -0700 Subject: [PATCH 01/16] Sort imports for readability --- property_tests/arbitraries/canister_arb.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 3605439099..c523738b2e 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -70,7 +70,9 @@ function generateSourceCode( ['Canister', 'query', 'update'] ) ) - ].join(); + ] + .sort((a, b) => a.localeCompare(b, 'en', { sensitivity: 'base' })) + .join(); const declarationsFromCanisterMethods = canisterMethods.flatMap( (method) => method.globalDeclarations From 744d08138c63e8337197661767280bce8b408b6f Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 5 Dec 2023 15:18:54 -0700 Subject: [PATCH 02/16] Add InitMethodArb --- .../candid/candid_definition_arb/types.ts | 2 + .../candid/candid_value_and_meta_arb.ts | 36 +- .../candid_value_and_meta_arb_generator.ts | 8 +- .../constructed/blob_arb/definition_arb.ts | 2 + .../constructed/opt_arb/definition_arb.ts | 9 + .../constructed/record_arb/definition_arb.ts | 15 + .../constructed/tuple_arb/definition_arb.ts | 12 + .../variant_arb/definition_arbs.ts | 15 + .../constructed/variant_arb/values_arb.ts | 8 +- .../constructed/vec_arb/definition_arb.ts | 9 + .../reference/func_arb/definition_arb.ts | 21 + .../candid/reference/func_arb/values_arb.ts | 4 +- .../candid_type_to_azle_candid_type.ts | 82 ++ .../candid/simple_type_arbs/definition_arb.ts | 3 + property_tests/arbitraries/canister_arb.ts | 34 +- .../arbitraries/canister_methods/index.ts | 22 +- .../canister_methods/init_method_arb.ts | 144 +++ property_tests/index.ts | 23 +- property_tests/tests/init_method/dfx.json | 16 + .../tests/init_method/package-lock.json | 996 ++++++++++++++++++ property_tests/tests/init_method/package.json | 12 + .../test/generate_callable_method_body.ts | 10 + .../init_method/test/generate_init_body.ts | 22 + .../tests/init_method/test/generate_tests.ts | 34 + property_tests/tests/init_method/test/test.ts | 108 ++ .../tests/init_method/tsconfig.json | 10 + 26 files changed, 1630 insertions(+), 27 deletions(-) create mode 100644 property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts create mode 100644 property_tests/arbitraries/canister_methods/init_method_arb.ts create mode 100644 property_tests/tests/init_method/dfx.json create mode 100644 property_tests/tests/init_method/package-lock.json create mode 100644 property_tests/tests/init_method/package.json create mode 100644 property_tests/tests/init_method/test/generate_callable_method_body.ts create mode 100644 property_tests/tests/init_method/test/generate_init_body.ts create mode 100644 property_tests/tests/init_method/test/generate_tests.ts create mode 100644 property_tests/tests/init_method/test/test.ts create mode 100644 property_tests/tests/init_method/tsconfig.json diff --git a/property_tests/arbitraries/candid/candid_definition_arb/types.ts b/property_tests/arbitraries/candid/candid_definition_arb/types.ts index a6e561a353..d4f0e42714 100644 --- a/property_tests/arbitraries/candid/candid_definition_arb/types.ts +++ b/property_tests/arbitraries/candid/candid_definition_arb/types.ts @@ -1,5 +1,6 @@ import fc from 'fast-check'; import { CandidType } from '../candid_type'; +import { CandidType as AzleCandidType } from '../../../../src/lib'; export type CandidDefinitionArb = fc.Arbitrary; @@ -69,6 +70,7 @@ export type ServiceMethodDefinition = { type CandidMeta = { candidTypeAnnotation: string; // Either a type reference or type literal candidTypeObject: string; + azleCandidTypeObject: AzleCandidType; variableAliasDeclarations: string[]; imports: Set; candidType: CandidType; diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts index 7baacb7e5e..f9cea118a5 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts @@ -23,11 +23,15 @@ import { OptArb } from './constructed/opt_arb'; import { VecArb } from './constructed/vec_arb'; import { FuncArb } from './reference/func_arb'; import { CorrespondingJSType } from './corresponding_js_type'; +import { CandidType } from '../../../src/lib'; // TODO we're thinking that Candid is not the best name for this. What is better? export type CandidValueAndMeta = { - agentArgumentValue: T; - agentResponseValue: E; + value: { + agentArgumentValue: T; + agentResponseValue: E; + candidTypeObject: CandidType; + }; src: { candidTypeAnnotation: string; candidTypeObject: string; @@ -71,3 +75,31 @@ export function CandidValueAndMetaArb(): fc.Arbitrary< } // TODO: This needs to support service. + +/** + * Azle currently (v0.18.6) cannot accept funcs in init methods. + * See https://github.com/demergent-labs/azle/issues/1474 + */ +export function CandidValueAndMetaArbWithoutFuncs(): fc.Arbitrary< + CandidValueAndMeta +> { + return fc.oneof( + BlobArb(), + Float32Arb(), + Float64Arb(), + IntArb(), + Int8Arb(), + Int16Arb(), + Int32Arb(), + Int64Arb(), + NatArb(), + Nat8Arb(), + Nat16Arb(), + Nat32Arb(), + Nat64Arb(), + BoolArb(), + NullArb(), + TextArb(), + PrincipalArb() + ); +} diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts index 01872541da..60c390672d 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts @@ -20,6 +20,7 @@ export function CandidValueAndMetaArbGenerator< candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports } @@ -34,8 +35,11 @@ export function CandidValueAndMetaArbGenerator< imports, valueLiteral }, - agentArgumentValue, - agentResponseValue + value: { + agentArgumentValue, + agentResponseValue, + candidTypeObject: azleCandidTypeObject + } }; } ); diff --git a/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts index b0a0fa2ca1..3b18c43098 100644 --- a/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts @@ -2,6 +2,7 @@ import fc from 'fast-check'; import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; import { BlobCandidDefinition } from '../../candid_definition_arb/types'; import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { blob } from '../../../../../src/lib'; export function BlobDefinitionArb(): fc.Arbitrary { return fc.oneof(SimpleCandidDefinitionArb('blob'), _VecNat8DefinitionArb()); @@ -19,6 +20,7 @@ export function _VecNat8DefinitionArb(): fc.Arbitrary { const imports = new Set(['Vec', 'nat8']); return { candidMeta: { + azleCandidTypeObject: blob, candidTypeAnnotation, candidTypeObject, variableAliasDeclarations, diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts index 0bcb18cfbf..e320e55871 100644 --- a/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts @@ -4,6 +4,7 @@ import { CandidDefinition, OptCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidType, Opt } from '../../../../../src/lib'; export function OptDefinitionArb( candidTypeArbForInnerType: fc.Arbitrary @@ -27,6 +28,9 @@ export function OptDefinitionArb( innerType ); + const azleCandidTypeObject = + generateAzleCandidTypeObject(innerType); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -39,6 +43,7 @@ export function OptDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Opt' @@ -90,6 +95,10 @@ function generateCandidTypeObject( return `Opt(${innerType.candidMeta.candidTypeObject})`; } +function generateAzleCandidTypeObject(innerType: CandidDefinition): CandidType { + return Opt(innerType.candidMeta.azleCandidTypeObject); +} + function generateImports(innerType: CandidDefinition): Set { return new Set([...innerType.candidMeta.imports, 'Opt', 'Some', 'None']); } diff --git a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts index 7eabe883f8..744a3d0db4 100644 --- a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts @@ -6,6 +6,7 @@ import { CandidDefinitionArb, RecordCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidType, Record } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; @@ -35,6 +36,8 @@ export function RecordDefinitionArb( fields ); + const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -47,6 +50,7 @@ export function RecordDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Record' @@ -97,6 +101,17 @@ function generateCandidTypeObject( .join(',')}})`; } +function generateAzleCandidTypeObject(fields: Field[]): CandidType { + const azleRecordConstructorObj = fields.reduce<{ + [key: string]: CandidType; + }>((acc, [fieldName, fieldDefinition]) => { + acc[fieldName] = fieldDefinition.candidMeta.azleCandidTypeObject; + return acc; + }, {}); + + return Record(azleRecordConstructorObj); +} + function generateVariableAliasDeclarations( useTypeDeclaration: boolean, name: string, diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts index b75d84d638..e0291faf81 100644 --- a/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts @@ -4,6 +4,7 @@ import { CandidDefinition, TupleCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidType, Tuple } from '../../../../../src/lib'; export function TupleDefinitionArb( candidTypeArbForFields: fc.Arbitrary @@ -30,6 +31,8 @@ export function TupleDefinitionArb( fields ); + const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -42,6 +45,7 @@ export function TupleDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Tuple' @@ -98,6 +102,14 @@ function generateCandidTypeObject( return `Tuple(${innerTypes.join(', ')})`; } +function generateAzleCandidTypeObject(fields: CandidDefinition[]): CandidType { + const innerTypes = fields.map( + (field) => field.candidMeta.azleCandidTypeObject + ); + + return Tuple(...innerTypes); +} + function generateImports(fields: CandidDefinition[]): Set { const fieldImports = fields.flatMap((field) => [ ...field.candidMeta.imports diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts index ab2ac8a16a..8af77aaba9 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts @@ -5,6 +5,7 @@ import { VariantCandidDefinition } from '../../candid_definition_arb/types'; import { JsFunctionNameArb } from '../../../js_function_name_arb'; +import { CandidType, Variant } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; @@ -30,6 +31,8 @@ export function VariantDefinitionArb( fields ); + const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -42,6 +45,7 @@ export function VariantDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Variant' @@ -120,3 +124,14 @@ function generateCandidTypeObject( ) .join(',')}})`; } + +function generateAzleCandidTypeObject(fields: Field[]): CandidType { + const azleVariantConstructorObj = fields.reduce<{ + [key: string]: CandidType; + }>((acc, [fieldName, fieldDefinition]) => { + acc[fieldName] = fieldDefinition.candidMeta.azleCandidTypeObject; + return acc; + }, {}); + + return Variant(azleVariantConstructorObj); +} diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts index dcef8de1e7..64512c414b 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts @@ -26,10 +26,10 @@ export function VariantValuesArb( return [name, values]; }); - return fieldValue.map((fieldValues) => { - const valueLiteral = generateValueLiteral(fieldValues); - const agentArgumentValue = generateValue(fieldValues); - const agentResponseValue = generateValue(fieldValues, true); + return fieldValue.map((field) => { + const valueLiteral = generateValueLiteral(field); + const agentArgumentValue = generateValue(field); + const agentResponseValue = generateValue(field, true); return { valueLiteral, diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts index b9f1dcb61b..4be3165086 100644 --- a/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts @@ -4,6 +4,7 @@ import { CandidDefinition, VecCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidType, Vec } from '../../../../../src/lib'; export function VecDefinitionArb( candidTypeArb: fc.Arbitrary @@ -27,6 +28,9 @@ export function VecDefinitionArb( innerType ); + const azleCandidTypeObject = + generateAzleCandidTypeObject(innerType); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -39,6 +43,7 @@ export function VecDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Vec' @@ -93,3 +98,7 @@ function generateCandidTypeObject( return `Vec(${innerType.candidMeta.candidTypeObject})`; } + +function generateAzleCandidTypeObject(innerType: CandidDefinition): CandidType { + return Vec(innerType.candidMeta.azleCandidTypeObject); +} diff --git a/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts index d219bc8558..e7cba8de4b 100644 --- a/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts @@ -5,6 +5,7 @@ import { FuncCandidDefinition } from '../../candid_definition_arb/types'; import { VoidDefinitionArb } from '../../primitive/void'; +import { CandidType, Func } from '../../../../../src/lib'; type Mode = 'query' | 'update' | 'oneway'; @@ -45,6 +46,12 @@ export function FuncDefinitionArb( mode ); + const azleCandidTypeObject = generateAzleCandidTypeObject( + params, + returnFunc, + mode + ); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -65,6 +72,7 @@ export function FuncDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Func' @@ -131,5 +139,18 @@ function generateCandidTypeObject( const params = paramCandids .map((param) => param.candidMeta.candidTypeObject) .join(', '); + return `Func([${params}], ${returnCandid.candidMeta.candidTypeObject}, '${mode}')`; } + +function generateAzleCandidTypeObject( + paramCandids: CandidDefinition[], + returnCandid: CandidDefinition, + mode: Mode +): CandidType { + const params = paramCandids.map( + (param) => param.candidMeta.azleCandidTypeObject + ); + + return Func(params, returnCandid.candidMeta.azleCandidTypeObject, mode); +} diff --git a/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts index 956965ce53..649caa5c8b 100644 --- a/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts +++ b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts @@ -7,8 +7,8 @@ import { PrincipalArb } from '../principal_arb'; export function FuncValueArb(): fc.Arbitrary> { return fc.tuple(TextArb(), PrincipalArb()).map(([name, principal]) => { const value: Func = [ - principal.agentArgumentValue, - name.agentArgumentValue + principal.value.agentArgumentValue, + name.value.agentArgumentValue ]; const valueLiteral = `[${principal.src.valueLiteral}, ${name.src.valueLiteral}]`; diff --git a/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts new file mode 100644 index 0000000000..eea6846607 --- /dev/null +++ b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts @@ -0,0 +1,82 @@ +import { + blob, + bool, + float32, + float64, + int, + int8, + int16, + int32, + int64, + nat, + nat8, + nat16, + nat32, + nat64, + Null, + text, + Void, + Principal, + CandidType +} from '../../../../src/lib'; +import { SimpleCandidType } from '../candid_type'; + +export function candidTypeToAzleCandidType( + candidType: SimpleCandidType +): CandidType { + if (candidType === 'blob') { + return blob; + } + if (candidType === 'bool') { + return bool; + } + if (candidType === 'float32') { + return float32; + } + if (candidType === 'float64') { + return float64; + } + if (candidType === 'int') { + return int; + } + if (candidType === 'int8') { + return int8; + } + if (candidType === 'int16') { + return int16; + } + if (candidType === 'int32') { + return int32; + } + if (candidType === 'int64') { + return int64; + } + if (candidType === 'nat') { + return nat; + } + if (candidType === 'nat8') { + return nat8; + } + if (candidType === 'nat16') { + return nat16; + } + if (candidType === 'nat32') { + return nat32; + } + if (candidType === 'nat64') { + return nat64; + } + if (candidType === 'Null') { + return Null; + } + if (candidType === 'text') { + return text; + } + if (candidType === 'Void') { + return Void; + } + if (candidType === 'Principal') { + return Principal; + } + throw new Error(`Unexpected SimpleCandidType: ${candidType}`); +} diff --git a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts index 0e0440f2cb..f7067c082f 100644 --- a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts +++ b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts @@ -2,6 +2,7 @@ import fc from 'fast-check'; import { PrimitiveDefinition } from '../candid_definition_arb/types'; import { SimpleCandidType } from '../candid_type'; import { UniqueIdentifierArb } from '../../unique_identifier_arb'; +import { candidTypeToAzleCandidType } from './candid_type_to_azle_candid_type'; export function SimpleCandidDefinitionArb( candidType: SimpleCandidType @@ -11,6 +12,7 @@ export function SimpleCandidDefinitionArb( .map(([name, useTypeDeclaration]) => { const candidTypeAnnotation = candidType; const candidTypeObject = useTypeDeclaration ? name : candidType; + const azleCandidTypeObject = candidTypeToAzleCandidType(candidType); const imports = new Set([candidType]); const variableAliasDeclarations = generateVariableAliasDeclarations( name, @@ -22,6 +24,7 @@ export function SimpleCandidDefinitionArb( candidTypeAnnotation, candidTypeObject, candidType, + azleCandidTypeObject, imports, variableAliasDeclarations } diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index c523738b2e..193f698476 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -2,26 +2,51 @@ import fc from 'fast-check'; import { QueryMethod } from './canister_methods/query_method_arb'; import { Test } from '../../test'; import { UpdateMethod } from './canister_methods/update_method_arb'; +import { InitMethod } from './canister_methods/init_method_arb'; +import { CorrespondingJSType } from './candid/corresponding_js_type'; export type Canister = { + initArgs: string[] | undefined; sourceCode: string; tests: Test[][]; }; -export type CanisterConfig = { +export type CanisterConfig< + ParamAgentArgumentValue extends CorrespondingJSType = undefined, + ParamAgentResponseValue = undefined +> = { globalDeclarations?: string[]; + initMethod?: InitMethod; queryMethods?: QueryMethod[]; updateMethods?: UpdateMethod[]; }; // TODO: Update the signature to support init, pre/post upgrade, heartbeat, etc. -export function CanisterArb(configArb: fc.Arbitrary) { +export function CanisterArb< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue +>( + configArb: fc.Arbitrary< + CanisterConfig + > +) { return configArb.map((config): Canister => { - const canisterMethods: (QueryMethod | UpdateMethod)[] = [ + const canisterMethods: ( + | QueryMethod + | UpdateMethod + | InitMethod + )[] = [ + ...(config.initMethod ? [config.initMethod] : []), ...(config.queryMethods ?? []), ...(config.updateMethods ?? []) ]; + const initArgs = config.initMethod?.params.map(({ el: { value } }) => { + return value.candidTypeObject + .getIdl([]) + .valueToString(value.agentArgumentValue); + }); + const sourceCode = generateSourceCode( config.globalDeclarations ?? [], canisterMethods @@ -51,6 +76,7 @@ export function CanisterArb(configArb: fc.Arbitrary) { ); return { + initArgs, sourceCode, tests }; @@ -91,7 +117,9 @@ function generateSourceCode( // @ts-ignore import deepEqual from 'deep-is'; + // #region Declarations ${declarations} + // #endregion Declarations export default Canister({ ${sourceCodes.join(',\n ')} diff --git a/property_tests/arbitraries/canister_methods/index.ts b/property_tests/arbitraries/canister_methods/index.ts index 4a716fde25..99b8a3cbbd 100644 --- a/property_tests/arbitraries/canister_methods/index.ts +++ b/property_tests/arbitraries/canister_methods/index.ts @@ -13,10 +13,12 @@ export type BodyGenerator< namedParams: Named< CandidValueAndMeta >[], - returnType: CandidValueAndMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > + returnType: + | CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > + | undefined ) => string; export type TestsGenerator< @@ -29,10 +31,12 @@ export type TestsGenerator< namedParams: Named< CandidValueAndMeta >[], - returnType: CandidValueAndMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > + returnType: + | CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > + | undefined ) => Test[][]; export type CallbackLocation = 'INLINE' | 'STANDALONE'; @@ -48,7 +52,7 @@ export function generateCallback< ReturnAgentType >( namedParams: Named>[], - returnType: CandidValueAndMeta, + returnType: CandidValueAndMeta | undefined, generateBody: BodyGenerator< ParamType, ParamAgentType, diff --git a/property_tests/arbitraries/canister_methods/init_method_arb.ts b/property_tests/arbitraries/canister_methods/init_method_arb.ts new file mode 100644 index 0000000000..c3b22ee33e --- /dev/null +++ b/property_tests/arbitraries/canister_methods/init_method_arb.ts @@ -0,0 +1,144 @@ +import fc from 'fast-check'; + +import { CandidValueAndMeta } from '../candid/candid_value_and_meta_arb'; +import { CorrespondingJSType } from '../candid/corresponding_js_type'; +import { UniqueIdentifierArb } from '../unique_identifier_arb'; +import { Named } from '../..'; +import { + BodyGenerator, + TestsGenerator, + CallbackLocation, + isDefined, + generateCallback +} from '.'; +import { Test } from '../../../test'; + +export type InitMethod< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue +> = { + imports: Set; + globalDeclarations: string[]; + params: Named< + CandidValueAndMeta + >[]; + sourceCode: string; + tests: Test[][]; +}; + +export function InitMethodArb< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue extends CorrespondingJSType, + ReturnTypeAgentResponseValue +>( + paramTypeArrayArb: fc.Arbitrary< + CandidValueAndMeta[] + >, + constraints: { + generateBody: BodyGenerator< + ParamAgentArgumentValue, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + >; + generateTests: TestsGenerator< + ParamAgentArgumentValue, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + >; + callbackLocation?: CallbackLocation; + } +) { + return fc + .tuple( + UniqueIdentifierArb('canisterMethod'), + paramTypeArrayArb, + fc.constantFrom( + 'INLINE', + 'STANDALONE' + ) as fc.Arbitrary, + UniqueIdentifierArb('typeDeclaration') + // TODO: This unique id would be better named globalScope or something + // But needs to match the same scope as typeDeclarations so I'm using + // that for now. + ) + .map( + ([ + functionName, + paramTypes, + defaultCallbackLocation, + callbackName + ]) => { + // TODO: Add a return type to this map callback of type InitMethod + + const callbackLocation = + constraints.callbackLocation ?? defaultCallbackLocation; + + const imports = new Set([ + 'init', + ...paramTypes.flatMap((param) => [...param.src.imports]) + ]); + + const namedParams = paramTypes.map( + (param: T, index: number): Named => ({ + name: `param${index}`, + el: param + }) + ); + + const callback = generateCallback( + namedParams, + undefined, + constraints.generateBody, + callbackLocation, + callbackName + ); + + const variableAliasDeclarations = paramTypes + .flatMap((param) => param.src.variableAliasDeclarations) + .filter(isDefined); + + const globalDeclarations = + callbackLocation === 'STANDALONE' + ? [...variableAliasDeclarations, callback] + : variableAliasDeclarations; + + const sourceCode = generateSourceCode( + functionName, + paramTypes, + callbackLocation === 'STANDALONE' ? callbackName : callback + ); + + const tests = constraints.generateTests( + functionName, + namedParams, + undefined + ); + + return { + imports, + globalDeclarations, + params: namedParams, + sourceCode, + tests + }; + } + ); +} + +function generateSourceCode< + ParamType extends CorrespondingJSType, + ParamAgentType +>( + functionName: string, + paramTypes: CandidValueAndMeta[], + callback: string +): string { + const paramCandidTypeObjects = paramTypes + .map((param) => param.src.candidTypeObject) + .join(', '); + + return `${functionName}: init([${paramCandidTypeObjects}], ${callback})`; +} diff --git a/property_tests/index.ts b/property_tests/index.ts index a595320573..f439b59465 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -16,6 +16,17 @@ export type Named = { export { getActor } from './get_actor'; export function runPropTests(canisterArb: fc.Arbitrary) { + const defaultParams = { + numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1), + endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet + }; + + const seed = process.env.AZLE_PROPTEST_SEED + ? Number(process.env.AZLE_PROPTEST_SEED) + : undefined; + + const executionParams = seed ? { ...defaultParams, seed } : defaultParams; + fc.assert( fc.asyncProperty(canisterArb, async (canister) => { if (!existsSync('src')) { @@ -33,7 +44,12 @@ export function runPropTests(canisterArb: fc.Arbitrary) { }); for (let i = 0; i < canister.tests.length; i++) { - execSync(`dfx deploy canister`, { + const argumentsString = + canister.initArgs && canister.initArgs.length > 0 + ? `--argument '(${canister.initArgs.join(', ')})'` + : ''; + + execSync(`dfx deploy canister ${argumentsString}`, { stdio: 'inherit' }); @@ -64,10 +80,7 @@ export function runPropTests(canisterArb: fc.Arbitrary) { return true; }), - { - numRuns: Number(process.env.AZLE_PROPTEST_NUM_RUNS ?? 1), - endOnFailure: true // TODO This essentially disables shrinking. We don't know how to do shrinking well yet - } + executionParams ); } diff --git a/property_tests/tests/init_method/dfx.json b/property_tests/tests/init_method/dfx.json new file mode 100644 index 0000000000..6ab9fbd7e4 --- /dev/null +++ b/property_tests/tests/init_method/dfx.json @@ -0,0 +1,16 @@ +{ + "canisters": { + "canister": { + "type": "custom", + "main": "src/index.ts", + "candid": "src/index.did", + "build": "npx azle canister", + "wasm": ".azle/canister/canister.wasm", + "gzip": true, + "declarations": { + "output": "test/dfx_generated/canister", + "node_compatibility": true + } + } + } +} diff --git a/property_tests/tests/init_method/package-lock.json b/property_tests/tests/init_method/package-lock.json new file mode 100644 index 0000000000..1867d2f341 --- /dev/null +++ b/property_tests/tests/init_method/package-lock.json @@ -0,0 +1,996 @@ +{ + "name": "init_method", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "azle": "^0.18.5" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } + }, + "node_modules/@cspotcode/source-map-consumer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz", + "integrity": "sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@dfinity/principal": { + "version": "0.19.3", + "resolved": "https://registry.npmjs.org/@dfinity/principal/-/principal-0.19.3.tgz", + "integrity": "sha512-+nixVvdGt7ECxRvLXDXsvU9q9sSPssBtDQ4bXa149SK6gcYcmZ6lfWIi3DJNqj3tGROxILVBsguel9tECappsA==", + "dependencies": { + "@noble/hashes": "^1.3.1" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.5.tgz", + "integrity": "sha512-bhvbzWFF3CwMs5tbjf3ObfGqbl/17ict2/uwOSfr3wmxDE6VdS2GqY/FuzIPe0q0bdhj65zQsvqfArI9MY6+AA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.5.tgz", + "integrity": "sha512-5d1OkoJxnYQfmC+Zd8NBFjkhyCNYwM4n9ODrycTFY6Jk1IGiZ+tjVJDDSwDt77nK+tfpGP4T50iMtVi4dEGzhQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.5.tgz", + "integrity": "sha512-9t+28jHGL7uBdkBjL90QFxe7DVA+KGqWlHCF8ChTKyaKO//VLuoBricQCgwhOjA1/qOczsw843Fy4cbs4H3DVA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.5.tgz", + "integrity": "sha512-mvXGcKqqIqyKoxq26qEDPHJuBYUA5KizJncKOAf9eJQez+L9O+KfvNFu6nl7SCZ/gFb2QPaRqqmG0doSWlgkqw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.5.tgz", + "integrity": "sha512-Ly8cn6fGLNet19s0X4unjcniX24I0RqjPv+kurpXabZYSXGM4Pwpmf85WHJN3lAgB8GSth7s5A0r856S+4DyiA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.5.tgz", + "integrity": "sha512-GGDNnPWTmWE+DMchq1W8Sd0mUkL+APvJg3b11klSGUDvRXh70JqLAO56tubmq1s2cgpVCSKYywEiKBfju8JztQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.5.tgz", + "integrity": "sha512-1CCwDHnSSoA0HNwdfoNY0jLfJpd7ygaLAp5EHFos3VWJCRX9DMwWODf96s9TSse39Br7oOTLryRVmBoFwXbuuQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.5.tgz", + "integrity": "sha512-lrWXLY/vJBzCPC51QN0HM71uWgIEpGSjSZZADQhq7DKhPcI6NH1IdzjfHkDQws2oNpJKpR13kv7/pFHBbDQDwQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.5.tgz", + "integrity": "sha512-o3vYippBmSrjjQUCEEiTZ2l+4yC0pVJD/Dl57WfPwwlvFkrxoSO7rmBZFii6kQB3Wrn/6GwJUPLU5t52eq2meA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.5.tgz", + "integrity": "sha512-MkjHXS03AXAkNp1KKkhSKPOCYztRtK+KXDNkBa6P78F8Bw0ynknCSClO/ztGszILZtyO/lVKpa7MolbBZ6oJtQ==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.5.tgz", + "integrity": "sha512-42GwZMm5oYOD/JHqHska3Jg0r+XFb/fdZRX+WjADm3nLWLcIsN27YKtqxzQmGNJgu0AyXg4HtcSK9HuOk3v1Dw==", + "cpu": [ + "loong64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.5.tgz", + "integrity": "sha512-kcjndCSMitUuPJobWCnwQ9lLjiLZUR3QLQmlgaBfMX23UEa7ZOrtufnRds+6WZtIS9HdTXqND4yH8NLoVVIkcg==", + "cpu": [ + "mips64el" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.5.tgz", + "integrity": "sha512-yJAxJfHVm0ZbsiljbtFFP1BQKLc8kUF6+17tjQ78QjqjAQDnhULWiTA6u0FCDmYT1oOKS9PzZ2z0aBI+Mcyj7Q==", + "cpu": [ + "ppc64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.5.tgz", + "integrity": "sha512-5u8cIR/t3gaD6ad3wNt1MNRstAZO+aNyBxu2We8X31bA8XUNyamTVQwLDA1SLoPCUehNCymhBhK3Qim1433Zag==", + "cpu": [ + "riscv64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.5.tgz", + "integrity": "sha512-Z6JrMyEw/EmZBD/OFEFpb+gao9xJ59ATsoTNlj39jVBbXqoZm4Xntu6wVmGPB/OATi1uk/DB+yeDPv2E8PqZGw==", + "cpu": [ + "s390x" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.5.tgz", + "integrity": "sha512-psagl+2RlK1z8zWZOmVdImisMtrUxvwereIdyJTmtmHahJTKb64pAcqoPlx6CewPdvGvUKe2Jw+0Z/0qhSbG1A==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.5.tgz", + "integrity": "sha512-kL2l+xScnAy/E/3119OggX8SrWyBEcqAh8aOY1gr4gPvw76la2GlD4Ymf832UCVbmuWeTf2adkZDK+h0Z/fB4g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.5.tgz", + "integrity": "sha512-sPOfhtzFufQfTBgRnE1DIJjzsXukKSvZxloZbkJDG383q0awVAq600pc1nfqBcl0ice/WN9p4qLc39WhBShRTA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.5.tgz", + "integrity": "sha512-dGZkBXaafuKLpDSjKcB0ax0FL36YXCvJNnztjKV+6CO82tTYVDSH2lifitJ29jxRMoUhgkg9a+VA/B03WK5lcg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.5.tgz", + "integrity": "sha512-dWVjD9y03ilhdRQ6Xig1NWNgfLtf2o/STKTS+eZuF90fI2BhbwD6WlaiCGKptlqXlURVB5AUOxUj09LuwKGDTg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.5.tgz", + "integrity": "sha512-4liggWIA4oDgUxqpZwrDhmEfAH4d0iljanDOK7AnVU89T6CzHon/ony8C5LeOdfgx60x5cnQJFZwEydVlYx4iw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.5.tgz", + "integrity": "sha512-czTrygUsB/jlM8qEW5MD8bgYU2Xg14lo6kBDXW6HdxKjh8M5PzETGiSHaz9MtbXBYDloHNUAUW2tMiKW4KM9Mw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz", + "integrity": "sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA==", + "dev": true, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@noble/hashes": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.2.tgz", + "integrity": "sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@swc/core": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core/-/core-1.3.93.tgz", + "integrity": "sha512-690GRr1wUGmGYZHk7fUduX/JUwViMF2o74mnZYIWEcJaCcd9MQfkhsxPBtjeg6tF+h266/Cf3RPYhsFBzzxXcA==", + "hasInstallScript": true, + "dependencies": { + "@swc/counter": "^0.1.1", + "@swc/types": "^0.1.5" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/swc" + }, + "optionalDependencies": { + "@swc/core-darwin-arm64": "1.3.93", + "@swc/core-darwin-x64": "1.3.93", + "@swc/core-linux-arm-gnueabihf": "1.3.93", + "@swc/core-linux-arm64-gnu": "1.3.93", + "@swc/core-linux-arm64-musl": "1.3.93", + "@swc/core-linux-x64-gnu": "1.3.93", + "@swc/core-linux-x64-musl": "1.3.93", + "@swc/core-win32-arm64-msvc": "1.3.93", + "@swc/core-win32-ia32-msvc": "1.3.93", + "@swc/core-win32-x64-msvc": "1.3.93" + }, + "peerDependencies": { + "@swc/helpers": "^0.5.0" + }, + "peerDependenciesMeta": { + "@swc/helpers": { + "optional": true + } + } + }, + "node_modules/@swc/core-darwin-arm64": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.93.tgz", + "integrity": "sha512-gEKgk7FVIgltnIfDO6GntyuQBBlAYg5imHpRgLxB1zSI27ijVVkksc6QwISzFZAhKYaBWIsFSVeL9AYSziAF7A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-darwin-x64": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-darwin-x64/-/core-darwin-x64-1.3.93.tgz", + "integrity": "sha512-ZQPxm/fXdDQtn3yrYSL/gFfA8OfZ5jTi33yFQq6vcg/Y8talpZ+MgdSlYM0FkLrZdMTYYTNFiuBQuuvkA+av+Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm-gnueabihf": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.93.tgz", + "integrity": "sha512-OYFMMI2yV+aNe3wMgYhODxHdqUB/jrK0SEMHHS44GZpk8MuBXEF+Mcz4qjkY5Q1EH7KVQqXb/gVWwdgTHpjM2A==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-gnu": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.93.tgz", + "integrity": "sha512-BT4dT78odKnJMNiq5HdjBsv29CiIdcCcImAPxeFqAeFw1LL6gh9nzI8E96oWc+0lVT5lfhoesCk4Qm7J6bty8w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-arm64-musl": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.93.tgz", + "integrity": "sha512-yH5fWEl1bktouC0mhh0Chuxp7HEO4uCtS/ly1Vmf18gs6wZ8DOOkgAEVv2dNKIryy+Na++ljx4Ym7C8tSJTrLw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-gnu": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.93.tgz", + "integrity": "sha512-OFUdx64qvrGJhXKEyxosHxgoUVgba2ztYh7BnMiU5hP8lbI8G13W40J0SN3CmFQwPP30+3oEbW7LWzhKEaYjlg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-linux-x64-musl": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.93.tgz", + "integrity": "sha512-4B8lSRwEq1XYm6xhxHhvHmKAS7pUp1Q7E33NQ2TlmFhfKvCOh86qvThcjAOo57x8DRwmpvEVrqvpXtYagMN6Ig==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-arm64-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.93.tgz", + "integrity": "sha512-BHShlxtkven8ZjjvZ5QR6sC5fZCJ9bMujEkiha6W4cBUTY7ce7qGFyHmQd+iPC85d9kD/0cCiX/Xez8u0BhO7w==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-ia32-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.93.tgz", + "integrity": "sha512-nEwNWnz4JzYAK6asVvb92yeylfxMYih7eMQOnT7ZVlZN5ba9WF29xJ6kcQKs9HRH6MvWhz9+wRgv3FcjlU6HYA==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/core-win32-x64-msvc": { + "version": "1.3.93", + "resolved": "https://registry.npmjs.org/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.93.tgz", + "integrity": "sha512-jibQ0zUr4kwJaQVwgmH+svS04bYTPnPw/ZkNInzxS+wFAtzINBYcU8s2PMWbDb2NGYiRSEeoSGyAvS9H+24JFA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=10" + } + }, + "node_modules/@swc/counter": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.2.tgz", + "integrity": "sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw==" + }, + "node_modules/@swc/types": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.5.tgz", + "integrity": "sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==" + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.9", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz", + "integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==" + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==" + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==" + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==" + }, + "node_modules/@types/node": { + "version": "20.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.7.tgz", + "integrity": "sha512-21TKHHh3eUHIi2MloeptJWALuCu5H7HQTdTrWIFReA8ad+aggoX+lRes3ex7/FtpC+sVUpFMQ+QTfYr74mruiQ==", + "peer": true, + "dependencies": { + "undici-types": "~5.25.1" + } + }, + "node_modules/@types/uuid": { + "version": "9.0.6", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.6.tgz", + "integrity": "sha512-BT2Krtx4xaO6iwzwMFUYvWBWkV2pr37zD68Vmp1CDV196MzczBRxuEpD6Pr395HAgebC/co7hOphs53r8V7jew==" + }, + "node_modules/acorn": { + "version": "8.10.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", + "integrity": "sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", + "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==" + }, + "node_modules/azle": { + "version": "0.18.5", + "resolved": "https://registry.npmjs.org/azle/-/azle-0.18.5.tgz", + "integrity": "sha512-9lLhVKwexVCd8OOYMXgjk06L+Mu0q29Rpchmz07HYV6idwF5kg+8QCxzytpU9GpnUeoADTQNkEkyLABtkd2hCA==", + "dependencies": { + "@dfinity/candid": "github:demergent-labs/candid#minimum_viable", + "@dfinity/principal": "^0.19.0", + "@swc/core": "^1.3.86", + "@types/uuid": "^9.0.4", + "buffer": "^6.0.3", + "esbuild": "^0.19.3", + "fs-extra": "10.0.1", + "js-sha256": "0.9.0", + "text-encoding": "0.7.0", + "ts-node": "10.3.1", + "typescript": "^5.2.2", + "uuid": "^9.0.1" + }, + "bin": { + "azle": "bin.js" + } + }, + "node_modules/azle/node_modules/@cspotcode/source-map-support": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz", + "integrity": "sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==", + "dependencies": { + "@cspotcode/source-map-consumer": "0.8.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/azle/node_modules/@dfinity/candid": { + "version": "0.19.2", + "resolved": "git+ssh://git@github.com/demergent-labs/candid.git#5797fa906b1a7cc30c161dbb0eb919283ce2f80d", + "license": "Apache-2.0", + "peerDependencies": { + "@dfinity/principal": "^0.19.2" + } + }, + "node_modules/azle/node_modules/ts-node": { + "version": "10.3.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.3.1.tgz", + "integrity": "sha512-Yw3W2mYzhHfCHOICGNJqa0i+rbL0rAyg7ZIHxU+K4pgY8gd2Lh1j+XbHCusJMykbj6RZMJVOY0MlHVd+GOivcw==", + "dependencies": { + "@cspotcode/source-map-support": "0.7.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==" + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/esbuild": { + "version": "0.19.5", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.5.tgz", + "integrity": "sha512-bUxalY7b1g8vNhQKdB24QDmHeY4V4tw/s6Ak5z+jJX9laP5MoQseTOMemAr0gxssjNcH0MCViG8ONI2kksvfFQ==", + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.19.5", + "@esbuild/android-arm64": "0.19.5", + "@esbuild/android-x64": "0.19.5", + "@esbuild/darwin-arm64": "0.19.5", + "@esbuild/darwin-x64": "0.19.5", + "@esbuild/freebsd-arm64": "0.19.5", + "@esbuild/freebsd-x64": "0.19.5", + "@esbuild/linux-arm": "0.19.5", + "@esbuild/linux-arm64": "0.19.5", + "@esbuild/linux-ia32": "0.19.5", + "@esbuild/linux-loong64": "0.19.5", + "@esbuild/linux-mips64el": "0.19.5", + "@esbuild/linux-ppc64": "0.19.5", + "@esbuild/linux-riscv64": "0.19.5", + "@esbuild/linux-s390x": "0.19.5", + "@esbuild/linux-x64": "0.19.5", + "@esbuild/netbsd-x64": "0.19.5", + "@esbuild/openbsd-x64": "0.19.5", + "@esbuild/sunos-x64": "0.19.5", + "@esbuild/win32-arm64": "0.19.5", + "@esbuild/win32-ia32": "0.19.5", + "@esbuild/win32-x64": "0.19.5" + } + }, + "node_modules/fs-extra": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", + "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + }, + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/js-sha256": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", + "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" + }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==" + }, + "node_modules/text-encoding": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.7.0.tgz", + "integrity": "sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==", + "deprecated": "no longer maintained" + }, + "node_modules/ts-node": { + "version": "10.9.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", + "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "dev": true, + "dependencies": { + "@cspotcode/source-map-support": "^0.8.0", + "@tsconfig/node10": "^1.0.7", + "@tsconfig/node12": "^1.0.7", + "@tsconfig/node14": "^1.0.0", + "@tsconfig/node16": "^1.0.2", + "acorn": "^8.4.1", + "acorn-walk": "^8.1.1", + "arg": "^4.1.0", + "create-require": "^1.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "v8-compile-cache-lib": "^3.0.1", + "yn": "3.1.1" + }, + "bin": { + "ts-node": "dist/bin.js", + "ts-node-cwd": "dist/bin-cwd.js", + "ts-node-esm": "dist/bin-esm.js", + "ts-node-script": "dist/bin-script.js", + "ts-node-transpile-only": "dist/bin-transpile.js", + "ts-script": "dist/bin-script-deprecated.js" + }, + "peerDependencies": { + "@swc/core": ">=1.2.50", + "@swc/wasm": ">=1.2.50", + "@types/node": "*", + "typescript": ">=2.7" + }, + "peerDependenciesMeta": { + "@swc/core": { + "optional": true + }, + "@swc/wasm": { + "optional": true + } + } + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "peer": true + }, + "node_modules/universalify": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", + "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/v8-compile-cache-lib": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", + "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", + "dev": true + }, + "node_modules/yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "engines": { + "node": ">=6" + } + } + } +} diff --git a/property_tests/tests/init_method/package.json b/property_tests/tests/init_method/package.json new file mode 100644 index 0000000000..e5b0aa2544 --- /dev/null +++ b/property_tests/tests/init_method/package.json @@ -0,0 +1,12 @@ +{ + "scripts": { + "test": "ts-node --transpile-only --ignore=false test/test.ts" + }, + "dependencies": { + "azle": "^0.18.5" + }, + "devDependencies": { + "ts-node": "^10.9.1", + "typescript": "^5.2.2" + } +} diff --git a/property_tests/tests/init_method/test/generate_callable_method_body.ts b/property_tests/tests/init_method/test/generate_callable_method_body.ts new file mode 100644 index 0000000000..bcfbcc017f --- /dev/null +++ b/property_tests/tests/init_method/test/generate_callable_method_body.ts @@ -0,0 +1,10 @@ +import { Named } from 'azle/property_tests'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; + +export function generateBody( + _namedParams: Named>[], + returnType: CandidValueAndMeta | undefined +) { + return `return ${returnType?.src.valueLiteral}`; +} diff --git a/property_tests/tests/init_method/test/generate_init_body.ts b/property_tests/tests/init_method/test/generate_init_body.ts new file mode 100644 index 0000000000..f53d66c2f0 --- /dev/null +++ b/property_tests/tests/init_method/test/generate_init_body.ts @@ -0,0 +1,22 @@ +import { Named } from 'azle/property_tests'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; + +export function generateBody( + namedParams: Named>[] +) { + const paramsAreCorrectlyOrdered = areParamsCorrectlyOrdered(namedParams); + + const storeVariablesGlobally = namedParams + .map((param, i) => `initParam${i} = ${param.name};`) + .join('\n'); + + return ` + initialized = true; + + ${paramsAreCorrectlyOrdered} + + ${storeVariablesGlobally} + `; +} diff --git a/property_tests/tests/init_method/test/generate_tests.ts b/property_tests/tests/init_method/test/generate_tests.ts new file mode 100644 index 0000000000..96aad6036b --- /dev/null +++ b/property_tests/tests/init_method/test/generate_tests.ts @@ -0,0 +1,34 @@ +import { deepEqual, Named, getActor } from 'azle/property_tests'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; +import { Test } from 'azle/test'; + +export function generateTests( + _functionName: string, + params: Named>[] +): Test[][] { + const expectedResult = [ + true, + ...params.map((param) => param.el.value.agentResponseValue) + ]; + + return [ + [ + { + name: `init method`, + test: async () => { + const actor = getActor('./tests/init_method/test'); + const result = await actor.getInitValues(); + + const valuesAreEqual = deepEqual(result, expectedResult); + + return valuesAreEqual + ? { Ok: true } + : { + Err: `\n Incorrect return value\n expected: ${expectedResult}\n received: ${result}` + }; + } + } + ] + ]; +} diff --git a/property_tests/tests/init_method/test/test.ts b/property_tests/tests/init_method/test/test.ts new file mode 100644 index 0000000000..6fd7e4691e --- /dev/null +++ b/property_tests/tests/init_method/test/test.ts @@ -0,0 +1,108 @@ +import fc from 'fast-check'; + +import { runPropTests } from 'azle/property_tests'; +import { CandidValueAndMetaArbWithoutFuncs as CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { UpdateMethodArb } from 'azle/property_tests/arbitraries/canister_methods/update_method_arb'; +import { + QueryMethod, + QueryMethodArb +} from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; +import { InitMethodArb } from 'azle/property_tests/arbitraries/canister_methods/init_method_arb'; + +import { generateBody as callableMethodBodyGenerator } from './generate_callable_method_body'; +import { generateBody as initBodyGenerator } from './generate_init_body'; +import { generateTests } from './generate_tests'; +import { CorrespondingJSType } from '../../../arbitraries/candid/corresponding_js_type'; + +const SimpleInitMethodArb = InitMethodArb(fc.array(CandidValueAndMetaArb()), { + generateBody: initBodyGenerator, + generateTests +}); + +const HeterogeneousQueryMethodArb = QueryMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), + { + generateBody: callableMethodBodyGenerator, + generateTests: () => [] + } +); + +const HeterogeneousUpdateMethodArb = UpdateMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), + { + generateBody: callableMethodBodyGenerator, + generateTests: () => [] + } +); + +const small = { + minLength: 0, + maxLength: 20 +}; + +const CanisterConfigArb = fc + .tuple( + SimpleInitMethodArb, + fc.array(HeterogeneousQueryMethodArb, small), + fc.array(HeterogeneousUpdateMethodArb, small) + ) + .map( + ([initMethod, queryMethods, updateMethods]): CanisterConfig< + CorrespondingJSType, + CorrespondingJSType + > => { + const initParamTypes = initMethod.params.map( + (param) => param.el.src.candidTypeObject + ); + + const globalInitVariableNames = initMethod.params.map( + (_, i) => `initParam${i}` + ); + const globalInitVariableDeclarations = initMethod.params.map( + (param, i) => + `let initParam${i}: ${param.el.src.candidTypeAnnotation};` + ); + + const globalDeclarations = [ + 'let initialized: boolean = false;', + ...globalInitVariableDeclarations + ]; + + const getInitValues = generateGetInitValuesCanisterMethod( + initParamTypes, + globalInitVariableNames + ); + + return { + initMethod, + globalDeclarations, + queryMethods: [getInitValues, ...queryMethods], + updateMethods + }; + } + ); + +runPropTests(CanisterArb(CanisterConfigArb)); + +function generateGetInitValuesCanisterMethod( + paramTypes: string[], + globalInitVariableNames: string[] +): QueryMethod { + return { + imports: new Set(['Tuple', 'bool']), + globalDeclarations: [], + sourceCode: /*TS*/ `getInitValues: query( + [], + Tuple(bool, ${paramTypes.join()}), + () => { return [initialized, ${globalInitVariableNames.join()}]}) + `, + tests: [] + }; +} diff --git a/property_tests/tests/init_method/tsconfig.json b/property_tests/tests/init_method/tsconfig.json new file mode 100644 index 0000000000..d20bea88d9 --- /dev/null +++ b/property_tests/tests/init_method/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "strict": true, + "target": "ES2020", + "moduleResolution": "node", + "allowJs": true, + "outDir": "HACK_BECAUSE_OF_ALLOW_JS", + "esModuleInterop": true + } +} From 496b2314c4aa20345426707929dc7adc1267f511 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 12 Dec 2023 08:36:45 -0700 Subject: [PATCH 03/16] Update tests --- .../arbitraries/canister_methods/index.ts | 22 ++++++++----------- .../canister_methods/init_method_arb.ts | 15 ++++++++----- .../tests/blob/test/generate_body.ts | 10 ++++----- .../tests/blob/test/generate_tests.ts | 8 ++++--- .../tests/bool/test/generate_tests.ts | 6 ++--- .../tests/float32/test/generate_tests.ts | 6 ++--- .../tests/float64/test/generate_tests.ts | 6 ++--- .../tests/func/test/generate_tests.ts | 7 ++++-- .../test/generate_callable_method_body.ts | 4 ++-- .../tests/int/test/generate_tests.ts | 6 ++--- .../tests/int16/test/generate_tests.ts | 6 ++--- .../tests/int32/test/generate_tests.ts | 6 ++--- .../tests/int64/test/generate_tests.ts | 6 ++--- .../tests/int8/test/generate_tests.ts | 6 ++--- .../tests/nat/test/generate_tests.ts | 6 ++--- .../tests/nat16/test/generate_tests.ts | 6 ++--- .../tests/nat32/test/generate_tests.ts | 6 ++--- .../tests/nat64/test/generate_tests.ts | 6 ++--- .../tests/nat8/test/generate_tests.ts | 6 ++--- .../tests/null/test/generate_tests.ts | 2 +- .../tests/opt/test/generate_tests.ts | 4 ++-- .../tests/principal/test/generate_tests.ts | 6 ++--- .../query_methods/test/generate_tests.ts | 6 +++-- .../tests/record/test/generate_body.ts | 4 +++- .../tests/record/test/generate_tests.ts | 7 ++++-- .../tests/service/test/generate_body.ts | 2 +- .../tests/service/test/generate_tests.ts | 4 ++-- .../stable_b_tree_map/test/contains_key.ts | 4 ++-- .../tests/stable_b_tree_map/test/get.ts | 8 +++---- .../tests/stable_b_tree_map/test/insert.ts | 8 +++---- .../tests/stable_b_tree_map/test/items.ts | 8 +++---- .../tests/stable_b_tree_map/test/keys.ts | 4 ++-- .../tests/stable_b_tree_map/test/remove.ts | 8 +++---- .../tests/stable_b_tree_map/test/values.ts | 4 ++-- .../tests/text/test/generate_tests.ts | 6 ++--- .../tests/tuple/test/generate_body.ts | 2 +- .../tests/tuple/test/generate_tests.ts | 4 ++-- .../update_methods/test/generate_tests.ts | 6 +++-- .../tests/variant/test/generate_tests.ts | 4 ++-- .../tests/vec/test/generate_tests.ts | 4 ++-- 40 files changed, 131 insertions(+), 118 deletions(-) diff --git a/property_tests/arbitraries/canister_methods/index.ts b/property_tests/arbitraries/canister_methods/index.ts index 99b8a3cbbd..4a716fde25 100644 --- a/property_tests/arbitraries/canister_methods/index.ts +++ b/property_tests/arbitraries/canister_methods/index.ts @@ -13,12 +13,10 @@ export type BodyGenerator< namedParams: Named< CandidValueAndMeta >[], - returnType: - | CandidValueAndMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > - | undefined + returnType: CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > ) => string; export type TestsGenerator< @@ -31,12 +29,10 @@ export type TestsGenerator< namedParams: Named< CandidValueAndMeta >[], - returnType: - | CandidValueAndMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > - | undefined + returnType: CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > ) => Test[][]; export type CallbackLocation = 'INLINE' | 'STANDALONE'; @@ -52,7 +48,7 @@ export function generateCallback< ReturnAgentType >( namedParams: Named>[], - returnType: CandidValueAndMeta | undefined, + returnType: CandidValueAndMeta, generateBody: BodyGenerator< ParamType, ParamAgentType, diff --git a/property_tests/arbitraries/canister_methods/init_method_arb.ts b/property_tests/arbitraries/canister_methods/init_method_arb.ts index c3b22ee33e..cd8cb368ff 100644 --- a/property_tests/arbitraries/canister_methods/init_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/init_method_arb.ts @@ -12,6 +12,7 @@ import { generateCallback } from '.'; import { Test } from '../../../test'; +import { VoidArb } from '../candid/primitive/void'; export type InitMethod< ParamAgentArgumentValue extends CorrespondingJSType, @@ -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; } @@ -55,6 +56,7 @@ export function InitMethodArb< .tuple( UniqueIdentifierArb('canisterMethod'), paramTypeArrayArb, + VoidArb(), fc.constantFrom( 'INLINE', 'STANDALONE' @@ -68,6 +70,7 @@ export function InitMethodArb< ([ functionName, paramTypes, + returnType, defaultCallbackLocation, callbackName ]) => { @@ -90,7 +93,7 @@ export function InitMethodArb< const callback = generateCallback( namedParams, - undefined, + returnType, constraints.generateBody, callbackLocation, callbackName @@ -114,7 +117,7 @@ export function InitMethodArb< const tests = constraints.generateTests( functionName, namedParams, - undefined + returnType ); return { diff --git a/property_tests/tests/blob/test/generate_body.ts b/property_tests/tests/blob/test/generate_body.ts index 13864f6bc3..2a2aee3be9 100644 --- a/property_tests/tests/blob/test/generate_body.ts +++ b/property_tests/tests/blob/test/generate_body.ts @@ -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} diff --git a/property_tests/tests/blob/test/generate_tests.ts b/property_tests/tests/blob/test/generate_tests.ts index 2e54c7a776..a59be42e7c 100644 --- a/property_tests/tests/blob/test/generate_tests.ts +++ b/property_tests/tests/blob/test/generate_tests.ts @@ -9,10 +9,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] ) ); @@ -24,7 +24,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 { diff --git a/property_tests/tests/bool/test/generate_tests.ts b/property_tests/tests/bool/test/generate_tests.ts index 4ee57f1ca4..9033d40c3a 100644 --- a/property_tests/tests/bool/test/generate_tests.ts +++ b/property_tests/tests/bool/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnBool: CandidValueAndMeta ): 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 [ diff --git a/property_tests/tests/float32/test/generate_tests.ts b/property_tests/tests/float32/test/generate_tests.ts index b231b971c5..ed3c41f0fc 100644 --- a/property_tests/tests/float32/test/generate_tests.ts +++ b/property_tests/tests/float32/test/generate_tests.ts @@ -9,10 +9,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 [ [ diff --git a/property_tests/tests/float64/test/generate_tests.ts b/property_tests/tests/float64/test/generate_tests.ts index d0aa401345..df02a4eed8 100644 --- a/property_tests/tests/float64/test/generate_tests.ts +++ b/property_tests/tests/float64/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/func/test/generate_tests.ts b/property_tests/tests/func/test/generate_tests.ts index 6fd1acc6f5..f5d41447ca 100644 --- a/property_tests/tests/func/test/generate_tests.ts +++ b/property_tests/tests/func/test/generate_tests.ts @@ -17,12 +17,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 + ) }; } } diff --git a/property_tests/tests/init_method/test/generate_callable_method_body.ts b/property_tests/tests/init_method/test/generate_callable_method_body.ts index bcfbcc017f..d1adc9fbb2 100644 --- a/property_tests/tests/init_method/test/generate_callable_method_body.ts +++ b/property_tests/tests/init_method/test/generate_callable_method_body.ts @@ -4,7 +4,7 @@ import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candi export function generateBody( _namedParams: Named>[], - returnType: CandidValueAndMeta | undefined + returnType: CandidValueAndMeta ) { - return `return ${returnType?.src.valueLiteral}`; + return `return ${returnType.src.valueLiteral}`; } diff --git a/property_tests/tests/int/test/generate_tests.ts b/property_tests/tests/int/test/generate_tests.ts index 6528b9ad20..82c07b7a5e 100644 --- a/property_tests/tests/int/test/generate_tests.ts +++ b/property_tests/tests/int/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnInt: CandidValueAndMeta ): 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 [ diff --git a/property_tests/tests/int16/test/generate_tests.ts b/property_tests/tests/int16/test/generate_tests.ts index afc1280729..e87a8f6414 100644 --- a/property_tests/tests/int16/test/generate_tests.ts +++ b/property_tests/tests/int16/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/int32/test/generate_tests.ts b/property_tests/tests/int32/test/generate_tests.ts index dabccb58f2..a8de81c0cb 100644 --- a/property_tests/tests/int32/test/generate_tests.ts +++ b/property_tests/tests/int32/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/int64/test/generate_tests.ts b/property_tests/tests/int64/test/generate_tests.ts index dc8fc6ed90..dd20871dd6 100644 --- a/property_tests/tests/int64/test/generate_tests.ts +++ b/property_tests/tests/int64/test/generate_tests.ts @@ -10,12 +10,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 [ [ diff --git a/property_tests/tests/int8/test/generate_tests.ts b/property_tests/tests/int8/test/generate_tests.ts index 57228f09df..dc79248920 100644 --- a/property_tests/tests/int8/test/generate_tests.ts +++ b/property_tests/tests/int8/test/generate_tests.ts @@ -10,12 +10,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 [ [ diff --git a/property_tests/tests/nat/test/generate_tests.ts b/property_tests/tests/nat/test/generate_tests.ts index e0b7c92771..55eb9a3035 100644 --- a/property_tests/tests/nat/test/generate_tests.ts +++ b/property_tests/tests/nat/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnNat: CandidValueAndMeta ): 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 [ diff --git a/property_tests/tests/nat16/test/generate_tests.ts b/property_tests/tests/nat16/test/generate_tests.ts index f4b0d5c3fb..6784fd908f 100644 --- a/property_tests/tests/nat16/test/generate_tests.ts +++ b/property_tests/tests/nat16/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/nat32/test/generate_tests.ts b/property_tests/tests/nat32/test/generate_tests.ts index 05476022fd..bc3dc80563 100644 --- a/property_tests/tests/nat32/test/generate_tests.ts +++ b/property_tests/tests/nat32/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/nat64/test/generate_tests.ts b/property_tests/tests/nat64/test/generate_tests.ts index 5eaf547f84..c2500dffc3 100644 --- a/property_tests/tests/nat64/test/generate_tests.ts +++ b/property_tests/tests/nat64/test/generate_tests.ts @@ -10,11 +10,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 [ diff --git a/property_tests/tests/nat8/test/generate_tests.ts b/property_tests/tests/nat8/test/generate_tests.ts index 003d4c7646..4ac73f7d73 100644 --- a/property_tests/tests/nat8/test/generate_tests.ts +++ b/property_tests/tests/nat8/test/generate_tests.ts @@ -10,12 +10,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 [ diff --git a/property_tests/tests/null/test/generate_tests.ts b/property_tests/tests/null/test/generate_tests.ts index c1c0e9aa85..24671f940d 100644 --- a/property_tests/tests/null/test/generate_tests.ts +++ b/property_tests/tests/null/test/generate_tests.ts @@ -16,7 +16,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamNulls.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ) ); diff --git a/property_tests/tests/opt/test/generate_tests.ts b/property_tests/tests/opt/test/generate_tests.ts index aeb24ce24e..9bd4f66255 100644 --- a/property_tests/tests/opt/test/generate_tests.ts +++ b/property_tests/tests/opt/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( namedParamOpts: Named>[], returnOpt: CandidValueAndMeta ): Test[][] { - const expectedResult = returnOpt.agentResponseValue; + const expectedResult = returnOpt.value.agentResponseValue; return [ [ @@ -18,7 +18,7 @@ export function generateTests( const actor = getActor(__dirname); const params = namedParamOpts.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ); const result = await actor[functionName](...params); diff --git a/property_tests/tests/principal/test/generate_tests.ts b/property_tests/tests/principal/test/generate_tests.ts index c305230f51..a67e9b0e60 100644 --- a/property_tests/tests/principal/test/generate_tests.ts +++ b/property_tests/tests/principal/test/generate_tests.ts @@ -11,8 +11,8 @@ export function generateTests( ): Test[][] { const expectedResult = namedParamPrincipals.length > 0 - ? namedParamPrincipals[0].el.agentResponseValue - : returnPrincipal.agentResponseValue; + ? namedParamPrincipals[0].el.value.agentResponseValue + : returnPrincipal.value.agentResponseValue; return [ [ @@ -22,7 +22,7 @@ export function generateTests( const actor = getActor(__dirname); const result = await actor[functionName]( ...namedParamPrincipals.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ) ); diff --git a/property_tests/tests/query_methods/test/generate_tests.ts b/property_tests/tests/query_methods/test/generate_tests.ts index 4a3fef960a..b12d5b0fdd 100644 --- a/property_tests/tests/query_methods/test/generate_tests.ts +++ b/property_tests/tests/query_methods/test/generate_tests.ts @@ -9,8 +9,10 @@ export function generateTests( params: Named>[], returnType: CandidValueAndMeta ): Test[][] { - const paramValues = params.map((param) => param.el.agentArgumentValue); - const expectedResult = returnType.agentResponseValue; + const paramValues = params.map( + (param) => param.el.value.agentArgumentValue + ); + const expectedResult = returnType.value.agentResponseValue; return [ [ diff --git a/property_tests/tests/record/test/generate_body.ts b/property_tests/tests/record/test/generate_body.ts index c4f7d5e942..680ffb535e 100644 --- a/property_tests/tests/record/test/generate_body.ts +++ b/property_tests/tests/record/test/generate_body.ts @@ -9,7 +9,9 @@ export function generateBody( ): string { const paramsAreRecords = namedParamRecords .map((param) => { - const fieldsCount = Object.keys(param.el.agentArgumentValue).length; + const fieldsCount = Object.keys( + param.el.value.agentArgumentValue + ).length; const paramIsObject = `typeof ${param.name} === 'object'`; const paramHasCorrectNumberOfFields = `Object.keys(${param.name}).length === ${fieldsCount}`; diff --git a/property_tests/tests/record/test/generate_tests.ts b/property_tests/tests/record/test/generate_tests.ts index 9d659e61b6..25fe166ea8 100644 --- a/property_tests/tests/record/test/generate_tests.ts +++ b/property_tests/tests/record/test/generate_tests.ts @@ -17,12 +17,15 @@ export function generateTests( const result = await actor[functionName]( ...namedParamRecords.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ) ); return { - Ok: deepEqual(result, returnRecord.agentResponseValue) + Ok: deepEqual( + result, + returnRecord.value.agentResponseValue + ) }; } } diff --git a/property_tests/tests/service/test/generate_body.ts b/property_tests/tests/service/test/generate_body.ts index 34fb22ecbd..707a43aa89 100644 --- a/property_tests/tests/service/test/generate_body.ts +++ b/property_tests/tests/service/test/generate_body.ts @@ -11,7 +11,7 @@ export function generateBody( .map((param) => { const paramIsAService = `(${ param.name - } as any).principal.toText() === "${param.el.agentArgumentValue.toText()}"`; + } as any).principal.toText() === "${param.el.value.agentArgumentValue.toText()}"`; const throwError = `throw new Error('${param.name} must be a Service');`; diff --git a/property_tests/tests/service/test/generate_tests.ts b/property_tests/tests/service/test/generate_tests.ts index 38f55f4e23..e8a927b92b 100644 --- a/property_tests/tests/service/test/generate_tests.ts +++ b/property_tests/tests/service/test/generate_tests.ts @@ -22,7 +22,7 @@ export function generateTests( const paramsString = namedParamServices .map( (param) => - `service "${param.el.agentArgumentValue.toText()}"` + `service "${param.el.value.agentArgumentValue.toText()}"` ) .join(); @@ -35,7 +35,7 @@ export function generateTests( return { Ok: result === - `(service "${returnService.agentArgumentValue.toText()}")` + `(service "${returnService.value.agentArgumentValue.toText()}")` }; } } diff --git a/property_tests/tests/stable_b_tree_map/test/contains_key.ts b/property_tests/tests/stable_b_tree_map/test/contains_key.ts index 7a98501007..bcdaaf6491 100644 --- a/property_tests/tests/stable_b_tree_map/test/contains_key.ts +++ b/property_tests/tests/stable_b_tree_map/test/contains_key.ts @@ -20,7 +20,7 @@ export function ContainsKeyTestArb(stableBTreeMap: StableBTreeMap) { const body = generateBody(stableBTreeMap.name); const tests = generateTests( functionName, - stableBTreeMap.keySample.agentArgumentValue + stableBTreeMap.keySample.value.agentArgumentValue ); return { @@ -42,7 +42,7 @@ function generateBody(stableBTreeMapName: string): string { function generateTests( functionName: string, - keySampleAgentArgumentValue: StableBTreeMap['keySample']['agentArgumentValue'] + keySampleAgentArgumentValue: StableBTreeMap['keySample']['value']['agentArgumentValue'] ): Test[][] { return [ [ diff --git a/property_tests/tests/stable_b_tree_map/test/get.ts b/property_tests/tests/stable_b_tree_map/test/get.ts index ad35de12e8..233aaa7ea6 100644 --- a/property_tests/tests/stable_b_tree_map/test/get.ts +++ b/property_tests/tests/stable_b_tree_map/test/get.ts @@ -21,8 +21,8 @@ export function GetTestArb(stableBTreeMap: StableBTreeMap) { const tests = generateTests( functionName, - stableBTreeMap.keySample.agentArgumentValue, - stableBTreeMap.valueSample.agentArgumentValue + stableBTreeMap.keySample.value.agentArgumentValue, + stableBTreeMap.valueSample.value.agentArgumentValue ); return { @@ -44,8 +44,8 @@ function generateBody(stableBTreeMapName: string): string { function generateTests( functionName: string, - keySampleAgentArgumentValue: StableBTreeMap['keySample']['agentArgumentValue'], - valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['agentArgumentValue'] + keySampleAgentArgumentValue: StableBTreeMap['keySample']['value']['agentArgumentValue'], + valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['value']['agentArgumentValue'] ): Test[][] { return [ [ diff --git a/property_tests/tests/stable_b_tree_map/test/insert.ts b/property_tests/tests/stable_b_tree_map/test/insert.ts index bcc18d03da..2951e43fba 100644 --- a/property_tests/tests/stable_b_tree_map/test/insert.ts +++ b/property_tests/tests/stable_b_tree_map/test/insert.ts @@ -22,8 +22,8 @@ export function InsertTestArb(stableBTreeMap: StableBTreeMap) { const tests = generateTests( functionName, - stableBTreeMap.keySample.agentArgumentValue, - stableBTreeMap.valueSample.agentArgumentValue + stableBTreeMap.keySample.value.agentArgumentValue, + stableBTreeMap.valueSample.value.agentArgumentValue ); return { @@ -45,8 +45,8 @@ function generateBody(stableBTreeMapName: string): string { function generateTests( functionName: string, - keySampleAgentArgumentValue: StableBTreeMap['keySample']['agentArgumentValue'], - valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['agentArgumentValue'] + keySampleAgentArgumentValue: StableBTreeMap['keySample']['value']['agentArgumentValue'], + valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['value']['agentArgumentValue'] ): Test[][] { return [ [ diff --git a/property_tests/tests/stable_b_tree_map/test/items.ts b/property_tests/tests/stable_b_tree_map/test/items.ts index 7cb4bd8e0f..d358ecfb99 100644 --- a/property_tests/tests/stable_b_tree_map/test/items.ts +++ b/property_tests/tests/stable_b_tree_map/test/items.ts @@ -21,8 +21,8 @@ export function ItemsTestArb(stableBTreeMap: StableBTreeMap) { const tests = generateTests( functionName, - stableBTreeMap.keySample.agentArgumentValue, - stableBTreeMap.valueSample.agentArgumentValue + stableBTreeMap.keySample.value.agentArgumentValue, + stableBTreeMap.valueSample.value.agentArgumentValue ); return { @@ -44,8 +44,8 @@ function generateBody(stableBTreeMapName: string): string { function generateTests( functionName: string, - keySampleAgentArgumentValue: StableBTreeMap['keySample']['agentArgumentValue'], - valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['agentArgumentValue'] + keySampleAgentArgumentValue: StableBTreeMap['keySample']['value']['agentArgumentValue'], + valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['value']['agentArgumentValue'] ): Test[][] { return [ [ diff --git a/property_tests/tests/stable_b_tree_map/test/keys.ts b/property_tests/tests/stable_b_tree_map/test/keys.ts index 311cfdec4c..798a88f780 100644 --- a/property_tests/tests/stable_b_tree_map/test/keys.ts +++ b/property_tests/tests/stable_b_tree_map/test/keys.ts @@ -63,7 +63,7 @@ function generateTests( ).from(result), getArrayForCandidType( keySample.src.candidTypeAnnotation - ).from([keySample.agentArgumentValue]) + ).from([keySample.value.agentArgumentValue]) ) }; } @@ -84,7 +84,7 @@ function generateTests( ).from(result), getArrayForCandidType( keySample.src.candidTypeAnnotation - ).from([keySample.agentArgumentValue]) + ).from([keySample.value.agentArgumentValue]) ) }; } diff --git a/property_tests/tests/stable_b_tree_map/test/remove.ts b/property_tests/tests/stable_b_tree_map/test/remove.ts index 40cf2ac0e7..02d0720b9a 100644 --- a/property_tests/tests/stable_b_tree_map/test/remove.ts +++ b/property_tests/tests/stable_b_tree_map/test/remove.ts @@ -21,8 +21,8 @@ export function RemoveTestArb(stableBTreeMap: StableBTreeMap) { const tests = generateTests( functionName, - stableBTreeMap.keySample.agentArgumentValue, - stableBTreeMap.valueSample.agentArgumentValue + stableBTreeMap.keySample.value.agentArgumentValue, + stableBTreeMap.valueSample.value.agentArgumentValue ); return { @@ -44,8 +44,8 @@ function generateBody(stableBTreeMapName: string): string { function generateTests( functionName: string, - keySampleAgentArgumentValue: StableBTreeMap['keySample']['agentArgumentValue'], - valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['agentArgumentValue'] + keySampleAgentArgumentValue: StableBTreeMap['keySample']['value']['agentArgumentValue'], + valueSampleAgentArgumentValue: StableBTreeMap['valueSample']['value']['agentArgumentValue'] ): Test[][] { return [ [], diff --git a/property_tests/tests/stable_b_tree_map/test/values.ts b/property_tests/tests/stable_b_tree_map/test/values.ts index 3bfb002858..8b1ae5d1f4 100644 --- a/property_tests/tests/stable_b_tree_map/test/values.ts +++ b/property_tests/tests/stable_b_tree_map/test/values.ts @@ -66,7 +66,7 @@ function generateTests( ).from(result), getArrayForCandidType( valueSample.src.candidTypeAnnotation - ).from([valueSample.agentArgumentValue]) + ).from([valueSample.value.agentArgumentValue]) ) }; } @@ -87,7 +87,7 @@ function generateTests( ).from(result), getArrayForCandidType( valueSample.src.candidTypeAnnotation - ).from([valueSample.agentArgumentValue]) + ).from([valueSample.value.agentArgumentValue]) ) }; } diff --git a/property_tests/tests/text/test/generate_tests.ts b/property_tests/tests/text/test/generate_tests.ts index 585c5bad49..23d5f9d7de 100644 --- a/property_tests/tests/text/test/generate_tests.ts +++ b/property_tests/tests/text/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnTexts: CandidValueAndMeta ): Test[][] { const expectedResult = namedParamTexts.reduce( - (acc, param) => acc + param.el.agentResponseValue, - returnTexts.agentResponseValue + (acc, param) => acc + param.el.value.agentResponseValue, + returnTexts.value.agentResponseValue ); const paramValues = namedParamTexts.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/tuple/test/generate_body.ts b/property_tests/tests/tuple/test/generate_body.ts index a304a1238c..62b5c3a96f 100644 --- a/property_tests/tests/tuple/test/generate_body.ts +++ b/property_tests/tests/tuple/test/generate_body.ts @@ -12,7 +12,7 @@ export function generateBody( ): string { const paramsAreTuples = namedParamTuples .map((param) => { - const fieldsCount = param.el.agentArgumentValue.length; + const fieldsCount = param.el.value.agentArgumentValue.length; const paramIsArray = `Array.isArray(${param.name})`; const paramHasCorrectNumberOfFields = `${param.name}.length === ${fieldsCount}`; diff --git a/property_tests/tests/tuple/test/generate_tests.ts b/property_tests/tests/tuple/test/generate_tests.ts index bb4b11ed33..756eeab18e 100644 --- a/property_tests/tests/tuple/test/generate_tests.ts +++ b/property_tests/tests/tuple/test/generate_tests.ts @@ -11,7 +11,7 @@ export function generateTests( namedParamTuples: Named>[], returnTuple: CandidValueAndMeta ): Test[][] { - const expectedResult = returnTuple.agentResponseValue; + const expectedResult = returnTuple.value.agentResponseValue; return [ [ @@ -22,7 +22,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamTuples.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ) ); diff --git a/property_tests/tests/update_methods/test/generate_tests.ts b/property_tests/tests/update_methods/test/generate_tests.ts index 9220f55893..89b0055056 100644 --- a/property_tests/tests/update_methods/test/generate_tests.ts +++ b/property_tests/tests/update_methods/test/generate_tests.ts @@ -9,8 +9,10 @@ export function generateTests( params: Named>[], returnType: CandidValueAndMeta ): Test[][] { - const paramValues = params.map((param) => param.el.agentArgumentValue); - const expectedResult = returnType.agentResponseValue; + const paramValues = params.map( + (param) => param.el.value.agentArgumentValue + ); + const expectedResult = returnType.value.agentResponseValue; return [ [ diff --git a/property_tests/tests/variant/test/generate_tests.ts b/property_tests/tests/variant/test/generate_tests.ts index 9f877e1fbe..aedf7e9893 100644 --- a/property_tests/tests/variant/test/generate_tests.ts +++ b/property_tests/tests/variant/test/generate_tests.ts @@ -8,7 +8,7 @@ export function generateTests( namedParamVariants: Named>[], returnVariant: CandidValueAndMeta ): Test[][] { - const expectedResult = returnVariant.agentResponseValue; + const expectedResult = returnVariant.value.agentResponseValue; return [ [ @@ -19,7 +19,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamVariants.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ) ); diff --git a/property_tests/tests/vec/test/generate_tests.ts b/property_tests/tests/vec/test/generate_tests.ts index 51b5f5c667..6b85ec07a4 100644 --- a/property_tests/tests/vec/test/generate_tests.ts +++ b/property_tests/tests/vec/test/generate_tests.ts @@ -7,7 +7,7 @@ export function generateTests( namedParamVecs: Named>[], returnVec: CandidValueAndMeta ): Test[][] { - const expectedResult = returnVec.agentResponseValue; + const expectedResult = returnVec.value.agentResponseValue; return [ [ @@ -17,7 +17,7 @@ export function generateTests( const actor = getActor(__dirname); const params = namedParamVecs.map( - (param) => param.el.agentArgumentValue + (param) => param.el.value.agentArgumentValue ); const result = await actor[functionName](...params); From b48fbadb30329dd78d65161c40644ca985ceff53 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 12 Dec 2023 10:37:29 -0700 Subject: [PATCH 04/16] Fix Services --- .../candid/candid_definition_arb/types.ts | 9 +- .../reference/service_arb/definition_arb.ts | 71 +++++----------- .../service_arb/service_method_arb.ts | 85 +++++++++++++++++++ 3 files changed, 110 insertions(+), 55 deletions(-) create mode 100644 property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts diff --git a/property_tests/arbitraries/candid/candid_definition_arb/types.ts b/property_tests/arbitraries/candid/candid_definition_arb/types.ts index d4f0e42714..1bf1865b32 100644 --- a/property_tests/arbitraries/candid/candid_definition_arb/types.ts +++ b/property_tests/arbitraries/candid/candid_definition_arb/types.ts @@ -1,6 +1,7 @@ import fc from 'fast-check'; import { CandidType } from '../candid_type'; -import { CandidType as AzleCandidType } from '../../../../src/lib'; +import { CandidType as AzleCandidType } from '../../../../src/lib/candid/candid_type'; +import { ServiceMethodDefinition } from '../reference/service_arb/service_method_arb'; export type CandidDefinitionArb = fc.Arbitrary; @@ -60,12 +61,6 @@ export type ServiceCandidDefinition = { candidMeta: CandidMeta; funcs: ServiceMethodDefinition[]; }; -export type ServiceMethodDefinition = { - name: string; - imports: Set; - variableAliasDeclarations: string[]; - src: string; -}; type CandidMeta = { candidTypeAnnotation: string; // Either a type reference or type literal diff --git a/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts index 6af47cac4b..d83d2832b5 100644 --- a/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts @@ -1,13 +1,15 @@ import fc from 'fast-check'; -import { JsFunctionNameArb } from '../../../js_function_name_arb'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; import { - CandidDefinition, - ServiceCandidDefinition, + ServiceMethodArb, ServiceMethodDefinition +} from './service_method_arb'; +import { + CandidDefinition, + ServiceCandidDefinition } from '../../candid_definition_arb/types'; -import { VoidDefinitionArb } from '../../primitive/void'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { Canister } from '../../../../../src/lib/candid/types/reference/service'; export function ServiceDefinitionArb( fieldCandidDefArb: fc.Arbitrary @@ -34,6 +36,8 @@ export function ServiceDefinitionArb( fields ); + const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, name, @@ -47,6 +51,7 @@ export function ServiceDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, + azleCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Service' @@ -56,49 +61,6 @@ export function ServiceDefinitionArb( }); } -function ServiceMethodArb( - candidDefArb: fc.Arbitrary -): fc.Arbitrary { - return fc - .tuple( - JsFunctionNameArb, - fc.constantFrom('query', 'update'), - fc.array(candidDefArb), - fc.oneof(candidDefArb, VoidDefinitionArb()) - ) - .map(([name, mode, params, returnType]): ServiceMethodDefinition => { - const paramCandidTypeObjects = params.map( - (param) => param.candidMeta.candidTypeObject - ); - - const variableAliasDeclarations = params.reduce( - ( - acc, - { candidMeta: { variableAliasDeclarations } } - ): string[] => { - return [...acc, ...variableAliasDeclarations]; - }, - returnType.candidMeta.variableAliasDeclarations - ); - - const src = `${name}: ${mode}([${paramCandidTypeObjects}], ${returnType.candidMeta.candidTypeObject})`; - - const imports = params.reduce( - (acc, param) => { - return new Set([...acc, ...param.candidMeta.imports]); - }, - new Set([mode, ...returnType.candidMeta.imports]) - ); - - return { - name, - imports, - variableAliasDeclarations: variableAliasDeclarations, - src - }; - }); -} - function generateVariableAliasDeclarations( useTypeDeclaration: boolean, name: string, @@ -148,6 +110,19 @@ function generateCandidTypeObject( return `Canister({${methods}})`; } +function generateAzleCandidTypeObject( + serviceMethods: ServiceMethodDefinition[] +) { + const methods = serviceMethods.reduce((acc, serviceMethod) => { + return { + ...acc, + [serviceMethod.name]: serviceMethod.azleCandidTypeObject + }; + }, {}); + + return Canister(methods); +} + function generateImports( serviceMethods: ServiceMethodDefinition[] ): Set { diff --git a/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts new file mode 100644 index 0000000000..88c996e30c --- /dev/null +++ b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts @@ -0,0 +1,85 @@ +import fc from 'fast-check'; + +import { CandidType } from '../../candid_type'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { VoidDefinitionArb } from '../../primitive/void'; +import { JsFunctionNameArb } from '../../../js_function_name_arb'; +import { + query, + update +} from '../../../../../src/lib/canister_methods/methods/'; +import { CanisterMethodInfo } from '../../../../../src/lib/canister_methods/types/canister_method_info'; + +type Mode = 'query' | 'update'; + +export type ServiceMethodDefinition = { + name: string; + azleCandidTypeObject: CanisterMethodInfo; + imports: Set; + variableAliasDeclarations: string[]; + src: string; +}; + +export function ServiceMethodArb( + candidDefArb: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + JsFunctionNameArb, + fc.constantFrom('query', 'update') as fc.Arbitrary, + fc.array(candidDefArb), + fc.oneof(candidDefArb, VoidDefinitionArb()) + ) + .map(([name, mode, params, returnType]): ServiceMethodDefinition => { + const paramCandidTypeObjects = params.map( + (param) => param.candidMeta.candidTypeObject + ); + + const variableAliasDeclarations = params.reduce( + ( + acc, + { candidMeta: { variableAliasDeclarations } } + ): string[] => { + return [...acc, ...variableAliasDeclarations]; + }, + returnType.candidMeta.variableAliasDeclarations + ); + + const src = `${name}: ${mode}([${paramCandidTypeObjects}], ${returnType.candidMeta.candidTypeObject})`; + + const imports = params.reduce( + (acc, param) => { + return new Set([...acc, ...param.candidMeta.imports]); + }, + new Set([mode, ...returnType.candidMeta.imports]) + ); + + const azleCandidTypeObject = generateAzleCandidTypeObject( + mode, + params, + returnType + ); + + return { + name, + azleCandidTypeObject: azleCandidTypeObject, + imports, + variableAliasDeclarations: variableAliasDeclarations, + src + }; + }); +} + +function generateAzleCandidTypeObject( + mode: Mode, + params: CandidDefinition[], + returnType: CandidDefinition +) { + const modeFunction = mode === 'query' ? query : update; + const paramCandidTypeObjects = params.map( + (param) => param.candidMeta.azleCandidTypeObject + ); + const returnCandidTypeObject = returnType.candidMeta.azleCandidTypeObject; + + return modeFunction(paramCandidTypeObjects, returnCandidTypeObject); +} From 3f04106ecdde3babedb8bb15ade79bba51187c8a Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 12 Dec 2023 11:01:53 -0700 Subject: [PATCH 05/16] Add default value for return types --- property_tests/arbitraries/canister_methods/index.ts | 8 ++++---- .../arbitraries/canister_methods/init_method_arb.ts | 12 +++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/property_tests/arbitraries/canister_methods/index.ts b/property_tests/arbitraries/canister_methods/index.ts index 4a716fde25..b3d11ab16a 100644 --- a/property_tests/arbitraries/canister_methods/index.ts +++ b/property_tests/arbitraries/canister_methods/index.ts @@ -7,8 +7,8 @@ import { Test } from '../../../test'; export type BodyGenerator< ParamAgentArgumentValue extends CorrespondingJSType, ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CorrespondingJSType, - ReturnTypeAgentResponseValue + ReturnTypeAgentArgumentValue extends CorrespondingJSType = undefined, + ReturnTypeAgentResponseValue = undefined > = ( namedParams: Named< CandidValueAndMeta @@ -22,8 +22,8 @@ export type BodyGenerator< export type TestsGenerator< ParamAgentArgumentValue extends CorrespondingJSType, ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CorrespondingJSType, - ReturnTypeAgentResponseValue + ReturnTypeAgentArgumentValue extends CorrespondingJSType = undefined, + ReturnTypeAgentResponseValue = undefined > = ( methodName: string, namedParams: Named< diff --git a/property_tests/arbitraries/canister_methods/init_method_arb.ts b/property_tests/arbitraries/canister_methods/init_method_arb.ts index cd8cb368ff..55f72aa528 100644 --- a/property_tests/arbitraries/canister_methods/init_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/init_method_arb.ts @@ -29,9 +29,7 @@ export type InitMethod< export function InitMethodArb< ParamAgentArgumentValue extends CorrespondingJSType, - ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CorrespondingJSType, - ReturnTypeAgentResponseValue + ParamAgentResponseValue >( paramTypeArrayArb: fc.Arbitrary< CandidValueAndMeta[] @@ -39,15 +37,11 @@ export function InitMethodArb< constraints: { generateBody: BodyGenerator< ParamAgentArgumentValue, - ParamAgentResponseValue, - ReturnTypeAgentArgumentValue | undefined, - ReturnTypeAgentResponseValue | undefined + ParamAgentResponseValue >; generateTests: TestsGenerator< ParamAgentArgumentValue, - ParamAgentResponseValue, - ReturnTypeAgentArgumentValue | undefined, - ReturnTypeAgentResponseValue | undefined + ParamAgentResponseValue >; callbackLocation?: CallbackLocation; } From a361babbeec543d29545792e5d3778f243a149a9 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 12 Dec 2023 11:09:50 -0700 Subject: [PATCH 06/16] Add missing property tests to CI/CD --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fd3fee6710..d84d135f8b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -136,6 +136,7 @@ jobs: "property_tests/tests/float32", "property_tests/tests/float64", "property_tests/tests/func", + "property_tests/tests/init_method", "property_tests/tests/int", "property_tests/tests/int8", "property_tests/tests/int16", @@ -147,12 +148,15 @@ jobs: "property_tests/tests/nat32", "property_tests/tests/nat64", "property_tests/tests/null", + "property_tests/tests/opt", "property_tests/tests/principal", + "property_tests/tests/query_methods", "property_tests/tests/record", "property_tests/tests/service", "property_tests/tests/stable_b_tree_map", "property_tests/tests/text", "property_tests/tests/tuple", + "property_tests/tests/update_methods", "property_tests/tests/variant", "property_tests/tests/vec" ] From 7ec8bb81e5cc055179204d55857c6729b11a30e7 Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 12 Dec 2023 13:02:47 -0700 Subject: [PATCH 07/16] Escape candid strings for bash --- property_tests/arbitraries/canister_arb.ts | 32 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 193f698476..2f2ccd0ab3 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -41,11 +41,22 @@ export function CanisterArb< ...(config.updateMethods ?? []) ]; - const initArgs = config.initMethod?.params.map(({ el: { value } }) => { - return value.candidTypeObject - .getIdl([]) - .valueToString(value.agentArgumentValue); - }); + const initArgs = config.initMethod?.params.map( + ({ + el: { + src: { candidTypeAnnotation }, + value + } + }) => { + const paramCandidString = value.candidTypeObject + .getIdl([]) + .valueToString(value.agentArgumentValue); + + return candidTypeAnnotation === 'text' + ? escapeCandidStringForBash(paramCandidString) + : paramCandidString; + } + ); const sourceCode = generateSourceCode( config.globalDeclarations ?? [], @@ -126,3 +137,14 @@ function generateSourceCode( }); `; } + +function escapeCandidStringForBash(input: string) { + return `"${escapeForBash(input.slice(1, -1))}"`; +} + +function escapeForBash(input: string) { + return input + .replace(/\\/g, '\\\\') // Escape backslashes + .replace(/'/g, "'\\''") // Escape single quotes + .replace(/"/g, '\\"'); // Escape double quotes +} From ab1dd53370db77fa0695b898d52981e52533acea Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 08:41:35 -0700 Subject: [PATCH 08/16] pr fixes --- .../candid/candid_value_and_meta_arb.ts | 28 ------------------ .../constructed/record_arb/definition_arb.ts | 23 ++++++++++----- .../variant_arb/definition_arbs.ts | 19 ++++++++---- .../constructed/variant_arb/values_arb.ts | 10 +++---- .../service_arb/service_method_arb.ts | 4 +-- property_tests/arbitraries/canister_arb.ts | 29 ++++++++----------- .../canister_methods/init_method_arb.ts | 12 ++++---- property_tests/index.ts | 3 +- property_tests/tests/init_method/test/test.ts | 2 +- .../candid/did_file/visitor/visit/service.ts | 2 +- 10 files changed, 56 insertions(+), 76 deletions(-) diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts index f9cea118a5..9bab7b2f86 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts @@ -75,31 +75,3 @@ export function CandidValueAndMetaArb(): fc.Arbitrary< } // TODO: This needs to support service. - -/** - * Azle currently (v0.18.6) cannot accept funcs in init methods. - * See https://github.com/demergent-labs/azle/issues/1474 - */ -export function CandidValueAndMetaArbWithoutFuncs(): fc.Arbitrary< - CandidValueAndMeta -> { - return fc.oneof( - BlobArb(), - Float32Arb(), - Float64Arb(), - IntArb(), - Int8Arb(), - Int16Arb(), - Int32Arb(), - Int64Arb(), - NatArb(), - Nat8Arb(), - Nat16Arb(), - Nat32Arb(), - Nat64Arb(), - BoolArb(), - NullArb(), - TextArb(), - PrincipalArb() - ); -} diff --git a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts index 744a3d0db4..3f52c3b65f 100644 --- a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts @@ -10,6 +10,10 @@ import { CandidType, Record } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; +type RunTimeRecord = { + [key: string]: CandidType; +}; + export function RecordDefinitionArb( fieldCandidDefArb: CandidDefinitionArb ): fc.Arbitrary { @@ -61,7 +65,7 @@ export function RecordDefinitionArb( } function generateImports(fields: Field[]): Set { - const fieldImports = fields.flatMap((field) => [ + const fieldImports = fields.flatMap((field): string[] => [ ...field[1].candidMeta.imports ]); return new Set([...fieldImports, 'Record']); @@ -102,12 +106,15 @@ function generateCandidTypeObject( } function generateAzleCandidTypeObject(fields: Field[]): CandidType { - const azleRecordConstructorObj = fields.reduce<{ - [key: string]: CandidType; - }>((acc, [fieldName, fieldDefinition]) => { - acc[fieldName] = fieldDefinition.candidMeta.azleCandidTypeObject; - return acc; - }, {}); + const azleRecordConstructorObj = fields.reduce( + (acc, [fieldName, fieldDefinition]): RunTimeRecord => { + return { + ...acc, + [fieldName]: fieldDefinition.candidMeta.azleCandidTypeObject + }; + }, + {} + ); return Record(azleRecordConstructorObj); } @@ -118,7 +125,7 @@ function generateVariableAliasDeclarations( fields: Field[] ): string[] { const fieldVariableAliasDefinitions = fields.flatMap( - (field) => field[1].candidMeta.variableAliasDeclarations + (field): string[] => field[1].candidMeta.variableAliasDeclarations ); if (useTypeDeclaration) { return [ diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts index 8af77aaba9..1917ea69da 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts @@ -9,6 +9,10 @@ import { CandidType, Variant } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; +type RunTimeVariant = { + [key: string]: CandidType; +}; + export function VariantDefinitionArb( candidTypeArbForFields: fc.Arbitrary ): fc.Arbitrary { @@ -126,12 +130,15 @@ function generateCandidTypeObject( } function generateAzleCandidTypeObject(fields: Field[]): CandidType { - const azleVariantConstructorObj = fields.reduce<{ - [key: string]: CandidType; - }>((acc, [fieldName, fieldDefinition]) => { - acc[fieldName] = fieldDefinition.candidMeta.azleCandidTypeObject; - return acc; - }, {}); + const azleVariantConstructorObj = fields.reduce( + (acc, [fieldName, fieldDefinition]): RunTimeVariant => { + return { + ...acc, + [fieldName]: fieldDefinition.candidMeta.azleCandidTypeObject + }; + }, + {} + ); return Variant(azleVariantConstructorObj); } diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts index 64512c414b..ffc2a4e75e 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts @@ -22,14 +22,14 @@ export function VariantValuesArb( const [name, innerType] = variantDefinition.innerTypes[randomIndex]; - const fieldValue = CandidValueArb(innerType).map((values): Field => { + const fieldValues = CandidValueArb(innerType).map((values): Field => { return [name, values]; }); - return fieldValue.map((field) => { - const valueLiteral = generateValueLiteral(field); - const agentArgumentValue = generateValue(field); - const agentResponseValue = generateValue(field, true); + return fieldValues.map((fieldValue) => { + const valueLiteral = generateValueLiteral(fieldValue); + const agentArgumentValue = generateValue(fieldValue); + const agentResponseValue = generateValue(fieldValue, true); return { valueLiteral, diff --git a/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts index 88c996e30c..a13b2067c1 100644 --- a/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts +++ b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts @@ -75,11 +75,11 @@ function generateAzleCandidTypeObject( params: CandidDefinition[], returnType: CandidDefinition ) { - const modeFunction = mode === 'query' ? query : update; + const queryOrUpdate = mode === 'query' ? query : update; const paramCandidTypeObjects = params.map( (param) => param.candidMeta.azleCandidTypeObject ); const returnCandidTypeObject = returnType.candidMeta.azleCandidTypeObject; - return modeFunction(paramCandidTypeObjects, returnCandidTypeObject); + return queryOrUpdate(paramCandidTypeObjects, returnCandidTypeObject); } diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 2f2ccd0ab3..da8e83e65d 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -41,22 +41,17 @@ export function CanisterArb< ...(config.updateMethods ?? []) ]; - const initArgs = config.initMethod?.params.map( - ({ - el: { - src: { candidTypeAnnotation }, - value - } - }) => { - const paramCandidString = value.candidTypeObject - .getIdl([]) - .valueToString(value.agentArgumentValue); - - return candidTypeAnnotation === 'text' - ? escapeCandidStringForBash(paramCandidString) - : paramCandidString; - } - ); + const initArgs = config.initMethod?.params.map((paramValue) => { + const value = paramValue.el.value; + const candidTypeAnnotation = paramValue.el.src.candidTypeAnnotation; + const paramCandidString = value.candidTypeObject + .getIdl([]) + .valueToString(value.agentArgumentValue); + + return candidTypeAnnotation === 'text' + ? escapeCandidStringForBash(paramCandidString) + : paramCandidString; + }); const sourceCode = generateSourceCode( config.globalDeclarations ?? [], @@ -124,7 +119,7 @@ function generateSourceCode( return /*TS*/ ` import { ${imports} } from 'azle'; - + // @ts-ignore import deepEqual from 'deep-is'; diff --git a/property_tests/arbitraries/canister_methods/init_method_arb.ts b/property_tests/arbitraries/canister_methods/init_method_arb.ts index 55f72aa528..6de40d3247 100644 --- a/property_tests/arbitraries/canister_methods/init_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/init_method_arb.ts @@ -51,10 +51,7 @@ export function InitMethodArb< UniqueIdentifierArb('canisterMethod'), paramTypeArrayArb, VoidArb(), - fc.constantFrom( - 'INLINE', - 'STANDALONE' - ) as fc.Arbitrary, + fc.constantFrom('INLINE', 'STANDALONE'), UniqueIdentifierArb('typeDeclaration') // TODO: This unique id would be better named globalScope or something // But needs to match the same scope as typeDeclarations so I'm using @@ -67,9 +64,10 @@ export function InitMethodArb< returnType, defaultCallbackLocation, callbackName - ]) => { - // TODO: Add a return type to this map callback of type InitMethod - + ]): InitMethod< + ParamAgentArgumentValue, + ParamAgentResponseValue + > => { const callbackLocation = constraints.callbackLocation ?? defaultCallbackLocation; diff --git a/property_tests/index.ts b/property_tests/index.ts index f439b59465..6e2bcca905 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -45,7 +45,8 @@ export function runPropTests(canisterArb: fc.Arbitrary) { for (let i = 0; i < canister.tests.length; i++) { const argumentsString = - canister.initArgs && canister.initArgs.length > 0 + canister.initArgs !== undefined && + canister.initArgs.length > 0 ? `--argument '(${canister.initArgs.join(', ')})'` : ''; diff --git a/property_tests/tests/init_method/test/test.ts b/property_tests/tests/init_method/test/test.ts index 6fd7e4691e..4b9ce8dadf 100644 --- a/property_tests/tests/init_method/test/test.ts +++ b/property_tests/tests/init_method/test/test.ts @@ -1,7 +1,7 @@ import fc from 'fast-check'; import { runPropTests } from 'azle/property_tests'; -import { CandidValueAndMetaArbWithoutFuncs as CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; +import { CandidValueAndMetaArb } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { CandidReturnTypeArb } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; import { CanisterArb, diff --git a/src/lib/candid/did_file/visitor/visit/service.ts b/src/lib/candid/did_file/visitor/visit/service.ts index d1f9fb1a52..c7c7a11510 100644 --- a/src/lib/candid/did_file/visitor/visit/service.ts +++ b/src/lib/candid/did_file/visitor/visit/service.ts @@ -125,7 +125,7 @@ function createCanisterParamsString( } const parts = initMethodCandidString[0].split('->'); if (parts.length >= 2) { - return parts[0].trim(); + return parts.slice(0, -1).join('->').trim(); } return '()'; // If we can't find any init or post upgrade params return empty () } From bd441e17b969ad9fb0d5390e6c929a83bafff5ef Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 08:46:50 -0700 Subject: [PATCH 09/16] renaming --- property_tests/arbitraries/canister_arb.ts | 11 ++++++----- .../arbitraries/canister_methods/init_method_arb.ts | 2 +- .../arbitraries/canister_methods/query_method_arb.ts | 2 +- .../arbitraries/canister_methods/update_method_arb.ts | 2 +- property_tests/are_params_correctly_ordered.ts | 4 ++-- property_tests/index.ts | 8 ++++---- property_tests/tests/blob/test/generate_tests.ts | 4 ++-- property_tests/tests/bool/test/generate_tests.ts | 4 ++-- property_tests/tests/float32/test/generate_tests.ts | 4 ++-- property_tests/tests/float64/test/generate_tests.ts | 4 ++-- property_tests/tests/func/test/generate_tests.ts | 2 +- .../tests/init_method/test/generate_tests.ts | 2 +- property_tests/tests/init_method/test/test.ts | 4 ++-- property_tests/tests/int/test/generate_tests.ts | 4 ++-- property_tests/tests/int16/test/generate_tests.ts | 4 ++-- property_tests/tests/int32/test/generate_tests.ts | 4 ++-- property_tests/tests/int64/test/generate_tests.ts | 4 ++-- property_tests/tests/int8/test/generate_tests.ts | 4 ++-- property_tests/tests/nat/test/generate_tests.ts | 4 ++-- property_tests/tests/nat16/test/generate_tests.ts | 4 ++-- property_tests/tests/nat32/test/generate_tests.ts | 4 ++-- property_tests/tests/nat64/test/generate_tests.ts | 4 ++-- property_tests/tests/nat8/test/generate_tests.ts | 4 ++-- property_tests/tests/null/test/generate_tests.ts | 2 +- property_tests/tests/opt/test/generate_tests.ts | 2 +- property_tests/tests/principal/test/generate_tests.ts | 4 ++-- .../tests/query_methods/test/generate_tests.ts | 2 +- property_tests/tests/record/test/generate_body.ts | 2 +- property_tests/tests/record/test/generate_tests.ts | 2 +- property_tests/tests/service/test/generate_body.ts | 2 +- property_tests/tests/service/test/generate_tests.ts | 2 +- property_tests/tests/text/test/generate_tests.ts | 4 ++-- property_tests/tests/tuple/test/generate_body.ts | 2 +- property_tests/tests/tuple/test/generate_tests.ts | 2 +- .../tests/update_methods/test/generate_tests.ts | 2 +- property_tests/tests/variant/test/generate_tests.ts | 2 +- property_tests/tests/vec/test/generate_tests.ts | 2 +- 37 files changed, 63 insertions(+), 62 deletions(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index da8e83e65d..175e690e2b 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -6,7 +6,7 @@ import { InitMethod } from './canister_methods/init_method_arb'; import { CorrespondingJSType } from './candid/corresponding_js_type'; export type Canister = { - initArgs: string[] | undefined; + deployArgs: string[] | undefined; sourceCode: string; tests: Test[][]; }; @@ -41,9 +41,10 @@ export function CanisterArb< ...(config.updateMethods ?? []) ]; - const initArgs = config.initMethod?.params.map((paramValue) => { - const value = paramValue.el.value; - const candidTypeAnnotation = paramValue.el.src.candidTypeAnnotation; + const deployArgs = config.initMethod?.params.map((paramValue) => { + const value = paramValue.value.value; + const candidTypeAnnotation = + paramValue.value.src.candidTypeAnnotation; const paramCandidString = value.candidTypeObject .getIdl([]) .valueToString(value.agentArgumentValue); @@ -82,7 +83,7 @@ export function CanisterArb< ); return { - initArgs, + deployArgs, sourceCode, tests }; diff --git a/property_tests/arbitraries/canister_methods/init_method_arb.ts b/property_tests/arbitraries/canister_methods/init_method_arb.ts index 6de40d3247..9f2bf2f082 100644 --- a/property_tests/arbitraries/canister_methods/init_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/init_method_arb.ts @@ -79,7 +79,7 @@ export function InitMethodArb< const namedParams = paramTypes.map( (param: T, index: number): Named => ({ name: `param${index}`, - el: param + value: param }) ); diff --git a/property_tests/arbitraries/canister_methods/query_method_arb.ts b/property_tests/arbitraries/canister_methods/query_method_arb.ts index e8fd209dd0..d6e18900af 100644 --- a/property_tests/arbitraries/canister_methods/query_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/query_method_arb.ts @@ -85,7 +85,7 @@ export function QueryMethodArb< const namedParams = paramTypes.map( (param: T, index: number): Named => ({ name: `param${index}`, - el: param + value: param }) ); diff --git a/property_tests/arbitraries/canister_methods/update_method_arb.ts b/property_tests/arbitraries/canister_methods/update_method_arb.ts index f9a8b5e670..633eb4d59f 100644 --- a/property_tests/arbitraries/canister_methods/update_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/update_method_arb.ts @@ -86,7 +86,7 @@ export function UpdateMethodArb< const namedParams = paramTypes.map( (param: T, index: number): Named => ({ name: `param${index}`, - el: param + value: param }) ); diff --git a/property_tests/are_params_correctly_ordered.ts b/property_tests/are_params_correctly_ordered.ts index 18cbe45c91..7fec6a500d 100644 --- a/property_tests/are_params_correctly_ordered.ts +++ b/property_tests/are_params_correctly_ordered.ts @@ -6,10 +6,10 @@ export function areParamsCorrectlyOrdered( params: Named>[] ) { return params - .map(({ name, el }) => { + .map(({ name, value }) => { const areEqual = `deepEqual( ${name}, - ${el.src.valueLiteral} + ${value.src.valueLiteral} )`; return `if (!${areEqual}) {console.log('value', ${name}); throw new Error('${name} is incorrectly ordered');}`; diff --git a/property_tests/index.ts b/property_tests/index.ts index 6e2bcca905..0db13cb903 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -10,7 +10,7 @@ import { clear as clearUniquePrimitiveArb } from './arbitraries/unique_primitive export type Named = { name: string; - el: T; + value: T; }; export { getActor } from './get_actor'; @@ -45,9 +45,9 @@ export function runPropTests(canisterArb: fc.Arbitrary) { for (let i = 0; i < canister.tests.length; i++) { const argumentsString = - canister.initArgs !== undefined && - canister.initArgs.length > 0 - ? `--argument '(${canister.initArgs.join(', ')})'` + canister.deployArgs !== undefined && + canister.deployArgs.length > 0 + ? `--argument '(${canister.deployArgs.join(', ')})'` : ''; execSync(`dfx deploy canister ${argumentsString}`, { diff --git a/property_tests/tests/blob/test/generate_tests.ts b/property_tests/tests/blob/test/generate_tests.ts index a59be42e7c..807b248a0f 100644 --- a/property_tests/tests/blob/test/generate_tests.ts +++ b/property_tests/tests/blob/test/generate_tests.ts @@ -9,7 +9,7 @@ export function generateTests( ): Test[][] { const expectedResult = Uint8Array.from( paramBlobs - .map((blob) => blob.el.value.agentResponseValue) + .map((blob) => blob.value.value.agentResponseValue) .reduce( (acc, blob) => [...acc, ...blob], [...returnBlob.value.agentResponseValue] @@ -25,7 +25,7 @@ export function generateTests( const result = await actor[functionName]( ...paramBlobs.map( - (blob) => blob.el.value.agentArgumentValue + (blob) => blob.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/bool/test/generate_tests.ts b/property_tests/tests/bool/test/generate_tests.ts index 9033d40c3a..5e433736d1 100644 --- a/property_tests/tests/bool/test/generate_tests.ts +++ b/property_tests/tests/bool/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnBool: CandidValueAndMeta ): Test[][] { const expectedResult = namedParamBools.reduce( - (acc, param) => acc && param.el.value.agentResponseValue, + (acc, param) => acc && param.value.value.agentResponseValue, returnBool.value.agentResponseValue ); const paramValues = namedParamBools.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/float32/test/generate_tests.ts b/property_tests/tests/float32/test/generate_tests.ts index ed3c41f0fc..c24b4f746f 100644 --- a/property_tests/tests/float32/test/generate_tests.ts +++ b/property_tests/tests/float32/test/generate_tests.ts @@ -10,9 +10,9 @@ export function generateTests( const expectedResult = namedParamFloat32s.length === 0 ? returnFloat32.value.agentResponseValue - : namedParamFloat32s[0].el.value.agentResponseValue; + : namedParamFloat32s[0].value.value.agentResponseValue; const paramValues = namedParamFloat32s.map( - (paramFloats) => paramFloats.el.value.agentArgumentValue + (paramFloats) => paramFloats.value.value.agentArgumentValue ); return [ [ diff --git a/property_tests/tests/float64/test/generate_tests.ts b/property_tests/tests/float64/test/generate_tests.ts index df02a4eed8..921fb0cba3 100644 --- a/property_tests/tests/float64/test/generate_tests.ts +++ b/property_tests/tests/float64/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamFloat64s.length + 1; const expectedResult = namedParamFloat64s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnFloat64.value.agentResponseValue ) / count; const paramValues = namedParamFloat64s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/func/test/generate_tests.ts b/property_tests/tests/func/test/generate_tests.ts index f5d41447ca..ad13f8691e 100644 --- a/property_tests/tests/func/test/generate_tests.ts +++ b/property_tests/tests/func/test/generate_tests.ts @@ -17,7 +17,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamFuncs.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/init_method/test/generate_tests.ts b/property_tests/tests/init_method/test/generate_tests.ts index 96aad6036b..6228575c15 100644 --- a/property_tests/tests/init_method/test/generate_tests.ts +++ b/property_tests/tests/init_method/test/generate_tests.ts @@ -9,7 +9,7 @@ export function generateTests( ): Test[][] { const expectedResult = [ true, - ...params.map((param) => param.el.value.agentResponseValue) + ...params.map((param) => param.value.value.agentResponseValue) ]; return [ diff --git a/property_tests/tests/init_method/test/test.ts b/property_tests/tests/init_method/test/test.ts index 4b9ce8dadf..9ea7fa6a81 100644 --- a/property_tests/tests/init_method/test/test.ts +++ b/property_tests/tests/init_method/test/test.ts @@ -59,7 +59,7 @@ const CanisterConfigArb = fc CorrespondingJSType > => { const initParamTypes = initMethod.params.map( - (param) => param.el.src.candidTypeObject + (param) => param.value.src.candidTypeObject ); const globalInitVariableNames = initMethod.params.map( @@ -67,7 +67,7 @@ const CanisterConfigArb = fc ); const globalInitVariableDeclarations = initMethod.params.map( (param, i) => - `let initParam${i}: ${param.el.src.candidTypeAnnotation};` + `let initParam${i}: ${param.value.src.candidTypeAnnotation};` ); const globalDeclarations = [ diff --git a/property_tests/tests/int/test/generate_tests.ts b/property_tests/tests/int/test/generate_tests.ts index 82c07b7a5e..f5ee4c664c 100644 --- a/property_tests/tests/int/test/generate_tests.ts +++ b/property_tests/tests/int/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnInt: CandidValueAndMeta ): Test[][] { const expectedResult = namedParamInts.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnInt.value.agentResponseValue ); const paramValues = namedParamInts.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/int16/test/generate_tests.ts b/property_tests/tests/int16/test/generate_tests.ts index e87a8f6414..c71b2e8368 100644 --- a/property_tests/tests/int16/test/generate_tests.ts +++ b/property_tests/tests/int16/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamInt16s.length + 1; const expectedResult = Math.floor( namedParamInt16s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnInt16.value.agentResponseValue ) / count ); const paramValues = namedParamInt16s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/int32/test/generate_tests.ts b/property_tests/tests/int32/test/generate_tests.ts index a8de81c0cb..a26a235294 100644 --- a/property_tests/tests/int32/test/generate_tests.ts +++ b/property_tests/tests/int32/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamInt32s.length + 1; const expectedResult = Math.floor( namedParamInt32s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnInt32.value.agentResponseValue ) / count ); const paramValues = namedParamInt32s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/int64/test/generate_tests.ts b/property_tests/tests/int64/test/generate_tests.ts index dd20871dd6..01edd1730e 100644 --- a/property_tests/tests/int64/test/generate_tests.ts +++ b/property_tests/tests/int64/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamInt64s.length + 1; const expectedResult = namedParamInt64s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnInt64.value.agentResponseValue ) / BigInt(count); const paramValues = namedParamInt64s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ [ diff --git a/property_tests/tests/int8/test/generate_tests.ts b/property_tests/tests/int8/test/generate_tests.ts index dc79248920..b63b263e52 100644 --- a/property_tests/tests/int8/test/generate_tests.ts +++ b/property_tests/tests/int8/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamInt8s.length + 1; const expectedResult = Math.floor( namedParamInt8s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnInt8.value.agentResponseValue ) / count ); const paramValues = namedParamInt8s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ [ diff --git a/property_tests/tests/nat/test/generate_tests.ts b/property_tests/tests/nat/test/generate_tests.ts index 55eb9a3035..98c25e8312 100644 --- a/property_tests/tests/nat/test/generate_tests.ts +++ b/property_tests/tests/nat/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnNat: CandidValueAndMeta ): Test[][] { const expectedResult = namedParamNats.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnNat.value.agentResponseValue ); const paramValues = namedParamNats.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/nat16/test/generate_tests.ts b/property_tests/tests/nat16/test/generate_tests.ts index 6784fd908f..a2919564d7 100644 --- a/property_tests/tests/nat16/test/generate_tests.ts +++ b/property_tests/tests/nat16/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamNat16s.length + 1; const expectedResult = Math.floor( namedParamNat16s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnNat16.value.agentResponseValue ) / count ); const paramValues = namedParamNat16s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/nat32/test/generate_tests.ts b/property_tests/tests/nat32/test/generate_tests.ts index bc3dc80563..7ff0d4244d 100644 --- a/property_tests/tests/nat32/test/generate_tests.ts +++ b/property_tests/tests/nat32/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamNat32s.length + 1; const expectedResult = Math.floor( namedParamNat32s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnNat32.value.agentResponseValue ) / count ); const paramValues = namedParamNat32s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/nat64/test/generate_tests.ts b/property_tests/tests/nat64/test/generate_tests.ts index c2500dffc3..56bc57c16c 100644 --- a/property_tests/tests/nat64/test/generate_tests.ts +++ b/property_tests/tests/nat64/test/generate_tests.ts @@ -10,11 +10,11 @@ export function generateTests( const count = namedParamNat64s.length + 1; const expectedResult = namedParamNat64s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnNat64.value.agentResponseValue ) / BigInt(count); const paramValues = namedParamNat64s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/nat8/test/generate_tests.ts b/property_tests/tests/nat8/test/generate_tests.ts index 4ac73f7d73..fbbf4e7a98 100644 --- a/property_tests/tests/nat8/test/generate_tests.ts +++ b/property_tests/tests/nat8/test/generate_tests.ts @@ -10,12 +10,12 @@ export function generateTests( const count = namedParamNat8s.length + 1; const expectedResult = Math.floor( namedParamNat8s.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnNat8.value.agentResponseValue ) / count ); const paramValues = namedParamNat8s.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/null/test/generate_tests.ts b/property_tests/tests/null/test/generate_tests.ts index 24671f940d..da9350041c 100644 --- a/property_tests/tests/null/test/generate_tests.ts +++ b/property_tests/tests/null/test/generate_tests.ts @@ -16,7 +16,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamNulls.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/opt/test/generate_tests.ts b/property_tests/tests/opt/test/generate_tests.ts index 9bd4f66255..2574e48dd7 100644 --- a/property_tests/tests/opt/test/generate_tests.ts +++ b/property_tests/tests/opt/test/generate_tests.ts @@ -18,7 +18,7 @@ export function generateTests( const actor = getActor(__dirname); const params = namedParamOpts.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); const result = await actor[functionName](...params); diff --git a/property_tests/tests/principal/test/generate_tests.ts b/property_tests/tests/principal/test/generate_tests.ts index a67e9b0e60..aa42fbbc34 100644 --- a/property_tests/tests/principal/test/generate_tests.ts +++ b/property_tests/tests/principal/test/generate_tests.ts @@ -11,7 +11,7 @@ export function generateTests( ): Test[][] { const expectedResult = namedParamPrincipals.length > 0 - ? namedParamPrincipals[0].el.value.agentResponseValue + ? namedParamPrincipals[0].value.value.agentResponseValue : returnPrincipal.value.agentResponseValue; return [ @@ -22,7 +22,7 @@ export function generateTests( const actor = getActor(__dirname); const result = await actor[functionName]( ...namedParamPrincipals.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/query_methods/test/generate_tests.ts b/property_tests/tests/query_methods/test/generate_tests.ts index b12d5b0fdd..038614e43e 100644 --- a/property_tests/tests/query_methods/test/generate_tests.ts +++ b/property_tests/tests/query_methods/test/generate_tests.ts @@ -10,7 +10,7 @@ export function generateTests( returnType: CandidValueAndMeta ): Test[][] { const paramValues = params.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); const expectedResult = returnType.value.agentResponseValue; diff --git a/property_tests/tests/record/test/generate_body.ts b/property_tests/tests/record/test/generate_body.ts index 680ffb535e..63332122f2 100644 --- a/property_tests/tests/record/test/generate_body.ts +++ b/property_tests/tests/record/test/generate_body.ts @@ -10,7 +10,7 @@ export function generateBody( const paramsAreRecords = namedParamRecords .map((param) => { const fieldsCount = Object.keys( - param.el.value.agentArgumentValue + param.value.value.agentArgumentValue ).length; const paramIsObject = `typeof ${param.name} === 'object'`; diff --git a/property_tests/tests/record/test/generate_tests.ts b/property_tests/tests/record/test/generate_tests.ts index 25fe166ea8..3b5bcd1c84 100644 --- a/property_tests/tests/record/test/generate_tests.ts +++ b/property_tests/tests/record/test/generate_tests.ts @@ -17,7 +17,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamRecords.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/service/test/generate_body.ts b/property_tests/tests/service/test/generate_body.ts index 707a43aa89..384cf734de 100644 --- a/property_tests/tests/service/test/generate_body.ts +++ b/property_tests/tests/service/test/generate_body.ts @@ -11,7 +11,7 @@ export function generateBody( .map((param) => { const paramIsAService = `(${ param.name - } as any).principal.toText() === "${param.el.value.agentArgumentValue.toText()}"`; + } as any).principal.toText() === "${param.value.value.agentArgumentValue.toText()}"`; const throwError = `throw new Error('${param.name} must be a Service');`; diff --git a/property_tests/tests/service/test/generate_tests.ts b/property_tests/tests/service/test/generate_tests.ts index e8a927b92b..3ed780de99 100644 --- a/property_tests/tests/service/test/generate_tests.ts +++ b/property_tests/tests/service/test/generate_tests.ts @@ -22,7 +22,7 @@ export function generateTests( const paramsString = namedParamServices .map( (param) => - `service "${param.el.value.agentArgumentValue.toText()}"` + `service "${param.value.value.agentArgumentValue.toText()}"` ) .join(); diff --git a/property_tests/tests/text/test/generate_tests.ts b/property_tests/tests/text/test/generate_tests.ts index 23d5f9d7de..18090ce7cd 100644 --- a/property_tests/tests/text/test/generate_tests.ts +++ b/property_tests/tests/text/test/generate_tests.ts @@ -8,11 +8,11 @@ export function generateTests( returnTexts: CandidValueAndMeta ): Test[][] { const expectedResult = namedParamTexts.reduce( - (acc, param) => acc + param.el.value.agentResponseValue, + (acc, param) => acc + param.value.value.agentResponseValue, returnTexts.value.agentResponseValue ); const paramValues = namedParamTexts.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); return [ diff --git a/property_tests/tests/tuple/test/generate_body.ts b/property_tests/tests/tuple/test/generate_body.ts index 62b5c3a96f..f0558e84f6 100644 --- a/property_tests/tests/tuple/test/generate_body.ts +++ b/property_tests/tests/tuple/test/generate_body.ts @@ -12,7 +12,7 @@ export function generateBody( ): string { const paramsAreTuples = namedParamTuples .map((param) => { - const fieldsCount = param.el.value.agentArgumentValue.length; + const fieldsCount = param.value.value.agentArgumentValue.length; const paramIsArray = `Array.isArray(${param.name})`; const paramHasCorrectNumberOfFields = `${param.name}.length === ${fieldsCount}`; diff --git a/property_tests/tests/tuple/test/generate_tests.ts b/property_tests/tests/tuple/test/generate_tests.ts index 756eeab18e..e0ba2bb7ae 100644 --- a/property_tests/tests/tuple/test/generate_tests.ts +++ b/property_tests/tests/tuple/test/generate_tests.ts @@ -22,7 +22,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamTuples.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/update_methods/test/generate_tests.ts b/property_tests/tests/update_methods/test/generate_tests.ts index 89b0055056..887d1001ba 100644 --- a/property_tests/tests/update_methods/test/generate_tests.ts +++ b/property_tests/tests/update_methods/test/generate_tests.ts @@ -10,7 +10,7 @@ export function generateTests( returnType: CandidValueAndMeta ): Test[][] { const paramValues = params.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); const expectedResult = returnType.value.agentResponseValue; diff --git a/property_tests/tests/variant/test/generate_tests.ts b/property_tests/tests/variant/test/generate_tests.ts index aedf7e9893..700fe5cf93 100644 --- a/property_tests/tests/variant/test/generate_tests.ts +++ b/property_tests/tests/variant/test/generate_tests.ts @@ -19,7 +19,7 @@ export function generateTests( const result = await actor[functionName]( ...namedParamVariants.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ) ); diff --git a/property_tests/tests/vec/test/generate_tests.ts b/property_tests/tests/vec/test/generate_tests.ts index 6b85ec07a4..162e75c72c 100644 --- a/property_tests/tests/vec/test/generate_tests.ts +++ b/property_tests/tests/vec/test/generate_tests.ts @@ -17,7 +17,7 @@ export function generateTests( const actor = getActor(__dirname); const params = namedParamVecs.map( - (param) => param.el.value.agentArgumentValue + (param) => param.value.value.agentArgumentValue ); const result = await actor[functionName](...params); From 9f1de010beb354113c19bfab0c64fbb3cd20af49 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 08:57:45 -0700 Subject: [PATCH 10/16] rename azleCandidType to runtimeCandidType --- .../candid/candid_definition_arb/types.ts | 4 ++-- .../candid/candid_value_and_meta_arb.ts | 4 ++-- .../candid/candid_value_and_meta_arb_generator.ts | 4 ++-- .../candid/constructed/blob_arb/definition_arb.ts | 2 +- .../candid/constructed/opt_arb/definition_arb.ts | 12 +++++++----- .../constructed/record_arb/definition_arb.ts | 9 +++++---- .../constructed/tuple_arb/definition_arb.ts | 11 +++++++---- .../constructed/variant_arb/definition_arbs.ts | 9 +++++---- .../candid/constructed/vec_arb/definition_arb.ts | 12 +++++++----- .../candid/reference/func_arb/definition_arb.ts | 10 +++++----- .../reference/service_arb/definition_arb.ts | 9 +++++---- .../reference/service_arb/service_method_arb.ts | 15 ++++++++------- .../candid_type_to_azle_candid_type.ts | 2 +- .../candid/simple_type_arbs/definition_arb.ts | 7 ++++--- property_tests/arbitraries/canister_arb.ts | 2 +- 15 files changed, 62 insertions(+), 50 deletions(-) diff --git a/property_tests/arbitraries/candid/candid_definition_arb/types.ts b/property_tests/arbitraries/candid/candid_definition_arb/types.ts index 1bf1865b32..83ef8bf79e 100644 --- a/property_tests/arbitraries/candid/candid_definition_arb/types.ts +++ b/property_tests/arbitraries/candid/candid_definition_arb/types.ts @@ -1,6 +1,6 @@ import fc from 'fast-check'; import { CandidType } from '../candid_type'; -import { CandidType as AzleCandidType } from '../../../../src/lib/candid/candid_type'; +import { CandidType as RuntimeCandidType } from '../../../../src/lib/candid/candid_type'; import { ServiceMethodDefinition } from '../reference/service_arb/service_method_arb'; export type CandidDefinitionArb = fc.Arbitrary; @@ -65,7 +65,7 @@ export type ServiceCandidDefinition = { type CandidMeta = { candidTypeAnnotation: string; // Either a type reference or type literal candidTypeObject: string; - azleCandidTypeObject: AzleCandidType; + runtimeCandidTypeObject: RuntimeCandidType; variableAliasDeclarations: string[]; imports: Set; candidType: CandidType; diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts index 9bab7b2f86..d37172a9ce 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts @@ -23,14 +23,14 @@ import { OptArb } from './constructed/opt_arb'; import { VecArb } from './constructed/vec_arb'; import { FuncArb } from './reference/func_arb'; import { CorrespondingJSType } from './corresponding_js_type'; -import { CandidType } from '../../../src/lib'; +import { CandidType as RuntimeCandidType } from '../../../src/lib'; // TODO we're thinking that Candid is not the best name for this. What is better? export type CandidValueAndMeta = { value: { agentArgumentValue: T; agentResponseValue: E; - candidTypeObject: CandidType; + runtimeCandidTypeObject: RuntimeCandidType; }; src: { candidTypeAnnotation: string; diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts index 60c390672d..1434b37a07 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts @@ -20,7 +20,7 @@ export function CandidValueAndMetaArbGenerator< candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports } @@ -38,7 +38,7 @@ export function CandidValueAndMetaArbGenerator< value: { agentArgumentValue, agentResponseValue, - candidTypeObject: azleCandidTypeObject + runtimeCandidTypeObject } }; } diff --git a/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts index 3b18c43098..6f7c593416 100644 --- a/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts @@ -20,7 +20,7 @@ export function _VecNat8DefinitionArb(): fc.Arbitrary { const imports = new Set(['Vec', 'nat8']); return { candidMeta: { - azleCandidTypeObject: blob, + runtimeCandidTypeObject: blob, candidTypeAnnotation, candidTypeObject, variableAliasDeclarations, diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts index e320e55871..1d0a506abb 100644 --- a/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts @@ -28,8 +28,8 @@ export function OptDefinitionArb( innerType ); - const azleCandidTypeObject = - generateAzleCandidTypeObject(innerType); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(innerType); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -43,7 +43,7 @@ export function OptDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Opt' @@ -95,8 +95,10 @@ function generateCandidTypeObject( return `Opt(${innerType.candidMeta.candidTypeObject})`; } -function generateAzleCandidTypeObject(innerType: CandidDefinition): CandidType { - return Opt(innerType.candidMeta.azleCandidTypeObject); +function generateRuntimeCandidTypeObject( + innerType: CandidDefinition +): CandidType { + return Opt(innerType.candidMeta.runtimeCandidTypeObject); } function generateImports(innerType: CandidDefinition): Set { diff --git a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts index 3f52c3b65f..52bc41958f 100644 --- a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts @@ -40,7 +40,8 @@ export function RecordDefinitionArb( fields ); - const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(fields); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -54,7 +55,7 @@ export function RecordDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Record' @@ -105,12 +106,12 @@ function generateCandidTypeObject( .join(',')}})`; } -function generateAzleCandidTypeObject(fields: Field[]): CandidType { +function generateRuntimeCandidTypeObject(fields: Field[]): CandidType { const azleRecordConstructorObj = fields.reduce( (acc, [fieldName, fieldDefinition]): RunTimeRecord => { return { ...acc, - [fieldName]: fieldDefinition.candidMeta.azleCandidTypeObject + [fieldName]: fieldDefinition.candidMeta.runtimeCandidTypeObject }; }, {} diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts index e0291faf81..be168988c4 100644 --- a/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts @@ -31,7 +31,8 @@ export function TupleDefinitionArb( fields ); - const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(fields); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -45,7 +46,7 @@ export function TupleDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Tuple' @@ -102,9 +103,11 @@ function generateCandidTypeObject( return `Tuple(${innerTypes.join(', ')})`; } -function generateAzleCandidTypeObject(fields: CandidDefinition[]): CandidType { +function generateRuntimeCandidTypeObject( + fields: CandidDefinition[] +): CandidType { const innerTypes = fields.map( - (field) => field.candidMeta.azleCandidTypeObject + (field) => field.candidMeta.runtimeCandidTypeObject ); return Tuple(...innerTypes); diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts index 1917ea69da..1aa7f8ff04 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts @@ -35,7 +35,8 @@ export function VariantDefinitionArb( fields ); - const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(fields); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -49,7 +50,7 @@ export function VariantDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Variant' @@ -129,12 +130,12 @@ function generateCandidTypeObject( .join(',')}})`; } -function generateAzleCandidTypeObject(fields: Field[]): CandidType { +function generateRuntimeCandidTypeObject(fields: Field[]): CandidType { const azleVariantConstructorObj = fields.reduce( (acc, [fieldName, fieldDefinition]): RunTimeVariant => { return { ...acc, - [fieldName]: fieldDefinition.candidMeta.azleCandidTypeObject + [fieldName]: fieldDefinition.candidMeta.runtimeCandidTypeObject }; }, {} diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts index 4be3165086..f0304133d5 100644 --- a/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts @@ -28,8 +28,8 @@ export function VecDefinitionArb( innerType ); - const azleCandidTypeObject = - generateAzleCandidTypeObject(innerType); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(innerType); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -43,7 +43,7 @@ export function VecDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Vec' @@ -99,6 +99,8 @@ function generateCandidTypeObject( return `Vec(${innerType.candidMeta.candidTypeObject})`; } -function generateAzleCandidTypeObject(innerType: CandidDefinition): CandidType { - return Vec(innerType.candidMeta.azleCandidTypeObject); +function generateRuntimeCandidTypeObject( + innerType: CandidDefinition +): CandidType { + return Vec(innerType.candidMeta.runtimeCandidTypeObject); } diff --git a/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts index e7cba8de4b..25594b0d5c 100644 --- a/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts @@ -46,7 +46,7 @@ export function FuncDefinitionArb( mode ); - const azleCandidTypeObject = generateAzleCandidTypeObject( + const runtimeCandidTypeObject = generateRuntimeCandidTypeObject( params, returnFunc, mode @@ -72,7 +72,7 @@ export function FuncDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Func' @@ -143,14 +143,14 @@ function generateCandidTypeObject( return `Func([${params}], ${returnCandid.candidMeta.candidTypeObject}, '${mode}')`; } -function generateAzleCandidTypeObject( +function generateRuntimeCandidTypeObject( paramCandids: CandidDefinition[], returnCandid: CandidDefinition, mode: Mode ): CandidType { const params = paramCandids.map( - (param) => param.candidMeta.azleCandidTypeObject + (param) => param.candidMeta.runtimeCandidTypeObject ); - return Func(params, returnCandid.candidMeta.azleCandidTypeObject, mode); + return Func(params, returnCandid.candidMeta.runtimeCandidTypeObject, mode); } diff --git a/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts index d83d2832b5..fe110a81f7 100644 --- a/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts @@ -36,7 +36,8 @@ export function ServiceDefinitionArb( fields ); - const azleCandidTypeObject = generateAzleCandidTypeObject(fields); + const runtimeCandidTypeObject = + generateRuntimeCandidTypeObject(fields); const variableAliasDeclarations = generateVariableAliasDeclarations( useTypeDeclaration, @@ -51,7 +52,7 @@ export function ServiceDefinitionArb( candidMeta: { candidTypeAnnotation, candidTypeObject, - azleCandidTypeObject, + runtimeCandidTypeObject, variableAliasDeclarations, imports, candidType: 'Service' @@ -110,13 +111,13 @@ function generateCandidTypeObject( return `Canister({${methods}})`; } -function generateAzleCandidTypeObject( +function generateRuntimeCandidTypeObject( serviceMethods: ServiceMethodDefinition[] ) { const methods = serviceMethods.reduce((acc, serviceMethod) => { return { ...acc, - [serviceMethod.name]: serviceMethod.azleCandidTypeObject + [serviceMethod.name]: serviceMethod.runtimeCandidTypeObject }; }, {}); diff --git a/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts index a13b2067c1..13ffd63a11 100644 --- a/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts +++ b/property_tests/arbitraries/candid/reference/service_arb/service_method_arb.ts @@ -14,7 +14,7 @@ type Mode = 'query' | 'update'; export type ServiceMethodDefinition = { name: string; - azleCandidTypeObject: CanisterMethodInfo; + runtimeCandidTypeObject: CanisterMethodInfo; imports: Set; variableAliasDeclarations: string[]; src: string; @@ -54,7 +54,7 @@ export function ServiceMethodArb( new Set([mode, ...returnType.candidMeta.imports]) ); - const azleCandidTypeObject = generateAzleCandidTypeObject( + const runtimeCandidTypeObject = generateRuntimeCandidTypeObject( mode, params, returnType @@ -62,24 +62,25 @@ export function ServiceMethodArb( return { name, - azleCandidTypeObject: azleCandidTypeObject, + runtimeCandidTypeObject, imports, - variableAliasDeclarations: variableAliasDeclarations, + variableAliasDeclarations, src }; }); } -function generateAzleCandidTypeObject( +function generateRuntimeCandidTypeObject( mode: Mode, params: CandidDefinition[], returnType: CandidDefinition ) { const queryOrUpdate = mode === 'query' ? query : update; const paramCandidTypeObjects = params.map( - (param) => param.candidMeta.azleCandidTypeObject + (param) => param.candidMeta.runtimeCandidTypeObject ); - const returnCandidTypeObject = returnType.candidMeta.azleCandidTypeObject; + const returnCandidTypeObject = + returnType.candidMeta.runtimeCandidTypeObject; return queryOrUpdate(paramCandidTypeObjects, returnCandidTypeObject); } diff --git a/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts index eea6846607..d22aee0024 100644 --- a/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts +++ b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts @@ -21,7 +21,7 @@ import { } from '../../../../src/lib'; import { SimpleCandidType } from '../candid_type'; -export function candidTypeToAzleCandidType( +export function candidTypeToRuntimeCandidType( candidType: SimpleCandidType ): CandidType { if (candidType === 'blob') { diff --git a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts index f7067c082f..ab9ccfc06e 100644 --- a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts +++ b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts @@ -2,7 +2,7 @@ import fc from 'fast-check'; import { PrimitiveDefinition } from '../candid_definition_arb/types'; import { SimpleCandidType } from '../candid_type'; import { UniqueIdentifierArb } from '../../unique_identifier_arb'; -import { candidTypeToAzleCandidType } from './candid_type_to_azle_candid_type'; +import { candidTypeToRuntimeCandidType } from './candid_type_to_azle_candid_type'; export function SimpleCandidDefinitionArb( candidType: SimpleCandidType @@ -12,7 +12,8 @@ export function SimpleCandidDefinitionArb( .map(([name, useTypeDeclaration]) => { const candidTypeAnnotation = candidType; const candidTypeObject = useTypeDeclaration ? name : candidType; - const azleCandidTypeObject = candidTypeToAzleCandidType(candidType); + const runtimeCandidTypeObject = + candidTypeToRuntimeCandidType(candidType); const imports = new Set([candidType]); const variableAliasDeclarations = generateVariableAliasDeclarations( name, @@ -24,7 +25,7 @@ export function SimpleCandidDefinitionArb( candidTypeAnnotation, candidTypeObject, candidType, - azleCandidTypeObject, + runtimeCandidTypeObject, imports, variableAliasDeclarations } diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 175e690e2b..1d8889a111 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -45,7 +45,7 @@ export function CanisterArb< const value = paramValue.value.value; const candidTypeAnnotation = paramValue.value.src.candidTypeAnnotation; - const paramCandidString = value.candidTypeObject + const paramCandidString = value.runtimeCandidTypeObject .getIdl([]) .valueToString(value.agentArgumentValue); From 86a188d609a56a0a335974c699afcaebdbb2a05a Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 09:28:41 -0700 Subject: [PATCH 11/16] add text value arb constraints --- .../arbitraries/candid/primitive/text.ts | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/property_tests/arbitraries/candid/primitive/text.ts b/property_tests/arbitraries/candid/primitive/text.ts index aa50d5047d..d49c77372a 100644 --- a/property_tests/arbitraries/candid/primitive/text.ts +++ b/property_tests/arbitraries/candid/primitive/text.ts @@ -1,4 +1,4 @@ -import fc from 'fast-check'; +import fc, { StringSharedConstraints } from 'fast-check'; import { stringToSrcLiteral } from '../to_src_literal/string'; import { TextCandidDefinition } from '../candid_definition_arb/types'; import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; @@ -6,15 +6,37 @@ import { SimpleCandidDefinitionArb } from '../simple_type_arbs/definition_arb'; import { CandidValues } from '../candid_values_arb'; import { CandidValueAndMeta } from '../candid_value_and_meta_arb'; import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator'; +import { JsFunctionNameArb } from '../../js_function_name_arb'; -export function TextArb(): fc.Arbitrary> { - return CandidValueAndMetaArbGenerator(TextDefinitionArb(), TextValueArb); +export interface TextConstraints extends StringSharedConstraints { + canStartWithDigit?: boolean; + isJsFunctionName?: boolean; +} + +export function TextArb( + constraints?: TextConstraints +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + TextDefinitionArb(), + TextValueArb, + constraints + ); } export function TextDefinitionArb(): fc.Arbitrary { return SimpleCandidDefinitionArb('text'); } -export function TextValueArb(): fc.Arbitrary> { - return SimpleCandidValuesArb(fc.string(), stringToSrcLiteral); +export function TextValueArb( + _?: TextCandidDefinition, + constraints?: TextConstraints +): fc.Arbitrary> { + const canStartWithDigit = constraints?.canStartWithDigit ?? true; + const isJSName = constraints?.isJsFunctionName ?? false; + const textArb = isJSName + ? JsFunctionNameArb + : fc + .string(constraints) + .filter((string) => canStartWithDigit || /^\d/.test(string)); + return SimpleCandidValuesArb(textArb, stringToSrcLiteral); } From 3f560c85043a89e950def2139b52262bfcc7cb3b Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 09:31:52 -0700 Subject: [PATCH 12/16] add constraints to text arb make sure func names are jsfunction names --- .../candid_value_and_meta_arb_generator.ts | 8 ++++-- .../candid/reference/func_arb/values_arb.ts | 26 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts index 1434b37a07..e26451343f 100644 --- a/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts @@ -10,10 +10,14 @@ export function CandidValueAndMetaArbGenerator< V extends CandidValues >( DefinitionArb: fc.Arbitrary, - ValueArb: (arb: D) => fc.Arbitrary + ValueArb: (arb: D, constraints?: any) => fc.Arbitrary, + valueConstraints?: any ): fc.Arbitrary> { return DefinitionArb.chain((candidDefinition) => - fc.tuple(fc.constant(candidDefinition), ValueArb(candidDefinition)) + fc.tuple( + fc.constant(candidDefinition), + ValueArb(candidDefinition, valueConstraints) + ) ).map( ([ { diff --git a/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts index 649caa5c8b..72423f6e3e 100644 --- a/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts +++ b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts @@ -5,18 +5,20 @@ import { CandidValues } from '../../candid_values_arb'; import { PrincipalArb } from '../principal_arb'; export function FuncValueArb(): fc.Arbitrary> { - return fc.tuple(TextArb(), PrincipalArb()).map(([name, principal]) => { - const value: Func = [ - principal.value.agentArgumentValue, - name.value.agentArgumentValue - ]; + return fc + .tuple(TextArb({ isJsFunctionName: true }), PrincipalArb()) + .map(([name, principal]) => { + const value: Func = [ + principal.value.agentArgumentValue, + name.value.agentArgumentValue + ]; - const valueLiteral = `[${principal.src.valueLiteral}, ${name.src.valueLiteral}]`; + const valueLiteral = `[${principal.src.valueLiteral}, ${name.src.valueLiteral}]`; - return { - valueLiteral, - agentArgumentValue: value, - agentResponseValue: value - }; - }); + return { + valueLiteral, + agentArgumentValue: value, + agentResponseValue: value + }; + }); } From cc1222a8a435e17651bc451813e87fb21b4319b9 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 9 Jan 2024 10:08:31 -0700 Subject: [PATCH 13/16] pr fixes --- .../candid/constructed/record_arb/definition_arb.ts | 4 ++-- .../candid/constructed/variant_arb/definition_arbs.ts | 4 ++-- .../simple_type_arbs/candid_type_to_azle_candid_type.ts | 2 +- .../arbitraries/candid/simple_type_arbs/definition_arb.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts index 52bc41958f..754f8674cf 100644 --- a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts +++ b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts @@ -10,7 +10,7 @@ import { CandidType, Record } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; -type RunTimeRecord = { +type RuntimeRecord = { [key: string]: CandidType; }; @@ -108,7 +108,7 @@ function generateCandidTypeObject( function generateRuntimeCandidTypeObject(fields: Field[]): CandidType { const azleRecordConstructorObj = fields.reduce( - (acc, [fieldName, fieldDefinition]): RunTimeRecord => { + (acc, [fieldName, fieldDefinition]): RuntimeRecord => { return { ...acc, [fieldName]: fieldDefinition.candidMeta.runtimeCandidTypeObject diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts index 1aa7f8ff04..f71d8fd784 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts @@ -9,7 +9,7 @@ import { CandidType, Variant } from '../../../../../src/lib'; type Field = [string, CandidDefinition]; -type RunTimeVariant = { +type RuntimeVariant = { [key: string]: CandidType; }; @@ -132,7 +132,7 @@ function generateCandidTypeObject( function generateRuntimeCandidTypeObject(fields: Field[]): CandidType { const azleVariantConstructorObj = fields.reduce( - (acc, [fieldName, fieldDefinition]): RunTimeVariant => { + (acc, [fieldName, fieldDefinition]): RuntimeVariant => { return { ...acc, [fieldName]: fieldDefinition.candidMeta.runtimeCandidTypeObject diff --git a/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts index d22aee0024..99a87e2d67 100644 --- a/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts +++ b/property_tests/arbitraries/candid/simple_type_arbs/candid_type_to_azle_candid_type.ts @@ -21,7 +21,7 @@ import { } from '../../../../src/lib'; import { SimpleCandidType } from '../candid_type'; -export function candidTypeToRuntimeCandidType( +export function candidTypeToRuntimeCandidTypeObject( candidType: SimpleCandidType ): CandidType { if (candidType === 'blob') { diff --git a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts index ab9ccfc06e..a667beb054 100644 --- a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts +++ b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts @@ -2,7 +2,7 @@ import fc from 'fast-check'; import { PrimitiveDefinition } from '../candid_definition_arb/types'; import { SimpleCandidType } from '../candid_type'; import { UniqueIdentifierArb } from '../../unique_identifier_arb'; -import { candidTypeToRuntimeCandidType } from './candid_type_to_azle_candid_type'; +import { candidTypeToRuntimeCandidTypeObject } from './candid_type_to_azle_candid_type'; export function SimpleCandidDefinitionArb( candidType: SimpleCandidType @@ -13,7 +13,7 @@ export function SimpleCandidDefinitionArb( const candidTypeAnnotation = candidType; const candidTypeObject = useTypeDeclaration ? name : candidType; const runtimeCandidTypeObject = - candidTypeToRuntimeCandidType(candidType); + candidTypeToRuntimeCandidTypeObject(candidType); const imports = new Set([candidType]); const variableAliasDeclarations = generateVariableAliasDeclarations( name, From 8951e69816a98f555ce7a0181ce4f9241e4760f4 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Fri, 12 Jan 2024 15:03:11 -0700 Subject: [PATCH 14/16] more robust solution to escaping strings --- property_tests/arbitraries/canister_arb.ts | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 1d8889a111..5e5af91ea7 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -4,6 +4,11 @@ import { Test } from '../../test'; import { UpdateMethod } from './canister_methods/update_method_arb'; import { InitMethod } from './canister_methods/init_method_arb'; import { CorrespondingJSType } from './candid/corresponding_js_type'; +import { TextClass } from '@dfinity/candid/lib/cjs/idl'; + +TextClass.prototype.valueToString = function (x): string { + return `"${escapeForBash(x)}"`; +}; export type Canister = { deployArgs: string[] | undefined; @@ -41,18 +46,13 @@ export function CanisterArb< ...(config.updateMethods ?? []) ]; - const deployArgs = config.initMethod?.params.map((paramValue) => { - const value = paramValue.value.value; - const candidTypeAnnotation = - paramValue.value.src.candidTypeAnnotation; - const paramCandidString = value.runtimeCandidTypeObject - .getIdl([]) - .valueToString(value.agentArgumentValue); - - return candidTypeAnnotation === 'text' - ? escapeCandidStringForBash(paramCandidString) - : paramCandidString; - }); + const deployArgs = config.initMethod?.params.map( + ({ value: { value } }) => { + return value.runtimeCandidTypeObject + .getIdl([]) + .valueToString(value.agentArgumentValue); + } + ); const sourceCode = generateSourceCode( config.globalDeclarations ?? [], From 6b95dc44eff1e3ccb0244f160c1bfd8a17f781ae Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Fri, 12 Jan 2024 15:41:58 -0700 Subject: [PATCH 15/16] better serialization of number to float32 --- property_tests/arbitraries/canister_arb.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 5e5af91ea7..de5043bea9 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -4,12 +4,24 @@ import { Test } from '../../test'; import { UpdateMethod } from './canister_methods/update_method_arb'; import { InitMethod } from './canister_methods/init_method_arb'; import { CorrespondingJSType } from './candid/corresponding_js_type'; -import { TextClass } from '@dfinity/candid/lib/cjs/idl'; +import { TextClass, FloatClass } from '@dfinity/candid/lib/cjs/idl'; TextClass.prototype.valueToString = function (x): string { return `"${escapeForBash(x)}"`; }; +/** + * If a float doesn't have a decimal it won't serialize properly, so 10 while + * is a float won't serialize unless it's 10.0 + */ +FloatClass.prototype.valueToString = function (x): string { + const floatString = x.toString(); + if (floatString.includes('.')) { + return floatString; + } + return floatString + '.0'; +}; + export type Canister = { deployArgs: string[] | undefined; sourceCode: string; From 19804515b4e720a867942302965c460e57bd95c5 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Fri, 12 Jan 2024 16:25:59 -0700 Subject: [PATCH 16/16] pr fix --- property_tests/arbitraries/canister_arb.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index de5043bea9..33b33a3800 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -6,7 +6,7 @@ import { InitMethod } from './canister_methods/init_method_arb'; import { CorrespondingJSType } from './candid/corresponding_js_type'; import { TextClass, FloatClass } from '@dfinity/candid/lib/cjs/idl'; -TextClass.prototype.valueToString = function (x): string { +TextClass.prototype.valueToString = (x): string => { return `"${escapeForBash(x)}"`; }; @@ -14,7 +14,7 @@ TextClass.prototype.valueToString = function (x): string { * If a float doesn't have a decimal it won't serialize properly, so 10 while * is a float won't serialize unless it's 10.0 */ -FloatClass.prototype.valueToString = function (x): string { +FloatClass.prototype.valueToString = (x): string => { const floatString = x.toString(); if (floatString.includes('.')) { return floatString;