test: add unit tests for get-partial-stacked-by-cycle

This commit is contained in:
Brice Dobry
2024-04-25 16:58:38 -04:00
parent ff2b49ee42
commit 90a6e74fa0

View File

@@ -2726,3 +2726,142 @@ describe("test `delegate-stack-extend`", () => {
expect(tuple.data["lock-period"]).toBeUint(1);
});
});
describe("test `get-partial-stacked-by-cycle`", () => {
it("returns the correct amount", () => {
const account = stackers[0];
const amount = getStackingMinimum() * 2n;
const maxAmount = amount * 2n;
const rewardCycle = 1;
delegateStx(maxAmount, address2, null, account.btcAddr, account.stxAddress);
delegateStackStx(
account.stxAddress,
amount,
account.btcAddr,
1000,
1,
address2
);
const info = simnet.callReadOnlyFn(
POX_CONTRACT,
"get-partial-stacked-by-cycle",
[
poxAddressToTuple(account.btcAddr),
Cl.uint(rewardCycle),
Cl.principal(address2),
],
address2
);
expect(info.result).toBeSome(
Cl.tuple({
"stacked-amount": Cl.uint(amount),
})
);
});
it("returns `none` when there are no partially stacked STX", () => {
const account = stackers[0];
const rewardCycle = 1;
const info = simnet.callReadOnlyFn(
POX_CONTRACT,
"get-partial-stacked-by-cycle",
[
poxAddressToTuple(account.btcAddr),
Cl.uint(rewardCycle),
Cl.principal(address2),
],
address2
);
expect(info.result).toBeNone();
});
it("returns `none` after fully stacked", () => {
const account = stackers[0];
const amount = getStackingMinimum() * 2n;
const maxAmount = amount * 2n;
const rewardCycle = 1;
const authId = 1;
delegateStx(maxAmount, address2, null, account.btcAddr, account.stxAddress);
delegateStackStx(
account.stxAddress,
amount,
account.btcAddr,
1000,
1,
address2
);
let info = simnet.callReadOnlyFn(
POX_CONTRACT,
"get-partial-stacked-by-cycle",
[
poxAddressToTuple(account.btcAddr),
Cl.uint(rewardCycle),
Cl.principal(address2),
],
address2
);
expect(info.result).toBeSome(
Cl.tuple({
"stacked-amount": Cl.uint(amount),
})
);
stackAggregationCommitIndexed(
account,
rewardCycle,
maxAmount,
authId,
address2
);
info = simnet.callReadOnlyFn(
POX_CONTRACT,
"get-partial-stacked-by-cycle",
[
poxAddressToTuple(account.btcAddr),
Cl.uint(rewardCycle),
Cl.principal(address2),
],
address2
);
expect(info.result).toBeNone();
});
it("returns the correct amount for multiple cycles", () => {
const account = stackers[0];
const amount = getStackingMinimum() * 2n;
const maxAmount = amount * 2n;
const rewardCycle = 4;
delegateStx(maxAmount, address2, null, account.btcAddr, account.stxAddress);
delegateStackStx(
account.stxAddress,
amount,
account.btcAddr,
1000,
6,
address2
);
const info = simnet.callReadOnlyFn(
POX_CONTRACT,
"get-partial-stacked-by-cycle",
[
poxAddressToTuple(account.btcAddr),
Cl.uint(rewardCycle),
Cl.principal(address2),
],
address2
);
expect(info.result).toBeSome(
Cl.tuple({
"stacked-amount": Cl.uint(amount),
})
);
});
});