mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-28 19:55:20 +08:00
test: add unit tests for get-delegation-info
This commit is contained in:
@@ -132,6 +132,101 @@ describe("test `get-check-delegation`", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("test `get-delegation-info`", () => {
|
||||
it("returns none when principal is not delegated", () => {
|
||||
const response = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-delegation-info",
|
||||
[Cl.principal(address1)],
|
||||
address1
|
||||
);
|
||||
expect(response.result).toBeNone();
|
||||
});
|
||||
|
||||
it("returns info after delegation", () => {
|
||||
const amount = getStackingMinimum() * 2n;
|
||||
|
||||
const untilBurnHeight = 10;
|
||||
const delegateResponse = delegateStx(
|
||||
amount,
|
||||
address2,
|
||||
untilBurnHeight,
|
||||
stackers[0].btcAddr,
|
||||
address1
|
||||
);
|
||||
expect(delegateResponse.events).toHaveLength(1);
|
||||
expect(delegateResponse.result).toBeOk(Cl.bool(true));
|
||||
|
||||
const delegateInfo = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-delegation-info",
|
||||
[Cl.principal(address1)],
|
||||
address1
|
||||
);
|
||||
expect(delegateInfo.result).toBeSome(
|
||||
Cl.tuple({
|
||||
"amount-ustx": Cl.uint(amount),
|
||||
"delegated-to": Cl.principal(
|
||||
"ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"
|
||||
),
|
||||
"pox-addr": Cl.some(poxAddressToTuple(stackers[0].btcAddr)),
|
||||
"until-burn-ht": Cl.some(Cl.uint(untilBurnHeight)),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("does not expire if no burn height limit is set", () => {
|
||||
const amount = getStackingMinimum() * 2n;
|
||||
|
||||
delegateStx(amount, address2, null, stackers[0].btcAddr, address1);
|
||||
|
||||
const delegateInfo = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-delegation-info",
|
||||
[Cl.principal(address1)],
|
||||
address1
|
||||
);
|
||||
|
||||
simnet.mineEmptyBlocks(10_000);
|
||||
expect(delegateInfo.result).toBeSome(
|
||||
Cl.tuple({
|
||||
"amount-ustx": Cl.uint(amount),
|
||||
"delegated-to": Cl.principal(
|
||||
"ST2CY5V39NHDPWSXMW9QDT3HC3GD6Q6XX4CFRK9AG"
|
||||
),
|
||||
"pox-addr": Cl.some(poxAddressToTuple(stackers[0].btcAddr)),
|
||||
"until-burn-ht": Cl.none(),
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("returns none after burn height expiration", () => {
|
||||
const amount = getStackingMinimum() * 2n;
|
||||
simnet.mineEmptyBlock();
|
||||
|
||||
const untilBurnHeight = 10;
|
||||
delegateStx(
|
||||
amount,
|
||||
address2,
|
||||
untilBurnHeight,
|
||||
stackers[0].btcAddr,
|
||||
address1
|
||||
);
|
||||
|
||||
simnet.mineEmptyBlocks(2 + untilBurnHeight - simnet.blockHeight);
|
||||
// a stacks block height of 12 means a burnchain block height of 11
|
||||
assert(simnet.blockHeight === 12);
|
||||
|
||||
const delegateInfo = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-delegation-info",
|
||||
[Cl.principal(address1)],
|
||||
address1
|
||||
);
|
||||
expect(delegateInfo.result).toBeNone();
|
||||
});
|
||||
});
|
||||
|
||||
describe("test `delegate-stack-stx`", () => {
|
||||
it("does not delegate if principal is not delegated", () => {
|
||||
const amount = getStackingMinimum() * 2n;
|
||||
|
||||
Reference in New Issue
Block a user