Skip to content

Commit d29f7df

Browse files
committed
test: add unit tests for get-allowance-contract-callers
Opened #4718 to update the comment on this function in the next iteration of PoX.
1 parent 5875554 commit d29f7df

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

contrib/boot-contracts-unit-tests/tests/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ export const delegateStackIncrease = (
347347

348348
export const allowContractCaller = (
349349
caller: string,
350-
untilBurnHeight: bigint | null,
350+
untilBurnHeight: bigint | number | null,
351351
sender: string
352352
) => {
353353
const args = [

contrib/boot-contracts-unit-tests/tests/pool-delegate.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,62 @@ describe("test `get-delegation-info`", () => {
227227
});
228228
});
229229

230+
describe("test `get-allowance-contract-callers`", () => {
231+
it("returns `none` when not allowed", () => {
232+
const response = simnet.callReadOnlyFn(
233+
POX_CONTRACT,
234+
"get-allowance-contract-callers",
235+
[Cl.principal(address1), Cl.contractPrincipal(deployer, "indirect")],
236+
address1
237+
);
238+
expect(response.result).toBeNone();
239+
});
240+
241+
it("returns `(some none)` when allowed indefinitely", () => {
242+
allowContractCaller(`${deployer}.indirect`, null, address1);
243+
244+
const delegateInfo = simnet.callReadOnlyFn(
245+
POX_CONTRACT,
246+
"get-allowance-contract-callers",
247+
[Cl.principal(address1), Cl.contractPrincipal(deployer, "indirect")],
248+
address1
249+
);
250+
expect(delegateInfo.result).toBeSome(
251+
Cl.tuple({
252+
"until-burn-ht": Cl.none(),
253+
})
254+
);
255+
});
256+
257+
it("returns `(some (some X))` when allowed until burn height X", () => {
258+
const untilBurnHeight = 10;
259+
allowContractCaller(`${deployer}.indirect`, untilBurnHeight, address1);
260+
261+
const delegateInfo = simnet.callReadOnlyFn(
262+
POX_CONTRACT,
263+
"get-allowance-contract-callers",
264+
[Cl.principal(address1), Cl.contractPrincipal(deployer, "indirect")],
265+
address1
266+
);
267+
expect(delegateInfo.result).toBeSome(
268+
Cl.tuple({
269+
"until-burn-ht": Cl.some(Cl.uint(untilBurnHeight)),
270+
})
271+
);
272+
});
273+
274+
it("returns `none` when a different caller is allowed", () => {
275+
allowContractCaller(`${deployer}.not-indirect`, null, address1);
276+
const response = simnet.callReadOnlyFn(
277+
POX_CONTRACT,
278+
"get-allowance-contract-callers",
279+
[Cl.principal(address1), Cl.contractPrincipal(deployer, "indirect")],
280+
address1
281+
);
282+
expect(response.result).toBeNone();
283+
});
284+
});
285+
230286
describe("test `delegate-stack-stx`", () => {
231287
it("does not delegate if principal is not delegated", () => {
232288
const amount = getStackingMinimum() * 2n;

0 commit comments

Comments
 (0)