From 12d72062492ec88c752582ee04bfbfd3df2f835c Mon Sep 17 00:00:00 2001 From: Dan Steren Date: Tue, 5 Dec 2023 15:18:54 -0700 Subject: [PATCH] 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 | 36 + property_tests/tests/init_method/test/test.ts | 108 ++ .../tests/init_method/tsconfig.json | 9 + 26 files changed, 1631 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 249faf4730..97186d8191 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, + ParamAgentResponseValue +> = { 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( // TODO solve the underlying principal problem https://github.com/demergent-labs/azle/issues/1443 import { Principal as DfinityPrincipal } from '@dfinity/principal'; + // #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 5e896d5901..c462e809e6 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -13,6 +13,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')) { @@ -30,7 +41,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' }); @@ -61,10 +77,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..07b20f4b79 --- /dev/null +++ b/property_tests/tests/init_method/test/generate_tests.ts @@ -0,0 +1,36 @@ +import { deepEqual } from 'fast-equals'; + +import { 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..2638f0d8bc --- /dev/null +++ b/property_tests/tests/init_method/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "strict": true, + "target": "ES2020", + "moduleResolution": "node", + "allowJs": true, + "outDir": "HACK_BECAUSE_OF_ALLOW_JS" + } +}