Skip to content

Commit

Permalink
style(pox-4): Run formatter on tests/pox-4/*.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
moodmosaic committed Mar 27, 2024
1 parent a7b698a commit e21db00
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 36 deletions.
49 changes: 38 additions & 11 deletions contrib/core-contract-tests/tests/pox-4/pox-4.stateful-prop.test.ts
Expand Up @@ -31,15 +31,42 @@ describe("PoX-4 invariant tests", () => {
};

const wallets = [
["wallet_1", "7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801"],
["wallet_2", "530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101"],
["wallet_3", "d655b2523bcd65e34889725c73064feb17ceb796831c0e111ba1a552b0f31b3901"],
["wallet_4", "f9d7206a47f14d2870c163ebab4bf3e70d18f5d14ce1031f3902fbbc894fe4c701"],
["wallet_5", "3eccc5dac8056590432db6a35d52b9896876a3d5cbdea53b72400bc9c2099fe801"],
["wallet_6", "7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01"],
["wallet_7", "b463f0df6c05d2f156393eee73f8016c5372caa0e9e29a901bb7171d90dc4f1401"],
["wallet_8", "6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01"],
["wallet_9", "de433bdfa14ec43aa1098d5be594c8ffb20a31485ff9de2923b2689471c401b801"],
[
"wallet_1",
"7287ba251d44a4d3fd9276c88ce34c5c52a038955511cccaf77e61068649c17801",
],
[
"wallet_2",
"530d9f61984c888536871c6573073bdfc0058896dc1adfe9a6a10dfacadc209101",
],
[
"wallet_3",
"d655b2523bcd65e34889725c73064feb17ceb796831c0e111ba1a552b0f31b3901",
],
[
"wallet_4",
"f9d7206a47f14d2870c163ebab4bf3e70d18f5d14ce1031f3902fbbc894fe4c701",
],
[
"wallet_5",
"3eccc5dac8056590432db6a35d52b9896876a3d5cbdea53b72400bc9c2099fe801",
],
[
"wallet_6",
"7036b29cb5e235e5fd9b09ae3e8eec4404e44906814d5d01cbca968a60ed4bfb01",
],
[
"wallet_7",
"b463f0df6c05d2f156393eee73f8016c5372caa0e9e29a901bb7171d90dc4f1401",
],
[
"wallet_8",
"6a1a754ba863d7bab14adbbc3f8ebb090af9e871ace621d3e5ab634e1422885e01",
],
[
"wallet_9",
"de433bdfa14ec43aa1098d5be594c8ffb20a31485ff9de2923b2689471c401b801",
],
].map((wallet) => {
const label = wallet[0];
const prvKey = wallet[1];
Expand Down Expand Up @@ -71,8 +98,8 @@ describe("PoX-4 invariant tests", () => {
amountLocked: 0,
amountUnlocked: initialUstxBalance,
unlockHeight: 0,
allowedContractCaller: '',
callerAllowedBy: []
allowedContractCaller: "",
callerAllowedBy: [],
};
});

Expand Down
@@ -1,6 +1,18 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { expect } from "vitest";
import { boolCV, Cl, ClarityType, OptionalCV, UIntCV } from "@stacks/transactions";
import {
boolCV,
Cl,
ClarityType,
OptionalCV,
UIntCV,
} from "@stacks/transactions";

/**
* The `AllowContractCallerComand` gives a `contract-caller` authorization to call stacking methods.
Expand All @@ -23,7 +35,6 @@ export class AllowContractCallerCommand implements PoxCommand {
* @param allowanceTo - Represents the authorized `contract-caller` (i.e. a stacking pool)
* @param alllowUntilBurnHt - The burn block height until the authorization is valid.
*/

constructor(
wallet: Wallet,
allowanceTo: Wallet,
Expand Down Expand Up @@ -59,14 +70,20 @@ export class AllowContractCallerCommand implements PoxCommand {
// Get the wallets involved from the model and update it with the new state.
const wallet = model.wallets.get(this.wallet.stxAddress)!;
const callerToAllow = model.wallets.get(this.allowanceTo.stxAddress)!;
// Update model so that we know this wallet has authorized a contract-caller.
// Update model so that we know this wallet has authorized a contract-caller.

wallet.allowedContractCaller = this.allowanceTo.stxAddress;
callerToAllow.callerAllowedBy.push(wallet.stxAddress);

// 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(`✓ ${this.wallet.label}`, "allow-contract-caller", this.allowanceTo.label, "until", optionalCVToString(this.allowUntilBurnHt));
logCommand(
`✓ ${this.wallet.label}`,
"allow-contract-caller",
this.allowanceTo.label,
"until",
optionalCVToString(this.allowUntilBurnHt),
);
}

toString() {
Expand Down
9 changes: 5 additions & 4 deletions contrib/core-contract-tests/tests/pox-4/pox_Commands.ts
Expand Up @@ -11,7 +11,8 @@ import { RevokeDelegateStxCommand } from "./pox_RevokeDelegateStxCommand";
import { AllowContractCallerCommand } from "./pox_AllowContractCallerCommand";

export function PoxCommands(
wallets: Map<StxAddress, Wallet>, network: Simnet,
wallets: Map<StxAddress, Wallet>,
network: Simnet,
): fc.Arbitrary<Iterable<fc.Command<Stub, Real>>> {
const cmds = [
// GetStackingMinimumCommand
Expand Down Expand Up @@ -52,7 +53,7 @@ export function PoxCommands(
wallet: fc.constantFrom(...wallets.values()),
delegateTo: fc.constantFrom(...wallets.values()),
untilBurnHt: fc.integer({ min: 1 }),
amount: fc.bigInt({ min:0n, max: 100_000_000_000_000n }),
amount: fc.bigInt({ min: 0n, max: 100_000_000_000_000n }),
}).map((
r: {
wallet: Wallet;
Expand All @@ -77,7 +78,7 @@ export function PoxCommands(
},
) =>
new RevokeDelegateStxCommand(
r.wallet
r.wallet,
)
),
// DelegateStackStxCommand
Expand All @@ -89,7 +90,7 @@ export function PoxCommands(
max: nextCycleFirstBlock(network),
}),
period: fc.integer({ min: 1, max: 12 }),
amount: fc.bigInt({ min:0n, max: 100_000_000_000_000n }),
amount: fc.bigInt({ min: 0n, max: 100_000_000_000_000n }),
}).chain((r) =>
fc.record({
unlockBurnHt: fc.constant(
Expand Down
@@ -1,4 +1,10 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { poxAddressToTuple } from "@stacks/stacking";
import { assert, expect } from "vitest";
import { Cl, ClarityType, isClarityType } from "@stacks/transactions";
Expand Down Expand Up @@ -104,7 +110,7 @@ export class DelegateStackStxCommand implements PoxCommand {
// (start-burn-ht uint)
Cl.uint(this.startBurnHt),
// (lock-period uint)
Cl.uint(this.period)
Cl.uint(this.period),
],
this.operator.stxAddress,
);
Expand Down Expand Up @@ -146,7 +152,14 @@ export class DelegateStackStxCommand implements PoxCommand {

// 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(`✓ ${this.operator.label} Ӿ ${this.stacker.label}`, "delegate-stack-stx", "lock-amount", this.amountUstx.toString(), "until", this.stacker.unlockHeight.toString());
logCommand(
`✓ ${this.operator.label} Ӿ ${this.stacker.label}`,
"delegate-stack-stx",
"lock-amount",
this.amountUstx.toString(),
"until",
this.stacker.unlockHeight.toString(),
);
}

toString() {
Expand Down
25 changes: 19 additions & 6 deletions contrib/core-contract-tests/tests/pox-4/pox_DelegateStxCommand.ts
@@ -1,11 +1,17 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { poxAddressToTuple } from "@stacks/stacking";
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
* 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:
Expand Down Expand Up @@ -50,7 +56,7 @@ export class DelegateStxCommand implements PoxCommand {

run(model: Stub, real: Real): void {
// The amount of uSTX delegated by the Stacker to the Delegatee.
// Even if there are no constraints about the delegated amount,
// Even if there are no constraints about the delegated amount,
// it will be checked in the future, when calling delegate-stack-stx.
const amountUstx = Number(this.amount);

Expand Down Expand Up @@ -83,12 +89,19 @@ export class DelegateStxCommand implements PoxCommand {
wallet.hasDelegated = true;
wallet.delegatedTo = this.delegateTo.stxAddress;
wallet.delegatedMaxAmount = amountUstx;
wallet.delegatedUntilBurnHt = this.untilBurnHt
wallet.delegatedUntilBurnHt = this.untilBurnHt;

delegatedWallet.hasPoolMembers.push(wallet.stxAddress);
// 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(`✓ ${this.wallet.label}`, "delegate-stx", "amount", amountUstx.toString(), "delegated to", this.delegateTo.label);
logCommand(
`✓ ${this.wallet.label}`,
"delegate-stx",
"amount",
amountUstx.toString(),
"delegated to",
this.delegateTo.label,
);
}

toString() {
Expand Down
@@ -1,4 +1,10 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { assert } from "vitest";
import { ClarityType, isClarityType } from "@stacks/transactions";

Expand Down Expand Up @@ -42,7 +48,12 @@ export class GetStackingMinimumCommand implements PoxCommand {

// 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(`✓ ${this.wallet.label}`, "get-stacking-minimum", "pox-4", stackingMinimum.value.toString());
logCommand(
`✓ ${this.wallet.label}`,
"get-stacking-minimum",
"pox-4",
stackingMinimum.value.toString(),
);
}

toString() {
Expand Down
@@ -1,4 +1,10 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { expect } from "vitest";
import { Cl } from "@stacks/transactions";

Expand Down Expand Up @@ -35,7 +41,16 @@ export class GetStxAccountCommand implements PoxCommand {

// 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(`✓ ${this.wallet.label}`, "stx-account", "lock-amount", actual.amountLocked.toString(), "unlocked-amount", actual.amountUnlocked.toString(), "unlocked-height", actual.unlockHeight.toString());
logCommand(
`✓ ${this.wallet.label}`,
"stx-account",
"lock-amount",
actual.amountLocked.toString(),
"unlocked-amount",
actual.amountUnlocked.toString(),
"unlocked-height",
actual.unlockHeight.toString(),
);
}

toString() {
Expand Down
@@ -1,4 +1,10 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { poxAddressToTuple } from "@stacks/stacking";
import { expect } from "vitest";
import { Cl, someCV, tupleCV } from "@stacks/transactions";
Expand Down
15 changes: 13 additions & 2 deletions contrib/core-contract-tests/tests/pox-4/pox_StackStxCommand.ts
@@ -1,4 +1,10 @@
import { PoxCommand, Real, Stub, Wallet, logCommand } from "./pox_CommandModel.ts";
import {
logCommand,
PoxCommand,
Real,
Stub,
Wallet,
} from "./pox_CommandModel.ts";
import { Pox4SignatureTopic, poxAddressToTuple } from "@stacks/stacking";
import { assert, expect } from "vitest";
import { Cl, ClarityType, isClarityType } from "@stacks/transactions";
Expand Down Expand Up @@ -155,7 +161,12 @@ export class StackStxCommand implements PoxCommand {

// 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(`✓ ${this.wallet.label}`, "stack-stx", "lock-amount", amountUstx.toString());
logCommand(
`✓ ${this.wallet.label}`,
"stack-stx",
"lock-amount",
amountUstx.toString(),
);
}

toString() {
Expand Down

0 comments on commit e21db00

Please sign in to comment.