-
Notifications
You must be signed in to change notification settings - Fork 647
/
pox_Commands.ts
162 lines (157 loc) · 4.35 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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 { Cl, cvToValue } from "@stacks/transactions";
import { RevokeDelegateStxCommand } from "./pox_RevokeDelegateStxCommand";
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,
)
),
// RevokeDelegateStxCommand
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 RevokeDelegateStxCommand(
r.wallet
)
),
// 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" });
}
const currentCycle = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"current-pox-reward-cycle",
[],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));
const currentCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network))],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));
const nextCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network) + 1)],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));