mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-30 12:42:10 +08:00
test: add basic test for stack-aggregation-increase
This commit is contained in:
@@ -299,19 +299,30 @@ export const disallowContractCaller = (caller: string, sender: string) => {
|
||||
};
|
||||
|
||||
export const stackAggregationCommitIndexed = (
|
||||
poxAddr: string,
|
||||
stacker: StackerInfo,
|
||||
rewardCycle: bigint | number,
|
||||
signerSignature: string | null,
|
||||
signerKey: string,
|
||||
period: bigint | number,
|
||||
maxAmount: bigint | number,
|
||||
authId: bigint | number,
|
||||
sender: string
|
||||
) => {
|
||||
const sigArgs = {
|
||||
authId,
|
||||
maxAmount,
|
||||
rewardCycle: Number(rewardCycle),
|
||||
period: Number(period),
|
||||
topic: Pox4SignatureTopic.AggregateCommit,
|
||||
poxAddress: stacker.btcAddr,
|
||||
signerPrivateKey: stacker.signerPrivKey,
|
||||
};
|
||||
const signerSignature = stacker.client.signPoxSignature(sigArgs);
|
||||
const signerKey = Cl.bufferFromHex(stacker.signerPubKey);
|
||||
|
||||
const args = [
|
||||
poxAddressToTuple(poxAddr),
|
||||
poxAddressToTuple(stacker.btcAddr),
|
||||
Cl.uint(rewardCycle),
|
||||
signerSignature ? Cl.some(Cl.bufferFromHex(signerSignature)) : Cl.none(),
|
||||
Cl.bufferFromHex(signerKey),
|
||||
signerKey,
|
||||
Cl.uint(maxAmount),
|
||||
Cl.uint(authId),
|
||||
];
|
||||
@@ -323,6 +334,44 @@ export const stackAggregationCommitIndexed = (
|
||||
);
|
||||
};
|
||||
|
||||
export const stackAggregationIncrease = (
|
||||
stacker: StackerInfo,
|
||||
rewardCycle: bigint | number,
|
||||
rewardCycleIndex: bigint | number,
|
||||
period: bigint | number,
|
||||
maxAmount: bigint | number,
|
||||
authId: bigint | number,
|
||||
sender: string
|
||||
) => {
|
||||
const sigArgs = {
|
||||
authId,
|
||||
maxAmount,
|
||||
rewardCycle: Number(rewardCycle),
|
||||
period: Number(period),
|
||||
topic: Pox4SignatureTopic.AggregateIncrease,
|
||||
poxAddress: stacker.btcAddr,
|
||||
signerPrivateKey: stacker.signerPrivKey,
|
||||
};
|
||||
const signerSignature = stacker.client.signPoxSignature(sigArgs);
|
||||
const signerKey = Cl.bufferFromHex(stacker.signerPubKey);
|
||||
|
||||
const args = [
|
||||
poxAddressToTuple(stacker.btcAddr),
|
||||
Cl.uint(rewardCycle),
|
||||
Cl.uint(rewardCycleIndex),
|
||||
signerSignature ? Cl.some(Cl.bufferFromHex(signerSignature)) : Cl.none(),
|
||||
signerKey,
|
||||
Cl.uint(maxAmount),
|
||||
Cl.uint(authId),
|
||||
];
|
||||
return simnet.callPublicFn(
|
||||
POX_CONTRACT,
|
||||
"stack-aggregation-increase",
|
||||
args,
|
||||
sender
|
||||
);
|
||||
};
|
||||
|
||||
// Validate a pox-4 event and return the value of the event.
|
||||
export const checkPox4Event = (event: ClarityEvent): TupleCV => {
|
||||
expect(event.event).toEqual("print_event");
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
import { assert, beforeEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { Cl } from "@stacks/transactions";
|
||||
import {
|
||||
Cl,
|
||||
ClarityType,
|
||||
ResponseCV,
|
||||
SomeCV,
|
||||
TupleCV,
|
||||
UIntCV,
|
||||
} from "@stacks/transactions";
|
||||
import { Pox4SignatureTopic, poxAddressToTuple } from "@stacks/stacking";
|
||||
import {
|
||||
ERRORS,
|
||||
POX_CONTRACT,
|
||||
allowContractCaller,
|
||||
delegateStackIncrease,
|
||||
delegateStackStx,
|
||||
delegateStx,
|
||||
getStackingMinimum,
|
||||
stackAggregationCommitIndexed,
|
||||
stackAggregationIncrease,
|
||||
stackers,
|
||||
} from "./helpers";
|
||||
|
||||
@@ -905,3 +915,74 @@ describe("test `stack-aggregation-commit`", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("test `stack-aggregation-increase`", () => {
|
||||
it("returns `(ok uint)` on success", () => {
|
||||
const account = stackers[0];
|
||||
const minAmount = getStackingMinimum();
|
||||
const amount = minAmount * 2n;
|
||||
const maxAmount = minAmount * 4n;
|
||||
const rewardCycle = 1;
|
||||
const period = 1;
|
||||
const authId = 1;
|
||||
|
||||
delegateStx(maxAmount, address2, null, account.btcAddr, account.stxAddress);
|
||||
delegateStackStx(
|
||||
account.stxAddress,
|
||||
amount,
|
||||
account.btcAddr,
|
||||
1000,
|
||||
6,
|
||||
address2
|
||||
);
|
||||
|
||||
let response = stackAggregationCommitIndexed(
|
||||
account,
|
||||
rewardCycle,
|
||||
period,
|
||||
maxAmount,
|
||||
authId,
|
||||
address2
|
||||
);
|
||||
expect(response.result.type).toBe(ClarityType.ResponseOk);
|
||||
let index = ((response.result as ResponseCV).value as UIntCV).value;
|
||||
|
||||
delegateStackIncrease(
|
||||
account.stxAddress,
|
||||
account.btcAddr,
|
||||
maxAmount - amount,
|
||||
address2
|
||||
);
|
||||
|
||||
// check the amount in the reward set
|
||||
let info = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-reward-set-pox-address",
|
||||
[Cl.uint(rewardCycle), Cl.uint(index)],
|
||||
address2
|
||||
);
|
||||
let tuple = (info.result as SomeCV).value as TupleCV;
|
||||
expect(tuple.data["total-ustx"]).toBeUint(amount);
|
||||
|
||||
response = stackAggregationIncrease(
|
||||
account,
|
||||
rewardCycle,
|
||||
index,
|
||||
period,
|
||||
maxAmount,
|
||||
authId,
|
||||
address2
|
||||
);
|
||||
expect(response.result).toBeOk(Cl.bool(true));
|
||||
|
||||
// check that the amount was increased
|
||||
info = simnet.callReadOnlyFn(
|
||||
POX_CONTRACT,
|
||||
"get-reward-set-pox-address",
|
||||
[Cl.uint(rewardCycle), Cl.uint(index)],
|
||||
address2
|
||||
);
|
||||
tuple = (info.result as SomeCV).value as TupleCV;
|
||||
expect(tuple.data["total-ustx"]).toBeUint(maxAmount);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user