diff --git a/property_tests/arbitraries/candid/candid_arb.ts b/property_tests/arbitraries/candid/candid_arb.ts deleted file mode 100644 index 4959b060b4..0000000000 --- a/property_tests/arbitraries/candid/candid_arb.ts +++ /dev/null @@ -1,37 +0,0 @@ -import fc from 'fast-check'; -import { CandidType } from './candid_type_arb'; - -// TODO we're thinking that Candid is not the best name for this. What is better? -export type CandidMeta = { - agentArgumentValue: T; - agentResponseValue: E; - src: Src; -}; - -export type Src = { - candidTypeObject: string; - candidType: string; - typeDeclaration?: string; - imports: Set; - valueLiteral: string; -}; - -export const CandidMetaArb = ( - arb: fc.Arbitrary, - candidTypeObject: string, - candidType: string, - toLiteral: (value: T) => string -) => { - return arb.map( - (agentArgumentValue): CandidMeta => ({ - src: { - candidTypeObject, - candidType, - imports: new Set([candidTypeObject]), - valueLiteral: toLiteral(agentArgumentValue) - }, - agentArgumentValue, - agentResponseValue: agentArgumentValue - }) - ); -}; diff --git a/property_tests/arbitraries/candid/candid_definition_arb/index.ts b/property_tests/arbitraries/candid/candid_definition_arb/index.ts new file mode 100644 index 0000000000..0ac60d9217 --- /dev/null +++ b/property_tests/arbitraries/candid/candid_definition_arb/index.ts @@ -0,0 +1,84 @@ +import fc from 'fast-check'; +import { BoolDefinitionArb } from '../primitive/bool'; +import { Float32DefinitionArb } from '../primitive/floats/float32_arb'; +import { Float64DefinitionArb } from '../primitive/floats/float64_arb'; +import { FuncDefinitionArb } from '../reference/func_arb/definition_arb'; +import { Int16DefinitionArb } from '../primitive/ints/int16_arb'; +import { Int32DefinitionArb } from '../primitive/ints/int32_arb'; +import { Int64DefinitionArb } from '../primitive/ints/int64_arb'; +import { Int8DefinitionArb } from '../primitive/ints/int8_arb'; +import { IntDefinitionArb } from '../primitive/ints/int_arb'; +import { Nat16DefinitionArb } from '../primitive/nats/nat16_arb'; +import { Nat32DefinitionArb } from '../primitive/nats/nat32_arb'; +import { Nat64DefinitionArb } from '../primitive/nats/nat64_arb'; +import { Nat8DefinitionArb } from '../primitive/nats/nat8_arb'; +import { NatDefinitionArb } from '../primitive/nats/nat_arb'; +import { OptDefinitionArb } from '../constructed/opt_arb/definition_arb'; +import { PrincipalDefinitionArb } from '../reference/principal_arb'; +import { RecordDefinitionArb } from '../constructed/record_arb/definition_arb'; +import { TextDefinitionArb } from '../primitive/text'; +import { TupleDefinitionArb } from '../constructed/tuple_arb/definition_arb'; +import { VariantDefinitionArb } from '../constructed/variant_arb/definition_arbs'; +import { VecDefinitionArb } from '../constructed/vec_arb/definition_arb'; +import { + CandidDefinition, + FuncCandidDefinition, + OptCandidDefinition, + RecordCandidDefinition, + TupleCandidDefinition, + VariantCandidDefinition, + VecCandidDefinition +} from './types'; +import { BlobDefinitionArb } from '../constructed/blob_arb/definition_arb'; + +export const CandidDefinitionArb: fc.Arbitrary = fc.letrec( + (tie) => ({ + CandidDefinition: fc.oneof( + BlobDefinitionArb(), + tie('Opt').map((sample) => sample as OptCandidDefinition), + tie('Record').map((sample) => sample as RecordCandidDefinition), + tie('Tuple').map((sample) => sample as TupleCandidDefinition), + tie('Variant').map((sample) => sample as VariantCandidDefinition), + tie('Vec').map((sample) => sample as VecCandidDefinition), + BoolDefinitionArb(), + Float32DefinitionArb(), + Float64DefinitionArb(), + IntDefinitionArb(), + Int8DefinitionArb(), + Int16DefinitionArb(), + Int32DefinitionArb(), + Int64DefinitionArb(), + NatDefinitionArb(), + Nat8DefinitionArb(), + Nat16DefinitionArb(), + Nat32DefinitionArb(), + Nat64DefinitionArb(), + // NullDefinitionArb(), // Must be excluded until https://github.com/demergent-labs/azle/issues/1453 gets resolved + TextDefinitionArb(), + tie('Func').map((sample) => sample as FuncCandidDefinition), + PrincipalDefinitionArb() + // tie('Service').map((sample) => sample as ServiceCandidDefinition) // Services Aren't working with deep equals + ), + Func: FuncDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ), + Opt: OptDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ), + Record: RecordDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ), + // Service: ServiceDefinitionArb( + // tie('CandidDefinition') as fc.Arbitrary + // ), + Tuple: TupleDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ), + Variant: VariantDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ), + Vec: VecDefinitionArb( + tie('CandidDefinition') as fc.Arbitrary + ) + }) +).CandidDefinition; diff --git a/property_tests/arbitraries/candid/candid_definition_arb/types.ts b/property_tests/arbitraries/candid/candid_definition_arb/types.ts new file mode 100644 index 0000000000..4a0637850f --- /dev/null +++ b/property_tests/arbitraries/candid/candid_definition_arb/types.ts @@ -0,0 +1,71 @@ +import { CandidType } from '../candid_type'; + +export type CandidDefinition = + | MultiTypeConstructedDefinition + | SingleTypeConstructedDefinition + | PrimitiveDefinition + | UnnamedMultiTypeConstructedDefinition + | FuncCandidDefinition + | ServiceCandidDefinition; + +export type MultiTypeConstructedDefinition = { + candidMeta: CandidMeta; + innerTypes: [string, CandidDefinition][]; +}; + +export type UnnamedMultiTypeConstructedDefinition = { + candidMeta: CandidMeta; + innerTypes: CandidDefinition[]; +}; + +export type SingleTypeConstructedDefinition = { + candidMeta: CandidMeta; + innerType: CandidDefinition; +}; + +export type PrimitiveDefinition = { + candidMeta: CandidMeta; +}; + +// Constructed +export type OptCandidDefinition = SingleTypeConstructedDefinition; +export type VecCandidDefinition = SingleTypeConstructedDefinition; +export type RecordCandidDefinition = MultiTypeConstructedDefinition; +export type VariantCandidDefinition = MultiTypeConstructedDefinition; +export type TupleCandidDefinition = UnnamedMultiTypeConstructedDefinition; +export type BlobCandidDefinition = PrimitiveDefinition; + +// Primitives +export type FloatCandidDefinition = PrimitiveDefinition; +export type IntCandidDefinition = PrimitiveDefinition; +export type NatCandidDefinition = PrimitiveDefinition; +export type BoolCandidDefinition = PrimitiveDefinition; +export type NullCandidDefinition = PrimitiveDefinition; +export type TextCandidDefinition = PrimitiveDefinition; +export type VoidCandidDefinition = PrimitiveDefinition; + +// Reference +export type FuncCandidDefinition = { + candidMeta: CandidMeta; + paramCandidMeta: CandidDefinition[]; + returnCandidMeta: CandidDefinition; +}; +export type PrincipalCandidDefinition = PrimitiveDefinition; +export type ServiceCandidDefinition = { + name: string; + candidMeta: CandidMeta; + funcs: ServiceMethodDefinition[]; +}; +export type ServiceMethodDefinition = { + name: string; + imports: Set; + typeAliasDeclarations: string[]; + src: string; +}; + +type CandidMeta = { + typeAnnotation: string; // Either a type reference or type literal + typeAliasDeclarations: string[]; + imports: Set; + candidType: CandidType; +}; diff --git a/property_tests/arbitraries/candid/candid_return_type_arb.ts b/property_tests/arbitraries/candid/candid_return_type_arb.ts index 44182006ef..109abe4840 100644 --- a/property_tests/arbitraries/candid/candid_return_type_arb.ts +++ b/property_tests/arbitraries/candid/candid_return_type_arb.ts @@ -1,12 +1,19 @@ import fc from 'fast-check'; -import { CandidMeta } from './candid_arb'; -import { CandidType, CandidTypeArb } from './candid_type_arb'; +import { + CandidValueAndMeta, + CandidValueAndMetaArb +} from './candid_value_and_meta_arb'; import { VoidArb } from './primitive/void'; +import { CorrespondingJSType } from './corresponding_js_type'; -export type CandidReturnType = CandidType | undefined; +export type CandidReturnType = CorrespondingJSType | undefined; -export const CandidReturnTypeArb = fc.oneof( - { arbitrary: CandidTypeArb, weight: 17 }, - { arbitrary: VoidArb, weight: 1 } -) as fc.Arbitrary>; +export function CandidReturnTypeArb(): fc.Arbitrary< + CandidValueAndMeta +> { + return fc.oneof( + { arbitrary: CandidValueAndMetaArb(), weight: 17 }, + { arbitrary: VoidArb(), weight: 1 } + ); +} diff --git a/property_tests/arbitraries/candid/candid_type.ts b/property_tests/arbitraries/candid/candid_type.ts new file mode 100644 index 0000000000..cb8b48a836 --- /dev/null +++ b/property_tests/arbitraries/candid/candid_type.ts @@ -0,0 +1,30 @@ +export type CandidType = ComplexCandidType | SimpleCandidType; + +export type ComplexCandidType = + | 'Func' + | 'Opt' + | 'Record' + | 'Service' + | 'Tuple' + | 'Variant' + | 'Vec'; + +export type SimpleCandidType = + | 'blob' + | 'bool' + | 'float32' + | 'float64' + | 'int' + | 'int16' + | 'int32' + | 'int64' + | 'int8' + | 'nat' + | 'nat16' + | 'nat32' + | 'nat64' + | 'nat8' + | 'Null' + | 'Principal' + | 'text' + | 'Void'; diff --git a/property_tests/arbitraries/candid/candid_type_arb.ts b/property_tests/arbitraries/candid/candid_type_arb.ts deleted file mode 100644 index 26b09856bd..0000000000 --- a/property_tests/arbitraries/candid/candid_type_arb.ts +++ /dev/null @@ -1,106 +0,0 @@ -import fc from 'fast-check'; -import { IntArb } from './primitive/ints/int_arb'; -import { Int8Arb } from './primitive/ints/int8_arb'; -import { Int16Arb } from './primitive/ints/int16_arb'; -import { Int32Arb } from './primitive/ints/int32_arb'; -import { Int64Arb } from './primitive/ints/int64_arb'; -import { NatArb } from './primitive/nats/nat_arb'; -import { Nat8Arb } from './primitive/nats/nat8_arb'; -import { Nat16Arb } from './primitive/nats/nat16_arb'; -import { Nat32Arb } from './primitive/nats/nat32_arb'; -import { Nat64Arb } from './primitive/nats/nat64_arb'; -import { NullArb } from './primitive/null'; -import { BoolArb } from './primitive/bool'; -import { Principal } from '@dfinity/principal'; -import { PrincipalArb } from './reference/principal_arb'; -import { Float32Arb } from './primitive/floats/float32_arb'; -import { Float64Arb } from './primitive/floats/float64_arb'; -import { TextArb } from './primitive/text'; -import { BlobArb } from './constructed/blob_arb'; -import { CandidMeta } from './candid_arb'; -import { Func } from './reference/func_arb'; -import { Opt } from './constructed/opt_arb'; -import { Variant } from './constructed/variant_arb'; -import { BaseVariantArb } from './constructed/variant_arb/base'; -import { Record } from './constructed/record_arb'; -import { Tuple } from './constructed/tuple_arb'; -import { RecordArb } from './constructed/record_arb/base'; -import { TupleArb } from './constructed/tuple_arb/base'; -import { OptArb } from './constructed/opt_arb/base'; -import { Vec, VecArb } from './constructed/vec_arb'; -import { FuncArb } from './reference/func_arb/base'; - -export type CandidType = - | number - | bigint - | null - | boolean - | Principal - | Uint8Array - | string - | Func - | Opt - | Variant - | Record - | Tuple - | undefined - | Int16Array - | Int32Array - | Int8Array - | BigInt64Array - | Uint16Array - | Uint32Array - | Uint8Array - | BigUint64Array - | Vec; - -/** - * An arbitrary representing all possible Candid types. - * - * **Note:** This currently only supports ints, nats, and null arbitraries - */ -export const CandidTypeArb: fc.Arbitrary> = fc.letrec( - (tie) => ({ - CandidType: fc.oneof( - BlobArb, - tie('Opt').map((sample) => sample as CandidMeta), - tie('Record').map((sample) => sample as CandidMeta), - tie('Tuple').map((sample) => sample as CandidMeta), - tie('Variant').map((sample) => sample as CandidMeta), - tie('Vec').map((sample) => sample as CandidMeta), - Float32Arb, - Float64Arb, - IntArb, - Int8Arb, - Int16Arb, - Int32Arb, - Int64Arb, - NatArb, - Nat8Arb, - Nat16Arb, - Nat32Arb, - Nat64Arb, - BoolArb, - NullArb, - TextArb, - tie('Func').map((sample) => sample as CandidMeta), - PrincipalArb - ), - Func: FuncArb( - tie('CandidType') as fc.Arbitrary> - ), - Vec: VecArb, - Opt: OptArb(tie('CandidType') as fc.Arbitrary>), - Variant: BaseVariantArb( - tie('CandidType') as fc.Arbitrary> - ), - Tuple: TupleArb( - tie('CandidType') as fc.Arbitrary> - ), - Record: RecordArb( - tie('CandidType') as fc.Arbitrary> - ) - }) -).CandidType; - -// TODO: This needs to support service. diff --git a/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts new file mode 100644 index 0000000000..db2cc006c2 --- /dev/null +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb.ts @@ -0,0 +1,72 @@ +import fc from 'fast-check'; +import { IntArb } from './primitive/ints/int_arb'; +import { Int8Arb } from './primitive/ints/int8_arb'; +import { Int16Arb } from './primitive/ints/int16_arb'; +import { Int32Arb } from './primitive/ints/int32_arb'; +import { Int64Arb } from './primitive/ints/int64_arb'; +import { NatArb } from './primitive/nats/nat_arb'; +import { Nat8Arb } from './primitive/nats/nat8_arb'; +import { Nat16Arb } from './primitive/nats/nat16_arb'; +import { Nat32Arb } from './primitive/nats/nat32_arb'; +import { Nat64Arb } from './primitive/nats/nat64_arb'; +import { NullArb } from './primitive/null'; +import { BoolArb } from './primitive/bool'; +import { PrincipalArb } from './reference/principal_arb'; +import { Float32Arb } from './primitive/floats/float32_arb'; +import { Float64Arb } from './primitive/floats/float64_arb'; +import { TextArb } from './primitive/text'; +import { BlobArb } from './constructed/blob_arb'; +import { VariantArb } from './constructed/variant_arb'; +import { RecordArb } from './constructed/record_arb'; +import { TupleArb } from './constructed/tuple_arb'; +import { OptArb } from './constructed/opt_arb'; +import { VecArb } from './constructed/vec_arb'; +import { FuncArb } from './reference/func_arb'; +import { CorrespondingJSType } from './corresponding_js_type'; + +// TODO we're thinking that Candid is not the best name for this. What is better? +export type CandidValueAndMeta = { + agentArgumentValue: T; + agentResponseValue: E; + src: { + typeAnnotation: string; + typeAliasDeclarations: string[]; + imports: Set; + valueLiteral: string; + }; +}; + +/** + * An arbitrary representing all possible Candid types. + */ +export function CandidValueAndMetaArb(): fc.Arbitrary< + CandidValueAndMeta +> { + return fc.oneof( + BlobArb(), + OptArb(), + RecordArb(), + TupleArb(), + VariantArb(), + VecArb(), + Float32Arb(), + Float64Arb(), + IntArb(), + Int8Arb(), + Int16Arb(), + Int32Arb(), + Int64Arb(), + NatArb(), + Nat8Arb(), + Nat16Arb(), + Nat32Arb(), + Nat64Arb(), + BoolArb(), + NullArb(), + TextArb(), + FuncArb(), + PrincipalArb() + ); +} + +// TODO: This needs to support service. 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 new file mode 100644 index 0000000000..468bca4820 --- /dev/null +++ b/property_tests/arbitraries/candid/candid_value_and_meta_arb_generator.ts @@ -0,0 +1,36 @@ +import fc from 'fast-check'; +import { CorrespondingJSType } from './corresponding_js_type'; +import { CandidDefinition } from './candid_definition_arb/types'; +import { CandidValueAndMeta } from './candid_value_and_meta_arb'; +import { CandidValues } from './candid_values_arb'; + +export function CandidValueAndMetaArbGenerator< + T extends CorrespondingJSType, + D extends CandidDefinition, + V extends CandidValues +>( + DefinitionArb: fc.Arbitrary, + ValueArb: (arb: D) => fc.Arbitrary +): fc.Arbitrary> { + return DefinitionArb.chain((candidDefinition) => + fc.tuple(fc.constant(candidDefinition), ValueArb(candidDefinition)) + ).map( + ([ + { + candidMeta: { typeAnnotation, typeAliasDeclarations, imports } + }, + { agentArgumentValue, agentResponseValue, valueLiteral } + ]) => { + return { + src: { + typeAnnotation, + typeAliasDeclarations, + imports, + valueLiteral + }, + agentArgumentValue, + agentResponseValue + }; + } + ); +} diff --git a/property_tests/arbitraries/candid/candid_values_arb.ts b/property_tests/arbitraries/candid/candid_values_arb.ts new file mode 100644 index 0000000000..d4ba790994 --- /dev/null +++ b/property_tests/arbitraries/candid/candid_values_arb.ts @@ -0,0 +1,124 @@ +import fc from 'fast-check'; +import { RecordValuesArb } from './constructed/record_arb/values_arb'; +import { BoolValueArb } from './primitive/bool'; +import { VecValuesArb } from './constructed/vec_arb/values_arb'; +import { TextValueArb } from './primitive/text'; +import { NullValueArb } from './primitive/null'; +import { Float32ValueArb } from './primitive/floats/float32_arb'; +import { Float64ValueArb } from './primitive/floats/float64_arb'; +import { IntValueArb } from './primitive/ints/int_arb'; +import { Int8ValueArb } from './primitive/ints/int8_arb'; +import { Int16ValueArb } from './primitive/ints/int16_arb'; +import { Int32ValueArb } from './primitive/ints/int32_arb'; +import { Int64ValueArb } from './primitive/ints/int64_arb'; +import { NatValueArb } from './primitive/nats/nat_arb'; +import { Nat8ValueArb } from './primitive/nats/nat8_arb'; +import { Nat16ValueArb } from './primitive/nats/nat16_arb'; +import { Nat32ValueArb } from './primitive/nats/nat32_arb'; +import { Nat64ValueArb } from './primitive/nats/nat64_arb'; +import { VariantValuesArb } from './constructed/variant_arb/values_arb'; +import { TupleValuesArb } from './constructed/tuple_arb/values_arbs'; +import { OptValuesArb } from './constructed/opt_arb/values_arb'; +import { PrincipalValueArb } from './reference/principal_arb'; +import { FuncValueArb } from './reference/func_arb/values_arb'; +import { VoidValueArb } from './primitive/void'; +import { ServiceValueArb } from './reference/service_arb/values_arb'; +import { + CandidDefinition, + OptCandidDefinition, + RecordCandidDefinition, + ServiceCandidDefinition, + TupleCandidDefinition, + VariantCandidDefinition, + VecCandidDefinition +} from './candid_definition_arb/types'; +import { BlobValuesArb } from './constructed/blob_arb/values_arb'; +import { CorrespondingJSType } from './corresponding_js_type'; + +export type CandidValues = { + agentArgumentValue: T; + agentResponseValue: E; + valueLiteral: string; +}; + +export function CandidValueArb( + candidTypeMeta: CandidDefinition +): fc.Arbitrary> { + const candidType = candidTypeMeta.candidMeta.candidType; + if (candidType === 'blob') { + return BlobValuesArb(); + } + if (candidType === 'Opt') { + return OptValuesArb(candidTypeMeta as OptCandidDefinition); + } + if (candidType === 'Record') { + return RecordValuesArb(candidTypeMeta as RecordCandidDefinition); + } + if (candidType === 'Tuple') { + return TupleValuesArb(candidTypeMeta as TupleCandidDefinition); + } + if (candidType === 'Variant') { + return VariantValuesArb(candidTypeMeta as VariantCandidDefinition); + } + if (candidType === 'Vec') { + return VecValuesArb(candidTypeMeta as VecCandidDefinition); + } + if (candidType === 'bool') { + return BoolValueArb(); + } + if (candidType === 'float32') { + return Float32ValueArb(); + } + if (candidType === 'float64') { + return Float64ValueArb(); + } + if (candidType === 'int') { + return IntValueArb(); + } + if (candidType === 'int8') { + return Int8ValueArb(); + } + if (candidType === 'int16') { + return Int16ValueArb(); + } + if (candidType === 'int32') { + return Int32ValueArb(); + } + if (candidType === 'int64') { + return Int64ValueArb(); + } + if (candidType === 'nat') { + return NatValueArb(); + } + if (candidType === 'nat8') { + return Nat8ValueArb(); + } + if (candidType === 'nat16') { + return Nat16ValueArb(); + } + if (candidType === 'nat32') { + return Nat32ValueArb(); + } + if (candidType === 'nat64') { + return Nat64ValueArb(); + } + if (candidType === 'Null') { + return NullValueArb(); + } + if (candidType === 'text') { + return TextValueArb(); + } + if (candidType === 'Void') { + return VoidValueArb(); + } + if (candidType === 'Func') { + return FuncValueArb(); + } + if (candidType === 'Principal') { + return PrincipalValueArb(); + } + if (candidType === 'Service') { + return ServiceValueArb(candidTypeMeta as ServiceCandidDefinition); + } + throw new Error('Unreachable'); +} diff --git a/property_tests/arbitraries/candid/constructed/blob_arb.ts b/property_tests/arbitraries/candid/constructed/blob_arb.ts deleted file mode 100644 index 59cce4ccb4..0000000000 --- a/property_tests/arbitraries/candid/constructed/blob_arb.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fc from 'fast-check'; -import { CandidMeta, CandidMetaArb } from '../candid_arb'; -import { blobToSrcLiteral } from '../to_src_literal/blob'; - -export const BlobArb = fc - .oneof( - CandidMetaArb( - fc.uint8Array(), - 'Vec(nat8)', - 'Vec', - blobToSrcLiteral - ), - CandidMetaArb(fc.uint8Array(), 'blob', 'blob', blobToSrcLiteral) - ) - .map( - (sample): CandidMeta => ({ - ...sample, - src: { ...sample.src, imports: new Set(['blob', 'nat8', 'Vec']) } - }) - ); diff --git a/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts new file mode 100644 index 0000000000..057ffd622b --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/blob_arb/definition_arb.ts @@ -0,0 +1,28 @@ +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'; + +export function BlobDefinitionArb(): fc.Arbitrary { + return fc.oneof(SimpleCandidDefinitionArb('blob'), _VecNat8DefinitionArb()); +} + +export function _VecNat8DefinitionArb(): fc.Arbitrary { + return fc + .tuple(UniqueIdentifierArb('typeDeclaration'), fc.boolean()) + .map(([name, useTypeDeclaration]): BlobCandidDefinition => { + const typeAnnotation = 'Vec(nat8)'; + const typeAliasDeclarations = useTypeDeclaration + ? [`const ${name} = ${typeAnnotation}`] + : []; + const imports = new Set(['Vec', 'nat8']); + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'blob' + } + }; + }); +} diff --git a/property_tests/arbitraries/candid/constructed/blob_arb/index.ts b/property_tests/arbitraries/candid/constructed/blob_arb/index.ts new file mode 100644 index 0000000000..e8dc86a93f --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/blob_arb/index.ts @@ -0,0 +1,12 @@ +import fc from 'fast-check'; +import { BlobValuesArb } from './values_arb'; +import { BlobDefinitionArb, _VecNat8DefinitionArb } from './definition_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; + +export function BlobArb(): fc.Arbitrary> { + return fc.oneof( + CandidValueAndMetaArbGenerator(_VecNat8DefinitionArb(), BlobValuesArb), + CandidValueAndMetaArbGenerator(BlobDefinitionArb(), BlobValuesArb) + ); +} diff --git a/property_tests/arbitraries/candid/constructed/blob_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/blob_arb/values_arb.ts new file mode 100644 index 0000000000..9cd184272e --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/blob_arb/values_arb.ts @@ -0,0 +1,9 @@ +import fc from 'fast-check'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { blobToSrcLiteral } from '../../to_src_literal/blob'; +import { CandidValues } from '../../candid_values_arb'; +import { _VecNat8DefinitionArb } from './definition_arb'; + +export function BlobValuesArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.uint8Array(), blobToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/base.ts b/property_tests/arbitraries/candid/constructed/opt_arb/base.ts deleted file mode 100644 index bf605ea019..0000000000 --- a/property_tests/arbitraries/candid/constructed/opt_arb/base.ts +++ /dev/null @@ -1,99 +0,0 @@ -import fc from 'fast-check'; -import { CandidType } from '../../candid_type_arb'; -import { CandidMeta } from '../../candid_arb'; -import { Opt } from './index'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; - -type SomeOrNone = 'Some' | 'None'; - -export function OptArb( - candidTypeArb: fc.Arbitrary> -): fc.Arbitrary> { - return fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.constantFrom('Some', 'None') as fc.Arbitrary, - candidTypeArb, - fc.boolean() - ) - .map(([name, someOrNone, innerType, useTypeDeclaration]) => { - const { candidTypeObject, candidType } = useTypeDeclaration - ? { - candidTypeObject: name, - candidType: `typeof ${name}.tsType` - } - : generateCandidType(innerType); - - const typeDeclaration = generateTypeDeclaration( - name, - innerType, - useTypeDeclaration - ); - - return { - src: { - candidTypeObject, - candidType, - imports: generateImports(innerType), - typeDeclaration, - valueLiteral: generateValueLiteral(someOrNone, innerType) - }, - agentArgumentValue: generateValue(someOrNone, innerType), - agentResponseValue: generateValue(someOrNone, innerType, true) - }; - }); -} - -function generateTypeDeclaration( - name: string, - innerType: CandidMeta, - useTypeDeclaration: boolean -) { - if (useTypeDeclaration) { - return `${innerType.src.typeDeclaration ?? ''}\nconst ${name} = ${ - generateCandidType(innerType).candidTypeObject - }`; - } - return innerType.src.typeDeclaration; -} - -function generateCandidType(innerType: CandidMeta): { - candidTypeObject: string; - candidType: string; -} { - return { - candidTypeObject: `Opt(${innerType.src.candidTypeObject})`, - candidType: `Opt<${innerType.src.candidType}>` - }; -} - -function generateImports(innerType: CandidMeta): Set { - return new Set([...innerType.src.imports, 'Opt', 'Some', 'None']); -} - -function generateValue( - someOrNone: SomeOrNone, - innerType: CandidMeta, - useAgentResponseValue: boolean = false -): Opt { - if (someOrNone === 'Some') { - return [ - useAgentResponseValue - ? innerType.agentResponseValue - : innerType.agentArgumentValue - ]; - } else { - return []; - } -} - -function generateValueLiteral( - someOrNone: SomeOrNone, - innerType: CandidMeta -): string { - if (someOrNone === 'Some') { - return `Some(${innerType.src.valueLiteral})`; - } else { - return `None`; - } -} diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts new file mode 100644 index 0000000000..9a948681af --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/opt_arb/definition_arb.ts @@ -0,0 +1,62 @@ +import fc from 'fast-check'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + OptCandidDefinition +} from '../../candid_definition_arb/types'; + +export function OptDefinitionArb( + candidTypeArbForInnerType: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + candidTypeArbForInnerType, + fc.boolean() + ) + .map(([name, innerType, useTypeDeclaration]): OptCandidDefinition => { + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(innerType); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + innerType, + useTypeDeclaration + ); + + const imports = generateImports(innerType); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Opt' + }, + innerType + }; + }); +} + +function generateTypeAliasDeclarations( + name: string, + innerType: CandidDefinition, + useTypeDeclaration: boolean +): string[] { + if (useTypeDeclaration) { + return [ + ...innerType.candidMeta.typeAliasDeclarations, + `const ${name} = ${generateTypeAnnotation(innerType)};` + ]; + } + return innerType.candidMeta.typeAliasDeclarations; +} + +function generateTypeAnnotation(innerType: CandidDefinition): string { + return `Opt(${innerType.candidMeta.typeAnnotation})`; +} + +function generateImports(innerType: CandidDefinition): Set { + return new Set([...innerType.candidMeta.imports, 'Opt', 'Some', 'None']); +} diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/index.ts b/property_tests/arbitraries/candid/constructed/opt_arb/index.ts index c92da68bec..eb732a38a0 100644 --- a/property_tests/arbitraries/candid/constructed/opt_arb/index.ts +++ b/property_tests/arbitraries/candid/constructed/opt_arb/index.ts @@ -1,6 +1,19 @@ -import { CandidType, CandidTypeArb } from '../../candid_type_arb'; -import { OptArb as Base } from './base'; +import fc from 'fast-check'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { OptDefinitionArb } from './definition_arb'; +import { OptValuesArb } from './values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CorrespondingJSType } from '../../corresponding_js_type'; -export type Opt = [CandidType] | never[]; +export type Opt = [CorrespondingJSType] | never[]; -export const OptArb = Base(CandidTypeArb); +export function OptArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + OptDefinitionArb(candidDefinitionArb), + OptValuesArb + ); +} diff --git a/property_tests/arbitraries/candid/constructed/opt_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/opt_arb/values_arb.ts new file mode 100644 index 0000000000..6fe6c9a4a4 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/opt_arb/values_arb.ts @@ -0,0 +1,55 @@ +import fc from 'fast-check'; +import { Opt } from '.'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { OptCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues, CandidValueArb } from '../../candid_values_arb'; + +type SomeOrNone = 'Some' | 'None'; + +export function OptValuesArb( + optDefinition: OptCandidDefinition +): fc.Arbitrary> { + const innerValue = fc.tuple( + fc.constantFrom('Some', 'None') as fc.Arbitrary, + CandidValueArb(optDefinition.innerType) + ); + + return innerValue.map(([someOrNone, innerType]) => { + const valueLiteral = generateValueLiteral(someOrNone, innerType); + const agentArgumentValue = generateValue(someOrNone, innerType); + const agentResponseValue = generateValue(someOrNone, innerType, true); + + return { + valueLiteral, + agentArgumentValue, + agentResponseValue + }; + }); +} + +function generateValue( + someOrNone: SomeOrNone, + innerType: CandidValues, + useAgentResponseValue: boolean = false +): Opt { + if (someOrNone === 'Some') { + return [ + useAgentResponseValue + ? innerType.agentResponseValue + : innerType.agentArgumentValue + ]; + } else { + return []; + } +} + +function generateValueLiteral( + someOrNone: SomeOrNone, + innerType: CandidValues +): string { + if (someOrNone === 'Some') { + return `Some(${innerType.valueLiteral})`; + } else { + return `None`; + } +} diff --git a/property_tests/arbitraries/candid/constructed/record_arb/base.ts b/property_tests/arbitraries/candid/constructed/record_arb/base.ts deleted file mode 100644 index e7d383d3f2..0000000000 --- a/property_tests/arbitraries/candid/constructed/record_arb/base.ts +++ /dev/null @@ -1,125 +0,0 @@ -import fc from 'fast-check'; - -import { CandidMeta } from '../../candid_arb'; -import { CandidType } from '../../candid_type_arb'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; -import { JsFunctionNameArb } from '../../../js_function_name_arb'; -import { Record } from './index'; - -type Field = [string, CandidMeta]; - -export function RecordArb(candidTypeArb: fc.Arbitrary>) { - return fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.uniqueArray(fc.tuple(JsFunctionNameArb, candidTypeArb), { - selector: (entry) => entry[0] - }), - fc.boolean() - ) - .map(([name, fields, useTypeDeclaration]): CandidMeta => { - const { candidTypeObject, candidType } = useTypeDeclaration - ? { - candidTypeObject: name, - candidType: `typeof ${name}.tsType` - } - : generateCandidType(fields); - - const typeDeclaration = generateTypeDeclaration( - name, - fields, - useTypeDeclaration - ); - - const imports = generateImports(fields); - - const valueLiteral = generateValueLiteral(fields); - - const agentArgumentValue = generateValue(fields); - - const agentResponseValue = generateValue(fields, true); - - return { - src: { - candidTypeObject, - candidType, - typeDeclaration, - imports, - valueLiteral - }, - agentArgumentValue, - agentResponseValue - }; - }); -} - -function generateImports(fields: Field[]): Set { - const fieldImports = fields.flatMap((field) => [...field[1].src.imports]); - return new Set([...fieldImports, 'Record']); -} - -function generateCandidType(fields: Field[]): { - candidTypeObject: string; - candidType: string; -} { - return { - candidTypeObject: `Record({${fields - .map( - ([fieldName, fieldDataType]) => - `${fieldName}: ${fieldDataType.src.candidTypeObject}` - ) - .join(',')}})`, - candidType: `{${fields - .map( - ([fieldName, fieldDataType]) => - `${fieldName}: ${fieldDataType.src.candidType}` - ) - .join(',')}}` - }; -} - -function generateTypeDeclaration( - name: string, - fields: Field[], - useTypeDeclaration: boolean -): string { - const fieldTypeDeclarations = fields - .map((field) => field[1].src.typeDeclaration) - .join('\n'); - if (useTypeDeclaration) { - return `${fieldTypeDeclarations}\nconst ${name} = ${ - generateCandidType(fields).candidTypeObject - };`; - } - return fieldTypeDeclarations; -} - -function generateValue(fields: Field[], returned: boolean = false): Record { - return fields.length === 0 - ? {} - : fields.reduce((record, [fieldName, fieldDataType]) => { - return { - ...record, - [fieldName]: returned - ? fieldDataType.agentResponseValue - : fieldDataType.agentArgumentValue - }; - }, {}); -} - -function generateValueLiteral(fields: Field[]): string { - if (fields.length === 0) { - return '{}'; - } - - const fieldLiterals = fields - .map( - ([fieldName, fieldValue]) => - `${fieldName}: ${fieldValue.src.valueLiteral}` - ) - .join(',\n'); - - return `{ - ${fieldLiterals} - }`; -} diff --git a/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts new file mode 100644 index 0000000000..94083842b9 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/record_arb/definition_arb.ts @@ -0,0 +1,80 @@ +import fc from 'fast-check'; +import { JsFunctionNameArb } from '../../../js_function_name_arb'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + RecordCandidDefinition +} from '../../candid_definition_arb/types'; + +type Field = [string, CandidDefinition]; + +export function RecordDefinitionArb( + fieldCandidDefArb: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + fc.uniqueArray(fc.tuple(JsFunctionNameArb, fieldCandidDefArb), { + selector: ([name, _]) => name, + minLength: 1 // Zero length records are giving that same null error 'vec length of zero sized values too large' // I don't know if that's the same error but it seems like it is + // https://github.com/demergent-labs/azle/issues/1453 + }), + fc.boolean() + ) + .map(([name, fields, useTypeDeclaration]): RecordCandidDefinition => { + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(fields); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + fields, + useTypeDeclaration + ); + + const imports = generateImports(fields); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Record' + }, + innerTypes: fields + }; + }); +} + +function generateImports(fields: Field[]): Set { + const fieldImports = fields.flatMap((field) => [ + ...field[1].candidMeta.imports + ]); + return new Set([...fieldImports, 'Record']); +} + +function generateTypeAnnotation(fields: Field[]): string { + return `Record({${fields + .map( + ([fieldName, fieldDefinition]) => + `${fieldName}: ${fieldDefinition.candidMeta.typeAnnotation}` + ) + .join(',')}})`; +} + +function generateTypeAliasDeclarations( + name: string, + fields: Field[], + useTypeDeclaration: boolean +): string[] { + const fieldTypeAliasDeclarations = fields.flatMap( + (field) => field[1].candidMeta.typeAliasDeclarations + ); + if (useTypeDeclaration) { + return [ + ...fieldTypeAliasDeclarations, + `const ${name} = ${generateTypeAnnotation(fields)};` + ]; + } + return fieldTypeAliasDeclarations; +} diff --git a/property_tests/arbitraries/candid/constructed/record_arb/index.ts b/property_tests/arbitraries/candid/constructed/record_arb/index.ts index 93db47cd24..937e9e3aac 100644 --- a/property_tests/arbitraries/candid/constructed/record_arb/index.ts +++ b/property_tests/arbitraries/candid/constructed/record_arb/index.ts @@ -1,8 +1,22 @@ -import { CandidType, CandidTypeArb } from '../../candid_type_arb'; -import { RecordArb as Base } from './base'; +import fc from 'fast-check'; + +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { RecordDefinitionArb } from './definition_arb'; +import { RecordValuesArb } from './values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { CandidDefinitionArb } from '../../candid_definition_arb'; export type Record = { - [x: string]: CandidType; + [x: string]: CorrespondingJSType; }; -export const RecordArb = Base(CandidTypeArb); +export function RecordArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + RecordDefinitionArb(candidDefinitionArb), + RecordValuesArb + ); +} diff --git a/property_tests/arbitraries/candid/constructed/record_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/record_arb/values_arb.ts new file mode 100644 index 0000000000..ece496386d --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/record_arb/values_arb.ts @@ -0,0 +1,62 @@ +import fc from 'fast-check'; +import { Record } from './index'; +import { RecordCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues, CandidValueArb } from '../../candid_values_arb'; +import { CorrespondingJSType } from '../../corresponding_js_type'; + +type Field = [string, CandidValues]; +type ArbField = [string, fc.Arbitrary>]; + +export function RecordValuesArb( + recordDefinition: RecordCandidDefinition +): fc.Arbitrary> { + const fieldValues = recordDefinition.innerTypes.map(([name, innerType]) => { + const result: ArbField = [name, CandidValueArb(innerType)]; + return result; + }); + const arbitraryFieldValues = fieldValues.map(([key, arbValue]) => + arbValue.map((value): Field => [key, value]) + ); + + return fc.tuple(...arbitraryFieldValues).map((fieldValues) => { + const valueLiteral = generateValueLiteral(fieldValues); + const agentArgumentValue = generateValue(fieldValues); + const agentResponseValue = generateValue(fieldValues, true); + + return { + valueLiteral, + agentArgumentValue, + agentResponseValue + }; + }); +} + +function generateValue(fields: Field[], returned: boolean = false): Record { + return fields.length === 0 + ? {} + : fields.reduce((record, [fieldName, fieldCandidValues]) => { + return { + ...record, + [fieldName]: returned + ? fieldCandidValues.agentResponseValue + : fieldCandidValues.agentArgumentValue + }; + }, {}); +} + +function generateValueLiteral(fields: Field[]): string { + if (fields.length === 0) { + return '{}'; + } + + const fieldLiterals = fields + .map( + ([fieldName, fieldCandidValues]) => + `${fieldName}: ${fieldCandidValues.valueLiteral}` + ) + .join(',\n'); + + return `{ + ${fieldLiterals} + }`; +} diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/base.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/base.ts deleted file mode 100644 index d5c6765f69..0000000000 --- a/property_tests/arbitraries/candid/constructed/tuple_arb/base.ts +++ /dev/null @@ -1,113 +0,0 @@ -import fc from 'fast-check'; - -import { CandidMeta } from '../../candid_arb'; -import { CandidType } from '../../candid_type_arb'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; -import { ReturnTuple, Tuple } from './index'; - -export function TupleArb(candidTypeArb: fc.Arbitrary>) { - return fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.array(candidTypeArb, { - minLength: 1 - }), - fc.boolean() - ) - .map( - ([name, fields, useTypeDeclaration]): CandidMeta< - Tuple, - ReturnTuple - > => { - const { candidTypeObject, candidType } = useTypeDeclaration - ? { - candidTypeObject: name, - candidType: `typeof ${name}.tsType` - } - : generateCandidType(fields); - - const typeDeclaration = generateTypeDeclaration( - name, - fields, - useTypeDeclaration - ); - - const imports = generateImports(fields); - - const valueLiteral = generateValueLiteral(fields); - - const agentArgumentValue = generateVale(fields); - - const agentResponseValue = generateExpectedValue(fields); - - return { - src: { - candidTypeObject, - candidType, - typeDeclaration, - imports, - valueLiteral - }, - agentArgumentValue, - agentResponseValue - }; - } - ); -} - -function generateVale(fields: CandidMeta[]) { - return fields.map((field) => field.agentArgumentValue); -} - -function generateExpectedValue(fields: CandidMeta[]): ReturnTuple { - if (fields.length === 0) { - return {}; - } - return fields.map((field) => field.agentResponseValue); -} - -function generateTypeDeclaration( - name: string, - fields: CandidMeta[], - useTypeDeclaration: boolean -): string { - const fieldTypeDeclarations = fields - .map((field) => field.src.typeDeclaration) - .join('\n'); - if (useTypeDeclaration) { - return `${fieldTypeDeclarations}\nconst ${name} = ${ - generateCandidType(fields).candidTypeObject - };`; - } - return fieldTypeDeclarations; -} - -function generateCandidType(fields: CandidMeta[]): { - candidTypeObject: string; - candidType: string; -} { - const innerCandidTypeObjects = fields.map( - (field) => field.src.candidTypeObject - ); - const innerCandidTypes = fields.map((field) => field.src.candidType); - - return { - candidTypeObject: `Tuple(${innerCandidTypeObjects.join(', ')})`, - candidType: `Tuple<[${innerCandidTypes.join(', ')}]>` - }; -} - -function generateImports(fields: CandidMeta[]): Set { - const fieldImports = fields.flatMap((field) => [...field.src.imports]); - return new Set([...fieldImports, 'Tuple']); -} - -function generateValueLiteral(fields: CandidMeta[]) { - const fieldLiterals = fields - .map((field) => field.src.valueLiteral) - .join(',\n'); - - return `[ - ${fieldLiterals} - ]`; -} diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts new file mode 100644 index 0000000000..6a6c8acd56 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/tuple_arb/definition_arb.ts @@ -0,0 +1,73 @@ +import fc from 'fast-check'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + TupleCandidDefinition +} from '../../candid_definition_arb/types'; + +export function TupleDefinitionArb( + candidTypeArbForFields: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + fc.array(candidTypeArbForFields, { minLength: 1 }), + // Although no minLength is technically required (according to the + // spec), there are some issues with vecs of empty objects that are causing some problems + // https://github.com/demergent-labs/azle/issues/1453 + fc.boolean() + ) + .map(([name, fields, useTypeDeclaration]): TupleCandidDefinition => { + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(fields); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + fields, + useTypeDeclaration + ); + + const imports = generateImports(fields); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Tuple' + }, + innerTypes: fields + }; + }); +} + +function generateTypeAliasDeclarations( + name: string, + fields: CandidDefinition[], + useTypeDeclaration: boolean +): string[] { + const fieldTypeAliasDeclarations = fields.flatMap( + (field) => field.candidMeta.typeAliasDeclarations + ); + if (useTypeDeclaration) { + return [ + ...fieldTypeAliasDeclarations, + `const ${name} = ${generateTypeAnnotation(fields)};` + ]; + } + return fieldTypeAliasDeclarations; +} + +function generateTypeAnnotation(fields: CandidDefinition[]) { + const innerTypes = fields.map((field) => field.candidMeta.typeAnnotation); + + return `Tuple(${innerTypes.join(', ')})`; +} + +function generateImports(fields: CandidDefinition[]): Set { + const fieldImports = fields.flatMap((field) => [ + ...field.candidMeta.imports + ]); + return new Set([...fieldImports, 'Tuple']); +} diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/index.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/index.ts index 7b32141484..1f4b0e952d 100644 --- a/property_tests/arbitraries/candid/constructed/tuple_arb/index.ts +++ b/property_tests/arbitraries/candid/constructed/tuple_arb/index.ts @@ -1,7 +1,20 @@ -import { CandidType, CandidTypeArb } from '../../candid_type_arb'; -import { TupleArb as Base } from './base'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { TupleDefinitionArb } from './definition_arb'; +import { TupleValuesArb } from './values_arbs'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import fc from 'fast-check'; -export type Tuple = CandidType[]; +export type Tuple = CorrespondingJSType[]; export type ReturnTuple = Tuple | {}; -export const TupleArb = Base(CandidTypeArb); +export function TupleArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + TupleDefinitionArb(candidDefinitionArb), + TupleValuesArb + ); +} diff --git a/property_tests/arbitraries/candid/constructed/tuple_arb/values_arbs.ts b/property_tests/arbitraries/candid/constructed/tuple_arb/values_arbs.ts new file mode 100644 index 0000000000..6e23b01fcf --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/tuple_arb/values_arbs.ts @@ -0,0 +1,50 @@ +import fc from 'fast-check'; +import { Tuple, ReturnTuple } from '.'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { TupleCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues, CandidValueArb } from '../../candid_values_arb'; + +export function TupleValuesArb( + tupleDefinition: TupleCandidDefinition +): fc.Arbitrary> { + const fieldValues = tupleDefinition.innerTypes.map((innerType) => { + const result: fc.Arbitrary> = + CandidValueArb(innerType); + return result; + }); + + return fc.tuple(...fieldValues).map((fieldValues) => { + const valueLiteral = generateValueLiteral(fieldValues); + const agentArgumentValue = generateAgentArgumentValue(fieldValues); + const agentResponseValue = generateAgentResponseValue(fieldValues); + + return { + valueLiteral, + agentArgumentValue, + agentResponseValue + }; + }); +} + +function generateAgentArgumentValue( + fields: CandidValues[] +): Tuple { + return fields.map((field) => field.agentArgumentValue); +} + +function generateAgentResponseValue( + fields: CandidValues[] +): ReturnTuple { + if (fields.length === 0) { + return {}; + } + return fields.map((field) => field.agentResponseValue); +} + +function generateValueLiteral(fields: CandidValues[]) { + const fieldLiterals = fields.map((field) => field.valueLiteral).join(',\n'); + + return `[ + ${fieldLiterals} + ]`; +} diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/base.ts b/property_tests/arbitraries/candid/constructed/variant_arb/base.ts deleted file mode 100644 index 95d6a5021f..0000000000 --- a/property_tests/arbitraries/candid/constructed/variant_arb/base.ts +++ /dev/null @@ -1,143 +0,0 @@ -import fc from 'fast-check'; -import { CandidMeta } from '../../candid_arb'; -import { CandidType } from '../../candid_type_arb'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; -import { JsFunctionNameArb } from '../../../js_function_name_arb'; -import { Variant } from '.'; - -type Field = [string, CandidMeta]; - -function VariantFieldsArb( - candidTypeArb: fc.Arbitrary> -): fc.Arbitrary { - return fc.uniqueArray(fc.tuple(JsFunctionNameArb, candidTypeArb), { - selector: (entry) => entry[0], - minLength: 1 - // Although no minLength is technically required (according to the - // spec), the DFX CLI itself currently errors out trying to pass - // an empty object. - }); -} - -export function BaseVariantArb( - candidTypeArb: fc.Arbitrary> -): fc.Arbitrary> { - return fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - VariantFieldsArb(candidTypeArb), - fc.boolean() - ) - .map(([name, fields, useTypeDeclaration]): CandidMeta => { - const randomIndex = Math.floor(Math.random() * fields.length); - - const { candidTypeObject, candidType } = useTypeDeclaration - ? { - candidTypeObject: name, - candidType: `typeof ${name}.tsType` - } - : generateCandidType(fields); - - const typeDeclaration = generateTypeDeclaration( - name, - fields, - useTypeDeclaration - ); - - const imports = generateImports(fields); - - const valueLiteral = generateValueLiteral(randomIndex, fields); - - const agentArgumentValue = generateValue(randomIndex, fields); - - const agentResponseValue = generateValue(randomIndex, fields, true); - - return { - src: { - candidTypeObject, - candidType, - typeDeclaration, - imports, - valueLiteral - }, - agentArgumentValue, - agentResponseValue - }; - }); -} - -function generateImports(fields: Field[]): Set { - const fieldImports = fields.flatMap((field) => [...field[1].src.imports]); - return new Set([...fieldImports, 'Variant', 'RequireExactlyOne']); -} - -function generateTypeDeclaration( - name: string, - fields: Field[], - useTypeDeclaration: boolean -): string { - const fieldTypeDeclarations = fields - .map((field) => field[1].src.typeDeclaration) - .join('\n'); - if (useTypeDeclaration) { - return `${fieldTypeDeclarations}\nconst ${name} = ${ - generateCandidType(fields).candidTypeObject - };`; - } - return fieldTypeDeclarations; -} - -function generateCandidType(fields: Field[]): { - candidTypeObject: string; - candidType: string; -} { - return { - candidTypeObject: `Variant({${fields - .map( - ([fieldName, fieldDataType]) => - `${fieldName}: ${fieldDataType.src.candidTypeObject}` - ) - .join(',')}})`, - candidType: `RequireExactlyOne<{${fields - .map( - ([fieldName, fieldDataType]) => - `${fieldName}: ${fieldDataType.src.candidType}` - ) - .join(',')}}>` - }; -} - -function generateValue( - index: number, - fields: Field[], - returned: boolean = false -): Variant { - if (fields.length === 0) { - return {}; - } - const [ - randomFieldName, - { - agentArgumentValue: randomFieldValue, - agentResponseValue: randomFieldExpectedValue - } - ] = fields[index]; - - return { - [randomFieldName]: returned - ? randomFieldExpectedValue - : randomFieldValue - }; -} - -function generateValueLiteral(index: number, fields: Field[]): string { - if (fields.length === 0) { - return '{}'; - } - - const [fieldName, fieldValue] = fields[index]; - - return `{ - ${fieldName}: ${fieldValue.src.valueLiteral} - }`; -} diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts new file mode 100644 index 0000000000..da9efa7b52 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/variant_arb/definition_arbs.ts @@ -0,0 +1,88 @@ +import fc from 'fast-check'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + VariantCandidDefinition +} from '../../candid_definition_arb/types'; +import { JsFunctionNameArb } from '../../../js_function_name_arb'; + +type Field = [string, CandidDefinition]; + +export function VariantDefinitionArb( + candidTypeArbForFields: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + VariantFieldsArb(candidTypeArbForFields), + fc.boolean() + ) + .map(([name, fields, useTypeDeclaration]): VariantCandidDefinition => { + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(fields); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + fields, + useTypeDeclaration + ); + + const imports = generateImports(fields); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Variant' + }, + innerTypes: fields + }; + }); +} + +function VariantFieldsArb( + candidTypeArb: fc.Arbitrary +): fc.Arbitrary { + return fc.uniqueArray(fc.tuple(JsFunctionNameArb, candidTypeArb), { + selector: ([name, _]) => name, + minLength: 1 + // Although no minLength is technically required (according to the + // spec), the DFX CLI itself currently errors out trying to pass + // an empty object. + }); +} + +function generateImports(fields: Field[]): Set { + const fieldImports = fields.flatMap((field) => [ + ...field[1].candidMeta.imports + ]); + return new Set([...fieldImports, 'Variant']); +} + +function generateTypeAliasDeclarations( + name: string, + fields: Field[], + useTypeDeclaration: boolean +): string[] { + const fieldTypeDeclarations = fields.flatMap( + (field) => field[1].candidMeta.typeAliasDeclarations + ); + if (useTypeDeclaration) { + return [ + ...fieldTypeDeclarations, + `const ${name} = ${generateTypeAnnotation(fields)};` + ]; + } + return fieldTypeDeclarations; +} + +function generateTypeAnnotation(fields: Field[]): string { + return `Variant({${fields + .map( + ([fieldName, fieldDataType]) => + `${fieldName}: ${fieldDataType.candidMeta.typeAnnotation}` + ) + .join(',')}})`; +} diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/index.ts b/property_tests/arbitraries/candid/constructed/variant_arb/index.ts index d4a5ee7ebb..0f93c527a6 100644 --- a/property_tests/arbitraries/candid/constructed/variant_arb/index.ts +++ b/property_tests/arbitraries/candid/constructed/variant_arb/index.ts @@ -1,8 +1,22 @@ -import { CandidType, CandidTypeArb } from '../../candid_type_arb'; -import { BaseVariantArb } from './base'; +import fc from 'fast-check'; + +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { VariantDefinitionArb } from './definition_arbs'; +import { VariantValuesArb } from './values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; export type Variant = { - [x: string]: CandidType; + [x: string]: CorrespondingJSType; }; -export const VariantArb = BaseVariantArb(CandidTypeArb); +export function VariantArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + VariantDefinitionArb(candidDefinitionArb), + VariantValuesArb + ); +} diff --git a/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts new file mode 100644 index 0000000000..dcef8de1e7 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/variant_arb/values_arb.ts @@ -0,0 +1,56 @@ +import fc from 'fast-check'; +import { Variant } from '.'; +import { VariantCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues, CandidValueArb } from '../../candid_values_arb'; +import { CorrespondingJSType } from '../../corresponding_js_type'; + +type Field = [string, CandidValues]; + +export function VariantValuesArb( + variantDefinition: VariantCandidDefinition +): fc.Arbitrary> { + if (variantDefinition.innerTypes.length === 0) { + return fc.constant({ + valueLiteral: '{}', + agentArgumentValue: {}, + agentResponseValue: {} + }); + } + const randomIndex = Math.floor( + Math.random() * variantDefinition.innerTypes.length + ); + + const [name, innerType] = variantDefinition.innerTypes[randomIndex]; + + const fieldValue = CandidValueArb(innerType).map((values): Field => { + return [name, values]; + }); + + return fieldValue.map((fieldValues) => { + const valueLiteral = generateValueLiteral(fieldValues); + const agentArgumentValue = generateValue(fieldValues); + const agentResponseValue = generateValue(fieldValues, true); + + return { + valueLiteral, + agentArgumentValue, + agentResponseValue + }; + }); +} + +function generateValue(field: Field, returned: boolean = false): Variant { + const [fieldName, { agentArgumentValue, agentResponseValue }] = field; + + return { + [fieldName]: returned ? agentResponseValue : agentArgumentValue + }; +} + +function generateValueLiteral(field: Field): string { + const [fieldName, fieldValue] = field; + + return `{ + ${fieldName}: ${fieldValue.valueLiteral} + }`; +} diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/base.ts b/property_tests/arbitraries/candid/constructed/vec_arb/base.ts deleted file mode 100644 index 115c501903..0000000000 --- a/property_tests/arbitraries/candid/constructed/vec_arb/base.ts +++ /dev/null @@ -1,236 +0,0 @@ -import fc, { sample } from 'fast-check'; -import { CandidMeta, Src } from '../../candid_arb'; -import { CandidType } from '../../candid_type_arb'; -import { Vec } from './index'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; - -export function VecInnerArb( - arb: fc.Arbitrary> -): fc.Arbitrary> { - return fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.array(arb), - arb, - fc.boolean() - ) - .map( - ([ - name, - vecOfInnerType, - { src: innerTypeSrc }, - useTypeDeclaration - ]): CandidMeta => { - const valueLiteral = generateValueLiteral( - vecOfInnerType, - innerTypeSrc.candidTypeObject - ); - const { candidTypeObject, candidType } = useTypeDeclaration - ? { - candidTypeObject: name, - candidType: `typeof ${name}.tsType` - } - : generateCandidType(innerTypeSrc); - - const imports = generateImports(innerTypeSrc); - - const typeDeclaration = generateTypeDeclaration( - name, - innerTypeSrc, - useTypeDeclaration - ); - - const agentArgumentValue = generateValue( - vecOfInnerType, - innerTypeSrc.candidTypeObject - ); - - const agentResponseValue = generateValue( - vecOfInnerType, - innerTypeSrc.candidTypeObject - ); - - return { - agentArgumentValue, - agentResponseValue, - src: { - candidTypeObject, - candidType, - imports, - typeDeclaration, - valueLiteral - } - }; - } - ); -} - -// Exploration for making VecArb use CandidTypeArb -// export function VecArb( -// candidTypeArb: fc.Arbitrary> -// ): fc.Arbitrary> { -// candidTypeArb.chain((innerType) => { -// return fc.array(fc.constant(innerType)); -// }); -// return fc -// .tuple( -// UniqueIdentifierArb('typeDeclaration'), -// fc.array(candidTypeArb), -// fc.boolean() -// ) -// .map(([name, innerType, useTypeDeclaration]) => { -// const candidType = useTypeDeclaration -// ? name -// : generateCandidType(innerType); - -// const imports = generateImports(innerType); - -// const typeDeclaration = generateTypeDeclaration( -// name, -// innerType, -// useTypeDeclaration -// ); - -// const valueLiteral = generateValueLiteral(innerType); - -// return { -// src: { -// candidType, -// imports, -// typeDeclaration, -// valueLiteral -// }, -// value, -// expectedValue -// }; -// }); -// } - -function generateTypeDeclaration( - name: string, - innerTypeSrc: Src, - useTypeDeclaration: boolean -) { - if (useTypeDeclaration) { - return `${innerTypeSrc.typeDeclaration ?? ''}\nconst ${name} = ${ - generateCandidType(innerTypeSrc).candidTypeObject - }`; - } - return innerTypeSrc.typeDeclaration; -} - -function generateImports(innerTypeSrc: Src): Set { - // Hack until https://github.com/demergent-labs/azle/issues/1453 gets fixed - if (innerTypeSrc.candidTypeObject === 'Null') { - return new Set([...innerTypeSrc.imports, 'Vec', 'bool']); - } - return new Set([...innerTypeSrc.imports, 'Vec']); -} - -function generateCandidType(innerTypeSrc: Src): { - candidTypeObject: string; - candidType: string; -} { - // Hack until https://github.com/demergent-labs/azle/issues/1453 gets fixed - if (innerTypeSrc.candidTypeObject === 'Null') { - return { - candidTypeObject: `Vec(bool)`, - candidType: `Vec` - }; - } - - return { - candidTypeObject: `Vec(${innerTypeSrc.candidTypeObject})`, - candidType: `Vec<${innerTypeSrc.candidType}>` - }; -} - -function generateValue( - array: CandidMeta[], - candidType: string, - returned: boolean = false -): Vec { - // Hack until https://github.com/demergent-labs/azle/issues/1453 gets fixed - if (candidType === 'Null') { - return Array(array.length).fill(false); - } - const value = array.map((sample) => - returned ? sample.agentResponseValue : sample.agentArgumentValue - ); - - if (candidType === 'int8') { - return new Int8Array(value as number[]); - } - if (candidType === 'int16') { - return new Int16Array(value as number[]); - } - if (candidType === 'int32') { - return new Int32Array(value as number[]); - } - if (candidType === 'int64') { - return new BigInt64Array(value as bigint[]); - } - if (candidType === 'nat8') { - return new Uint8Array(value as number[]); - } - if (candidType === 'nat16') { - return new Uint16Array(value as number[]); - } - if (candidType === 'nat32') { - return new Uint32Array(value as number[]); - } - if (candidType === 'nat64') { - return new BigUint64Array(value as bigint[]); - } - - return value; -} - -function generateValueLiteral( - sample: CandidMeta[], - candidType: string -) { - // Hack until https://github.com/demergent-labs/azle/issues/1453 gets fixed - if (candidType === 'Null') { - return `[${Array(sample.length).fill(false)}]`; - } - const valueLiterals = sample - .map((sample) => sample.src.valueLiteral) - .join(','); - - const valueLiteral = `[${valueLiterals}]`; - - if (candidType === 'int64') { - return `BigInt64Array.from(${valueLiteral})`; - } - - if (candidType === 'int32') { - return `Int32Array.from(${valueLiteral})`; - } - - if (candidType === 'int16') { - return `Int16Array.from(${valueLiteral})`; - } - - if (candidType === 'int8') { - return `Int8Array.from(${valueLiteral})`; - } - - if (candidType === 'nat64') { - return `BigUint64Array.from(${valueLiteral})`; - } - - if (candidType === 'nat32') { - return `Uint32Array.from(${valueLiteral})`; - } - - if (candidType === 'nat16') { - return `Uint16Array.from(${valueLiteral})`; - } - - if (candidType === 'nat8') { - return `Uint8Array.from(${valueLiteral})`; - } - - return valueLiteral; -} diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts new file mode 100644 index 0000000000..3248573521 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/vec_arb/definition_arb.ts @@ -0,0 +1,62 @@ +import fc from 'fast-check'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + VecCandidDefinition +} from '../../candid_definition_arb/types'; + +export function VecDefinitionArb( + candidTypeArb: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + candidTypeArb, + fc.boolean() + ) + .map(([name, innerType, useTypeDeclaration]): VecCandidDefinition => { + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(innerType); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + innerType, + useTypeDeclaration + ); + + const imports = generateImports(innerType); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Vec' + }, + innerType: innerType + }; + }); +} + +function generateTypeAliasDeclarations( + name: string, + innerType: CandidDefinition, + useTypeDeclaration: boolean +): string[] { + if (useTypeDeclaration) { + return [ + ...innerType.candidMeta.typeAliasDeclarations, + `const ${name} = ${generateTypeAnnotation(innerType)};` + ]; + } + return innerType.candidMeta.typeAliasDeclarations; +} + +function generateImports(innerType: CandidDefinition): Set { + return new Set([...innerType.candidMeta.imports, 'Vec']); +} + +function generateTypeAnnotation(innerType: CandidDefinition): string { + return `Vec(${innerType.candidMeta.typeAnnotation})`; +} diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/index.ts b/property_tests/arbitraries/candid/constructed/vec_arb/index.ts index 7ba7555c0c..92fdd4e660 100644 --- a/property_tests/arbitraries/candid/constructed/vec_arb/index.ts +++ b/property_tests/arbitraries/candid/constructed/vec_arb/index.ts @@ -1,26 +1,15 @@ import fc from 'fast-check'; -import { IntArb } from '../../primitive/ints/int_arb'; -import { Int8Arb } from '../../primitive/ints/int8_arb'; -import { Int16Arb } from '../../primitive/ints/int16_arb'; -import { Int32Arb } from '../../primitive/ints/int32_arb'; -import { Int64Arb } from '../../primitive/ints/int64_arb'; -import { NatArb } from '../../primitive/nats/nat_arb'; -import { Nat8Arb } from '../../primitive/nats/nat8_arb'; -import { Nat16Arb } from '../../primitive/nats/nat16_arb'; -import { Nat32Arb } from '../../primitive/nats/nat32_arb'; -import { Nat64Arb } from '../../primitive/nats/nat64_arb'; -import { PrincipalArb } from '../../reference/principal_arb'; -import { BoolArb } from '../../primitive/bool'; -import { Float32Arb } from '../../primitive/floats/float32_arb'; -import { Float64Arb } from '../../primitive/floats/float64_arb'; -import { NullArb } from '../../primitive/null'; -import { TextArb } from '../../primitive/text'; -import { BlobArb } from '../blob_arb'; -import { VecInnerArb } from './base'; -import { CandidType } from '../../candid_type_arb'; + +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { VecDefinitionArb } from './definition_arb'; +import { VecValuesArb } from './values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; export type Vec = - | CandidType[] + | CorrespondingJSType[] | Uint16Array | Uint32Array | Uint8Array @@ -30,31 +19,11 @@ export type Vec = | BigUint64Array | BigInt64Array; -// TODO we have a big problem here. If we try to make a vec of CandidTypeArb you -// get a vec of multiple different types of candidTypeArbs, doing it this way -// makes it so you for sure have a homogeneous vec... but it doesn't benefit -// from code reuse -// The Problem goes even deeper than we first thought. If you pass in something -// like an opt for example, Opt gets an arbitrary inner value, so every index in -// the array will be an opt with a different inner value, so instead of having a -// homogenous vec of opt nat16 you will get a vec of opt nat16 and opt int and -// opt bool etc -export const VecArb = fc.oneof( - VecInnerArb(Float32Arb), - VecInnerArb(Float64Arb), - VecInnerArb(IntArb), - VecInnerArb(Int8Arb), - VecInnerArb(Int16Arb), - VecInnerArb(Int32Arb), - VecInnerArb(Int64Arb), - VecInnerArb(NatArb), - VecInnerArb(Nat8Arb), - VecInnerArb(Nat16Arb), - VecInnerArb(Nat32Arb), - VecInnerArb(Nat64Arb), - VecInnerArb(BoolArb), - VecInnerArb(NullArb), - VecInnerArb(TextArb), - VecInnerArb(PrincipalArb), - VecInnerArb(BlobArb) -); +export function VecArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + VecDefinitionArb(candidDefinitionArb), + VecValuesArb + ); +} diff --git a/property_tests/arbitraries/candid/constructed/vec_arb/values_arb.ts b/property_tests/arbitraries/candid/constructed/vec_arb/values_arb.ts new file mode 100644 index 0000000000..8ab1e6a195 --- /dev/null +++ b/property_tests/arbitraries/candid/constructed/vec_arb/values_arb.ts @@ -0,0 +1,116 @@ +import fc from 'fast-check'; +import { Vec } from '.'; +import { CandidType } from '../../candid_type'; +import { CorrespondingJSType } from '../../corresponding_js_type'; +import { VecCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues, CandidValueArb } from '../../candid_values_arb'; + +export function VecValuesArb( + vecDefinition: VecCandidDefinition +): fc.Arbitrary> { + const arbitraryMemberValues = fc + .tuple( + fc.array(fc.constant(null)), + fc.constant(vecDefinition.innerType) + ) + .chain(([arrayTemplate, innerType]) => + fc.tuple(...arrayTemplate.map(() => CandidValueArb(innerType))) + ); + + const innerCandidType = vecDefinition.innerType.candidMeta.candidType; + + return arbitraryMemberValues.map((fieldValues) => { + const valueLiteral = generateValueLiteral(fieldValues, innerCandidType); + const agentArgumentValue = generateValue(fieldValues, innerCandidType); + const agentResponseValue = generateValue( + fieldValues, + innerCandidType, + true + ); + return { + valueLiteral, + agentArgumentValue, + agentResponseValue + }; + }); +} + +function generateValue( + array: CandidValues[], + candidType: CandidType, + returned: boolean = false +): Vec { + const value = array.map((sample) => + returned ? sample.agentResponseValue : sample.agentArgumentValue + ); + + if (candidType === 'int8') { + return new Int8Array(value as number[]); + } + if (candidType === 'int16') { + return new Int16Array(value as number[]); + } + if (candidType === 'int32') { + return new Int32Array(value as number[]); + } + if (candidType === 'int64') { + return new BigInt64Array(value as bigint[]); + } + if (candidType === 'nat8') { + return new Uint8Array(value as number[]); + } + if (candidType === 'nat16') { + return new Uint16Array(value as number[]); + } + if (candidType === 'nat32') { + return new Uint32Array(value as number[]); + } + if (candidType === 'nat64') { + return new BigUint64Array(value as bigint[]); + } + + return value; +} + +function generateValueLiteral( + sample: CandidValues[], + innerCandidType: CandidType +) { + const valueLiterals = sample.map((sample) => sample.valueLiteral).join(','); + + const valueLiteral = `[${valueLiterals}]`; + + if (innerCandidType === 'int64') { + return `BigInt64Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'int32') { + return `Int32Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'int16') { + return `Int16Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'int8') { + return `Int8Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'nat64') { + return `BigUint64Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'nat32') { + return `Uint32Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'nat16') { + return `Uint16Array.from(${valueLiteral})`; + } + + if (innerCandidType === 'nat8') { + return `Uint8Array.from(${valueLiteral})`; + } + + return valueLiteral; +} diff --git a/property_tests/arbitraries/candid/corresponding_js_type.ts b/property_tests/arbitraries/candid/corresponding_js_type.ts new file mode 100644 index 0000000000..116e0d6993 --- /dev/null +++ b/property_tests/arbitraries/candid/corresponding_js_type.ts @@ -0,0 +1,31 @@ +import { Principal } from '@dfinity/principal'; +import { Func } from './reference/func_arb'; +import { Opt } from './constructed/opt_arb'; +import { Variant } from './constructed/variant_arb'; +import { Tuple } from './constructed/tuple_arb'; +import { Vec } from './constructed/vec_arb'; +import { Record } from './constructed/record_arb'; + +export type CorrespondingJSType = + | number + | bigint + | null + | boolean + | Principal + | Uint8Array + | string + | Func + | Opt + | Variant + | Record + | Tuple + | undefined + | Int16Array + | Int32Array + | Int8Array + | BigInt64Array + | Uint16Array + | Uint32Array + | Uint8Array + | BigUint64Array + | Vec; diff --git a/property_tests/arbitraries/candid/primitive/bool.ts b/property_tests/arbitraries/candid/primitive/bool.ts index 96758a73d5..43f9beea75 100644 --- a/property_tests/arbitraries/candid/primitive/bool.ts +++ b/property_tests/arbitraries/candid/primitive/bool.ts @@ -1,10 +1,19 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../candid_arb'; +import { SimpleCandidDefinitionArb } from '../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; import { booleanToSrcLiteral } from '../to_src_literal/boolean'; +import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator'; +import { BoolCandidDefinition } from '../candid_definition_arb/types'; +import { CandidValues } from '../candid_values_arb'; -export const BoolArb = CandidMetaArb( - fc.boolean(), - 'bool', - 'bool', - booleanToSrcLiteral -); +export function BoolArb(): fc.Arbitrary { + return CandidValueAndMetaArbGenerator(BoolDefinitionArb(), BoolValueArb); +} + +export function BoolDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('bool'); +} + +export function BoolValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.boolean(), booleanToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/floats/float32_arb.ts b/property_tests/arbitraries/candid/primitive/floats/float32_arb.ts index 3da96cc525..e103f310ba 100644 --- a/property_tests/arbitraries/candid/primitive/floats/float32_arb.ts +++ b/property_tests/arbitraries/candid/primitive/floats/float32_arb.ts @@ -1,10 +1,23 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { floatToSrcLiteral } from '../../to_src_literal/float'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { FloatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Float32Arb = CandidMetaArb( - fc.float(), - 'float32', - 'float32', - floatToSrcLiteral -); +export function Float32Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + Float32DefinitionArb(), + Float32ValueArb + ); +} + +export function Float32DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('float32'); +} + +export function Float32ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.float(), floatToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/floats/float64_arb.ts b/property_tests/arbitraries/candid/primitive/floats/float64_arb.ts index c0d0b01363..5a83c958a2 100644 --- a/property_tests/arbitraries/candid/primitive/floats/float64_arb.ts +++ b/property_tests/arbitraries/candid/primitive/floats/float64_arb.ts @@ -1,10 +1,29 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { floatToSrcLiteral } from '../../to_src_literal/float'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { FloatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; -export const Float64Arb = CandidMetaArb( - fc.float64Array({ maxLength: 1, minLength: 1 }).map((sample) => sample[0]), - 'float64', - 'float64', - floatToSrcLiteral -); +export function Float64Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + Float64DefinitionArb(), + Float64ValueArb + ); +} + +export function Float64DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('float64'); +} + +export function Float64ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(float64(), floatToSrcLiteral); +} + +function float64(): fc.Arbitrary { + return fc + .float64Array({ maxLength: 1, minLength: 1 }) + .map((sample) => sample[0]); +} diff --git a/property_tests/arbitraries/candid/primitive/ints/int16_arb.ts b/property_tests/arbitraries/candid/primitive/ints/int16_arb.ts index 263159074b..c44ab4c678 100644 --- a/property_tests/arbitraries/candid/primitive/ints/int16_arb.ts +++ b/property_tests/arbitraries/candid/primitive/ints/int16_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { NumberArb } from './'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import fc from 'fast-check'; +import { IntCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Int16Arb = CandidMetaArb( - NumberArb(16), - 'int16', - 'int16', - numberToSrcLiteral -); +export function Int16Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Int16DefinitionArb(), Int16ValueArb); +} + +export function Int16DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('int16'); +} + +export function Int16ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(NumberArb(16), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/ints/int32_arb.ts b/property_tests/arbitraries/candid/primitive/ints/int32_arb.ts index 94a752d366..0f9fbef5d0 100644 --- a/property_tests/arbitraries/candid/primitive/ints/int32_arb.ts +++ b/property_tests/arbitraries/candid/primitive/ints/int32_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { NumberArb } from './'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import fc from 'fast-check'; +import { IntCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Int32Arb = CandidMetaArb( - NumberArb(32), - 'int32', - 'int32', - numberToSrcLiteral -); +export function Int32Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Int32DefinitionArb(), Int32ValueArb); +} + +export function Int32DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('int32'); +} + +export function Int32ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(NumberArb(32), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/ints/int64_arb.ts b/property_tests/arbitraries/candid/primitive/ints/int64_arb.ts index 4ea54e9d90..f07001546c 100644 --- a/property_tests/arbitraries/candid/primitive/ints/int64_arb.ts +++ b/property_tests/arbitraries/candid/primitive/ints/int64_arb.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { bigintToSrcLiteral } from '../../to_src_literal/bigint'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { IntCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; -export const Int64Arb = CandidMetaArb( - fc.bigIntN(64), - 'int64', - 'int64', - bigintToSrcLiteral -); +export function Int64Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Int64DefinitionArb(), Int64ValueArb); +} + +export function Int64DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('int64'); +} + +export function Int64ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.bigIntN(64), bigintToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/ints/int8_arb.ts b/property_tests/arbitraries/candid/primitive/ints/int8_arb.ts index 1e9bb57b2d..fa85774b44 100644 --- a/property_tests/arbitraries/candid/primitive/ints/int8_arb.ts +++ b/property_tests/arbitraries/candid/primitive/ints/int8_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { NumberArb } from './'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import fc from 'fast-check'; +import { CandidValues } from '../../candid_values_arb'; +import { IntCandidDefinition } from '../../candid_definition_arb/types'; -export const Int8Arb = CandidMetaArb( - NumberArb(8), - 'int8', - 'int8', - numberToSrcLiteral -); +export function Int8Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Int8DefinitionArb(), Int8ValueArb); +} + +export function Int8DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('int8'); +} + +export function Int8ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(NumberArb(8), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/ints/int_arb.ts b/property_tests/arbitraries/candid/primitive/ints/int_arb.ts index 928f99685b..7574655e6d 100644 --- a/property_tests/arbitraries/candid/primitive/ints/int_arb.ts +++ b/property_tests/arbitraries/candid/primitive/ints/int_arb.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { bigintToSrcLiteral } from '../../to_src_literal/bigint'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidValues } from '../../candid_values_arb'; +import { IntCandidDefinition } from '../../candid_definition_arb/types'; -export const IntArb = CandidMetaArb( - fc.bigInt(), - 'int', - 'int', - bigintToSrcLiteral -); +export function IntArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(IntDefinitionArb(), IntValueArb); +} + +export function IntDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('int'); +} + +export function IntValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.bigInt(), bigintToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/nats/nat16_arb.ts b/property_tests/arbitraries/candid/primitive/nats/nat16_arb.ts index f3cb9be021..a4ba69b142 100644 --- a/property_tests/arbitraries/candid/primitive/nats/nat16_arb.ts +++ b/property_tests/arbitraries/candid/primitive/nats/nat16_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { UNumberArb } from './index'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import fc from 'fast-check'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { NatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Nat16Arb = CandidMetaArb( - UNumberArb(16), - 'nat16', - 'nat16', - numberToSrcLiteral -); +export function Nat16Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Nat16DefinitionArb(), Nat16ValueArb); +} + +export function Nat16DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('nat16'); +} + +export function Nat16ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(UNumberArb(16), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/nats/nat32_arb.ts b/property_tests/arbitraries/candid/primitive/nats/nat32_arb.ts index ed0bac3615..988333391a 100644 --- a/property_tests/arbitraries/candid/primitive/nats/nat32_arb.ts +++ b/property_tests/arbitraries/candid/primitive/nats/nat32_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { UNumberArb } from './index'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import fc from 'fast-check'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { NatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Nat32Arb = CandidMetaArb( - UNumberArb(32), - 'nat32', - 'nat32', - numberToSrcLiteral -); +export function Nat32Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Nat32DefinitionArb(), Nat32ValueArb); +} + +export function Nat32DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('nat32'); +} + +export function Nat32ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(UNumberArb(32), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/nats/nat64_arb.ts b/property_tests/arbitraries/candid/primitive/nats/nat64_arb.ts index ce1eedbdd8..0310c8614e 100644 --- a/property_tests/arbitraries/candid/primitive/nats/nat64_arb.ts +++ b/property_tests/arbitraries/candid/primitive/nats/nat64_arb.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { bigintToSrcLiteral } from '../../to_src_literal/bigint'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { NatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Nat64Arb = CandidMetaArb( - fc.bigUintN(64), - 'nat64', - 'nat64', - bigintToSrcLiteral -); +export function Nat64Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Nat64DefinitionArb(), Nat64ValueArb); +} + +export function Nat64DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('nat64'); +} + +export function Nat64ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.bigUintN(64), bigintToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/nats/nat8_arb.ts b/property_tests/arbitraries/candid/primitive/nats/nat8_arb.ts index ed0858dda9..f6d219daba 100644 --- a/property_tests/arbitraries/candid/primitive/nats/nat8_arb.ts +++ b/property_tests/arbitraries/candid/primitive/nats/nat8_arb.ts @@ -1,10 +1,21 @@ import { numberToSrcLiteral } from '../../to_src_literal/number'; -import { CandidMetaArb } from '../../candid_arb'; import { UNumberArb } from './index'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import fc from 'fast-check'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { NatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const Nat8Arb = CandidMetaArb( - UNumberArb(8), - 'nat8', - 'nat8', - numberToSrcLiteral -); +export function Nat8Arb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(Nat8DefinitionArb(), Nat8ValueArb); +} + +export function Nat8DefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('nat8'); +} + +export function Nat8ValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(UNumberArb(8), numberToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/nats/nat_arb.ts b/property_tests/arbitraries/candid/primitive/nats/nat_arb.ts index 487e28a2ab..720af1ad98 100644 --- a/property_tests/arbitraries/candid/primitive/nats/nat_arb.ts +++ b/property_tests/arbitraries/candid/primitive/nats/nat_arb.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../../candid_arb'; import { bigintToSrcLiteral } from '../../to_src_literal/bigint'; +import { SimpleCandidDefinitionArb } from '../../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { NatCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; -export const NatArb = CandidMetaArb( - fc.bigUint(), - 'nat', - 'nat', - bigintToSrcLiteral -); +export function NatArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(NatDefinitionArb(), NatValueArb); +} + +export function NatDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('nat'); +} + +export function NatValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.bigUint(), bigintToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/null.ts b/property_tests/arbitraries/candid/primitive/null.ts index 655bb46f31..a7d3e7f700 100644 --- a/property_tests/arbitraries/candid/primitive/null.ts +++ b/property_tests/arbitraries/candid/primitive/null.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../candid_arb'; +import { SimpleCandidDefinitionArb } from '../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; import { nullToSrcLiteral } from '../to_src_literal/null'; +import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator'; +import { NullCandidDefinition } from '../candid_definition_arb/types'; +import { CandidValues } from '../candid_values_arb'; +import { CandidValueAndMeta } from '../candid_value_and_meta_arb'; -export const NullArb = CandidMetaArb( - fc.constant(null), - 'Null', - 'Null', - nullToSrcLiteral -); +export function NullArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(NullDefinitionArb(), NullValueArb); +} + +export function NullDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('Null'); +} + +export function NullValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.constant(null), nullToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/text.ts b/property_tests/arbitraries/candid/primitive/text.ts index b06e2d30e8..aa50d5047d 100644 --- a/property_tests/arbitraries/candid/primitive/text.ts +++ b/property_tests/arbitraries/candid/primitive/text.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../candid_arb'; import { stringToSrcLiteral } from '../to_src_literal/string'; +import { TextCandidDefinition } from '../candid_definition_arb/types'; +import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; +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'; -export const TextArb = CandidMetaArb( - fc.string(), - 'text', - 'text', - stringToSrcLiteral -); +export function TextArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(TextDefinitionArb(), TextValueArb); +} + +export function TextDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('text'); +} + +export function TextValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.string(), stringToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/primitive/void.ts b/property_tests/arbitraries/candid/primitive/void.ts index 1026ced9ce..bd97f4b315 100644 --- a/property_tests/arbitraries/candid/primitive/void.ts +++ b/property_tests/arbitraries/candid/primitive/void.ts @@ -1,10 +1,20 @@ import fc from 'fast-check'; -import { CandidMetaArb } from '../candid_arb'; import { voidToSrcLiteral } from '../to_src_literal/void'; +import { SimpleCandidDefinitionArb } from '../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; +import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator'; +import { CandidValueAndMeta } from '../candid_value_and_meta_arb'; +import { VoidCandidDefinition } from '../candid_definition_arb/types'; +import { CandidValues } from '../candid_values_arb'; -export const VoidArb = CandidMetaArb( - fc.constant(undefined), - 'Void', - 'Void', - voidToSrcLiteral -); +export function VoidArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator(VoidDefinitionArb(), VoidValueArb); +} + +export function VoidDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('Void'); +} + +export function VoidValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(fc.constant(undefined), voidToSrcLiteral); +} diff --git a/property_tests/arbitraries/candid/reference/func_arb/base.ts b/property_tests/arbitraries/candid/reference/func_arb/base.ts deleted file mode 100644 index 7fda247125..0000000000 --- a/property_tests/arbitraries/candid/reference/func_arb/base.ts +++ /dev/null @@ -1,74 +0,0 @@ -import fc from 'fast-check'; - -import { PrincipalArb } from '../principal_arb'; -import { VoidArb } from '../../primitive/void'; -import { CandidMeta } from '../../candid_arb'; -import { CandidType } from '../../candid_type_arb'; -import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; -import { Func } from './index'; - -type Mode = 'query' | 'update' | 'oneway'; - -export function FuncArb(candidTypeArb: fc.Arbitrary>) { - return (fc.constantFrom('query', 'update', 'oneway') as fc.Arbitrary) - .chain((mode) => { - const returnType = mode === 'oneway' ? VoidArb : candidTypeArb; - - return fc.tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.array(candidTypeArb), - returnType, - fc.constant(mode), - PrincipalArb - ); - }) - .map( - ([name, params, returnFunc, mode, principal]): CandidMeta => { - const typeDeclaration = generateTypeDeclaration( - name, - params, - returnFunc, - mode - ); - - const imports = new Set([ - ...params.flatMap((param) => [...param.src.imports]), - ...returnFunc.src.imports, - 'Func' - ]); - - const value: Func = [principal.agentArgumentValue, name]; - - const valueLiteral = `[${principal.src.valueLiteral}, '${name}']`; - - return { - src: { - candidTypeObject: name, - candidType: `typeof ${name}.tsType`, - typeDeclaration, - imports, - valueLiteral - }, - agentArgumentValue: value, - agentResponseValue: value - }; - } - ); -} - -function generateTypeDeclaration( - name: string, - paramCandids: CandidMeta[], - returnCandid: CandidMeta, - mode: Mode -): string { - const paramTypeDeclarations = paramCandids - .map((param) => param.src.typeDeclaration ?? '') - .join('\n'); - const returnTypeDeclaration = returnCandid.src.typeDeclaration ?? ''; - const params = paramCandids - .map((param) => param.src.candidTypeObject) - .join(', '); - - return `${paramTypeDeclarations}\n${returnTypeDeclaration}\nconst ${name} = Func([${params}], ${returnCandid.src.candidTypeObject}, '${mode}')`; -} diff --git a/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts new file mode 100644 index 0000000000..b1f08a8dc1 --- /dev/null +++ b/property_tests/arbitraries/candid/reference/func_arb/definition_arb.ts @@ -0,0 +1,103 @@ +import fc from 'fast-check'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + FuncCandidDefinition +} from '../../candid_definition_arb/types'; +import { VoidDefinitionArb } from '../../primitive/void'; + +type Mode = 'query' | 'update' | 'oneway'; + +export function FuncDefinitionArb( + candidDefArb: fc.Arbitrary +): fc.Arbitrary { + return (fc.constantFrom('query', 'update', 'oneway') as fc.Arbitrary) + .chain((mode) => { + const returnType = + mode === 'oneway' ? VoidDefinitionArb() : candidDefArb; + + return fc.tuple( + UniqueIdentifierArb('typeDeclaration'), + fc.array(candidDefArb), + returnType, + fc.constant(mode), + fc.boolean() + ); + }) + .map( + ([ + name, + params, + returnFunc, + mode, + useTypeDeclaration + ]): FuncCandidDefinition => { + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + params, + returnFunc, + mode, + useTypeDeclaration + ); + + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(params, returnFunc, mode); + + const imports = new Set([ + ...params.flatMap((param) => [...param.candidMeta.imports]), + ...returnFunc.candidMeta.imports, + 'Func' + ]); + + return { + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Func' + }, + paramCandidMeta: params, + returnCandidMeta: returnFunc + }; + } + ); +} + +function generateTypeAliasDeclarations( + name: string, + paramCandids: CandidDefinition[], + returnCandid: CandidDefinition, + mode: Mode, + useTypeDeclaration: boolean +): string[] { + const paramTypeDeclarations = paramCandids.flatMap( + (param) => param.candidMeta.typeAliasDeclarations + ); + const returnTypeDeclaration = returnCandid.candidMeta.typeAliasDeclarations; + + if (useTypeDeclaration) { + return [ + ...paramTypeDeclarations, + ...returnTypeDeclaration, + `const ${name} = ${generateTypeAnnotation( + paramCandids, + returnCandid, + mode + )}` + ]; + } + + return [...paramTypeDeclarations, ...returnTypeDeclaration]; +} + +function generateTypeAnnotation( + paramCandids: CandidDefinition[], + returnCandid: CandidDefinition, + mode: Mode +): string { + const params = paramCandids + .map((param) => param.candidMeta.typeAnnotation) + .join(', '); + return `Func([${params}], ${returnCandid.candidMeta.typeAnnotation}, '${mode}')`; +} diff --git a/property_tests/arbitraries/candid/reference/func_arb/index.ts b/property_tests/arbitraries/candid/reference/func_arb/index.ts index 52c204e1cd..1e1d8c3a72 100644 --- a/property_tests/arbitraries/candid/reference/func_arb/index.ts +++ b/property_tests/arbitraries/candid/reference/func_arb/index.ts @@ -1,8 +1,20 @@ +import fc from 'fast-check'; import { Principal } from '@dfinity/principal'; -import { CandidTypeArb } from '../../candid_type_arb'; -import { FuncArb as Base } from './base'; +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { FuncDefinitionArb } from './definition_arb'; +import { FuncValueArb } from './values_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; export type Func = [Principal, string]; -export const FuncArb = Base(CandidTypeArb); +export function FuncArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + FuncDefinitionArb(candidDefinitionArb), + FuncValueArb + ); +} diff --git a/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts new file mode 100644 index 0000000000..956965ce53 --- /dev/null +++ b/property_tests/arbitraries/candid/reference/func_arb/values_arb.ts @@ -0,0 +1,22 @@ +import fc from 'fast-check'; +import { Func } from '.'; +import { TextArb } from '../../primitive/text'; +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.agentArgumentValue, + name.agentArgumentValue + ]; + + const valueLiteral = `[${principal.src.valueLiteral}, ${name.src.valueLiteral}]`; + + return { + valueLiteral, + agentArgumentValue: value, + agentResponseValue: value + }; + }); +} diff --git a/property_tests/arbitraries/candid/reference/principal_arb.ts b/property_tests/arbitraries/candid/reference/principal_arb.ts index bdf3771d75..74b2444298 100644 --- a/property_tests/arbitraries/candid/reference/principal_arb.ts +++ b/property_tests/arbitraries/candid/reference/principal_arb.ts @@ -1,16 +1,33 @@ import fc from 'fast-check'; import { Principal } from '@dfinity/principal'; -import { CandidMetaArb } from '../candid_arb'; import { principalToSrcLiteral } from '../to_src_literal/principal'; +import { SimpleCandidDefinitionArb } from '../simple_type_arbs/definition_arb'; +import { SimpleCandidValuesArb } from '../simple_type_arbs/values_arb'; +import { PrincipalCandidDefinition } from '../candid_definition_arb/types'; +import { CandidValues } from '../candid_values_arb'; +import { CandidValueAndMeta } from '../candid_value_and_meta_arb'; +import { CandidValueAndMetaArbGenerator } from '../candid_value_and_meta_arb_generator'; -export const PrincipalArb = CandidMetaArb( - fc +export function PrincipalArb(): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + PrincipalDefinitionArb(), + PrincipalValueArb + ); +} + +export function PrincipalDefinitionArb(): fc.Arbitrary { + return SimpleCandidDefinitionArb('Principal'); +} + +export function PrincipalValueArb(): fc.Arbitrary> { + return SimpleCandidValuesArb(principal(), principalToSrcLiteral); +} + +function principal() { + return fc .uint8Array({ minLength: 29, maxLength: 29 }) - .map((sample) => Principal.fromUint8Array(sample)), - 'Principal', - 'Principal', - principalToSrcLiteral -); + .map((sample) => Principal.fromUint8Array(sample)); +} diff --git a/property_tests/arbitraries/candid/reference/service_arb.ts b/property_tests/arbitraries/candid/reference/service_arb.ts deleted file mode 100644 index a3717fe0ea..0000000000 --- a/property_tests/arbitraries/candid/reference/service_arb.ts +++ /dev/null @@ -1,115 +0,0 @@ -import fc from 'fast-check'; -import { Principal } from '@dfinity/principal'; - -import { PrincipalArb } from './principal_arb'; -import { VoidArb } from '../primitive/void'; -import { CandidMeta } from '../candid_arb'; -import { CandidTypeArb } from '../candid_type_arb'; -import { UniqueIdentifierArb } from '../../unique_identifier_arb'; -import { JsFunctionNameArb } from '../../js_function_name_arb'; - -// TODO: -// - services that are more than type-definitions, i.e. have functionality -// - async service methods -// - non-query methods -// - actually using the service - -// Example Service: -// const SomeService = Canister({ -// method1: query([], Void), -// method2: query([text, text, nat64], nat64), -// }); - -type ServiceMethod = { - name: string; - imports: Set; - typeDeclarations: string[]; - src: string; -}; - -const ServiceMethodArb = fc - .tuple( - JsFunctionNameArb, - fc.constantFrom('query', 'update'), - fc.array(CandidTypeArb), - fc.oneof(CandidTypeArb, VoidArb) - ) - .map(([name, mode, params, returnType]): ServiceMethod => { - const paramCandidTypeObjects = params.map( - (param) => param.src.candidTypeObject - ); - - const typeDeclarations = params.reduce( - (acc, { src: { typeDeclaration } }) => { - return typeDeclaration ? [...acc, typeDeclaration] : acc; - }, - returnType.src.typeDeclaration - ? [returnType.src.typeDeclaration] - : new Array() - ); - - const src = `${name}: ${mode}([${paramCandidTypeObjects}], ${returnType.src.candidTypeObject})`; - - const imports = params.reduce( - (acc, param) => { - return new Set([...acc, ...param.src.imports]); - }, - new Set([mode, ...returnType.src.imports]) - ); - - return { - name, - imports, - typeDeclarations, - src - }; - }); - -export const ServiceArb = fc - .tuple( - UniqueIdentifierArb('typeDeclaration'), - fc.uniqueArray(ServiceMethodArb, { selector: (entry) => entry.name }), - PrincipalArb - ) - .map(([name, serviceMethods, principal]): CandidMeta => { - const imports = new Set([ - ...serviceMethods.flatMap((method) => [...method.imports]), - 'Canister', - 'query' - ]); - - const typeDeclaration = generateTypeDeclaration(name, serviceMethods); - - const typeDeclarationAndChildren = [ - ...serviceMethods.flatMap((method) => method.typeDeclarations), - typeDeclaration - ].join('\n'); - - const valueLiteral = `${name}(${principal.src.valueLiteral})`; - - const value = principal.agentArgumentValue; - - return { - src: { - candidTypeObject: name, - candidType: `typeof ${name}.tsType`, - typeDeclaration: typeDeclarationAndChildren, - imports, - valueLiteral - }, - agentArgumentValue: value, - agentResponseValue: value - }; - }); - -function generateTypeDeclaration( - name: string, - serviceMethods: ServiceMethod[] -): string { - const methods = serviceMethods - .map((serviceMethod) => serviceMethod.src) - .filter((typeDeclaration) => typeDeclaration) - .join(',\n'); - - return `const ${name} = Canister({${methods}});`; -} diff --git a/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts new file mode 100644 index 0000000000..89655590a6 --- /dev/null +++ b/property_tests/arbitraries/candid/reference/service_arb/definition_arb.ts @@ -0,0 +1,125 @@ +import fc from 'fast-check'; +import { JsFunctionNameArb } from '../../../js_function_name_arb'; +import { UniqueIdentifierArb } from '../../../unique_identifier_arb'; +import { + CandidDefinition, + ServiceCandidDefinition, + ServiceMethodDefinition +} from '../../candid_definition_arb/types'; +import { VoidDefinitionArb } from '../../primitive/void'; + +export function ServiceDefinitionArb( + fieldCandidDefArb: fc.Arbitrary +): fc.Arbitrary { + return fc + .tuple( + UniqueIdentifierArb('typeDeclaration'), + fc.uniqueArray(ServiceMethodArb(fieldCandidDefArb), { + selector: (entry) => entry.name + }), + fc.boolean() + ) + .map(([name, fields, useTypeDeclaration]): ServiceCandidDefinition => { + useTypeDeclaration = true; + const typeAnnotation = useTypeDeclaration + ? name + : generateTypeAnnotation(fields); + + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + fields, + useTypeDeclaration + ); + + const imports = generateImports(fields); + + return { + name, + candidMeta: { + typeAnnotation, + typeAliasDeclarations, + imports, + candidType: 'Service' + }, + funcs: fields + }; + }); +} + +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 paramCandidTypes = params.map( + (param) => param.candidMeta.typeAnnotation + ); + + const typeAliasDeclarations = params.reduce( + (acc, { candidMeta: { typeAliasDeclarations } }): string[] => { + return [...acc, ...typeAliasDeclarations]; + }, + returnType.candidMeta.typeAliasDeclarations + ); + + const src = `${name}: ${mode}([${paramCandidTypes}], ${returnType.candidMeta.typeAnnotation})`; + + const imports = params.reduce( + (acc, param) => { + return new Set([...acc, ...param.candidMeta.imports]); + }, + new Set([mode, ...returnType.candidMeta.imports]) + ); + + return { + name, + imports, + typeAliasDeclarations, + src + }; + }); +} + +function generateTypeAliasDeclarations( + name: string, + serviceMethods: ServiceMethodDefinition[], + useTypeDeclaration: boolean +): string[] { + const serviceMethodTypeAliasDecls = serviceMethods.flatMap( + (serviceMethod) => serviceMethod.typeAliasDeclarations + ); + if (useTypeDeclaration) { + return [ + ...serviceMethodTypeAliasDecls, + `const ${name} = ${generateTypeAnnotation(serviceMethods)};` + ]; + } + return serviceMethodTypeAliasDecls; +} + +function generateTypeAnnotation(serviceMethods: ServiceMethodDefinition[]) { + const methods = serviceMethods + .map((serviceMethod) => serviceMethod.src) + .filter((typeDeclaration) => typeDeclaration) + .join(',\n'); + + return `Canister({${methods}})`; +} + +function generateImports( + serviceMethods: ServiceMethodDefinition[] +): Set { + return new Set([ + ...serviceMethods.flatMap((serviceMethod) => + Array.from(serviceMethod.imports) + ), + 'Canister', + 'query' + ]); +} diff --git a/property_tests/arbitraries/candid/reference/service_arb/index.ts b/property_tests/arbitraries/candid/reference/service_arb/index.ts new file mode 100644 index 0000000000..28a9cbcc89 --- /dev/null +++ b/property_tests/arbitraries/candid/reference/service_arb/index.ts @@ -0,0 +1,30 @@ +import fc from 'fast-check'; +import { Principal } from '@dfinity/principal'; + +import { CandidDefinitionArb } from '../../candid_definition_arb'; +import { CandidValueAndMeta } from '../../candid_value_and_meta_arb'; +import { CandidDefinition } from '../../candid_definition_arb/types'; +import { ServiceValueArb } from './values_arb'; +import { ServiceDefinitionArb } from './definition_arb'; +import { CandidValueAndMetaArbGenerator } from '../../candid_value_and_meta_arb_generator'; + +// TODO: +// - services that are more than type-definitions, i.e. have functionality +// - async service methods +// - non-query methods +// - actually using the service + +// Example Service: +// const SomeService = Canister({ +// method1: query([], Void), +// method2: query([text, text, nat64], nat64), +// }); + +export function ServiceArb( + candidDefinitionArb: fc.Arbitrary = CandidDefinitionArb +): fc.Arbitrary> { + return CandidValueAndMetaArbGenerator( + ServiceDefinitionArb(candidDefinitionArb), + ServiceValueArb + ); +} diff --git a/property_tests/arbitraries/candid/reference/service_arb/values_arb.ts b/property_tests/arbitraries/candid/reference/service_arb/values_arb.ts new file mode 100644 index 0000000000..5b5d84fa25 --- /dev/null +++ b/property_tests/arbitraries/candid/reference/service_arb/values_arb.ts @@ -0,0 +1,20 @@ +import { Principal } from '@dfinity/principal'; +import fc from 'fast-check'; +import { ServiceCandidDefinition } from '../../candid_definition_arb/types'; +import { CandidValues } from '../../candid_values_arb'; +import { PrincipalValueArb } from '../principal_arb'; + +export function ServiceValueArb( + serviceDefinition: ServiceCandidDefinition +): fc.Arbitrary> { + return PrincipalValueArb().map((principal) => { + const valueLiteral = `${serviceDefinition.name}(${principal.valueLiteral})`; + const value = principal.agentArgumentValue; + + return { + valueLiteral, + agentArgumentValue: value, + agentResponseValue: value + }; + }); +} diff --git a/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts new file mode 100644 index 0000000000..089352d317 --- /dev/null +++ b/property_tests/arbitraries/candid/simple_type_arbs/definition_arb.ts @@ -0,0 +1,39 @@ +import fc from 'fast-check'; +import { PrimitiveDefinition } from '../candid_definition_arb/types'; +import { SimpleCandidType } from '../candid_type'; +import { UniqueIdentifierArb } from '../../unique_identifier_arb'; + +export function SimpleCandidDefinitionArb( + candidType: SimpleCandidType +): fc.Arbitrary { + return fc + .tuple(UniqueIdentifierArb('typeDeclaration'), fc.boolean()) + .map(([name, useTypeDeclaration]) => { + const typeAnnotation = useTypeDeclaration ? name : candidType; + const imports = new Set([candidType]); + const typeAliasDeclarations = generateTypeAliasDeclarations( + name, + candidType, + useTypeDeclaration + ); + return { + candidMeta: { + candidType, + typeAnnotation, + imports, + typeAliasDeclarations + } + }; + }); +} + +function generateTypeAliasDeclarations( + name: string, + candidType: string, + useTypeDeclaration: boolean +): string[] { + if (useTypeDeclaration) { + return [`const ${name} = ${candidType};`]; + } + return []; +} diff --git a/property_tests/arbitraries/candid/simple_type_arbs/values_arb.ts b/property_tests/arbitraries/candid/simple_type_arbs/values_arb.ts new file mode 100644 index 0000000000..cfd517045e --- /dev/null +++ b/property_tests/arbitraries/candid/simple_type_arbs/values_arb.ts @@ -0,0 +1,16 @@ +import fc from 'fast-check'; +import { CorrespondingJSType } from '../corresponding_js_type'; +import { CandidValues } from '../candid_values_arb'; + +export function SimpleCandidValuesArb( + arb: fc.Arbitrary, + toLiteral: (value: T) => string +): fc.Arbitrary> { + return arb.map((value): CandidValues => { + return { + valueLiteral: toLiteral(value), + agentArgumentValue: value, + agentResponseValue: value + }; + }); +} diff --git a/property_tests/arbitraries/canister_arb.ts b/property_tests/arbitraries/canister_arb.ts index 38a88b6ba4..ad06cc55ef 100644 --- a/property_tests/arbitraries/canister_arb.ts +++ b/property_tests/arbitraries/canister_arb.ts @@ -1,51 +1,67 @@ import fc from 'fast-check'; -import { QueryMethod } from './query_method_arb'; +import { QueryMethod } from './canister_methods/query_method_arb'; import { Test } from '../../test'; +import { UpdateMethod } from './canister_methods/update_method_arb'; export type Canister = { sourceCode: string; tests: Test[]; }; +export type CanisterConfig = { + globalDeclarations?: string[]; + queryMethods?: QueryMethod[]; + updateMethods?: UpdateMethod[]; +}; + // TODO: Update the signature to support init, pre/post upgrade, heartbeat, etc. -export function CanisterArb(queryMethodArb: fc.Arbitrary) { - return fc - .array(queryMethodArb, { - minLength: 20, // TODO work on these - maxLength: 100 - }) - .map((queryMethods): Canister => { - const sourceCode = generateSourceCode(queryMethods); - const tests = queryMethods.flatMap( - (queryMethod) => queryMethod.tests - ); - - return { - sourceCode, - tests - }; - }); +export function CanisterArb(configArb: fc.Arbitrary) { + return configArb.map((config): Canister => { + const canisterMethods: (QueryMethod | UpdateMethod)[] = [ + ...(config.queryMethods ?? []), + ...(config.updateMethods ?? []) + ]; + + const sourceCode = generateSourceCode( + config.globalDeclarations ?? [], + canisterMethods + ); + const tests = canisterMethods.flatMap( + (canisterMethod) => canisterMethod.tests + ); + + return { + sourceCode, + tests + }; + }); } -function generateSourceCode(queryMethods: QueryMethod[]) { +function generateSourceCode( + globalDeclarations: string[], + canisterMethods: (UpdateMethod | QueryMethod)[] +) { const imports = [ ...new Set( - queryMethods.reduce( - (acc, queryMethod) => { - return [...acc, ...queryMethod.imports]; + canisterMethods.reduce( + (acc, method) => { + return [...acc, ...method.imports]; }, - ['Canister', 'query'] + ['Canister', 'query', 'update'] ) ) ].join(); - const declarations = queryMethods - .flatMap((queryMethod) => queryMethod.globalDeclarations) + const declarationsFromCanisterMethods = canisterMethods + .flatMap((method) => method.globalDeclarations) .join('\n'); - const sourceCodes = queryMethods.map( - (queryMethod) => queryMethod.sourceCode - ); + const declarations = [ + ...globalDeclarations, + declarationsFromCanisterMethods + ]; + + const sourceCodes = canisterMethods.map((method) => method.sourceCode); return /*TS*/ ` import { ${imports} } from 'azle'; diff --git a/property_tests/arbitraries/canister_methods/index.ts b/property_tests/arbitraries/canister_methods/index.ts new file mode 100644 index 0000000000..5a63af1dee --- /dev/null +++ b/property_tests/arbitraries/canister_methods/index.ts @@ -0,0 +1,76 @@ +import { CandidValueAndMeta } from '../candid/candid_value_and_meta_arb'; +import { CandidReturnType } from '../candid/candid_return_type_arb'; +import { CorrespondingJSType } from '../candid/corresponding_js_type'; +import { Named } from '../..'; +import { Test } from '../../../test'; + +export type BodyGenerator< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue extends CorrespondingJSType, + ReturnTypeAgentResponseValue +> = ( + namedParams: Named< + CandidValueAndMeta + >[], + returnType: CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > +) => string; + +export type TestsGenerator< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue extends CorrespondingJSType, + ReturnTypeAgentResponseValue +> = ( + methodName: string, + namedParams: Named< + CandidValueAndMeta + >[], + returnType: CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > +) => Test[]; + +export type CallbackLocation = 'INLINE' | 'STANDALONE'; + +export function isDefined(value: T | undefined): value is T { + return value !== undefined; +} + +export function generateCallback< + ParamType extends CorrespondingJSType, + ParamAgentType, + ReturnType extends CandidReturnType, + ReturnAgentType +>( + namedParams: Named>[], + returnType: CandidValueAndMeta, + generateBody: BodyGenerator< + ParamType, + ParamAgentType, + ReturnType, + ReturnAgentType + >, + callbackLocation: CallbackLocation, + callbackName: string +): string { + const paramNames = namedParams + .map((namedParam) => namedParam.name) + .join(', '); + + const body = generateBody(namedParams, returnType); + + if (callbackLocation === 'INLINE') { + return `(${paramNames}) => {${body}}`; + } + + const paramNamesAndTypes = namedParams + .map((namedParam) => `${namedParam.name}: any`) // TODO: Use actual candid type, not any + .join(', '); + + return `function ${callbackName}(${paramNamesAndTypes}): any {${body}}`; // TODO: Use actual candid type, not any +} diff --git a/property_tests/arbitraries/query_method_arb.ts b/property_tests/arbitraries/canister_methods/query_method_arb.ts similarity index 55% rename from property_tests/arbitraries/query_method_arb.ts rename to property_tests/arbitraries/canister_methods/query_method_arb.ts index 38c4ede8fe..4f8e1f68fc 100644 --- a/property_tests/arbitraries/query_method_arb.ts +++ b/property_tests/arbitraries/canister_methods/query_method_arb.ts @@ -1,11 +1,18 @@ import fc from 'fast-check'; -import { CandidMeta } from './candid/candid_arb'; -import { CandidReturnType } from './candid/candid_return_type_arb'; -import { CandidType } from './candid/candid_type_arb'; -import { UniqueIdentifierArb } from './unique_identifier_arb'; -import { Test } from '../../test'; -import { Named } from '../'; +import { CandidValueAndMeta } from '../candid/candid_value_and_meta_arb'; +import { CandidReturnType } from '../candid/candid_return_type_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 QueryMethod = { imports: Set; @@ -14,50 +21,20 @@ export type QueryMethod = { tests: Test[]; }; -export type BodyGenerator< - ParamAgentArgumentValue extends CandidType, - ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CandidType, - ReturnTypeAgentResponseValue -> = ( - namedParams: Named< - CandidMeta - >[], - returnType: CandidMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > -) => string; - -export type TestsGenerator< - ParamAgentArgumentValue extends CandidType, - ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CandidType, - ReturnTypeAgentResponseValue -> = ( - methodName: string, - namedParams: Named< - CandidMeta - >[], - returnType: CandidMeta< - ReturnTypeAgentArgumentValue, - ReturnTypeAgentResponseValue - > -) => Test[]; - -export type CallbackLocation = 'INLINE' | 'STANDALONE'; - export function QueryMethodArb< - ParamAgentArgumentValue extends CandidType, + ParamAgentArgumentValue extends CorrespondingJSType, ParamAgentResponseValue, - ReturnTypeAgentArgumentValue extends CandidType, + ReturnTypeAgentArgumentValue extends CorrespondingJSType, ReturnTypeAgentResponseValue >( paramTypeArrayArb: fc.Arbitrary< - CandidMeta[] + CandidValueAndMeta[] >, returnTypeArb: fc.Arbitrary< - CandidMeta + CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > >, constraints: { generateBody: BodyGenerator< @@ -121,8 +98,10 @@ export function QueryMethodArb< ); const candidTypeDeclarations = [ - ...paramTypes.map((param) => param.src.typeDeclaration), - returnType.src.typeDeclaration + ...paramTypes.flatMap( + (param) => param.src.typeAliasDeclarations + ), + ...returnType.src.typeAliasDeclarations ].filter(isDefined); const globalDeclarations = @@ -153,60 +132,22 @@ export function QueryMethodArb< ); } -function isDefined(value: T | undefined): value is T { - return value !== undefined; -} - -function generateCallback< - ParamType extends CandidType, - ParamAgentType, - ReturnType extends CandidReturnType, - ReturnAgentType ->( - namedParams: Named>[], - returnType: CandidMeta, - generateBody: BodyGenerator< - ParamType, - ParamAgentType, - ReturnType, - ReturnAgentType - >, - callbackLocation: CallbackLocation, - callbackName: string -): string { - const paramNames = namedParams - .map((namedParam) => namedParam.name) - .join(', '); - - const body = generateBody(namedParams, returnType); - - if (callbackLocation === 'INLINE') { - return `(${paramNames}) => {${body}}`; - } - - const paramNamesAndTypes = namedParams - .map((namedParam) => `${namedParam.name}: any`) // TODO: Use actual candid type, not any - .join(', '); - - return `function ${callbackName}(${paramNamesAndTypes}): any {${body}}`; // TODO: Use actual candid type, not any -} - function generateSourceCode< - ParamType extends CandidType, + ParamType extends CorrespondingJSType, ParamAgentType, ReturnType extends CandidReturnType, ReturnAgentType >( functionName: string, - paramTypes: CandidMeta[], - returnType: CandidMeta, + paramTypes: CandidValueAndMeta[], + returnType: CandidValueAndMeta, callback: string ): string { const paramCandidTypes = paramTypes - .map((param) => param.src.candidTypeObject) + .map((param) => param.src.typeAnnotation) .join(', '); - const returnCandidType = returnType.src.candidTypeObject; + const returnCandidType = returnType.src.typeAnnotation; return `${functionName}: query([${paramCandidTypes}], ${returnCandidType}, ${callback})`; } diff --git a/property_tests/arbitraries/canister_methods/update_method_arb.ts b/property_tests/arbitraries/canister_methods/update_method_arb.ts new file mode 100644 index 0000000000..d5d1954fbe --- /dev/null +++ b/property_tests/arbitraries/canister_methods/update_method_arb.ts @@ -0,0 +1,154 @@ +import fc from 'fast-check'; + +import { CandidValueAndMeta } from '../candid/candid_value_and_meta_arb'; +import { CandidReturnType } from '../candid/candid_return_type_arb'; +import { CorrespondingJSType } from '../candid/corresponding_js_type'; +import { UniqueIdentifierArb } from '../unique_identifier_arb'; +import { Test } from '../../../test'; +import { Named } from '../..'; + +import { + BodyGenerator, + TestsGenerator, + CallbackLocation, + isDefined, + generateCallback +} from '.'; + +export type UpdateMethod = { + imports: Set; + globalDeclarations: string[]; + sourceCode: string; + tests: Test[]; +}; + +export function UpdateMethodArb< + ParamAgentArgumentValue extends CorrespondingJSType, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue extends CorrespondingJSType, + ReturnTypeAgentResponseValue +>( + paramTypeArrayArb: fc.Arbitrary< + CandidValueAndMeta[] + >, + returnTypeArb: fc.Arbitrary< + CandidValueAndMeta< + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + > + >, + constraints: { + generateBody: BodyGenerator< + ParamAgentArgumentValue, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + >; + generateTests: TestsGenerator< + ParamAgentArgumentValue, + ParamAgentResponseValue, + ReturnTypeAgentArgumentValue, + ReturnTypeAgentResponseValue + >; + callbackLocation?: CallbackLocation; + } +) { + return fc + .tuple( + UniqueIdentifierArb('canisterMethod'), + paramTypeArrayArb, + returnTypeArb, + 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, + returnType, + defaultCallbackLocation, + callbackName + ]): UpdateMethod => { + const callbackLocation = + constraints.callbackLocation ?? defaultCallbackLocation; + + const imports = new Set([ + ...paramTypes.flatMap((param) => [...param.src.imports]), + ...returnType.src.imports + ]); + + const namedParams = paramTypes.map( + (param: T, index: number): Named => ({ + name: `param${index}`, + el: param + }) + ); + + const callback = generateCallback( + namedParams, + returnType, + constraints.generateBody, + callbackLocation, + callbackName + ); + + const candidTypeDeclarations = [ + ...paramTypes.flatMap( + (param) => param.src.typeAliasDeclarations + ), + ...returnType.src.typeAliasDeclarations + ].filter(isDefined); + + const globalDeclarations = + callbackLocation === 'STANDALONE' + ? [...candidTypeDeclarations, callback] + : candidTypeDeclarations; + + const sourceCode = generateSourceCode( + functionName, + paramTypes, + returnType, + callbackLocation === 'STANDALONE' ? callbackName : callback + ); + + const tests = constraints.generateTests( + functionName, + namedParams, + returnType + ); + + return { + imports, + globalDeclarations, + sourceCode, + tests + }; + } + ); +} + +function generateSourceCode< + ParamType extends CorrespondingJSType, + ParamAgentType, + ReturnType extends CandidReturnType, + ReturnAgentType +>( + functionName: string, + paramTypes: CandidValueAndMeta[], + returnType: CandidValueAndMeta, + callback: string +): string { + const paramCandidTypes = paramTypes + .map((param) => param.src.typeAnnotation) + .join(', '); + + const returnCandidType = returnType.src.typeAnnotation; + + return `${functionName}: update([${paramCandidTypes}], ${returnCandidType}, ${callback})`; +} diff --git a/property_tests/are_params_correctly_ordered.ts b/property_tests/are_params_correctly_ordered.ts index b078f3972c..398dd31693 100644 --- a/property_tests/are_params_correctly_ordered.ts +++ b/property_tests/are_params_correctly_ordered.ts @@ -1,9 +1,9 @@ -import { CandidMeta } from './arbitraries/candid/candid_arb'; -import { CandidType } from './arbitraries/candid/candid_type_arb'; +import { CandidValueAndMeta } from './arbitraries/candid/candid_value_and_meta_arb'; +import { CorrespondingJSType } from './arbitraries/candid/corresponding_js_type'; import { Named } from '.'; -export function areParamsCorrectlyOrdered( - params: Named>[] +export function areParamsCorrectlyOrdered( + params: Named>[] ) { return params .map(({ name, el }) => { diff --git a/property_tests/index.ts b/property_tests/index.ts index 1e3b4e95d4..57a9b58df9 100644 --- a/property_tests/index.ts +++ b/property_tests/index.ts @@ -59,3 +59,8 @@ export function runPropTests(canisterArb: fc.Arbitrary) { } ); } + +export const defaultArrayConstraints = { + minLength: 20, + maxLength: 100 +}; diff --git a/property_tests/tests/blob/test/generate_body.ts b/property_tests/tests/blob/test/generate_body.ts index bcc0f66e66..13864f6bc3 100644 --- a/property_tests/tests/blob/test/generate_body.ts +++ b/property_tests/tests/blob/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamBlobs: Named>[], - returnBlob: CandidMeta + namedParamBlobs: Named>[], + returnBlob: CandidValueAndMeta ): string { // TODO these checks should be much more precise probably, imagine checking the elements inside of the arrays const paramsAreUint8Arrays = namedParamBlobs diff --git a/property_tests/tests/blob/test/generate_tests.ts b/property_tests/tests/blob/test/generate_tests.ts index 739b609bb8..4b01823c76 100644 --- a/property_tests/tests/blob/test/generate_tests.ts +++ b/property_tests/tests/blob/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - paramBlobs: Named>[], - returnBlob: CandidMeta + paramBlobs: Named>[], + returnBlob: CandidValueAndMeta ): Test[] { const expectedResult = Uint8Array.from( paramBlobs diff --git a/property_tests/tests/blob/test/test.ts b/property_tests/tests/blob/test/test.ts index 4836a897bb..50ea35ab7b 100644 --- a/property_tests/tests/blob/test/test.ts +++ b/property_tests/tests/blob/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { BlobArb } from 'azle/property_tests/arbitraries/candid/constructed/blob_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllBlobsQueryMethod = QueryMethodArb(fc.array(BlobArb), BlobArb, { +const AllBlobsQueryMethodArb = QueryMethodArb(fc.array(BlobArb()), BlobArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllBlobsQueryMethod)); +const CanisterConfigArb = fc + .array(AllBlobsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/bool/test/generate_body.ts b/property_tests/tests/bool/test/generate_body.ts index 28b40c0f80..1731b949f2 100644 --- a/property_tests/tests/bool/test/generate_body.ts +++ b/property_tests/tests/bool/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamBools: Named>[], - returnBool: CandidMeta + namedParamBools: Named>[], + returnBool: CandidValueAndMeta ): string { // TODO do we want to encapsulate 'boolean' in the CandidArb? Like an agentType instead of a candidType, like azleValue and agentValue? // TODO or will this not matter anymore once we start using a deep equal library diff --git a/property_tests/tests/bool/test/generate_tests.ts b/property_tests/tests/bool/test/generate_tests.ts index ca7062bea9..06fade587b 100644 --- a/property_tests/tests/bool/test/generate_tests.ts +++ b/property_tests/tests/bool/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamBools: Named>[], - returnBool: CandidMeta + namedParamBools: Named>[], + returnBool: CandidValueAndMeta ): Test[] { const expectedResult = namedParamBools.reduce( (acc, param) => acc && param.el.agentResponseValue, diff --git a/property_tests/tests/bool/test/test.ts b/property_tests/tests/bool/test/test.ts index d900fb9a5e..d05e1c9759 100644 --- a/property_tests/tests/bool/test/test.ts +++ b/property_tests/tests/bool/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { BoolArb } from 'azle/property_tests/arbitraries/candid/primitive/bool'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllBoolsQueryMethod = QueryMethodArb(fc.array(BoolArb), BoolArb, { +const AllBoolsQueryMethodArb = QueryMethodArb(fc.array(BoolArb()), BoolArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllBoolsQueryMethod)); +const CanisterConfigArb = fc + .array(AllBoolsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/float32/test/generate_body.ts b/property_tests/tests/float32/test/generate_body.ts index edb9dda4c7..e30bddd47f 100644 --- a/property_tests/tests/float32/test/generate_body.ts +++ b/property_tests/tests/float32/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamFloat32s: Named>[], - returnFloat32: CandidMeta + namedParamFloat32s: Named>[], + returnFloat32: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamFloat32s .map((param) => { diff --git a/property_tests/tests/float32/test/generate_tests.ts b/property_tests/tests/float32/test/generate_tests.ts index 466faf2884..e2e891e2b7 100644 --- a/property_tests/tests/float32/test/generate_tests.ts +++ b/property_tests/tests/float32/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamFloat32s: Named>[], - returnFloat32: CandidMeta + namedParamFloat32s: Named>[], + returnFloat32: CandidValueAndMeta ): Test[] { const expectedResult = namedParamFloat32s.length === 0 diff --git a/property_tests/tests/float32/test/test.ts b/property_tests/tests/float32/test/test.ts index a70655d041..57857e6035 100644 --- a/property_tests/tests/float32/test/test.ts +++ b/property_tests/tests/float32/test/test.ts @@ -1,20 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Float32Arb } from 'azle/property_tests/arbitraries/candid/primitive/floats/float32_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllFloat32sQueryMethod = QueryMethodArb( - fc.array(Float32Arb), - Float32Arb, +const AllFloat32sQueryMethodArb = QueryMethodArb( + fc.array(Float32Arb()), + Float32Arb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllFloat32sQueryMethod)); +const CanisterConfigArb = fc + .array(AllFloat32sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/float64/test/generate_body.ts b/property_tests/tests/float64/test/generate_body.ts index bd8fa38ac7..5693308553 100644 --- a/property_tests/tests/float64/test/generate_body.ts +++ b/property_tests/tests/float64/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamFloat64s: Named>[], - returnFloat64: CandidMeta + namedParamFloat64s: Named>[], + returnFloat64: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamFloat64s .map((param) => { diff --git a/property_tests/tests/float64/test/generate_tests.ts b/property_tests/tests/float64/test/generate_tests.ts index a232a6c8ab..9f1429ac9e 100644 --- a/property_tests/tests/float64/test/generate_tests.ts +++ b/property_tests/tests/float64/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamFloat64s: Named>[], - returnFloat64: CandidMeta + namedParamFloat64s: Named>[], + returnFloat64: CandidValueAndMeta ): Test[] { const count = namedParamFloat64s.length + 1; const expectedResult = diff --git a/property_tests/tests/float64/test/test.ts b/property_tests/tests/float64/test/test.ts index ee728dbf72..e25bab348f 100644 --- a/property_tests/tests/float64/test/test.ts +++ b/property_tests/tests/float64/test/test.ts @@ -1,20 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Float64Arb } from 'azle/property_tests/arbitraries/candid/primitive/floats/float64_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllFloat64sQueryMethod = QueryMethodArb( - fc.array(Float64Arb), - Float64Arb, +const AllFloat64sQueryMethodArb = QueryMethodArb( + fc.array(Float64Arb()), + Float64Arb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllFloat64sQueryMethod)); +const CanisterConfigArb = fc + .array(AllFloat64sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/func/test/generate_body.ts b/property_tests/tests/func/test/generate_body.ts index 2e5aa2fb8b..1a43c3195d 100644 --- a/property_tests/tests/func/test/generate_body.ts +++ b/property_tests/tests/func/test/generate_body.ts @@ -1,11 +1,11 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Func } from 'azle/property_tests/arbitraries/candid/reference/func_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamFuncs: Named>[], - returnFunc: CandidMeta + namedParamFuncs: Named>[], + returnFunc: CandidValueAndMeta ): string { const paramsAreFuncs = namedParamFuncs .map(({ name }) => { diff --git a/property_tests/tests/func/test/generate_tests.ts b/property_tests/tests/func/test/generate_tests.ts index 84d4149ce7..ee6e49c55f 100644 --- a/property_tests/tests/func/test/generate_tests.ts +++ b/property_tests/tests/func/test/generate_tests.ts @@ -1,14 +1,14 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Func } from 'azle/property_tests/arbitraries/candid/reference/func_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamFuncs: Named>[], - returnFunc: CandidMeta + namedParamFuncs: Named>[], + returnFunc: CandidValueAndMeta ): Test[] { return [ { diff --git a/property_tests/tests/func/test/test.ts b/property_tests/tests/func/test/test.ts index 6eae8b940a..1adbac60d6 100644 --- a/property_tests/tests/func/test/test.ts +++ b/property_tests/tests/func/test/test.ts @@ -1,20 +1,31 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { FuncArb } from 'azle/property_tests/arbitraries/candid/reference/func_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllFuncsQueryMethod = QueryMethodArb( - fc.uniqueArray(FuncArb, { selector: (entry) => entry.src.candidType }), - FuncArb, +const AllFuncsQueryMethodArb = QueryMethodArb( + fc.uniqueArray(FuncArb(), { + selector: (entry) => entry.src.typeAnnotation + }), + FuncArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllFuncsQueryMethod)); +const CanisterConfigArb = fc + .array(AllFuncsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/int/test/generate_body.ts b/property_tests/tests/int/test/generate_body.ts index d0d10b3515..88171062e8 100644 --- a/property_tests/tests/int/test/generate_body.ts +++ b/property_tests/tests/int/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamInts: Named>[], - returnInt: CandidMeta + namedParamInts: Named>[], + returnInt: CandidValueAndMeta ): string { const paramsAreBigInts = namedParamInts .map((param) => { diff --git a/property_tests/tests/int/test/generate_tests.ts b/property_tests/tests/int/test/generate_tests.ts index 136ac7206b..1b01b2a30b 100644 --- a/property_tests/tests/int/test/generate_tests.ts +++ b/property_tests/tests/int/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamInts: Named>[], - returnInt: CandidMeta + namedParamInts: Named>[], + returnInt: CandidValueAndMeta ): Test[] { const expectedResult = namedParamInts.reduce( (acc, param) => acc + param.el.agentResponseValue, diff --git a/property_tests/tests/int/test/test.ts b/property_tests/tests/int/test/test.ts index 4293bf6110..96e9919a77 100644 --- a/property_tests/tests/int/test/test.ts +++ b/property_tests/tests/int/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { IntArb } from 'azle/property_tests/arbitraries/candid/primitive/ints/int_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllIntsQueryMethod = QueryMethodArb(fc.array(IntArb), IntArb, { +const AllIntsQueryMethodArb = QueryMethodArb(fc.array(IntArb()), IntArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllIntsQueryMethod)); +const CanisterConfigArb = fc + .array(AllIntsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/int16/test/generate_body.ts b/property_tests/tests/int16/test/generate_body.ts index 8564972c07..e17bc72bfe 100644 --- a/property_tests/tests/int16/test/generate_body.ts +++ b/property_tests/tests/int16/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamInt16s: Named>[], - returnInt16: CandidMeta + namedParamInt16s: Named>[], + returnInt16: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamInt16s .map((param) => { diff --git a/property_tests/tests/int16/test/generate_tests.ts b/property_tests/tests/int16/test/generate_tests.ts index a7d368f18f..1372b4352e 100644 --- a/property_tests/tests/int16/test/generate_tests.ts +++ b/property_tests/tests/int16/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamInt16s: Named>[], - returnInt16: CandidMeta + namedParamInt16s: Named>[], + returnInt16: CandidValueAndMeta ): Test[] { const count = namedParamInt16s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/int16/test/test.ts b/property_tests/tests/int16/test/test.ts index 454adcb7eb..46008e7d56 100644 --- a/property_tests/tests/int16/test/test.ts +++ b/property_tests/tests/int16/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Int16Arb } from 'azle/property_tests/arbitraries/candid/primitive/ints/int16_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllInt16sQueryMethod = QueryMethodArb(fc.array(Int16Arb), Int16Arb, { - generateBody, - generateTests -}); +const AllInt16sQueryMethodArb = QueryMethodArb( + fc.array(Int16Arb()), + Int16Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllInt16sQueryMethod)); +const CanisterConfigArb = fc + .array(AllInt16sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/int32/test/generate_body.ts b/property_tests/tests/int32/test/generate_body.ts index 358e355a4d..16b9a29550 100644 --- a/property_tests/tests/int32/test/generate_body.ts +++ b/property_tests/tests/int32/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamInt32s: Named>[], - returnInt32: CandidMeta + namedParamInt32s: Named>[], + returnInt32: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamInt32s .map((param) => { diff --git a/property_tests/tests/int32/test/generate_tests.ts b/property_tests/tests/int32/test/generate_tests.ts index ce108815cb..748ebae928 100644 --- a/property_tests/tests/int32/test/generate_tests.ts +++ b/property_tests/tests/int32/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamInt32s: Named>[], - returnInt32: CandidMeta + namedParamInt32s: Named>[], + returnInt32: CandidValueAndMeta ): Test[] { const count = namedParamInt32s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/int32/test/test.ts b/property_tests/tests/int32/test/test.ts index e6f7bb0f99..b2790bf8c7 100644 --- a/property_tests/tests/int32/test/test.ts +++ b/property_tests/tests/int32/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Int32Arb } from 'azle/property_tests/arbitraries/candid/primitive/ints/int32_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllInt32sQueryMethod = QueryMethodArb(fc.array(Int32Arb), Int32Arb, { - generateBody, - generateTests -}); +const AllInt32sQueryMethodArb = QueryMethodArb( + fc.array(Int32Arb()), + Int32Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllInt32sQueryMethod)); +const CanisterConfigArb = fc + .array(AllInt32sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/int64/test/generate_body.ts b/property_tests/tests/int64/test/generate_body.ts index ca5308dcc6..90bafab51e 100644 --- a/property_tests/tests/int64/test/generate_body.ts +++ b/property_tests/tests/int64/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamInt64s: Named>[], - returnInt64: CandidMeta + namedParamInt64s: Named>[], + returnInt64: CandidValueAndMeta ): string { const paramsAreBigInts = namedParamInt64s .map((param) => { diff --git a/property_tests/tests/int64/test/generate_tests.ts b/property_tests/tests/int64/test/generate_tests.ts index 7023c94f05..958bd40c94 100644 --- a/property_tests/tests/int64/test/generate_tests.ts +++ b/property_tests/tests/int64/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamInt64s: Named>[], - returnInt64: CandidMeta + namedParamInt64s: Named>[], + returnInt64: CandidValueAndMeta ): Test[] { const count = namedParamInt64s.length + 1; const expectedResult = diff --git a/property_tests/tests/int64/test/test.ts b/property_tests/tests/int64/test/test.ts index 3dceb15bdc..8cc9552327 100644 --- a/property_tests/tests/int64/test/test.ts +++ b/property_tests/tests/int64/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Int64Arb } from 'azle/property_tests/arbitraries/candid/primitive/ints/int64_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllInt64sQueryMethod = QueryMethodArb(fc.array(Int64Arb), Int64Arb, { - generateBody, - generateTests -}); +const AllInt64sQueryMethodArb = QueryMethodArb( + fc.array(Int64Arb()), + Int64Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllInt64sQueryMethod)); +const CanisterConfigArb = fc + .array(AllInt64sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/int8/test/generate_body.ts b/property_tests/tests/int8/test/generate_body.ts index 61e93d39cf..86ec62ff08 100644 --- a/property_tests/tests/int8/test/generate_body.ts +++ b/property_tests/tests/int8/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamInt8s: Named>[], - returnInt8: CandidMeta + namedParamInt8s: Named>[], + returnInt8: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamInt8s .map((param) => { diff --git a/property_tests/tests/int8/test/generate_tests.ts b/property_tests/tests/int8/test/generate_tests.ts index a0237976e5..43f5c8fc3b 100644 --- a/property_tests/tests/int8/test/generate_tests.ts +++ b/property_tests/tests/int8/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamInt8s: Named>[], - returnInt8: CandidMeta + namedParamInt8s: Named>[], + returnInt8: CandidValueAndMeta ): Test[] { const count = namedParamInt8s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/int8/test/test.ts b/property_tests/tests/int8/test/test.ts index 7ee01da265..0d1a76c5e9 100644 --- a/property_tests/tests/int8/test/test.ts +++ b/property_tests/tests/int8/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Int8Arb } from 'azle/property_tests/arbitraries/candid/primitive/ints/int8_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllInt8sQueryMethod = QueryMethodArb(fc.array(Int8Arb), Int8Arb, { +const AllInt8sQueryMethodArb = QueryMethodArb(fc.array(Int8Arb()), Int8Arb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllInt8sQueryMethod)); +const CanisterConfigArb = fc + .array(AllInt8sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/nat/test/generate_body.ts b/property_tests/tests/nat/test/generate_body.ts index 5b0741b2da..fb4f9c7810 100644 --- a/property_tests/tests/nat/test/generate_body.ts +++ b/property_tests/tests/nat/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamNats: Named>[], - returnNat: CandidMeta + namedParamNats: Named>[], + returnNat: CandidValueAndMeta ): string { const paramsAreBigInts = namedParamNats .map((param) => { diff --git a/property_tests/tests/nat/test/generate_tests.ts b/property_tests/tests/nat/test/generate_tests.ts index 77ad9e4474..31a0047d76 100644 --- a/property_tests/tests/nat/test/generate_tests.ts +++ b/property_tests/tests/nat/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNats: Named>[], - returnNat: CandidMeta + namedParamNats: Named>[], + returnNat: CandidValueAndMeta ): Test[] { const expectedResult = namedParamNats.reduce( (acc, param) => acc + param.el.agentResponseValue, diff --git a/property_tests/tests/nat/test/test.ts b/property_tests/tests/nat/test/test.ts index 0f8a528086..455d096f7e 100644 --- a/property_tests/tests/nat/test/test.ts +++ b/property_tests/tests/nat/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { NatArb } from 'azle/property_tests/arbitraries/candid/primitive/nats/nat_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNatsQueryMethod = QueryMethodArb(fc.array(NatArb), NatArb, { +const AllNatsQueryMethodArb = QueryMethodArb(fc.array(NatArb()), NatArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllNatsQueryMethod)); +const CanisterConfigArb = fc + .array(AllNatsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/nat16/test/generate_body.ts b/property_tests/tests/nat16/test/generate_body.ts index 01fefac5b3..116fb89d0c 100644 --- a/property_tests/tests/nat16/test/generate_body.ts +++ b/property_tests/tests/nat16/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamNat16s: Named>[], - returnNat16: CandidMeta + namedParamNat16s: Named>[], + returnNat16: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamNat16s .map((param) => { diff --git a/property_tests/tests/nat16/test/generate_tests.ts b/property_tests/tests/nat16/test/generate_tests.ts index 1bf2afbc33..6adc8ebffe 100644 --- a/property_tests/tests/nat16/test/generate_tests.ts +++ b/property_tests/tests/nat16/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNat16s: Named>[], - returnNat16: CandidMeta + namedParamNat16s: Named>[], + returnNat16: CandidValueAndMeta ): Test[] { const count = namedParamNat16s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/nat16/test/test.ts b/property_tests/tests/nat16/test/test.ts index dd11eb8e8a..5ee8833562 100644 --- a/property_tests/tests/nat16/test/test.ts +++ b/property_tests/tests/nat16/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Nat16Arb } from 'azle/property_tests/arbitraries/candid/primitive/nats/nat16_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNat16sQueryMethod = QueryMethodArb(fc.array(Nat16Arb), Nat16Arb, { - generateBody, - generateTests -}); +const AllNat16sQueryMethodArb = QueryMethodArb( + fc.array(Nat16Arb()), + Nat16Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllNat16sQueryMethod)); +const CanisterConfigArb = fc + .array(AllNat16sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/nat32/test/generate_body.ts b/property_tests/tests/nat32/test/generate_body.ts index 2754c62538..c96a9cd2e3 100644 --- a/property_tests/tests/nat32/test/generate_body.ts +++ b/property_tests/tests/nat32/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamNat32s: Named>[], - returnNat32: CandidMeta + namedParamNat32s: Named>[], + returnNat32: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamNat32s .map((param) => { diff --git a/property_tests/tests/nat32/test/generate_tests.ts b/property_tests/tests/nat32/test/generate_tests.ts index 90570ee9a7..c1f484d48c 100644 --- a/property_tests/tests/nat32/test/generate_tests.ts +++ b/property_tests/tests/nat32/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNat32s: Named>[], - returnNat32: CandidMeta + namedParamNat32s: Named>[], + returnNat32: CandidValueAndMeta ): Test[] { const count = namedParamNat32s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/nat32/test/test.ts b/property_tests/tests/nat32/test/test.ts index 5826beda5c..e841f0a5c7 100644 --- a/property_tests/tests/nat32/test/test.ts +++ b/property_tests/tests/nat32/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Nat32Arb } from 'azle/property_tests/arbitraries/candid/primitive/nats/nat32_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNat32sQueryMethod = QueryMethodArb(fc.array(Nat32Arb), Nat32Arb, { - generateBody, - generateTests -}); +const AllNat32sQueryMethodArb = QueryMethodArb( + fc.array(Nat32Arb()), + Nat32Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllNat32sQueryMethod)); +const CanisterConfigArb = fc + .array(AllNat32sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/nat64/test/generate_body.ts b/property_tests/tests/nat64/test/generate_body.ts index 524c7bcde3..de3eaa9eba 100644 --- a/property_tests/tests/nat64/test/generate_body.ts +++ b/property_tests/tests/nat64/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamNat64s: Named>[], - returnNat64: CandidMeta + namedParamNat64s: Named>[], + returnNat64: CandidValueAndMeta ): string { const paramsAreBigInts = namedParamNat64s .map((param) => { diff --git a/property_tests/tests/nat64/test/generate_tests.ts b/property_tests/tests/nat64/test/generate_tests.ts index 963143ce2e..e6cb87ca50 100644 --- a/property_tests/tests/nat64/test/generate_tests.ts +++ b/property_tests/tests/nat64/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNat64s: Named>[], - returnNat64: CandidMeta + namedParamNat64s: Named>[], + returnNat64: CandidValueAndMeta ): Test[] { const count = namedParamNat64s.length + 1; const expectedResult = diff --git a/property_tests/tests/nat64/test/test.ts b/property_tests/tests/nat64/test/test.ts index ee00f5889c..5940b0f349 100644 --- a/property_tests/tests/nat64/test/test.ts +++ b/property_tests/tests/nat64/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Nat64Arb } from 'azle/property_tests/arbitraries/candid/primitive/nats/nat64_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNat64sQueryMethod = QueryMethodArb(fc.array(Nat64Arb), Nat64Arb, { - generateBody, - generateTests -}); +const AllNat64sQueryMethodArb = QueryMethodArb( + fc.array(Nat64Arb()), + Nat64Arb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllNat64sQueryMethod)); +const CanisterConfigArb = fc + .array(AllNat64sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/nat8/test/generate_body.ts b/property_tests/tests/nat8/test/generate_body.ts index 9591220de7..0b9479d261 100644 --- a/property_tests/tests/nat8/test/generate_body.ts +++ b/property_tests/tests/nat8/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamNat8s: Named>[], - returnNat8: CandidMeta + namedParamNat8s: Named>[], + returnNat8: CandidValueAndMeta ): string { const paramsAreNumbers = namedParamNat8s .map((param) => { diff --git a/property_tests/tests/nat8/test/generate_tests.ts b/property_tests/tests/nat8/test/generate_tests.ts index ac2937734c..60f29c0a2e 100644 --- a/property_tests/tests/nat8/test/generate_tests.ts +++ b/property_tests/tests/nat8/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNat8s: Named>[], - returnNat8: CandidMeta + namedParamNat8s: Named>[], + returnNat8: CandidValueAndMeta ): Test[] { const count = namedParamNat8s.length + 1; const expectedResult = Math.floor( diff --git a/property_tests/tests/nat8/test/test.ts b/property_tests/tests/nat8/test/test.ts index 4d61c6f73f..0e8efb63b3 100644 --- a/property_tests/tests/nat8/test/test.ts +++ b/property_tests/tests/nat8/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { Nat8Arb } from 'azle/property_tests/arbitraries/candid/primitive/nats/nat8_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNat8sQueryMethod = QueryMethodArb(fc.array(Nat8Arb), Nat8Arb, { +const AllNat8sQueryMethodArb = QueryMethodArb(fc.array(Nat8Arb()), Nat8Arb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllNat8sQueryMethod)); +const CanisterConfigArb = fc + .array(AllNat8sQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/null/test/generate_body.ts b/property_tests/tests/null/test/generate_body.ts index 23db849a81..553eaeb441 100644 --- a/property_tests/tests/null/test/generate_body.ts +++ b/property_tests/tests/null/test/generate_body.ts @@ -1,9 +1,9 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; export function generateBody( - namedParamNulls: Named>[], - returnNull: CandidMeta + namedParamNulls: Named>[], + returnNull: CandidValueAndMeta ): string { const areAllNull = namedParamNulls.reduce((acc, { name }) => { return `${acc} && ${name} === null`; diff --git a/property_tests/tests/null/test/generate_tests.ts b/property_tests/tests/null/test/generate_tests.ts index c769d27dce..0c19d354d3 100644 --- a/property_tests/tests/null/test/generate_tests.ts +++ b/property_tests/tests/null/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamNulls: Named>[], - _returnNull: CandidMeta + namedParamNulls: Named>[], + _returnNull: CandidValueAndMeta ): Test[] { return [ { diff --git a/property_tests/tests/null/test/test.ts b/property_tests/tests/null/test/test.ts index ccd91f029c..b51d768825 100644 --- a/property_tests/tests/null/test/test.ts +++ b/property_tests/tests/null/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { NullArb } from 'azle/property_tests/arbitraries/candid/primitive/null'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllNullsQueryMethod = QueryMethodArb(fc.array(NullArb), NullArb, { +const AllNullsQueryMethodArb = QueryMethodArb(fc.array(NullArb()), NullArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllNullsQueryMethod)); +const CanisterConfigArb = fc + .array(AllNullsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/opt/test/generate_body.ts b/property_tests/tests/opt/test/generate_body.ts index 9a837262b8..fe74aa8e7e 100644 --- a/property_tests/tests/opt/test/generate_body.ts +++ b/property_tests/tests/opt/test/generate_body.ts @@ -1,11 +1,11 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Opt } from 'azle/property_tests/arbitraries/candid/constructed/opt_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamOpts: Named>[], - returnOpt: CandidMeta + namedParamOpts: Named>[], + returnOpt: CandidValueAndMeta ): string { const areParamsOpts = namedParamOpts .map((param) => { diff --git a/property_tests/tests/opt/test/generate_tests.ts b/property_tests/tests/opt/test/generate_tests.ts index 9a8a4046bd..772d58eca0 100644 --- a/property_tests/tests/opt/test/generate_tests.ts +++ b/property_tests/tests/opt/test/generate_tests.ts @@ -1,14 +1,14 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Opt } from 'azle/property_tests/arbitraries/candid/constructed/opt_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamOpts: Named>[], - returnOpt: CandidMeta + namedParamOpts: Named>[], + returnOpt: CandidValueAndMeta ): Test[] { const expectedResult = returnOpt.agentResponseValue; diff --git a/property_tests/tests/opt/test/test.ts b/property_tests/tests/opt/test/test.ts index 890102c7cc..fa4b1ce89b 100644 --- a/property_tests/tests/opt/test/test.ts +++ b/property_tests/tests/opt/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { OptArb } from 'azle/property_tests/arbitraries/candid/constructed/opt_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllOptsQueryMethod = QueryMethodArb(fc.array(OptArb), OptArb, { +const AllOptsQueryMethodArb = QueryMethodArb(fc.array(OptArb()), OptArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllOptsQueryMethod)); +const CanisterConfigArb = fc + .array(AllOptsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/principal/test/generate_body.ts b/property_tests/tests/principal/test/generate_body.ts index 3f4a75739c..4119207627 100644 --- a/property_tests/tests/principal/test/generate_body.ts +++ b/property_tests/tests/principal/test/generate_body.ts @@ -1,12 +1,12 @@ import { Principal } from '@dfinity/principal'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamPrincipals: Named>[], - returnPrincipal: CandidMeta + namedParamPrincipals: Named>[], + returnPrincipal: CandidValueAndMeta ): string { const paramsArePrincipals = namedParamPrincipals .map((param) => { diff --git a/property_tests/tests/principal/test/generate_tests.ts b/property_tests/tests/principal/test/generate_tests.ts index 87df7bc478..5433012364 100644 --- a/property_tests/tests/principal/test/generate_tests.ts +++ b/property_tests/tests/principal/test/generate_tests.ts @@ -2,13 +2,13 @@ import { Principal } from '@dfinity/principal'; import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamPrincipals: Named>[], - returnPrincipal: CandidMeta + namedParamPrincipals: Named>[], + returnPrincipal: CandidValueAndMeta ): Test[] { const expectedResult = namedParamPrincipals.length > 0 diff --git a/property_tests/tests/principal/test/test.ts b/property_tests/tests/principal/test/test.ts index 566d06dc17..bd1cbc4784 100644 --- a/property_tests/tests/principal/test/test.ts +++ b/property_tests/tests/principal/test/test.ts @@ -1,20 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { PrincipalArb } from 'azle/property_tests/arbitraries/candid/reference/principal_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllPrincipalsQueryMethod = QueryMethodArb( - fc.array(PrincipalArb), - PrincipalArb, +const AllPrincipalsQueryMethodArb = QueryMethodArb( + fc.array(PrincipalArb()), + PrincipalArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllPrincipalsQueryMethod)); +const CanisterConfigArb = fc + .array(AllPrincipalsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/query_methods/test/generate_body.ts b/property_tests/tests/query_methods/test/generate_body.ts index fcbb578333..960b3c19a3 100644 --- a/property_tests/tests/query_methods/test/generate_body.ts +++ b/property_tests/tests/query_methods/test/generate_body.ts @@ -1,13 +1,12 @@ import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; -import { CandidType } from 'azle/property_tests/arbitraries/candid/candid_type_arb'; -import { BodyGenerator } from 'azle/property_tests/arbitraries/query_method_arb'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; export function generateBody( - namedParams: Named>[], - returnType: CandidMeta + namedParams: Named>[], + returnType: CandidValueAndMeta ): string { const paramsAreCorrectlyOrdered = areParamsCorrectlyOrdered(namedParams); diff --git a/property_tests/tests/query_methods/test/generate_tests.ts b/property_tests/tests/query_methods/test/generate_tests.ts index c74d39beb2..a2b0f1ccf3 100644 --- a/property_tests/tests/query_methods/test/generate_tests.ts +++ b/property_tests/tests/query_methods/test/generate_tests.ts @@ -1,15 +1,15 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidType } from 'azle/property_tests/arbitraries/candid/candid_type_arb'; -import { CandidReturnType } from '../../../arbitraries/candid/candid_return_type_arb'; -import { CandidMeta } from '../../../arbitraries/candid/candid_arb'; +import { CorrespondingJSType } from 'azle/property_tests/arbitraries/candid/corresponding_js_type'; +import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - params: Named>[], - returnType: CandidMeta + params: Named>[], + returnType: CandidValueAndMeta ): Test[] { const paramValues = params.map((param) => param.el.agentArgumentValue); const expectedResult = returnType.agentResponseValue; diff --git a/property_tests/tests/query_methods/test/test.ts b/property_tests/tests/query_methods/test/test.ts index a178b210e2..bc56880a19 100644 --- a/property_tests/tests/query_methods/test/test.ts +++ b/property_tests/tests/query_methods/test/test.ts @@ -1,10 +1,13 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; -import { CandidTypeArb } from 'azle/property_tests/arbitraries/candid/candid_type_arb'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; +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 } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; @@ -15,13 +18,19 @@ import { generateTests } from './generate_tests'; // TODO nat // TODO update methods -const HeterogeneousQueryMethod = QueryMethodArb( - fc.array(CandidTypeArb), - CandidReturnTypeArb, +const HeterogeneousQueryMethodArb = QueryMethodArb( + fc.array(CandidValueAndMetaArb()), + CandidReturnTypeArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(HeterogeneousQueryMethod)); +const CanisterConfigArb = fc + .array(HeterogeneousQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/record/test/generate_body.ts b/property_tests/tests/record/test/generate_body.ts index 874a0ce634..c4f7d5e942 100644 --- a/property_tests/tests/record/test/generate_body.ts +++ b/property_tests/tests/record/test/generate_body.ts @@ -1,11 +1,11 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Record } from 'azle/property_tests/arbitraries/candid/constructed/record_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamRecords: Named>[], - returnRecord: CandidMeta + namedParamRecords: Named>[], + returnRecord: CandidValueAndMeta ): string { const paramsAreRecords = namedParamRecords .map((param) => { diff --git a/property_tests/tests/record/test/generate_tests.ts b/property_tests/tests/record/test/generate_tests.ts index 2439d78371..803eceb80a 100644 --- a/property_tests/tests/record/test/generate_tests.ts +++ b/property_tests/tests/record/test/generate_tests.ts @@ -1,14 +1,14 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Record } from 'azle/property_tests/arbitraries/candid/constructed/record_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamRecords: Named>[], - returnRecord: CandidMeta + namedParamRecords: Named>[], + returnRecord: CandidValueAndMeta ): Test[] { return [ { diff --git a/property_tests/tests/record/test/test.ts b/property_tests/tests/record/test/test.ts index 3605baa67d..62a3647916 100644 --- a/property_tests/tests/record/test/test.ts +++ b/property_tests/tests/record/test/test.ts @@ -1,16 +1,29 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { RecordArb } from 'azle/property_tests/arbitraries/candid/constructed/record_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllRecordsQueryMethod = QueryMethodArb(fc.array(RecordArb), RecordArb, { - generateBody, - generateTests -}); +const AllRecordsQueryMethodArb = QueryMethodArb( + fc.array(RecordArb()), + RecordArb(), + { + generateBody, + generateTests + } +); -runPropTests(CanisterArb(AllRecordsQueryMethod)); +const CanisterConfigArb = fc + .array(AllRecordsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/service/test/generate_body.ts b/property_tests/tests/service/test/generate_body.ts index 4fd2908cbd..34fb22ecbd 100644 --- a/property_tests/tests/service/test/generate_body.ts +++ b/property_tests/tests/service/test/generate_body.ts @@ -1,11 +1,11 @@ import { Principal } from '@dfinity/principal'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; export function generateBody( - namedParamServices: Named>[], - returnService: CandidMeta + namedParamServices: Named>[], + returnService: CandidValueAndMeta ): string { const paramsAreServices = namedParamServices .map((param) => { diff --git a/property_tests/tests/service/test/generate_tests.ts b/property_tests/tests/service/test/generate_tests.ts index 6c2c59cc27..d3590a364f 100644 --- a/property_tests/tests/service/test/generate_tests.ts +++ b/property_tests/tests/service/test/generate_tests.ts @@ -1,14 +1,14 @@ import { Principal } from '@dfinity/principal'; import { execSync } from 'child_process'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamServices: Named>[], - returnService: CandidMeta + namedParamServices: Named>[], + returnService: CandidValueAndMeta ): Test[] { return [ { diff --git a/property_tests/tests/service/test/test.ts b/property_tests/tests/service/test/test.ts index 60b53fc161..feabe0f63e 100644 --- a/property_tests/tests/service/test/test.ts +++ b/property_tests/tests/service/test/test.ts @@ -1,20 +1,31 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { ServiceArb } from 'azle/property_tests/arbitraries/candid/reference/service_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllServicesQueryMethod = QueryMethodArb( - fc.uniqueArray(ServiceArb, { selector: (entry) => entry.src.candidType }), - ServiceArb, +const AllServicesQueryMethodArb = QueryMethodArb( + fc.uniqueArray(ServiceArb(), { + selector: (entry) => entry.src.typeAnnotation + }), + ServiceArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllServicesQueryMethod)); +const CanisterConfigArb = fc + .array(AllServicesQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/text/test/generate_body.ts b/property_tests/tests/text/test/generate_body.ts index 3075ff364d..14cb6370d0 100644 --- a/property_tests/tests/text/test/generate_body.ts +++ b/property_tests/tests/text/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamTexts: Named>[], - returnText: CandidMeta + namedParamTexts: Named>[], + returnText: CandidValueAndMeta ): string { const paramsAreStrings = namedParamTexts .map((param) => { diff --git a/property_tests/tests/text/test/generate_tests.ts b/property_tests/tests/text/test/generate_tests.ts index 293d95c2bd..5b603660c7 100644 --- a/property_tests/tests/text/test/generate_tests.ts +++ b/property_tests/tests/text/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamTexts: Named>[], - returnTexts: CandidMeta + namedParamTexts: Named>[], + returnTexts: CandidValueAndMeta ): Test[] { const expectedResult = namedParamTexts.reduce( (acc, param) => acc + param.el.agentResponseValue, diff --git a/property_tests/tests/text/test/test.ts b/property_tests/tests/text/test/test.ts index 6a294917cd..afe08eb274 100644 --- a/property_tests/tests/text/test/test.ts +++ b/property_tests/tests/text/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { TextArb } from 'azle/property_tests/arbitraries/candid/primitive/text'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllTextsQueryMethod = QueryMethodArb(fc.array(TextArb), TextArb, { +const AllTextsQueryMethodArb = QueryMethodArb(fc.array(TextArb()), TextArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllTextsQueryMethod)); +const CanisterConfigArb = fc + .array(AllTextsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/tuple/test/generate_body.ts b/property_tests/tests/tuple/test/generate_body.ts index a248a3f899..a304a1238c 100644 --- a/property_tests/tests/tuple/test/generate_body.ts +++ b/property_tests/tests/tuple/test/generate_body.ts @@ -1,4 +1,4 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Tuple, ReturnTuple @@ -7,8 +7,8 @@ import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamTuples: Named>[], - returnTuple: CandidMeta + namedParamTuples: Named>[], + returnTuple: CandidValueAndMeta ): string { const paramsAreTuples = namedParamTuples .map((param) => { diff --git a/property_tests/tests/tuple/test/generate_tests.ts b/property_tests/tests/tuple/test/generate_tests.ts index 87f0e0a2dd..b26960de6b 100644 --- a/property_tests/tests/tuple/test/generate_tests.ts +++ b/property_tests/tests/tuple/test/generate_tests.ts @@ -1,7 +1,7 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Tuple, ReturnTuple @@ -10,8 +10,8 @@ import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamTuples: Named>[], - returnTuple: CandidMeta + namedParamTuples: Named>[], + returnTuple: CandidValueAndMeta ): Test[] { const expectedResult = returnTuple.agentResponseValue; diff --git a/property_tests/tests/tuple/test/test.ts b/property_tests/tests/tuple/test/test.ts index 864983bd50..e0a692f2be 100644 --- a/property_tests/tests/tuple/test/test.ts +++ b/property_tests/tests/tuple/test/test.ts @@ -1,20 +1,31 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { TupleArb } from 'azle/property_tests/arbitraries/candid/constructed/tuple_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllTuplesQueryMethod = QueryMethodArb( - fc.uniqueArray(TupleArb, { selector: (entry) => entry.src.candidType }), - TupleArb, +const AllTuplesQueryMethodArb = QueryMethodArb( + fc.uniqueArray(TupleArb(), { + selector: (entry) => entry.src.typeAnnotation + }), + TupleArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllTuplesQueryMethod)); +const CanisterConfigArb = fc + .array(AllTuplesQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/update_methods/dfx.json b/property_tests/tests/update_methods/dfx.json new file mode 100644 index 0000000000..6ab9fbd7e4 --- /dev/null +++ b/property_tests/tests/update_methods/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/update_methods/package-lock.json b/property_tests/tests/update_methods/package-lock.json new file mode 100644 index 0000000000..37ec3c7f47 --- /dev/null +++ b/property_tests/tests/update_methods/package-lock.json @@ -0,0 +1,996 @@ +{ + "name": "update_methods", + "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/update_methods/package.json b/property_tests/tests/update_methods/package.json new file mode 100644 index 0000000000..e5b0aa2544 --- /dev/null +++ b/property_tests/tests/update_methods/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/update_methods/test/generate_body.ts b/property_tests/tests/update_methods/test/generate_body.ts new file mode 100644 index 0000000000..957793398a --- /dev/null +++ b/property_tests/tests/update_methods/test/generate_body.ts @@ -0,0 +1,19 @@ +import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; +import { CandidType } from 'azle/property_tests/arbitraries/candid/candid_type_arb'; +import { BodyGenerator } from 'azle/property_tests/arbitraries/canister_methods'; +import { CandidReturnType } from 'azle/property_tests/arbitraries/candid/candid_return_type_arb'; + +export const generateBody: BodyGenerator< + CandidType, + CandidReturnType, + CandidType, + CandidReturnType +> = (namedParams, returnType): string => { + const paramsAreCorrectlyOrdered = areParamsCorrectlyOrdered(namedParams); + + return ` + ${paramsAreCorrectlyOrdered} + + return ${returnType.src.valueLiteral} + `; +}; diff --git a/property_tests/tests/update_methods/test/generate_tests.ts b/property_tests/tests/update_methods/test/generate_tests.ts new file mode 100644 index 0000000000..e737830c1b --- /dev/null +++ b/property_tests/tests/update_methods/test/generate_tests.ts @@ -0,0 +1,34 @@ +import { deepEqual } from 'fast-equals'; + +import { getActor } from 'azle/property_tests'; +import { CandidType } from 'azle/property_tests/arbitraries/candid/candid_type_arb'; +import { TestsGenerator } from 'azle/property_tests/arbitraries/canister_methods'; +import { Test } from 'azle/test'; +import { CandidReturnType } from '../../../arbitraries/candid/candid_return_type_arb'; + +export const generateTests: TestsGenerator< + CandidType, + CandidReturnType, + CandidType, + CandidReturnType +> = (functionName, params, returnType): Test[] => { + const paramValues = params.map((param) => param.el.agentArgumentValue); + const expectedResult = returnType.agentResponseValue; + + return [ + { + name: `update method "${functionName}"`, + test: async () => { + const actor = getActor('./tests/update_methods/test'); + const result = await actor[functionName](...paramValues); + 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/update_methods/test/test.ts b/property_tests/tests/update_methods/test/test.ts new file mode 100644 index 0000000000..2e6cd928a4 --- /dev/null +++ b/property_tests/tests/update_methods/test/test.ts @@ -0,0 +1,30 @@ +import fc from 'fast-check'; + +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; +import { CandidTypeArb } from 'azle/property_tests/arbitraries/candid/candid_type_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 { generateBody } from './generate_body'; +import { generateTests } from './generate_tests'; + +const HeterogeneousUpdateMethodArb = UpdateMethodArb( + fc.array(CandidTypeArb), + CandidReturnTypeArb, + { + generateBody, + generateTests + } +); + +const CanisterConfigArb = fc + .array(HeterogeneousUpdateMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/update_methods/tsconfig.json b/property_tests/tests/update_methods/tsconfig.json new file mode 100644 index 0000000000..2638f0d8bc --- /dev/null +++ b/property_tests/tests/update_methods/tsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "strict": true, + "target": "ES2020", + "moduleResolution": "node", + "allowJs": true, + "outDir": "HACK_BECAUSE_OF_ALLOW_JS" + } +} diff --git a/property_tests/tests/variant/test/generate_body.ts b/property_tests/tests/variant/test/generate_body.ts index 48b8b8ca1d..c6c2ed6a69 100644 --- a/property_tests/tests/variant/test/generate_body.ts +++ b/property_tests/tests/variant/test/generate_body.ts @@ -1,11 +1,11 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Variant } from 'azle/property_tests/arbitraries/candid/constructed/variant_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamVariants: Named>[], - returnVariant: CandidMeta + namedParamVariants: Named>[], + returnVariant: CandidValueAndMeta ): string { const paramsAreVariants = namedParamVariants .map((param) => { diff --git a/property_tests/tests/variant/test/generate_tests.ts b/property_tests/tests/variant/test/generate_tests.ts index 50f1dcffae..4bf5262aa4 100644 --- a/property_tests/tests/variant/test/generate_tests.ts +++ b/property_tests/tests/variant/test/generate_tests.ts @@ -1,14 +1,14 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Variant } from 'azle/property_tests/arbitraries/candid/constructed/variant_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamVariants: Named>[], - returnVariant: CandidMeta + namedParamVariants: Named>[], + returnVariant: CandidValueAndMeta ): Test[] { const expectedResult = returnVariant.agentResponseValue; diff --git a/property_tests/tests/variant/test/test.ts b/property_tests/tests/variant/test/test.ts index cedb2ffe62..afb6d4018a 100644 --- a/property_tests/tests/variant/test/test.ts +++ b/property_tests/tests/variant/test/test.ts @@ -1,20 +1,31 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { VariantArb } from 'azle/property_tests/arbitraries/candid/constructed/variant_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllVariantsQueryMethod = QueryMethodArb( - fc.uniqueArray(VariantArb, { selector: (entry) => entry.src.candidType }), - VariantArb, +const AllVariantsQueryMethodArb = QueryMethodArb( + fc.uniqueArray(VariantArb(), { + selector: (entry) => entry.src.typeAnnotation + }), + VariantArb(), { generateBody, generateTests } ); -runPropTests(CanisterArb(AllVariantsQueryMethod)); +const CanisterConfigArb = fc + .array(AllVariantsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb)); diff --git a/property_tests/tests/vec/test/generate_body.ts b/property_tests/tests/vec/test/generate_body.ts index fada3786de..5ebd339506 100644 --- a/property_tests/tests/vec/test/generate_body.ts +++ b/property_tests/tests/vec/test/generate_body.ts @@ -1,10 +1,10 @@ -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Named } from 'azle/property_tests'; import { areParamsCorrectlyOrdered } from 'azle/property_tests/are_params_correctly_ordered'; export function generateBody( - namedParamVecs: Named>[], - returnVec: CandidMeta + namedParamVecs: Named>[], + returnVec: CandidValueAndMeta ): string { const paramsAreArrays = namedParamVecs .map((param) => { diff --git a/property_tests/tests/vec/test/generate_tests.ts b/property_tests/tests/vec/test/generate_tests.ts index 7c95b8deae..1c0e7400a4 100644 --- a/property_tests/tests/vec/test/generate_tests.ts +++ b/property_tests/tests/vec/test/generate_tests.ts @@ -1,13 +1,13 @@ import { deepEqual } from 'fast-equals'; import { getActor, Named } from 'azle/property_tests'; -import { CandidMeta } from 'azle/property_tests/arbitraries/candid/candid_arb'; +import { CandidValueAndMeta } from 'azle/property_tests/arbitraries/candid/candid_value_and_meta_arb'; import { Test } from 'azle/test'; export function generateTests( functionName: string, - namedParamVecs: Named>[], - returnVec: CandidMeta + namedParamVecs: Named>[], + returnVec: CandidValueAndMeta ): Test[] { const expectedResult = returnVec.agentResponseValue; diff --git a/property_tests/tests/vec/test/test.ts b/property_tests/tests/vec/test/test.ts index 3b5b4d94d2..269b1adfe6 100644 --- a/property_tests/tests/vec/test/test.ts +++ b/property_tests/tests/vec/test/test.ts @@ -1,16 +1,25 @@ import fc from 'fast-check'; -import { runPropTests } from 'azle/property_tests'; +import { defaultArrayConstraints, runPropTests } from 'azle/property_tests'; import { VecArb } from 'azle/property_tests/arbitraries/candid/constructed/vec_arb'; -import { CanisterArb } from 'azle/property_tests/arbitraries/canister_arb'; -import { QueryMethodArb } from 'azle/property_tests/arbitraries/query_method_arb'; +import { + CanisterArb, + CanisterConfig +} from 'azle/property_tests/arbitraries/canister_arb'; +import { QueryMethodArb } from 'azle/property_tests/arbitraries/canister_methods/query_method_arb'; import { generateBody } from './generate_body'; import { generateTests } from './generate_tests'; -const AllVecsQueryMethod = QueryMethodArb(fc.array(VecArb), VecArb, { +const AllVecsQueryMethodArb = QueryMethodArb(fc.array(VecArb()), VecArb(), { generateBody, generateTests }); -runPropTests(CanisterArb(AllVecsQueryMethod)); +const CanisterConfigArb = fc + .array(AllVecsQueryMethodArb, defaultArrayConstraints) + .map((queryMethods): CanisterConfig => { + return { queryMethods }; + }); + +runPropTests(CanisterArb(CanisterConfigArb));