Skip to content

Commit

Permalink
refactor(pox-4): Relocate cycle utility functions to PoxCommands
Browse files Browse the repository at this point in the history
- Removes `Cl` and `cvToValue` imports and cycle utility functions from
  `pox-4.stateful-prop.test.ts`, streamlining its focus on tests.
- Adds these imports and functions to `pox_Commands.ts`, centralizing
  cycle-related logic within command utilities for better cohesion and
  reusability. This shift enhances modularity and clarity in handling
  reward cycle calculations across PoX-4 tests.
  • Loading branch information
moodmosaic committed Mar 22, 2024
1 parent fe1b3af commit d6047eb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it } from "vitest";
import { initSimnet, Simnet } from "@hirosystems/clarinet-sdk";
import { initSimnet } from "@hirosystems/clarinet-sdk";
import { Real, Stub, StxAddress, Wallet } from "./pox_CommandModel.ts";

import {
Expand All @@ -8,9 +8,7 @@ import {
} from "@stacks/encryption";
import { StacksDevnet } from "@stacks/network";
import {
Cl,
createStacksPrivateKey,
cvToValue,
getAddressFromPrivateKey,
TransactionVersion,
} from "@stacks/transactions";
Expand All @@ -19,36 +17,6 @@ import { StackingClient } from "@stacks/stacking";
import fc from "fast-check";
import { PoxCommands } from "./pox_Commands.ts";

export const currentCycle = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"current-pox-reward-cycle",
[],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

export const currentCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network))],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

export const nextCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network) + 1)],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

describe("PoX-4 invariant tests", () => {
it("statefully does solo stacking with a signature", async () => {
// SUT stands for "System Under Test".
Expand Down
32 changes: 31 additions & 1 deletion contrib/core-contract-tests/tests/pox-4/pox_Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StackStxCommand } from "./pox_StackStxCommand";
import { DelegateStxCommand } from "./pox_DelegateStxCommand";
import { DelegateStackStxCommand } from "./pox_DelegateStackStxCommand";
import { Simnet } from "@hirosystems/clarinet-sdk";
import { currentCycleFirstBlock, nextCycleFirstBlock } from "./pox-4.stateful-prop.test";
import { Cl, cvToValue } from "@stacks/transactions";

export function PoxCommands(
wallets: Map<StxAddress, Wallet>, network: Simnet,
Expand Down Expand Up @@ -111,3 +111,33 @@ export function PoxCommands(
// More on cmds: https://github.com/dubzzz/fast-check/discussions/3026
return fc.commands(cmds, { size: "large" });
}

const currentCycle = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"current-pox-reward-cycle",
[],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

const currentCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network))],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

const nextCycleFirstBlock = (network: Simnet) =>
Number(cvToValue(
network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"reward-cycle-to-burn-height",
[Cl.uint(currentCycle(network) + 1)],
"ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM",
).result,
));

0 comments on commit d6047eb

Please sign in to comment.