Files
stacks-puppet-node/contrib/boot-contracts-stateful-prop-tests/tests/pox-4/pox_GetStxAccountCommand.ts
Nikos Baxevanis 482c195b0d refactor(pox-4-tests): Move PoX-4 stateful property-based tests
- Relocate PoX-4 stateful property-based tests from
  ../core-contract-tests/tests/pox-4/ to
  boot-contracts-stateful-prop-tests/tests/pox-4.
- Implement a minimalistic vitest and Clarinet project setup.
- Adjust configurations for optimal test isolation.
- Ensure Clarinet config is as minimalistic as possible.
- For more details, see: https://github.com/stacks-network/stacks-core/pull/4725#issuecomment-2082701083
2024-04-29 18:31:11 +02:00

73 lines
2.1 KiB
TypeScript

import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { expect } from "vitest";
import { Cl } from "@stacks/transactions";
/**
* Implements the `PoxCommand` interface to get the info returned from the
* `stx-account`.
*/
export class GetStxAccountCommand implements PoxCommand {
readonly wallet: Wallet;
/**
* Constructs a new `GetStxAccountCommand`.
*
* @param wallet The wallet information, including the STX address used to
* query the `stx-account`.
*/
constructor(wallet: Wallet) {
this.wallet = wallet;
}
check(_model: Readonly<Stub>): boolean {
// There are no constraints for running this command.
return true;
}
run(model: Stub, real: Real): void {
model.trackCommandRun(this.constructor.name);
const actual = model.stackers.get(this.wallet.stxAddress)!;
expect(real.network.runSnippet(`(stx-account '${this.wallet.stxAddress})`))
.toBeTuple({
"locked": Cl.uint(actual.amountLocked),
"unlocked": Cl.uint(actual.amountUnlocked),
"unlock-height": Cl.uint(actual.unlockHeight),
});
expect(actual.amountLocked + actual.amountUnlocked).toBe(
actual.ustxBalance,
);
// Log to console for debugging purposes. This is not necessary for the
// test to pass but it is useful for debugging and eyeballing the test.
logCommand(
`${model.burnBlockHeight}`,
`${this.wallet.label}`,
"stx-account",
"lock-amount",
actual.amountLocked.toString(),
"unlocked-amount",
actual.amountUnlocked.toString(),
"unlocked-height",
actual.unlockHeight.toString(),
);
// Refresh the model's state if the network gets to the next reward cycle.
model.refreshStateForNextRewardCycle(real);
}
toString() {
// fast-check will call toString() in case of errors, e.g. property failed.
// It will then make a minimal counterexample, a process called 'shrinking'
// https://github.com/dubzzz/fast-check/issues/2864#issuecomment-1098002642
return `${this.wallet.label} stx-account`;
}
}