Skip to content

Commit

Permalink
Merge branch 'main' of github.com:demergent-labs/azle into stable_b_t…
Browse files Browse the repository at this point in the history
…ree_map_property_tests
  • Loading branch information
lastmjs committed Dec 5, 2023
2 parents 6d17e38 + b38d4c9 commit 3805e2f
Show file tree
Hide file tree
Showing 149 changed files with 3,991 additions and 1,699 deletions.
37 changes: 0 additions & 37 deletions property_tests/arbitraries/candid/candid_arb.ts

This file was deleted.

84 changes: 84 additions & 0 deletions property_tests/arbitraries/candid/candid_definition_arb/index.ts
Original file line number Diff line number Diff line change
@@ -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<CandidDefinition> = 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<CandidDefinition>
),
Opt: OptDefinitionArb(
tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
),
Record: RecordDefinitionArb(
tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
),
// Service: ServiceDefinitionArb(
// tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
// ),
Tuple: TupleDefinitionArb(
tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
),
Variant: VariantDefinitionArb(
tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
),
Vec: VecDefinitionArb(
tie('CandidDefinition') as fc.Arbitrary<CandidDefinition>
)
})
).CandidDefinition;
71 changes: 71 additions & 0 deletions property_tests/arbitraries/candid/candid_definition_arb/types.ts
Original file line number Diff line number Diff line change
@@ -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<string>;
typeAliasDeclarations: string[];
src: string;
};

type CandidMeta = {
typeAnnotation: string; // Either a type reference or type literal
typeAliasDeclarations: string[];
imports: Set<string>;
candidType: CandidType;
};
21 changes: 14 additions & 7 deletions property_tests/arbitraries/candid/candid_return_type_arb.ts
Original file line number Diff line number Diff line change
@@ -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<CandidMeta<CandidReturnType>>;
export function CandidReturnTypeArb(): fc.Arbitrary<
CandidValueAndMeta<CandidReturnType>
> {
return fc.oneof(
{ arbitrary: CandidValueAndMetaArb(), weight: 17 },
{ arbitrary: VoidArb(), weight: 1 }
);
}
30 changes: 30 additions & 0 deletions property_tests/arbitraries/candid/candid_type.ts
Original file line number Diff line number Diff line change
@@ -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';
106 changes: 0 additions & 106 deletions property_tests/arbitraries/candid/candid_type_arb.ts

This file was deleted.

Loading

0 comments on commit 3805e2f

Please sign in to comment.