mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-28 11:46:07 +08:00
chore(pox-4-tests): Format code and wrap comments at 79 chars
- Ran `deno fmt` to ensure code formatting adheres to standard practices. - Manually wrapped comments to 79 characters width for improved readability across various code editors and diff tools. - Fixed minor typos and standardized comment punctuation. - Added missing periods at the end of parameter descriptions.
This commit is contained in:
@@ -15,10 +15,11 @@ import {
|
||||
} from "@stacks/transactions";
|
||||
|
||||
/**
|
||||
* The `AllowContractCallerComand` gives a `contract-caller` authorization to call stacking methods.
|
||||
* Normally, stacking methods may only be invoked by direct transactions (i.e., the tx-sender
|
||||
* issues a direct contract-call to the stacking methods).
|
||||
* By issuing an allowance, the tx-sender may call stacking methods through the allowed contract.
|
||||
* The `AllowContractCallerCommand` authorizes a `contract-caller` to call
|
||||
* stacking methods. Normally, stacking methods can only be invoked by direct
|
||||
* transactions (i.e., the tx-sender issues a direct contract-call to the
|
||||
* stacking methods). By issuing an allowance, the tx-sender may call stacking
|
||||
* methods through the allowed contract.
|
||||
*
|
||||
* There are no constraints for running this command.
|
||||
*/
|
||||
@@ -28,12 +29,14 @@ export class AllowContractCallerCommand implements PoxCommand {
|
||||
readonly allowUntilBurnHt: OptionalCV<UIntCV>;
|
||||
|
||||
/**
|
||||
* Constructs an `AllowContractCallerComand` that authorizes a `contract-caller` to call
|
||||
* stacking methods.
|
||||
* Constructs an `AllowContractCallerCommand` that authorizes a
|
||||
* `contract-caller` to call stacking methods.
|
||||
*
|
||||
* @param wallet - Represents the Stacker's wallet.
|
||||
* @param allowanceTo - Represents the authorized `contract-caller` (i.e. a stacking pool)
|
||||
* @param alllowUntilBurnHt - The burn block height until the authorization is valid.
|
||||
* @param allowanceTo - Represents the authorized `contract-caller` (i.e., a
|
||||
* stacking pool).
|
||||
* @param allowUntilBurnHt - The burn block height until which the
|
||||
* authorization is valid.
|
||||
*/
|
||||
constructor(
|
||||
wallet: Wallet,
|
||||
@@ -52,6 +55,7 @@ export class AllowContractCallerCommand implements PoxCommand {
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
// Act
|
||||
const allowContractCaller = real.network.callPublicFn(
|
||||
"ST000000000000000000002AMW42H.pox-4",
|
||||
|
||||
@@ -7,11 +7,7 @@ import {
|
||||
} from "./pox_CommandModel.ts";
|
||||
import { poxAddressToTuple } from "@stacks/stacking";
|
||||
import { assert, expect } from "vitest";
|
||||
import {
|
||||
Cl,
|
||||
ClarityType,
|
||||
isClarityType,
|
||||
} from "@stacks/transactions";
|
||||
import { Cl, ClarityType, isClarityType } from "@stacks/transactions";
|
||||
import {
|
||||
FIRST_BURNCHAIN_BLOCK_HEIGHT,
|
||||
REWARD_CYCLE_LENGTH,
|
||||
@@ -19,10 +15,10 @@ import {
|
||||
|
||||
/**
|
||||
* The `DelegateStackExtendCommand` allows a pool operator to
|
||||
* extend an active stacking lock, issuing a "partial commitment"
|
||||
* extend an active stacking lock, issuing a "partial commitment"
|
||||
* for the extended-to cycles.
|
||||
*
|
||||
* This method extends stacker's current lockup for an additional
|
||||
*
|
||||
* This method extends stacker's current lockup for an additional
|
||||
* extend-count and partially commits those new cycles to `pox-addr`.
|
||||
*
|
||||
* Constraints for running this command include:
|
||||
|
||||
@@ -13,7 +13,7 @@ import { Cl } from "@stacks/transactions";
|
||||
* The DelegateStackIncreaseCommand allows a pool operator to
|
||||
* increase an active stacking lock, issuing a "partial commitment"
|
||||
* for the increased cycles.
|
||||
*
|
||||
*
|
||||
* This method increases stacker's current lockup and partially
|
||||
* commits the additional STX to `pox-addr`.
|
||||
*
|
||||
@@ -38,7 +38,7 @@ export class DelegateStackIncreaseCommand implements PoxCommand {
|
||||
*
|
||||
* @param operator - Represents the Pool Operator's wallet.
|
||||
* @param stacker - Represents the Stacker's wallet.
|
||||
* @param increaseBy - Represents the locked amount to be increased by
|
||||
* @param increaseBy - Represents the locked amount to be increased by.
|
||||
*/
|
||||
constructor(operator: Wallet, stacker: Wallet, increaseBy: number) {
|
||||
this.operator = operator;
|
||||
@@ -103,7 +103,7 @@ export class DelegateStackIncreaseCommand implements PoxCommand {
|
||||
|
||||
// Get the Stacker's wallet from the model and update it with the new state.
|
||||
const stackerWallet = model.wallets.get(this.stacker.stxAddress)!;
|
||||
const operatorWallet = model.wallets.get(this.operator.stxAddress)!
|
||||
const operatorWallet = model.wallets.get(this.operator.stxAddress)!;
|
||||
// Update model so that we know this stacker has increased the stacked amount.
|
||||
// Update locked and unlocked fields in the model.
|
||||
stackerWallet.amountLocked = newTotalLocked;
|
||||
|
||||
@@ -11,21 +11,21 @@ import { Cl, ClarityType, isClarityType } from "@stacks/transactions";
|
||||
import { currentCycle } from "./pox_Commands.ts";
|
||||
|
||||
/**
|
||||
* The `DelegateStackStxCommand` locks STX for stacking within PoX-4 on behalf of a delegator.
|
||||
* This operation allows the `operator` to stack the `stacker`'s STX.
|
||||
* The `DelegateStackStxCommand` locks STX for stacking within PoX-4 on behalf
|
||||
* of a delegator. This operation allows the `operator` to stack the `stacker`'s
|
||||
* STX.
|
||||
*
|
||||
* Constraints for running this command include:
|
||||
* - A minimum threshold of uSTX must be met, determined by the
|
||||
* `get-stacking-minimum` function at the time of this call.
|
||||
* - The Stacker cannot currently be engaged in another stacking
|
||||
* operation.
|
||||
* `get-stacking-minimum` function at the time of this call.
|
||||
* - The Stacker cannot currently be engaged in another stacking operation.
|
||||
* - The Stacker has to currently be delegating to the Operator.
|
||||
* - The stacked STX amount should be less than or equal to the
|
||||
* delegated amount.
|
||||
* - The stacked uSTX amount should be less than or equal to the
|
||||
* Stacker's balance.
|
||||
* - The stacked uSTX amount should be greater than or equal to the
|
||||
* minimum threshold of uSTX.
|
||||
* - The stacked STX amount should be less than or equal to the delegated
|
||||
* amount.
|
||||
* - The stacked uSTX amount should be less than or equal to the Stacker's
|
||||
* balance.
|
||||
* - The stacked uSTX amount should be greater than or equal to the minimum
|
||||
* threshold of uSTX.
|
||||
* - The Operator has to currently be delegated by the Stacker.
|
||||
* - The Period has to fit the last delegation burn block height.
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
* @param startBurnHt - A burn height inside the current reward cycle.
|
||||
* @param period - Number of reward cycles to lock uSTX.
|
||||
* @param amountUstx - The uSTX amount stacked by the Operator on behalf
|
||||
* of the Stacker
|
||||
* of the Stacker.
|
||||
* @param unlockBurnHt - The burn height at which the uSTX is unlocked.
|
||||
*/
|
||||
constructor(
|
||||
@@ -55,7 +55,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
startBurnHt: number,
|
||||
period: number,
|
||||
amountUstx: bigint,
|
||||
unlockBurnHt: number
|
||||
unlockBurnHt: number,
|
||||
) {
|
||||
this.operator = operator;
|
||||
this.stacker = stacker;
|
||||
@@ -98,6 +98,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
// Act
|
||||
const delegateStackStx = real.network.callPublicFn(
|
||||
"ST000000000000000000002AMW42H.pox-4",
|
||||
@@ -114,13 +115,13 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
// (lock-period uint)
|
||||
Cl.uint(this.period),
|
||||
],
|
||||
this.operator.stxAddress
|
||||
this.operator.stxAddress,
|
||||
);
|
||||
const { result: rewardCycle } = real.network.callReadOnlyFn(
|
||||
"ST000000000000000000002AMW42H.pox-4",
|
||||
"burn-height-to-reward-cycle",
|
||||
[Cl.uint(real.network.blockHeight)],
|
||||
this.operator.stxAddress
|
||||
this.operator.stxAddress,
|
||||
);
|
||||
assert(isClarityType(rewardCycle, ClarityType.UInt));
|
||||
|
||||
@@ -128,7 +129,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
"ST000000000000000000002AMW42H.pox-4",
|
||||
"reward-cycle-to-burn-height",
|
||||
[Cl.uint(Number(rewardCycle.value) + this.period + 1)],
|
||||
this.operator.stxAddress
|
||||
this.operator.stxAddress,
|
||||
);
|
||||
assert(isClarityType(unlockBurnHeight, ClarityType.UInt));
|
||||
|
||||
@@ -138,7 +139,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
stacker: Cl.principal(this.stacker.stxAddress),
|
||||
"lock-amount": Cl.uint(this.amountUstx),
|
||||
"unlock-burn-height": Cl.uint(Number(unlockBurnHeight.value)),
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// Get the Stacker's wallet from the model and update it with the new state.
|
||||
@@ -154,8 +155,8 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
stackerWallet.amountUnlocked -= Number(this.amountUstx);
|
||||
stackerWallet.firstLockedRewardCycle = currentCycle(real.network) + 1;
|
||||
// Add stacker to the operators lock list. This will help knowing that
|
||||
// the stacker's funds are locked when calling delegate-stack-extend,
|
||||
// delegate-stack-increase
|
||||
// the stacker's funds are locked when calling delegate-stack-extend
|
||||
// and delegate-stack-increase.
|
||||
operatorWallet.lockedAddresses.push(stackerWallet.stxAddress);
|
||||
operatorWallet.amountToCommit += Number(this.amountUstx);
|
||||
|
||||
@@ -167,7 +168,7 @@ export class DelegateStackStxCommand implements PoxCommand {
|
||||
"lock-amount",
|
||||
this.amountUstx.toString(),
|
||||
"until",
|
||||
this.stacker.unlockHeight.toString()
|
||||
this.stacker.unlockHeight.toString(),
|
||||
);
|
||||
|
||||
// Refresh the model's state if the network gets to the next reward cycle.
|
||||
|
||||
@@ -10,13 +10,14 @@ import { expect } from "vitest";
|
||||
import { boolCV, Cl } from "@stacks/transactions";
|
||||
|
||||
/**
|
||||
* The `DelegateStxCommand` delegates STX for stacking within PoX-4. This operation
|
||||
* allows the `tx-sender` (the `wallet` in this case) to delegate stacking participation
|
||||
* to a `delegatee`.
|
||||
* The `DelegateStxCommand` delegates STX for stacking within PoX-4. This
|
||||
* operation allows the `tx-sender` (the `wallet` in this case) to delegate
|
||||
* stacking participation to a `delegatee`.
|
||||
*
|
||||
* Constraints for running this command include:
|
||||
* - The Stacker cannot currently be a delegator in another delegation.
|
||||
* - The PoX address provided should have a valid version (between 0 and 6 inclusive).
|
||||
* - The PoX address provided should have a valid version (between 0 and 6
|
||||
* inclusive).
|
||||
*/
|
||||
export class DelegateStxCommand implements PoxCommand {
|
||||
readonly wallet: Wallet;
|
||||
@@ -30,8 +31,8 @@ export class DelegateStxCommand implements PoxCommand {
|
||||
* @param wallet - Represents the Stacker's wallet.
|
||||
* @param delegateTo - Represents the Delegatee's STX address.
|
||||
* @param untilBurnHt - The burn block height until the delegation is valid.
|
||||
* @param amount - The maximum amount the `Stacker` delegates the `Delegatee` to
|
||||
* stack on his behalf
|
||||
* @param amount - The maximum amount the `Stacker` delegates the `Delegatee`
|
||||
* to stack on his behalf.
|
||||
*/
|
||||
constructor(
|
||||
wallet: Wallet,
|
||||
@@ -48,6 +49,7 @@ export class DelegateStxCommand implements PoxCommand {
|
||||
check(model: Readonly<Stub>): boolean {
|
||||
// Constraints for running this command include:
|
||||
// - The Stacker cannot currently be a delegator in another delegation.
|
||||
|
||||
return (
|
||||
model.stackingMinimum > 0 &&
|
||||
!model.wallets.get(this.wallet.stxAddress)?.hasDelegated
|
||||
@@ -56,6 +58,7 @@ export class DelegateStxCommand implements PoxCommand {
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
// The amount of uSTX delegated by the Stacker to the Delegatee.
|
||||
// Even if there are no constraints about the delegated amount,
|
||||
// it will be checked in the future, when calling delegate-stack-stx.
|
||||
@@ -104,7 +107,7 @@ export class DelegateStxCommand implements PoxCommand {
|
||||
"delegated to",
|
||||
this.delegateTo.label,
|
||||
"until",
|
||||
this.untilBurnHt.toString()
|
||||
this.untilBurnHt.toString(),
|
||||
);
|
||||
|
||||
// Refresh the model's state if the network gets to the next reward cycle.
|
||||
|
||||
@@ -27,7 +27,6 @@ export class DisallowContractCallerCommand implements PoxCommand {
|
||||
* @param stacker - Represents the `Stacker`'s wallet.
|
||||
* @param callerToDisallow - The `contract-caller` to be revoked.
|
||||
*/
|
||||
|
||||
constructor(stacker: Wallet, callerToDisallow: Wallet) {
|
||||
this.stacker = stacker;
|
||||
this.callerToDisallow = callerToDisallow;
|
||||
@@ -35,12 +34,14 @@ export class DisallowContractCallerCommand implements PoxCommand {
|
||||
|
||||
check(_model: Readonly<Stub>): boolean {
|
||||
// Constraints for running this command include:
|
||||
// - The Caller to be disallowed must have been previously
|
||||
// allowed by the Operator.
|
||||
// - The Caller to be disallowed must have been previously allowed
|
||||
// by the Operator.
|
||||
|
||||
return (
|
||||
this.stacker.allowedContractCaller === this.callerToDisallow.stxAddress &&
|
||||
this.callerToDisallow.callerAllowedBy.includes(this.stacker.stxAddress) ===
|
||||
this.callerToDisallow.callerAllowedBy.includes(
|
||||
this.stacker.stxAddress,
|
||||
) ===
|
||||
true
|
||||
);
|
||||
}
|
||||
@@ -62,13 +63,13 @@ export class DisallowContractCallerCommand implements PoxCommand {
|
||||
// Assert
|
||||
expect(disallowContractCaller.result).toBeOk(boolCV(true));
|
||||
|
||||
// Get the wallet to be revoked stacking rights from the model and
|
||||
// Get the wallet to be revoked stacking rights from the model and
|
||||
// update it with the new state.
|
||||
const callerToDisallow = model.wallets.get(
|
||||
this.callerToDisallow.stxAddress,
|
||||
)!;
|
||||
|
||||
// Update model so that we know that the stacker has revoked stacking
|
||||
// Update model so that we know that the stacker has revoked stacking
|
||||
// allowance.
|
||||
this.stacker.allowedContractCaller = "";
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ export class GetStackingMinimumCommand implements PoxCommand {
|
||||
}
|
||||
|
||||
check(_model: Readonly<Stub>): boolean {
|
||||
// Can always check the minimum number of uSTX to be stacked in the given
|
||||
// reward cycle.
|
||||
// There are no constraints for running this command.
|
||||
return true;
|
||||
}
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
// Act
|
||||
const { result: stackingMinimum } = real.network.callReadOnlyFn(
|
||||
"ST000000000000000000002AMW42H.pox-4",
|
||||
|
||||
@@ -26,12 +26,13 @@ export class GetStxAccountCommand implements PoxCommand {
|
||||
}
|
||||
|
||||
check(_model: Readonly<Stub>): boolean {
|
||||
// Can always check the `stx-account` info.
|
||||
// There are no constraints for running this command.
|
||||
return true;
|
||||
}
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
const actual = model.wallets.get(this.wallet.stxAddress)!;
|
||||
expect(real.network.runSnippet(`(stx-account '${actual.stxAddress})`))
|
||||
.toBeTuple({
|
||||
@@ -40,8 +41,10 @@ export class GetStxAccountCommand implements PoxCommand {
|
||||
"unlock-height": Cl.uint(actual.unlockHeight),
|
||||
});
|
||||
|
||||
expect(actual.amountLocked + actual.amountUnlocked).toBe(actual.ustxBalance);
|
||||
|
||||
expect(actual.amountLocked + actual.amountUnlocked).toBe(
|
||||
actual.ustxBalance,
|
||||
);
|
||||
|
||||
// Log to console for debugging purposes. This is not necessary for the
|
||||
// test to pass but it is useful for debugging and eyeballing the test.
|
||||
logCommand(
|
||||
|
||||
@@ -10,7 +10,8 @@ import { expect } from "vitest";
|
||||
import { Cl, someCV, tupleCV } from "@stacks/transactions";
|
||||
|
||||
/**
|
||||
* The `RevokeDelegateStxCommand` revokes the delegation for stacking within PoX-4.
|
||||
* The `RevokeDelegateStxCommand` revokes the delegation for stacking within
|
||||
* PoX-4.
|
||||
*
|
||||
* Constraints for running this command include:
|
||||
* - The `Stacker` has to currently be delegating.
|
||||
@@ -30,6 +31,7 @@ export class RevokeDelegateStxCommand implements PoxCommand {
|
||||
check(model: Readonly<Stub>): boolean {
|
||||
// Constraints for running this command include:
|
||||
// - The Stacker has to currently be delegating.
|
||||
|
||||
return (
|
||||
model.stackingMinimum > 0 &&
|
||||
model.wallets.get(this.wallet.stxAddress)!.hasDelegated === true
|
||||
@@ -38,7 +40,7 @@ export class RevokeDelegateStxCommand implements PoxCommand {
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
// Get the Operator's wallet
|
||||
|
||||
const operatorWallet = model.wallets.get(this.wallet.delegatedTo)!;
|
||||
|
||||
// Act
|
||||
@@ -65,17 +67,18 @@ export class RevokeDelegateStxCommand implements PoxCommand {
|
||||
),
|
||||
);
|
||||
|
||||
// Get the Stacker's wallet from the model and update the two wallets involved with the new state.
|
||||
// Get the Stacker's wallet from the model and update the two wallets
|
||||
// involved with the new state.
|
||||
const wallet = model.wallets.get(this.wallet.stxAddress)!;
|
||||
// Update model so that we know this wallet is not delegating anymore.
|
||||
// This is important in order to prevent the test from revoking the delegation
|
||||
// multiple times with the same address.
|
||||
// This is important in order to prevent the test from revoking the
|
||||
// delegation multiple times with the same address.
|
||||
wallet.hasDelegated = false;
|
||||
wallet.delegatedTo = "";
|
||||
wallet.delegatedUntilBurnHt = 0;
|
||||
wallet.delegatedMaxAmount = 0;
|
||||
|
||||
// Remove the Stacker from the Pool Operator's pool members list
|
||||
// Remove the Stacker from the Pool Operator's pool members list.
|
||||
const walletIndexInDelegatorsList = operatorWallet.poolMembers.indexOf(
|
||||
wallet.stxAddress,
|
||||
);
|
||||
|
||||
@@ -32,7 +32,7 @@ export class StackAggregationCommitIndexedAuthCommand implements PoxCommand {
|
||||
readonly currentCycle: number;
|
||||
|
||||
/**
|
||||
* Constructs a `StackAggregationCommitIndexedAuthCommand` to lock uSTX
|
||||
* Constructs a `StackAggregationCommitIndexedAuthCommand` to lock uSTX
|
||||
* for stacking.
|
||||
*
|
||||
* @param operator - Represents the `Operator`'s wallet.
|
||||
|
||||
@@ -33,7 +33,7 @@ export class StackAggregationCommitIndexedSigCommand implements PoxCommand {
|
||||
readonly currentCycle: number;
|
||||
|
||||
/**
|
||||
* Constructs a `StackAggregationCommitIndexedSigCommand` to lock uSTX
|
||||
* Constructs a `StackAggregationCommitIndexedSigCommand` to lock uSTX
|
||||
* for stacking.
|
||||
*
|
||||
* @param operator - Represents the `Operator`'s wallet.
|
||||
|
||||
@@ -109,4 +109,4 @@ export class StackAggregationIncreaseCommand implements PoxCommand {
|
||||
this.currentCycle + 1
|
||||
} index ${this.rewardCycleIndex}`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ export class StackStxCommand implements PoxCommand {
|
||||
// `get-stacking-minimum` function at the time of this call.
|
||||
// - The Stacker cannot currently be engaged in another stacking operation.
|
||||
// - The Stacker cannot currently be delegating STX to a delegatee.
|
||||
|
||||
return (
|
||||
model.stackingMinimum > 0 &&
|
||||
!model.wallets.get(this.wallet.stxAddress)?.isStacking &&
|
||||
@@ -66,6 +67,7 @@ export class StackStxCommand implements PoxCommand {
|
||||
|
||||
run(model: Stub, real: Real): void {
|
||||
model.trackCommandRun(this.constructor.name);
|
||||
|
||||
// The maximum amount of uSTX that can be used (per tx) with this signer
|
||||
// key. For our tests, we will use the minimum amount of uSTX to be stacked
|
||||
// in the given reward cycle multiplied by the margin, which is a randomly
|
||||
|
||||
Reference in New Issue
Block a user