Skip to content

Commit 2d31663

Browse files
authored
Merge pull request #23 from hirosystems/map-helper
Map-helper
2 parents ea7d72c + 4910819 commit 2d31663

File tree

2 files changed

+56
-7
lines changed

2 files changed

+56
-7
lines changed

tests/integration/pox/helpers.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import {
22
DevnetNetworkOrchestrator,
3-
StacksChainUpdate
3+
StacksChainUpdate,
44
} from "@hirosystems/stacks-devnet-js";
55
import { StacksNetwork } from "@stacks/network";
6-
import { TxBroadcastResult } from "@stacks/transactions";
6+
import {
7+
tupleCV,
8+
uintCV,
9+
cvToHex,
10+
TxBroadcastResult,
11+
} from "@stacks/transactions";
712

813
import { expect } from "vitest";
914
const fetch = require("node-fetch");
@@ -135,4 +140,36 @@ export const expectNoError = (response: TxBroadcastResult) => {
135140
" " +
136141
JSON.stringify(response.reason_data)
137142
).toBeUndefined();
138-
}
143+
};
144+
145+
export const readRewardCyclePoxAddressList = async (
146+
network: StacksNetwork,
147+
cycleId: number,
148+
index: number
149+
) => {
150+
const url = network.getMapEntryUrl(
151+
"ST000000000000000000002AMW42H",
152+
"pox-2",
153+
"reward-cycle-pox-address-list"
154+
);
155+
const cycleIdValue = uintCV(cycleId);
156+
const indexValue = uintCV(index);
157+
const keyValue = tupleCV({
158+
"reward-cycle": cycleIdValue,
159+
index: indexValue,
160+
});
161+
const response = await network.fetchFn(url, {
162+
method: "POST",
163+
body: JSON.stringify(cvToHex(keyValue)),
164+
headers: {
165+
"Content-Type": "application/json",
166+
},
167+
});
168+
if (!response.ok) {
169+
const msg = await response.text().catch(() => "");
170+
throw new Error(
171+
`Error calling read-only function. Response ${response.status}: ${response.statusText}. Attempted to fetch ${url} and failed with the message: "${msg}"`
172+
);
173+
}
174+
return response.json();
175+
};

tests/integration/pox/stacking/direct-stacking.spec.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import { StacksTestnet } from "@stacks/network";
33
import { Accounts } from "../../constants";
44
import {
55
buildDevnetNetworkOrchestrator,
6-
getNetworkIdFromEnv
6+
getNetworkIdFromEnv,
77
} from "../../helpers";
88
import {
99
getPoxInfo,
1010
waitForNextRewardPhase,
11-
waitForRewardCycleId
11+
waitForRewardCycleId,
12+
readRewardCyclePoxAddressList,
1213
} from "../helpers";
1314
import {
1415
broadcastStackIncrease,
15-
broadcastStackSTX
16+
broadcastStackSTX,
1617
} from "../helpers-direct-stacking";
18+
import { cvToString, hexToCV } from "@stacks/transactions";
1719

1820
describe("testing stacking under epoch 2.1", () => {
1921
let orchestrator: DevnetNetworkOrchestrator;
@@ -94,13 +96,23 @@ describe("testing stacking under epoch 2.1", () => {
9496

9597
// move on to the nexte cycle
9698
await waitForRewardCycleId(network, orchestrator, 2, 1);
97-
99+
98100
poxInfo = await getPoxInfo(network);
99101
// Assert that the current cycle has 100m STX locked and earning
100102
expect(poxInfo.current_cycle.id).toBe(2);
101103
expect(poxInfo.current_cycle.stacked_ustx).toBe(100_000_000_000_000);
102104
expect(poxInfo.current_cycle.is_pox_active).toBe(true);
103105

106+
const poxAddrInfo0 = await readRewardCyclePoxAddressList(network, 2, 0);
107+
const poxAddrInfoStr0 = cvToString(hexToCV(poxAddrInfo0.data));
108+
// HERE'S THE BUG: THIS SHOULD BE `u80000000000000`
109+
// expect(poxAddrInfoStr0).toContain("(total-ustx u80000000000000)");
110+
expect(poxAddrInfoStr0).toContain("(total-ustx u100000000000000)");
111+
112+
const poxAddrInfo1 = await readRewardCyclePoxAddressList(network, 2, 1);
113+
const poxAddrInfoStr1 = cvToString(hexToCV(poxAddrInfo1.data));
114+
expect(poxAddrInfoStr1).toContain("(total-ustx u50000000000000)");
115+
104116
// move on to the nexte cycle
105117
await waitForNextRewardPhase(network, orchestrator, 1);
106118

0 commit comments

Comments
 (0)