mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 22:43:42 +08:00
fix(pox-4-tests): Move balance check inside GetStxAccountCommand
This commit is contained in:
committed by
Nikos Baxevanis
parent
64857fd6f0
commit
7ff85f5832
@@ -1,66 +0,0 @@
|
||||
import {
|
||||
logCommand,
|
||||
PoxCommand,
|
||||
Real,
|
||||
Stub,
|
||||
Wallet,
|
||||
} from "./pox_CommandModel.ts";
|
||||
import { expect } from "vitest";
|
||||
import { ClarityValue, cvToValue } from "@stacks/transactions";
|
||||
|
||||
/**
|
||||
* Implements the `PoxCommand` interface to check a wallet's balance.
|
||||
*/
|
||||
export class CheckBalanceCommand implements PoxCommand {
|
||||
readonly wallet: Wallet;
|
||||
|
||||
/**
|
||||
* Constructs a new `CheckBalanceCommand`.
|
||||
*
|
||||
* @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 user's balance.
|
||||
return true;
|
||||
}
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
const actual = model.wallets.get(this.wallet.stxAddress)!;
|
||||
|
||||
// Get the real balance
|
||||
const stxAccount = cvToValue(
|
||||
real.network.runSnippet(
|
||||
`(stx-account '${actual.stxAddress})`,
|
||||
) as ClarityValue,
|
||||
);
|
||||
const lockedBalance = parseInt(stxAccount.locked.value);
|
||||
const unlockedBalance = parseInt(stxAccount.unlocked.value);
|
||||
const realBalance = lockedBalance + unlockedBalance;
|
||||
|
||||
// Check the real balance to equal wallet's ustxBalance
|
||||
expect(realBalance).toBe(this.wallet.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(
|
||||
`✓ ${this.wallet.label}`,
|
||||
"check-balance",
|
||||
"real-balance",
|
||||
realBalance.toString(),
|
||||
"wallet-balance",
|
||||
this.wallet.ustxBalance.toString(),
|
||||
);
|
||||
}
|
||||
|
||||
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} check-balance`;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import { Simnet } from "@hirosystems/clarinet-sdk";
|
||||
import { Cl, cvToValue, OptionalCV, UIntCV } from "@stacks/transactions";
|
||||
import { RevokeDelegateStxCommand } from "./pox_RevokeDelegateStxCommand";
|
||||
import { AllowContractCallerCommand } from "./pox_AllowContractCallerCommand";
|
||||
import { CheckBalanceCommand } from "./pox_CheckBalanceCommand";
|
||||
|
||||
export function PoxCommands(
|
||||
wallets: Map<StxAddress, Wallet>,
|
||||
@@ -168,18 +167,6 @@ export function PoxCommands(
|
||||
r.wallet,
|
||||
)
|
||||
),
|
||||
// CheckBalanceCommand
|
||||
fc.record({
|
||||
wallet: fc.constantFrom(...wallets.values()),
|
||||
}).map((
|
||||
r: {
|
||||
wallet: Wallet;
|
||||
},
|
||||
) =>
|
||||
new CheckBalanceCommand(
|
||||
r.wallet,
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
// More on size: https://github.com/dubzzz/fast-check/discussions/2978
|
||||
|
||||
@@ -39,6 +39,8 @@ export class GetStxAccountCommand implements PoxCommand {
|
||||
"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(
|
||||
|
||||
Reference in New Issue
Block a user