-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared.types.ts
94 lines (83 loc) · 2.68 KB
/
shared.types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {
boolCV,
bufferCV,
ClarityValue,
intCV,
listCV,
optionalCVOf,
principalCV,
responseErrorCV,
responseOkCV,
stringAsciiCV,
stringUtf8CV,
tupleCV,
uintCV,
} from "@stacks/transactions";
import fc from "fast-check";
// Types used for Clarity Value conversion.
export type ResponseStatus = "ok" | "error";
export type TupleData<T extends ClarityValue = ClarityValue> = {
[key: string]: T;
};
export type BaseTypesToCV = {
int128: (arg: number) => ReturnType<typeof intCV>;
uint128: (arg: number) => ReturnType<typeof uintCV>;
bool: (arg: boolean) => ReturnType<typeof boolCV>;
principal: (arg: string) => ReturnType<typeof principalCV>;
};
export type ComplexTypesToCV = {
buffer: (arg: string) => ReturnType<typeof bufferCV>;
"string-ascii": (arg: string) => ReturnType<typeof stringAsciiCV>;
"string-utf8": (arg: string) => ReturnType<typeof stringUtf8CV>;
list: (type: ClarityValue[]) => ReturnType<typeof listCV>;
tuple: (tupleData: TupleData) => ReturnType<typeof tupleCV>;
optional: (arg: ClarityValue | null) => ReturnType<typeof optionalCVOf>;
response: (
status: ResponseStatus,
value: ClarityValue
) => ReturnType<typeof responseOkCV | typeof responseErrorCV>;
};
// Types used for argument generation.
export type BaseType =
| "int128"
| "uint128"
| "bool"
| "principal"
| "trait_reference";
type ComplexType =
| { buffer: { length: number } }
| { "string-ascii": { length: number } }
| { "string-utf8": { length: number } }
| { list: { type: ParameterType; length: number } }
| { tuple: { name: string; type: ParameterType }[] }
| { optional: ParameterType }
| { response: { ok: ParameterType; error: ParameterType } };
export type ParameterType = BaseType | ComplexType;
export type BaseTypesToArbitrary = {
int128: ReturnType<typeof fc.integer>;
uint128: ReturnType<typeof fc.nat>;
bool: ReturnType<typeof fc.boolean>;
principal: (addresses: string[]) => ReturnType<typeof fc.constantFrom>;
// Trait reference is not yet supported. This is a placeholder.
trait_reference: undefined;
};
export type ComplexTypesToArbitrary = {
buffer: (length: number) => fc.Arbitrary<string>;
"string-ascii": (length: number) => fc.Arbitrary<string>;
"string-utf8": (length: number) => fc.Arbitrary<string>;
list: (
type: ParameterType,
length: number,
addresses: string[]
) => fc.Arbitrary<any[]>;
tuple: (
items: { name: string; type: ParameterType }[],
addresses: string[]
) => fc.Arbitrary<object>;
optional: (type: ParameterType, addresses: string[]) => fc.Arbitrary<any>;
response: (
okType: ParameterType,
errType: ParameterType,
addresses: string[]
) => fc.Arbitrary<any>;
};