Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(pox-4): Add GetStxAccountCommand
- Loading branch information
1 parent
7b31963
commit b86104d
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
contrib/core-contract-tests/tests/pox-4/pox_GetStxAccountCommand.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,57 @@ | ||
import { 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 { | ||
// Can always check the `stx-account` info. | ||
return true; | ||
} | ||
|
||
run(model: Stub, real: Real): void { | ||
const actual = model.wallets.get(this.wallet.stxAddress)!; | ||
expect(real.network.runSnippet(`(stx-account '${actual.stxAddress})`)) | ||
.toBeTuple({ | ||
"locked": Cl.uint(actual.amountLocked), | ||
"unlocked": Cl.uint(actual.ustxBalance), | ||
"unlock-height": Cl.uint(actual.unlockHeight), | ||
}); | ||
|
||
// 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. | ||
console.info( | ||
`✓ ${this.wallet.stxAddress.padStart(8, " ")} ${ | ||
"stx-account".padStart(34, " ") | ||
} ${"lock-amount".padStart(12, " ")} ${ | ||
actual.amountLocked.toString().padStart(13, " ") | ||
} ${"unlocked-amount".padStart(12, " ")} ${ | ||
actual.ustxBalance.toString().padStart(15, " ") | ||
} ${"unlocked-height".padStart(12, " ")} ${ | ||
actual.unlockHeight.toString().padStart(7, " ") | ||
}`, | ||
); | ||
} | ||
|
||
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.stxAddress} stx-account`; | ||
} | ||
} |