Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pox-4] Pool Stacking stateful property-based tests #4550

Merged
merged 131 commits into from Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
9905e7e
wip(pox-4-tests): StackStxCommand & stateful property tests planning
moodmosaic Mar 16, 2024
57cc223
test(pox-4-tests): Add GetStxAccountCommand
moodmosaic Mar 18, 2024
b047b94
test(pox-4-tests): Add DelegateStxCommand
BowTiedRadone Mar 18, 2024
c7dd8f4
test(pox-4-tests): Incorporate wallet labels for clearer test logging
moodmosaic Mar 19, 2024
8d886f5
refactor(pox-4-tests): Remove unused prvKey and pubKey from Wallet
moodmosaic Mar 19, 2024
d6536c3
refactor(pox-4-tests): Rename Wallet 'client' to 'stackingClient'
moodmosaic Mar 19, 2024
d50a402
refactor(pox-4-tests): Typify 'delegatedTo' field in Wallet
moodmosaic Mar 19, 2024
e8e2b5d
feat(pox-4-tests): Add amountUnlocked to Wallet for staking
moodmosaic Mar 19, 2024
71306da
test(pox-4-tests): Add DelegateStackStxCommand
BowTiedRadone Mar 19, 2024
70b6c44
refactor(pox-4-tests): Relocate cycle utility functions to PoxCommands
moodmosaic Mar 22, 2024
48490e6
test(pox-4-tests): Add RevokeDelegateStxCommand
BowTiedRadone Mar 22, 2024
48cdebf
test(pox-4-tests): Add AllowContractCallerCommand
BowTiedRadone Mar 25, 2024
da4d658
refactor(pox-4-tests): Remove unused generators from RevokeDelegateSt…
BowTiedRadone Mar 25, 2024
fe81e9d
wip(pox-4-tests): Add check for DelegateStackStx period
BowTiedRadone Mar 25, 2024
306c9d7
refactor(pox-4-tests): Integrate Clarity value generation
moodmosaic Mar 25, 2024
d318add
refactor(pox-4-tests): Dynamic `unlockBurnHt` and cleaner state
moodmosaic Mar 25, 2024
ddc7c4d
feat(dependencies): Update stacks.js packages for PoX-4 stacking client
moodmosaic Mar 26, 2024
a6c9657
feat(pox-4-tests): Add `logCommand` for structured output using `ololog`
moodmosaic Mar 26, 2024
4704f7b
style(pox-4-tests): Run formatter on tests/pox-4/*.ts
moodmosaic Mar 27, 2024
dae4ebd
fix(pox-4-tests): Address delegated PoX address comment
BowTiedRadone Mar 27, 2024
f0c7bf0
fix(pox-4-tests): Address current reward cycle comment
BowTiedRadone Mar 27, 2024
b77c81b
fix(pox-4-tests): Address check balance command comment
BowTiedRadone Mar 27, 2024
35df5a2
fix(pox-4-tests): Address stacker generation comment
BowTiedRadone Mar 27, 2024
ebb17e3
feat(pox-4-tests): Print command output in real-time
moodmosaic Mar 28, 2024
64857fd
fix(pox-4-tests): Update let to const RevokeDelegateStx
BowTiedRadone Mar 28, 2024
7ff85f5
fix(pox-4-tests): Move balance check inside GetStxAccountCommand
BowTiedRadone Mar 28, 2024
6254bac
fix(test-output): Remove global noopReporter to restore test visibility
moodmosaic Mar 29, 2024
848e0a8
feat(pox-4-tests): Track command execution in PoxCommand implementations
moodmosaic Mar 29, 2024
3b857f9
fix(pox-4-tests): Remove unnecessary check
BowTiedRadone Mar 29, 2024
5afc571
test(pox-4-tests): Add DelegateStackIncreaseCommand
BowTiedRadone Mar 29, 2024
8f59b98
fix(pox-4-tests): Remove noopReporter file
BowTiedRadone Mar 29, 2024
91d5411
fix(pox-4-tests): Adjust delegate-stack-increase generator to address…
BowTiedRadone Apr 1, 2024
0657943
fix(pox-4-tests): Rename `haslocked` to `lockedAddresses`
BowTiedRadone Apr 1, 2024
a2f87b9
chore(pox-4-tests): Update `DelegateStackIncreaseCommand` documentation
BowTiedRadone Apr 1, 2024
8532098
fix(pox-4-tests): Update `increaseBy` generator from bigint to number
BowTiedRadone Apr 1, 2024
ed44786
test(pox-4-tests): Add DelegateStackExtendCommand
BowTiedRadone Apr 1, 2024
43c3960
test(pox-4-tests): Add StackAggregationCommitCommand authorization-based
BowTiedRadone Apr 2, 2024
f12bcc0
test(pox-4-tests): Rename `StackAggregationCommit` to `StackAggregati…
BowTiedRadone Apr 3, 2024
caf62d6
Add StackAggregationCommitCommand signature-based
BowTiedRadone Apr 3, 2024
fdf1880
fix(pox-4-tests): Address commands documentation comment
BowTiedRadone Apr 3, 2024
bb5bb99
fix(pox-4-tests): Address format comment
BowTiedRadone Apr 3, 2024
ed6e4fd
fix(pox-4-tests): Address format comment
BowTiedRadone Apr 3, 2024
6646688
fix(pox-4-tests): Address documentation comment
BowTiedRadone Apr 3, 2024
03e4158
fix(pox-4-tests): Addres not needed new line comment
BowTiedRadone Apr 3, 2024
ba564dc
fix(pox-4-tests): Address not needed new line comment
BowTiedRadone Apr 3, 2024
fe10e3d
fix(pox-4-tests): Address committedAmount variable comment
BowTiedRadone Apr 3, 2024
b23cd8d
fix(pox-4-tests): Address same pool pox address comment
BowTiedRadone Apr 3, 2024
79893f5
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` signatu…
BowTiedRadone Apr 4, 2024
b726a24
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` authori…
BowTiedRadone Apr 4, 2024
04be682
chore(pox-4-tests): Update stdout logging to console.log
BowTiedRadone Apr 4, 2024
fb48e07
test(pox-4-tests): Add `StackAggregationIncreaseCommand`
BowTiedRadone Apr 7, 2024
e049330
test(pox-4-tests): Add `DisallowContractCallerCommand`
BowTiedRadone Apr 8, 2024
b75cb1e
fix(pox-4-tests): Refresh the model's state if the network gets to th…
BowTiedRadone Apr 10, 2024
c7b31f5
refactor(pox-4-tests): Rename stateRefresh to refreshStateForNextRewa…
moodmosaic Apr 11, 2024
466f45b
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic Apr 11, 2024
954e294
wip(pox-4-tests): StackStxCommand & stateful property tests planning
moodmosaic Mar 16, 2024
1496241
test(pox-4-tests): Add GetStxAccountCommand
moodmosaic Mar 18, 2024
cb1be4b
test(pox-4-tests): Add DelegateStxCommand
BowTiedRadone Mar 18, 2024
3b19a22
test(pox-4-tests): Incorporate wallet labels for clearer test logging
moodmosaic Mar 19, 2024
55f6bb3
refactor(pox-4-tests): Remove unused prvKey and pubKey from Wallet
moodmosaic Mar 19, 2024
092cb4d
refactor(pox-4-tests): Rename Wallet 'client' to 'stackingClient'
moodmosaic Mar 19, 2024
56e1f06
refactor(pox-4-tests): Typify 'delegatedTo' field in Wallet
moodmosaic Mar 19, 2024
559e1ec
feat(pox-4-tests): Add amountUnlocked to Wallet for staking
moodmosaic Mar 19, 2024
e064778
test(pox-4-tests): Add DelegateStackStxCommand
BowTiedRadone Mar 19, 2024
c5e0ea5
refactor(pox-4-tests): Relocate cycle utility functions to PoxCommands
moodmosaic Mar 22, 2024
fa6c6ee
test(pox-4-tests): Add RevokeDelegateStxCommand
BowTiedRadone Mar 22, 2024
849be91
test(pox-4-tests): Add AllowContractCallerCommand
BowTiedRadone Mar 25, 2024
83ef9c1
refactor(pox-4-tests): Remove unused generators from RevokeDelegateSt…
BowTiedRadone Mar 25, 2024
0139de9
wip(pox-4-tests): Add check for DelegateStackStx period
BowTiedRadone Mar 25, 2024
364ea59
refactor(pox-4-tests): Integrate Clarity value generation
moodmosaic Mar 25, 2024
271c15b
refactor(pox-4-tests): Dynamic `unlockBurnHt` and cleaner state
moodmosaic Mar 25, 2024
e1c0f04
feat(dependencies): Update stacks.js packages for PoX-4 stacking client
moodmosaic Mar 26, 2024
243c3c9
feat(pox-4-tests): Add `logCommand` for structured output using `ololog`
moodmosaic Mar 26, 2024
71f6358
style(pox-4-tests): Run formatter on tests/pox-4/*.ts
moodmosaic Mar 27, 2024
91b7d93
fix(pox-4-tests): Address delegated PoX address comment
BowTiedRadone Mar 27, 2024
642ec8d
fix(pox-4-tests): Address current reward cycle comment
BowTiedRadone Mar 27, 2024
b390186
fix(pox-4-tests): Address check balance command comment
BowTiedRadone Mar 27, 2024
d4cc53e
fix(pox-4-tests): Address stacker generation comment
BowTiedRadone Mar 27, 2024
1223c07
feat(pox-4-tests): Print command output in real-time
moodmosaic Mar 28, 2024
764a862
fix(pox-4-tests): Update let to const RevokeDelegateStx
BowTiedRadone Mar 28, 2024
b5850fd
fix(pox-4-tests): Move balance check inside GetStxAccountCommand
BowTiedRadone Mar 28, 2024
4a9e95c
fix(test-output): Remove global noopReporter to restore test visibility
moodmosaic Mar 29, 2024
3062bed
feat(pox-4-tests): Track command execution in PoxCommand implementations
moodmosaic Mar 29, 2024
47fcfbd
fix(pox-4-tests): Remove unnecessary check
BowTiedRadone Mar 29, 2024
b1272e0
test(pox-4-tests): Add DelegateStackIncreaseCommand
BowTiedRadone Mar 29, 2024
22feaa7
fix(pox-4-tests): Remove noopReporter file
BowTiedRadone Mar 29, 2024
fb5c0e7
fix(pox-4-tests): Adjust delegate-stack-increase generator to address…
BowTiedRadone Apr 1, 2024
4a7d4a8
fix(pox-4-tests): Rename `haslocked` to `lockedAddresses`
BowTiedRadone Apr 1, 2024
f7d4dfa
chore(pox-4-tests): Update `DelegateStackIncreaseCommand` documentation
BowTiedRadone Apr 1, 2024
6c7d2e2
fix(pox-4-tests): Update `increaseBy` generator from bigint to number
BowTiedRadone Apr 1, 2024
838c98f
test(pox-4-tests): Add DelegateStackExtendCommand
BowTiedRadone Apr 1, 2024
6b09445
test(pox-4-tests): Add StackAggregationCommitCommand authorization-based
BowTiedRadone Apr 2, 2024
bebb7b7
test(pox-4-tests): Rename `StackAggregationCommit` to `StackAggregati…
BowTiedRadone Apr 3, 2024
3d778ce
Add StackAggregationCommitCommand signature-based
BowTiedRadone Apr 3, 2024
82aa13d
fix(pox-4-tests): Address commands documentation comment
BowTiedRadone Apr 3, 2024
d572724
fix(pox-4-tests): Address format comment
BowTiedRadone Apr 3, 2024
2b421da
fix(pox-4-tests): Address format comment
BowTiedRadone Apr 3, 2024
016f5fd
fix(pox-4-tests): Address documentation comment
BowTiedRadone Apr 3, 2024
1bd3515
fix(pox-4-tests): Addres not needed new line comment
BowTiedRadone Apr 3, 2024
d65444f
fix(pox-4-tests): Address not needed new line comment
BowTiedRadone Apr 3, 2024
b24d149
fix(pox-4-tests): Address committedAmount variable comment
BowTiedRadone Apr 3, 2024
3be006e
fix(pox-4-tests): Address same pool pox address comment
BowTiedRadone Apr 3, 2024
f854333
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` signatu…
BowTiedRadone Apr 4, 2024
5741518
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` authori…
BowTiedRadone Apr 4, 2024
f17b071
chore(pox-4-tests): Update stdout logging to console.log
BowTiedRadone Apr 4, 2024
185b91d
test(pox-4-tests): Add `StackAggregationIncreaseCommand`
BowTiedRadone Apr 7, 2024
e320a4d
test(pox-4-tests): Add `DisallowContractCallerCommand`
BowTiedRadone Apr 8, 2024
58f02a3
fix(pox-4-tests): Refresh the model's state if the network gets to th…
BowTiedRadone Apr 10, 2024
0b9d36e
refactor(pox-4-tests): Rename stateRefresh to refreshStateForNextRewa…
moodmosaic Apr 11, 2024
20ca4e2
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic Apr 11, 2024
7f84a0c
Merge branch 'feat/pox-4-stateful-property-testing' of github.com:sta…
moodmosaic Apr 12, 2024
5185e58
fix(pox-4-tests): update @hirosystems/clarinet-sdk-wasm to 2.4.2 for …
moodmosaic Apr 12, 2024
fc23590
fix(pox-4-tests): Separate stacker from wallet
moodmosaic Apr 15, 2024
7dba975
fix(pox-4-tests): Use stackers instead of wallets, update model initi…
BowTiedRadone Apr 15, 2024
25ee419
fix(pox-4-tests): Update `StackAggregationIncreaseCommand` to use a s…
BowTiedRadone Apr 15, 2024
53170b9
fix(pox-4-tests): Update @stacks/stacking to version `6.13.2`
BowTiedRadone Apr 16, 2024
eb95d20
fix(pox-4-tests): Fix `DelegateStackStx`, `StackStx`, `DelegateStackE…
BowTiedRadone Apr 16, 2024
552648c
chore(pox-4-tests): Remove unused dependency `cvToJSON`
BowTiedRadone Apr 16, 2024
1c0206b
fix(pox-4-tests): Fix `StackAggregationCommitX`
BowTiedRadone Apr 16, 2024
5a8c017
fix(pox-4-tests): Fix `StackAggregationIncrease` reward cycle calcula…
BowTiedRadone Apr 16, 2024
4a3ca5c
chore(pox-4-tests): Remove state update log
BowTiedRadone Apr 16, 2024
3089e8b
chore(pox-4-tests): Remove StackAggregationIncrease logging
BowTiedRadone Apr 16, 2024
a0d8352
chore(pox-4-tests): Add burn height logging
BowTiedRadone Apr 16, 2024
cc17600
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic Apr 17, 2024
742dbf5
feat(pox-4-tests): Pretty-print burn block height in each command
moodmosaic Apr 17, 2024
9945c5e
fix(pox-4-tests): Set fast-check command size to 'small' from 'xsmall'
moodmosaic Apr 17, 2024
ab837a1
fix(pox-4-tests): Refine refresh command, fix state simulation issues
BowTiedRadone Apr 18, 2024
d2c1eb7
chore(pox-4-tests): Update comment
BowTiedRadone Apr 19, 2024
e33895f
fix(pox-4-tests): Update AllowContractCallerCommand to remove the wal…
BowTiedRadone Apr 22, 2024
5679afa
fix(pox-4-tests): Replace pox values `REWARD_CYCLE_LENGTH` and `FIRST…
BowTiedRadone Apr 22, 2024
b1d7d2e
Merge branch 'develop' into feat/pox-4-stateful-property-testing
moodmosaic Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 29 additions & 27 deletions contrib/core-contract-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion contrib/core-contract-tests/package.json
Expand Up @@ -13,7 +13,8 @@
"dependencies": {
"@hirosystems/clarinet-sdk": "^2.4.1",
"@stacks/clarunit": "0.0.1",
"@stacks/transactions": "^6.12.0",
"@stacks/stacking": "^6.13.2",
"@stacks/transactions": "^6.13.0",
"chokidar-cli": "^3.0.0",
"fast-check": "^3.15.1",
"typescript": "^5.4.2",
Expand Down
162 changes: 162 additions & 0 deletions contrib/core-contract-tests/tests/pox-4/pox-4.stateful-prop.test.ts
@@ -0,0 +1,162 @@
import { it } from "vitest";
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { Real, Stub } 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";

import fs from "fs";
import path from "path";

it("statefully interacts with PoX-4", async () => {
// SUT stands for "System Under Test".
const sut: Real = {
network: await initSimnet(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be causing the issue identified by @BowTiedRadone
I'm currently investigating

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hugocaillard

  • Can we disable the implicit/global simnet object for this test?
    it("statefully interacts with PoX-4", async () => {
      // No implicit/global `simnet` object for the scope of this test.
    });
  • Or perhaps I can reference the implicit/global simnet instead of await initSimnet().

FWIW, in the long term I want these tests to run outside of Vitest.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we disable the implicit/global simnet object for this test?

That would be doable by tweaking the setup file but I don't see a lot of advantage to do so.

Or perhaps I can reference the implicit/global simnet instead of await initSimnet().

That would make sense yes 👍 It wouldn't fix the issue though, it wouldn't have much of an impact but I still recommend it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I can reference the implicit/global simnet instead of await initSimnet().

};

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,
lockedAddresses: [],
amountToCommit: 0,
poolMembers: [],
delegatedTo: "",
delegatedMaxAmount: 0,
delegatedUntilBurnHt: 0,
delegatedPoxAddress: "",
amountLocked: 0,
amountUnlocked: initialUstxBalance,
unlockHeight: 0,
firstLockedRewardCycle: 0,
allowedContractCaller: "",
callerAllowedBy: [],
committedRewCycleIndexes: [],
};
});

// Track the number of times each command is run, so we can see if all the
// commands are run at least once.
const statistics = fs.readdirSync(path.join(__dirname)).filter((file) =>
file.startsWith("pox_") && file.endsWith(".ts") &&
file !== "pox_CommandModel.ts" && file !== "pox_Commands.ts"
).map((file) => file.slice(4, -3)); // Remove "pox_" prefix and ".ts" suffix.

// This is the initial state of the model.
const model = new Stub(
new Map(wallets.map((wallet) => [wallet.stxAddress, wallet])),
new Map(wallets.map((wallet) => [wallet.stxAddress, {
ustxBalance: 100_000_000_000_000,
isStacking: false,
isStackingSolo: false,
hasDelegated: false,
lockedAddresses: [],
amountToCommit: 0,
poolMembers: [],
delegatedTo: "",
delegatedMaxAmount: 0,
delegatedUntilBurnHt: 0,
delegatedPoxAddress: "",
amountLocked: 0,
amountUnlocked: 100_000_000_000_000,
unlockHeight: 0,
firstLockedRewardCycle: 0,
allowedContractCaller: "",
callerAllowedBy: [],
committedRewCycleIndexes: [],
}])),
new Map(statistics.map((commandName) => [commandName, 0])),
);

simnet.setEpoch("3.0");

fc.assert(
fc.property(
PoxCommands(model.wallets, model.stackers, 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: 1000,
// 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,
},
);

model.reportCommandRuns();
});