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
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 57cc223
test(pox-4-tests): Add GetStxAccountCommand
moodmosaic b047b94
test(pox-4-tests): Add DelegateStxCommand
BowTiedRadone c7dd8f4
test(pox-4-tests): Incorporate wallet labels for clearer test logging
moodmosaic 8d886f5
refactor(pox-4-tests): Remove unused prvKey and pubKey from Wallet
moodmosaic d6536c3
refactor(pox-4-tests): Rename Wallet 'client' to 'stackingClient'
moodmosaic d50a402
refactor(pox-4-tests): Typify 'delegatedTo' field in Wallet
moodmosaic e8e2b5d
feat(pox-4-tests): Add amountUnlocked to Wallet for staking
moodmosaic 71306da
test(pox-4-tests): Add DelegateStackStxCommand
BowTiedRadone 70b6c44
refactor(pox-4-tests): Relocate cycle utility functions to PoxCommands
moodmosaic 48490e6
test(pox-4-tests): Add RevokeDelegateStxCommand
BowTiedRadone 48cdebf
test(pox-4-tests): Add AllowContractCallerCommand
BowTiedRadone da4d658
refactor(pox-4-tests): Remove unused generators from RevokeDelegateSt…
BowTiedRadone fe81e9d
wip(pox-4-tests): Add check for DelegateStackStx period
BowTiedRadone 306c9d7
refactor(pox-4-tests): Integrate Clarity value generation
moodmosaic d318add
refactor(pox-4-tests): Dynamic `unlockBurnHt` and cleaner state
moodmosaic ddc7c4d
feat(dependencies): Update stacks.js packages for PoX-4 stacking client
moodmosaic a6c9657
feat(pox-4-tests): Add `logCommand` for structured output using `ololog`
moodmosaic 4704f7b
style(pox-4-tests): Run formatter on tests/pox-4/*.ts
moodmosaic dae4ebd
fix(pox-4-tests): Address delegated PoX address comment
BowTiedRadone f0c7bf0
fix(pox-4-tests): Address current reward cycle comment
BowTiedRadone b77c81b
fix(pox-4-tests): Address check balance command comment
BowTiedRadone 35df5a2
fix(pox-4-tests): Address stacker generation comment
BowTiedRadone ebb17e3
feat(pox-4-tests): Print command output in real-time
moodmosaic 64857fd
fix(pox-4-tests): Update let to const RevokeDelegateStx
BowTiedRadone 7ff85f5
fix(pox-4-tests): Move balance check inside GetStxAccountCommand
BowTiedRadone 6254bac
fix(test-output): Remove global noopReporter to restore test visibility
moodmosaic 848e0a8
feat(pox-4-tests): Track command execution in PoxCommand implementations
moodmosaic 3b857f9
fix(pox-4-tests): Remove unnecessary check
BowTiedRadone 5afc571
test(pox-4-tests): Add DelegateStackIncreaseCommand
BowTiedRadone 8f59b98
fix(pox-4-tests): Remove noopReporter file
BowTiedRadone 91d5411
fix(pox-4-tests): Adjust delegate-stack-increase generator to address…
BowTiedRadone 0657943
fix(pox-4-tests): Rename `haslocked` to `lockedAddresses`
BowTiedRadone a2f87b9
chore(pox-4-tests): Update `DelegateStackIncreaseCommand` documentation
BowTiedRadone 8532098
fix(pox-4-tests): Update `increaseBy` generator from bigint to number
BowTiedRadone ed44786
test(pox-4-tests): Add DelegateStackExtendCommand
BowTiedRadone 43c3960
test(pox-4-tests): Add StackAggregationCommitCommand authorization-based
BowTiedRadone f12bcc0
test(pox-4-tests): Rename `StackAggregationCommit` to `StackAggregati…
BowTiedRadone caf62d6
Add StackAggregationCommitCommand signature-based
BowTiedRadone fdf1880
fix(pox-4-tests): Address commands documentation comment
BowTiedRadone bb5bb99
fix(pox-4-tests): Address format comment
BowTiedRadone ed6e4fd
fix(pox-4-tests): Address format comment
BowTiedRadone 6646688
fix(pox-4-tests): Address documentation comment
BowTiedRadone 03e4158
fix(pox-4-tests): Addres not needed new line comment
BowTiedRadone ba564dc
fix(pox-4-tests): Address not needed new line comment
BowTiedRadone fe10e3d
fix(pox-4-tests): Address committedAmount variable comment
BowTiedRadone b23cd8d
fix(pox-4-tests): Address same pool pox address comment
BowTiedRadone 79893f5
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` signatu…
BowTiedRadone b726a24
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` authori…
BowTiedRadone 04be682
chore(pox-4-tests): Update stdout logging to console.log
BowTiedRadone fb48e07
test(pox-4-tests): Add `StackAggregationIncreaseCommand`
BowTiedRadone e049330
test(pox-4-tests): Add `DisallowContractCallerCommand`
BowTiedRadone b75cb1e
fix(pox-4-tests): Refresh the model's state if the network gets to th…
BowTiedRadone c7b31f5
refactor(pox-4-tests): Rename stateRefresh to refreshStateForNextRewa…
moodmosaic 466f45b
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic 954e294
wip(pox-4-tests): StackStxCommand & stateful property tests planning
moodmosaic 1496241
test(pox-4-tests): Add GetStxAccountCommand
moodmosaic cb1be4b
test(pox-4-tests): Add DelegateStxCommand
BowTiedRadone 3b19a22
test(pox-4-tests): Incorporate wallet labels for clearer test logging
moodmosaic 55f6bb3
refactor(pox-4-tests): Remove unused prvKey and pubKey from Wallet
moodmosaic 092cb4d
refactor(pox-4-tests): Rename Wallet 'client' to 'stackingClient'
moodmosaic 56e1f06
refactor(pox-4-tests): Typify 'delegatedTo' field in Wallet
moodmosaic 559e1ec
feat(pox-4-tests): Add amountUnlocked to Wallet for staking
moodmosaic e064778
test(pox-4-tests): Add DelegateStackStxCommand
BowTiedRadone c5e0ea5
refactor(pox-4-tests): Relocate cycle utility functions to PoxCommands
moodmosaic fa6c6ee
test(pox-4-tests): Add RevokeDelegateStxCommand
BowTiedRadone 849be91
test(pox-4-tests): Add AllowContractCallerCommand
BowTiedRadone 83ef9c1
refactor(pox-4-tests): Remove unused generators from RevokeDelegateSt…
BowTiedRadone 0139de9
wip(pox-4-tests): Add check for DelegateStackStx period
BowTiedRadone 364ea59
refactor(pox-4-tests): Integrate Clarity value generation
moodmosaic 271c15b
refactor(pox-4-tests): Dynamic `unlockBurnHt` and cleaner state
moodmosaic e1c0f04
feat(dependencies): Update stacks.js packages for PoX-4 stacking client
moodmosaic 243c3c9
feat(pox-4-tests): Add `logCommand` for structured output using `ololog`
moodmosaic 71f6358
style(pox-4-tests): Run formatter on tests/pox-4/*.ts
moodmosaic 91b7d93
fix(pox-4-tests): Address delegated PoX address comment
BowTiedRadone 642ec8d
fix(pox-4-tests): Address current reward cycle comment
BowTiedRadone b390186
fix(pox-4-tests): Address check balance command comment
BowTiedRadone d4cc53e
fix(pox-4-tests): Address stacker generation comment
BowTiedRadone 1223c07
feat(pox-4-tests): Print command output in real-time
moodmosaic 764a862
fix(pox-4-tests): Update let to const RevokeDelegateStx
BowTiedRadone b5850fd
fix(pox-4-tests): Move balance check inside GetStxAccountCommand
BowTiedRadone 4a9e95c
fix(test-output): Remove global noopReporter to restore test visibility
moodmosaic 3062bed
feat(pox-4-tests): Track command execution in PoxCommand implementations
moodmosaic 47fcfbd
fix(pox-4-tests): Remove unnecessary check
BowTiedRadone b1272e0
test(pox-4-tests): Add DelegateStackIncreaseCommand
BowTiedRadone 22feaa7
fix(pox-4-tests): Remove noopReporter file
BowTiedRadone fb5c0e7
fix(pox-4-tests): Adjust delegate-stack-increase generator to address…
BowTiedRadone 4a7d4a8
fix(pox-4-tests): Rename `haslocked` to `lockedAddresses`
BowTiedRadone f7d4dfa
chore(pox-4-tests): Update `DelegateStackIncreaseCommand` documentation
BowTiedRadone 6c7d2e2
fix(pox-4-tests): Update `increaseBy` generator from bigint to number
BowTiedRadone 838c98f
test(pox-4-tests): Add DelegateStackExtendCommand
BowTiedRadone 6b09445
test(pox-4-tests): Add StackAggregationCommitCommand authorization-based
BowTiedRadone bebb7b7
test(pox-4-tests): Rename `StackAggregationCommit` to `StackAggregati…
BowTiedRadone 3d778ce
Add StackAggregationCommitCommand signature-based
BowTiedRadone 82aa13d
fix(pox-4-tests): Address commands documentation comment
BowTiedRadone d572724
fix(pox-4-tests): Address format comment
BowTiedRadone 2b421da
fix(pox-4-tests): Address format comment
BowTiedRadone 016f5fd
fix(pox-4-tests): Address documentation comment
BowTiedRadone 1bd3515
fix(pox-4-tests): Addres not needed new line comment
BowTiedRadone d65444f
fix(pox-4-tests): Address not needed new line comment
BowTiedRadone b24d149
fix(pox-4-tests): Address committedAmount variable comment
BowTiedRadone 3be006e
fix(pox-4-tests): Address same pool pox address comment
BowTiedRadone f854333
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` signatu…
BowTiedRadone 5741518
test(pox-4-tests): Add `StackAggregationCommitIndexedCommand` authori…
BowTiedRadone f17b071
chore(pox-4-tests): Update stdout logging to console.log
BowTiedRadone 185b91d
test(pox-4-tests): Add `StackAggregationIncreaseCommand`
BowTiedRadone e320a4d
test(pox-4-tests): Add `DisallowContractCallerCommand`
BowTiedRadone 58f02a3
fix(pox-4-tests): Refresh the model's state if the network gets to th…
BowTiedRadone 0b9d36e
refactor(pox-4-tests): Rename stateRefresh to refreshStateForNextRewa…
moodmosaic 20ca4e2
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic 7f84a0c
Merge branch 'feat/pox-4-stateful-property-testing' of github.com:sta…
moodmosaic 5185e58
fix(pox-4-tests): update @hirosystems/clarinet-sdk-wasm to 2.4.2 for …
moodmosaic fc23590
fix(pox-4-tests): Separate stacker from wallet
moodmosaic 7dba975
fix(pox-4-tests): Use stackers instead of wallets, update model initi…
BowTiedRadone 25ee419
fix(pox-4-tests): Update `StackAggregationIncreaseCommand` to use a s…
BowTiedRadone 53170b9
fix(pox-4-tests): Update @stacks/stacking to version `6.13.2`
BowTiedRadone eb95d20
fix(pox-4-tests): Fix `DelegateStackStx`, `StackStx`, `DelegateStackE…
BowTiedRadone 552648c
chore(pox-4-tests): Remove unused dependency `cvToJSON`
BowTiedRadone 1c0206b
fix(pox-4-tests): Fix `StackAggregationCommitX`
BowTiedRadone 5a8c017
fix(pox-4-tests): Fix `StackAggregationIncrease` reward cycle calcula…
BowTiedRadone 4a3ca5c
chore(pox-4-tests): Remove state update log
BowTiedRadone 3089e8b
chore(pox-4-tests): Remove StackAggregationIncrease logging
BowTiedRadone a0d8352
chore(pox-4-tests): Add burn height logging
BowTiedRadone cc17600
chore(pox-4-tests): Format code and wrap comments at 79 chars
moodmosaic 742dbf5
feat(pox-4-tests): Pretty-print burn block height in each command
moodmosaic 9945c5e
fix(pox-4-tests): Set fast-check command size to 'small' from 'xsmall'
moodmosaic ab837a1
fix(pox-4-tests): Refine refresh command, fix state simulation issues
BowTiedRadone d2c1eb7
chore(pox-4-tests): Update comment
BowTiedRadone e33895f
fix(pox-4-tests): Update AllowContractCallerCommand to remove the wal…
BowTiedRadone 5679afa
fix(pox-4-tests): Replace pox values `REWARD_CYCLE_LENGTH` and `FIRST…
BowTiedRadone b1d7d2e
Merge branch 'develop' into feat/pox-4-stateful-property-testing
moodmosaic File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
contrib/core-contract-tests/tests/pox-4/pox-4.stateful-prop.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(), | ||
}; | ||
|
||
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(); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hugocaillard
simnet
object for this test?simnet
instead ofawait initSimnet()
.FWIW, in the long term I want these tests to run outside of Vitest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be doable by tweaking the setup file but I don't see a lot of advantage to do so.
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
There was a problem hiding this comment.
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 ofawait initSimnet()
.