-
Notifications
You must be signed in to change notification settings - Fork 647
/
pox_Commands.ts
113 lines (111 loc) · 3.02 KB
/
pox_Commands.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import fc from "fast-check";
import { Real, Stub, StxAddress, Wallet } from "./pox_CommandModel";
import { GetStackingMinimumCommand } from "./pox_GetStackingMinimumCommand";
import { GetStxAccountCommand } from "./pox_GetStxAccountCommand";
import { StackStxCommand } from "./pox_StackStxCommand";
import { DelegateStxCommand } from "./pox_DelegateStxCommand";
import { DelegateStackStxCommand } from "./pox_DelegateStackStxCommand";
import { Simnet } from "@hirosystems/clarinet-sdk";
import { currentCycleFirstBlock, nextCycleFirstBlock } from "./pox-4.stateful-prop.test";
export function PoxCommands(
wallets: Map<StxAddress, Wallet>, network: Simnet,
): fc.Arbitrary<Iterable<fc.Command<Stub, Real>>> {
const cmds = [
// GetStackingMinimumCommand
fc.record({
wallet: fc.constantFrom(...wallets.values()),
}).map((
r: {
wallet: Wallet;
},
) =>
new GetStackingMinimumCommand(
r.wallet,
)
),
// StackStxCommand
fc.record({
wallet: fc.constantFrom(...wallets.values()),
authId: fc.nat(),
period: fc.integer({ min: 1, max: 12 }),
margin: fc.integer({ min: 1, max: 9 }),
}).map((
r: {
wallet: Wallet;
authId: number;
period: number;
margin: number;
},
) =>
new StackStxCommand(
r.wallet,
r.authId,
r.period,
r.margin,
)
),
// DelegateStxCommand
fc.record({
wallet: fc.constantFrom(...wallets.values()),
delegateTo: fc.constantFrom(...wallets.values()),
untilBurnHt: fc.integer({ min: 1 }),
amount: fc.bigInt({ min:0n, max: 100_000_000_000_000n }),
}).map((
r: {
wallet: Wallet;
delegateTo: Wallet;
untilBurnHt: number;
amount: bigint;
},
) =>
new DelegateStxCommand(
r.wallet,
r.delegateTo,
r.untilBurnHt,
r.amount,
)
),
// DelegateStackStxCommand
fc.record({
operator: fc.constantFrom(...wallets.values()),
stacker: fc.constantFrom(...wallets.values()),
startBurnHt: fc.integer({
min: currentCycleFirstBlock(network),
max: nextCycleFirstBlock(network),
}),
period: fc.integer({ min: 1, max: 12 }),
amount: fc.bigInt({ min:0n, max: 100_000_000_000_000n }),
}).map((
r: {
operator: Wallet;
stacker: Wallet;
startBurnHt: number;
period: number;
amount: bigint;
},
) =>
new DelegateStackStxCommand(
r.operator,
r.stacker,
r.startBurnHt,
r.period,
r.amount
)
),
// GetStxAccountCommand
fc.record({
wallet: fc.constantFrom(...wallets.values()),
}).map((
r: {
wallet: Wallet;
},
) =>
new GetStxAccountCommand(
r.wallet,
)
),
];
// More on size: https://github.com/dubzzz/fast-check/discussions/2978
// More on cmds: https://github.com/dubzzz/fast-check/discussions/3026
return fc.commands(cmds, { size: "large" });
}