Skip to content

Commit

Permalink
Add: amount generator for DelegateStx; Fix: command logs
Browse files Browse the repository at this point in the history
  • Loading branch information
BowTiedRadone committed Mar 22, 2024
1 parent f98c4eb commit f8d274e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
6 changes: 3 additions & 3 deletions contrib/core-contract-tests/tests/pox-4/pox_Commands.ts
Expand Up @@ -50,20 +50,20 @@ export function PoxCommands(
wallet: fc.constantFrom(...wallets.values()),
delegateTo: fc.constantFrom(...wallets.values()),
untilBurnHt: fc.integer({ min: 1 }),
margin: fc.integer({ min: 1, max: 9 }),
amount: fc.bigInt({ min:0n, max: 100_000_000_000_000n }),
}).map((
r: {
wallet: Wallet;
delegateTo: Wallet;
untilBurnHt: number;
margin: number;
amount: bigint;
},
) =>
new DelegateStxCommand(
r.wallet,
r.delegateTo,
r.untilBurnHt,
r.margin,
r.amount,
)
),
// DelegateStackStxCommand
Expand Down
Expand Up @@ -100,7 +100,6 @@ export class DelegateStackStxCommand implements PoxCommand {
],
this.operator.stxAddress,
);

const { result: rewardCycle } = real.network.callReadOnlyFn(
"ST000000000000000000002AMW42H.pox-4",
"burn-height-to-reward-cycle",
Expand Down Expand Up @@ -140,10 +139,10 @@ 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.
console.info(
`✓ ${this.operator.label.padStart(8, " ")} Ӿ ${this.operator.label.padStart(8, " ")} ${
`✓ ${this.operator.label.padStart(8, " ")} Ӿ ${this.stacker.label.padStart(8, " ")} ${
"delegate-stack-stx".padStart(23, " ")
} ${"lock-amount".padStart(12, " ")} ${
this.amountUstx.toString().padStart(13, " ")
this.amountUstx.toString().padStart(15, " ")
} ${"until".padStart(37)} ${this.stacker.unlockHeight.toString().padStart(17)}`,
);
}
Expand Down
25 changes: 9 additions & 16 deletions contrib/core-contract-tests/tests/pox-4/pox_DelegateStxCommand.ts
Expand Up @@ -16,27 +16,27 @@ export class DelegateStxCommand implements PoxCommand {
readonly wallet: Wallet;
readonly delegateTo: Wallet;
readonly untilBurnHt: number;
readonly margin: number;
readonly amount: bigint;

/**
* Constructs a `DelegateStxCommand` to delegate uSTX for stacking.
*
* @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 margin - Multiplier for minimum required uSTX to stack so that each
* Stacker locks a different amount of uSTX across test runs.
* @param amount - The maximum amount the `Stacker` delegates the `Delegatee` to
* stack on his behalf
*/
constructor(
wallet: Wallet,
delegateTo: Wallet,
untilBurnHt: number,
margin: number,
amount: bigint,
) {
this.wallet = wallet;
this.delegateTo = delegateTo;
this.untilBurnHt = untilBurnHt;
this.margin = margin;
this.amount = amount;
}

check(model: Readonly<Stub>): boolean {
Expand All @@ -50,16 +50,9 @@ export class DelegateStxCommand implements PoxCommand {

run(model: Stub, real: Real): void {
// The amount of uSTX delegated by the Stacker to the Delegatee.
// 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
// generated number passed to the constructor of this class. Even if there
// are no constraints about the delegated amount, it will be checked in the
// future, when calling delegate-stack-stx.
const delegatedAmount = model.stackingMinimum * this.margin;

// The amount of uSTX to be delegated. For this test, we will use the
// delegated amount calculated before.
const amountUstx = delegatedAmount;
// 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);

// Act
const delegateStx = real.network.callPublicFn(
Expand Down Expand Up @@ -103,7 +96,7 @@ export class DelegateStxCommand implements PoxCommand {
} ${"amount".padStart(12, " ")} ${
amountUstx
.toString()
.padStart(13, " ")
.padStart(15, " ")
} delegated to ${
this.delegateTo.label.padStart(
42,
Expand Down
Expand Up @@ -46,7 +46,7 @@ export class GetStackingMinimumCommand implements PoxCommand {
`✓ ${this.wallet.label.padStart(8, " ")} ${
"get-stacking-minimum".padStart(34, " ")
} ${"pox-4".padStart(12, " ")} ${
stackingMinimum.value.toString().padStart(13, " ")
stackingMinimum.value.toString().padStart(15, " ")
}`,
);
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ export class GetStxAccountCommand implements PoxCommand {
`✓ ${this.wallet.label.padStart(8, " ")} ${
"stx-account".padStart(34, " ")
} ${"lock-amount".padStart(12, " ")} ${
actual.amountLocked.toString().padStart(13, " ")
actual.amountLocked.toString().padStart(15, " ")
} ${"unlocked-amount".padStart(12, " ")} ${
actual.amountUnlocked.toString().padStart(15, " ")
} ${"unlocked-height".padStart(12, " ")} ${
Expand Down
Expand Up @@ -159,7 +159,7 @@ export class StackStxCommand implements PoxCommand {
`✓ ${this.wallet.label.padStart(8, " ")} ${
"stack-stx".padStart(34, " ")
} ${"lock-amount".padStart(12, " ")} ${
amountUstx.toString().padStart(13, " ")
amountUstx.toString().padStart(15, " ")
}`,
);
}
Expand Down

0 comments on commit f8d274e

Please sign in to comment.