Skip to content

Commit ff2b49e

Browse files
committed
test: add unit tests for get-num-reward-set-pox-addresses
1 parent d29f7df commit ff2b49e

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

contrib/boot-contracts-unit-tests/tests/misc.test.ts

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
POX_CONTRACT,
77
StackerInfo,
88
allowContractCaller,
9+
delegateStackStx,
10+
delegateStx,
911
getStackingMinimum,
1012
setSignerKeyAuthorization,
13+
stackAggregationCommitIndexed,
1114
stackStx,
1215
stackers,
1316
} from "./helpers";
@@ -1602,3 +1605,121 @@ describe("test `set-signer-key-authorization`", () => {
16021605
expect(response.result).toBeErr(Cl.int(ERRORS.ERR_INVALID_REWARD_CYCLE));
16031606
});
16041607
});
1608+
1609+
describe("test `get-num-reward-set-pox-addresses`", () => {
1610+
it("returns 0 when there are no stackers", () => {
1611+
const response = simnet.callReadOnlyFn(
1612+
POX_CONTRACT,
1613+
"get-num-reward-set-pox-addresses",
1614+
[Cl.uint(1)],
1615+
address1
1616+
);
1617+
expect(response.result).toBeUint(0);
1618+
});
1619+
1620+
it("returns the number of stackers", () => {
1621+
const amount = getStackingMinimum() * 2n;
1622+
stackers.forEach((stacker) => {
1623+
stackStx(
1624+
stacker,
1625+
amount,
1626+
1000,
1627+
6,
1628+
amount,
1629+
stacker.authId,
1630+
stacker.stxAddress
1631+
);
1632+
});
1633+
1634+
const response = simnet.callReadOnlyFn(
1635+
POX_CONTRACT,
1636+
"get-num-reward-set-pox-addresses",
1637+
[Cl.uint(1)],
1638+
address1
1639+
);
1640+
expect(response.result).toBeUint(stackers.length);
1641+
});
1642+
1643+
it("returns the number of stackers for a specific reward cycle", () => {
1644+
const amount = getStackingMinimum() * 2n;
1645+
stackers.forEach((stacker) => {
1646+
stackStx(
1647+
stacker,
1648+
amount,
1649+
1000,
1650+
6,
1651+
amount,
1652+
stacker.authId,
1653+
stacker.stxAddress
1654+
);
1655+
});
1656+
1657+
const response = simnet.callReadOnlyFn(
1658+
POX_CONTRACT,
1659+
"get-num-reward-set-pox-addresses",
1660+
[Cl.uint(2)],
1661+
address1
1662+
);
1663+
expect(response.result).toBeUint(stackers.length);
1664+
});
1665+
1666+
it("returns 0 when there are expired stackers", () => {
1667+
const amount = getStackingMinimum() * 2n;
1668+
stackers.forEach((stacker) => {
1669+
stackStx(
1670+
stacker,
1671+
amount,
1672+
1000,
1673+
6,
1674+
amount,
1675+
stacker.authId,
1676+
stacker.stxAddress
1677+
);
1678+
});
1679+
1680+
const response = simnet.callReadOnlyFn(
1681+
POX_CONTRACT,
1682+
"get-num-reward-set-pox-addresses",
1683+
[Cl.uint(8)],
1684+
address1
1685+
);
1686+
expect(response.result).toBeUint(0);
1687+
});
1688+
1689+
it("handles delegated stacking", () => {
1690+
const account = stackers[0];
1691+
const minAmount = getStackingMinimum();
1692+
const amount = minAmount * 2n;
1693+
const maxAmount = minAmount * 4n;
1694+
const startBurnHeight = 1000;
1695+
const lockPeriod = 6;
1696+
const rewardCycle = 1;
1697+
const authId = 1;
1698+
1699+
delegateStx(maxAmount, address3, null, account.btcAddr, account.stxAddress);
1700+
delegateStackStx(
1701+
account.stxAddress,
1702+
amount,
1703+
account.btcAddr,
1704+
startBurnHeight,
1705+
lockPeriod,
1706+
address3
1707+
);
1708+
1709+
stackAggregationCommitIndexed(
1710+
account,
1711+
rewardCycle,
1712+
maxAmount,
1713+
authId,
1714+
address3
1715+
);
1716+
1717+
const response = simnet.callReadOnlyFn(
1718+
POX_CONTRACT,
1719+
"get-num-reward-set-pox-addresses",
1720+
[Cl.uint(1)],
1721+
address1
1722+
);
1723+
expect(response.result).toBeUint(1);
1724+
});
1725+
});

0 commit comments

Comments
 (0)