Skip to content

Commit 5875554

Browse files
committed
test: add unit tests for get-delegation-info
1 parent c9cec42 commit 5875554

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,101 @@ describe("test `get-check-delegation`", () => {
132132
});
133133
});
134134

135+
describe("test `get-delegation-info`", () => {
136+
it("returns none when principal is not delegated", () => {
137+
const response = simnet.callReadOnlyFn(
138+
POX_CONTRACT,
139+
"get-delegation-info",
140+
[Cl.principal(address1)],
141+
address1
142+
);
143+
expect(response.result).toBeNone();
144+
});
145+
146+
it("returns info after delegation", () => {
147+
const amount = getStackingMinimum() * 2n;
148+
149+
const untilBurnHeight = 10;
150+
const delegateResponse = delegateStx(
151+
amount,
152+
address2,
153+
untilBurnHeight,
154+
stackers[0].btcAddr,
155+
address1
156+
);
157+
expect(delegateResponse.events).toHaveLength(1);
158+
expect(delegateResponse.result).toBeOk(Cl.bool(true));
159+
160+
const delegateInfo = simnet.callReadOnlyFn(
161+
POX_CONTRACT,
162+
"get-delegation-info",
163+
[Cl.principal(address1)],
164+
address1
165+
);
166+
expect(delegateInfo.result).toBeSome(
167+
Cl.tuple({
168+
"amount-ustx": Cl.uint(amount),
169+
"delegated-to": Cl.principal(
170+
"ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"
171+
),
172+
"pox-addr": Cl.some(poxAddressToTuple(stackers[0].btcAddr)),
173+
"until-burn-ht": Cl.some(Cl.uint(untilBurnHeight)),
174+
})
175+
);
176+
});
177+
178+
it("does not expire if no burn height limit is set", () => {
179+
const amount = getStackingMinimum() * 2n;
180+
181+
delegateStx(amount, address2, null, stackers[0].btcAddr, address1);
182+
183+
const delegateInfo = simnet.callReadOnlyFn(
184+
POX_CONTRACT,
185+
"get-delegation-info",
186+
[Cl.principal(address1)],
187+
address1
188+
);
189+
190+
simnet.mineEmptyBlocks(10_000);
191+
expect(delegateInfo.result).toBeSome(
192+
Cl.tuple({
193+
"amount-ustx": Cl.uint(amount),
194+
"delegated-to": Cl.principal(
195+
"ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"
196+
),
197+
"pox-addr": Cl.some(poxAddressToTuple(stackers[0].btcAddr)),
198+
"until-burn-ht": Cl.none(),
199+
})
200+
);
201+
});
202+
203+
it("returns none after burn height expiration", () => {
204+
const amount = getStackingMinimum() * 2n;
205+
simnet.mineEmptyBlock();
206+
207+
const untilBurnHeight = 10;
208+
delegateStx(
209+
amount,
210+
address2,
211+
untilBurnHeight,
212+
stackers[0].btcAddr,
213+
address1
214+
);
215+
216+
simnet.mineEmptyBlocks(2 + untilBurnHeight - simnet.blockHeight);
217+
// a stacks block height of 12 means a burnchain block height of 11
218+
assert(simnet.blockHeight === 12);
219+
220+
const delegateInfo = simnet.callReadOnlyFn(
221+
POX_CONTRACT,
222+
"get-delegation-info",
223+
[Cl.principal(address1)],
224+
address1
225+
);
226+
expect(delegateInfo.result).toBeNone();
227+
});
228+
});
229+
135230
describe("test `delegate-stack-stx`", () => {
136231
it("does not delegate if principal is not delegated", () => {
137232
const amount = getStackingMinimum() * 2n;

0 commit comments

Comments
 (0)