Skip to content

Commit

Permalink
candid type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bdemann committed Nov 2, 2023
1 parent 63cd7d5 commit 9dbc653
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions property_tests/arbitraries/candid/candid_arb.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fc from 'fast-check';
import { deepEqual } from 'fast-equals';
import { CandidType } from './candid_type_arb';

// TODO we're thinking that Candid is not the best name for this. What is better?
export type Candid<T> = {
export type Candid<T extends CandidType> = {
value: T;
src: {
candidType: string;
Expand All @@ -13,7 +14,7 @@ export type Candid<T> = {
equals(a: T, b: T): boolean;
};

export const CandidArb = <T>(
export const CandidArb = <T extends CandidType>(
arb: fc.Arbitrary<T>,
candidType: string,
toLiteral: (value: T) => string,
Expand Down
6 changes: 5 additions & 1 deletion property_tests/arbitraries/candid/candid_type_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { Float64Arb } from './primitive/floats/float64_arb';
import { TextArb } from './primitive/text';
import { BlobArb } from './constructed/blob_arb';
import { Candid } from './candid_arb';
import { Func } from './reference/func_arb';
import { Opt } from './constructed/opt_arb';

export type CandidType =
| number
Expand All @@ -26,7 +28,9 @@ export type CandidType =
| boolean
| Principal
| Uint8Array
| string;
| string
| Func
| Opt;

/**
* An arbitrary representing all possible Candid types.
Expand Down
2 changes: 1 addition & 1 deletion property_tests/arbitraries/candid/constructed/opt_arb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Base = {

type RecursiveOpt<T> = { base: T } | { nextLayer: RecursiveOpt<T> };

export type Opt = [CandidType | Opt] | never[];
export type Opt = [CandidType] | never[];

// TODO look into making this recursive
// TODO we need to add all constructed and reference types
Expand Down

0 comments on commit 9dbc653

Please sign in to comment.