-
Notifications
You must be signed in to change notification settings - Fork 647
/
pox_GetStackingMinimumCommand.ts
60 lines (53 loc) · 2.06 KB
/
pox_GetStackingMinimumCommand.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { PoxCommand, Real, Stub, Wallet } from "./pox_CommandModel.ts";
import { assert } from "vitest";
import { ClarityType, isClarityType } from "@stacks/transactions";
/**
* Implements the `PoxCommand` interface to get the minimum stacking amount
* required for a given reward cycle.
*/
export class GetStackingMinimumCommand implements PoxCommand {
readonly wallet: Wallet;
/**
* Constructs a new `GetStackingMinimumCommand`.
*
* @param wallet The wallet information, including the STX address used to
* query the stacking minimum requirement.
*/
constructor(wallet: Wallet) {
this.wallet = wallet;
}
check(_model: Readonly<Stub>): boolean {
// Can always check the minimum number of uSTX to be stacked in the given
// reward cycle.
return true;
}
run(model: Stub, real: Real): void {
// Act
const { result: stackingMinimum } = real.network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"get-stacking-minimum",
[],
this.wallet.stxAddress,
);
assert(isClarityType(stackingMinimum, ClarityType.UInt));
// Update the model with the new stacking minimum. This is important for
// the `check` method of the `StackStxCommand` class to work correctly, as
// we as other tests that may depend on the stacking minimum.
model.stackingMinimum = Number(stackingMinimum.value);
// 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.label.padStart(8, " ")} ${
"get-stacking-minimum".padStart(34, " ")
} ${"pox-4".padStart(12, " ")} ${
stackingMinimum.value.toString().padStart(15, " ")
}`,
);
}
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} get-stacking-minimum`;
}
}