-
Notifications
You must be signed in to change notification settings - Fork 647
/
pox-4.stateful-prop.test.ts
105 lines (96 loc) · 3.63 KB
/
pox-4.stateful-prop.test.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
import { describe, it } from "vitest";
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { Real, Stub, StxAddress, Wallet } from "./pox_CommandModel.ts";
import {
getPublicKeyFromPrivate,
publicKeyToBtcAddress,
} from "@stacks/encryption";
import { StacksDevnet } from "@stacks/network";
import {
createStacksPrivateKey,
getAddressFromPrivateKey,
TransactionVersion,
} from "@stacks/transactions";
import { StackingClient } from "@stacks/stacking";
import fc from "fast-check";
import { PoxCommands } from "./pox_Commands.ts";
describe("PoX-4 invariant tests", () => {
it("statefully does solo stacking with a signature", async () => {
// SUT stands for "System Under Test".
const sut: Real = {
network: await initSimnet(),
};
// This is the initial state of the model.
const model: Stub = {
stackingMinimum: 0,
wallets: new Map<StxAddress, Wallet>(),
};
const wallets = [
["wallet_1", "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801"],
["wallet_2", "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101"],
["wallet_3", "d655b2523bcd65e34889725c73064feb17ceb796831c0e111ba1a552b0f31b3901"],
["wallet_4", "f9d7206a47f14d2870c163ebab4bf3e70d18f5d14ce1031f3902fbbc894fe4c701"],
["wallet_5", "3eccc5dac8056590432db6a35d52b9896876a3d5cbdea53b72400bc9c2099fe801"],
["wallet_6", "7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01"],
["wallet_7", "b463f0df6c05d2f156393eee73f8016c5372caa0e9e29a901bb7171d90dc4f1401"],
["wallet_8", "6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01"],
["wallet_9", "de433bdfa14ec43aa1098d5be594c8ffb20a31485ff9de2923b2689471c401b801"],
].map((wallet) => {
const label = wallet[0];
const prvKey = wallet[1];
const pubKey = getPublicKeyFromPrivate(prvKey);
const devnet = new StacksDevnet();
const initialUstxBalance = 100_000_000_000_000;
const signerPrvKey = createStacksPrivateKey(prvKey);
const signerPubKey = getPublicKeyFromPrivate(signerPrvKey.data);
const btcAddress = publicKeyToBtcAddress(pubKey);
const stxAddress = getAddressFromPrivateKey(
prvKey,
TransactionVersion.Testnet,
);
return {
label,
stxAddress,
btcAddress,
signerPrvKey,
signerPubKey,
stackingClient: new StackingClient(stxAddress, devnet),
ustxBalance: initialUstxBalance,
isStacking: false,
hasDelegated: false,
hasPoolMembers: [],
delegatedTo: "",
delegatedMaxAmount: 0,
delegatedUntilBurnHt: 0,
amountLocked: 0,
amountUnlocked: initialUstxBalance,
unlockHeight: 0,
allowedContractCaller: '',
callerAllowedBy: []
};
});
// Add the wallets to the model.
wallets.forEach((wallet) => {
model.wallets.set(wallet.stxAddress, wallet);
});
simnet.setEpoch("3.0");
fc.assert(
fc.property(
PoxCommands(model.wallets, sut.network),
(cmds) => {
const initialState = () => ({ model: model, real: sut });
fc.modelRun(initialState, cmds);
},
),
{
// Defines the number of test iterations to run; default is 100.
numRuns: 10,
// Adjusts the level of detail in test reports. Default is 0 (minimal).
// At level 2, reports include extensive details, helpful for deep
// debugging. This includes not just the failing case and its seed, but
// also a comprehensive log of all executed steps and their outcomes.
verbose: 2,
},
);
});
});