Skip to content

Commit

Permalink
feat(pox-4): Add amountUnlocked to Wallet for staking
Browse files Browse the repository at this point in the history
Introduces `amountUnlocked` to the Wallet model in PoX-4 tests to
clearly differentiate between locked and available balances. This
addition complements the existing balance field, enhancing
understanding of staking dynamics without renaming or removing
existing structures. Adjustments made in related commands and tests
ensure accuracy and consistency.
  • Loading branch information
moodmosaic committed Mar 19, 2024
1 parent f5d0cad commit 59c0a26
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe("PoX-4 invariant tests", () => {
const prvKey = wallet[1];
const pubKey = getPublicKeyFromPrivate(prvKey);
const devnet = new StacksDevnet();
const initialUstxBalance = 100_000_000_000_000;
const signerPrvKey = createStacksPrivateKey(prvKey);
const signerPubKey = getPublicKeyFromPrivate(signerPrvKey.data);
const btcAddress = publicKeyToBtcAddress(pubKey);
Expand All @@ -61,11 +62,12 @@ describe("PoX-4 invariant tests", () => {
signerPrvKey,
signerPubKey,
stackingClient: new StackingClient(stxAddress, devnet),
ustxBalance: 100_000_000_000_000,
ustxBalance: initialUstxBalance,
isStacking: false,
hasDelegated: false,
delegatedTo: "",
amountLocked: 0,
amountUnlocked: initialUstxBalance,
unlockHeight: 0,
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Wallet = {
hasDelegated: boolean;
delegatedTo: StxAddress;
amountLocked: number;
amountUnlocked: number;
unlockHeight: number;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class GetStxAccountCommand implements PoxCommand {
expect(real.network.runSnippet(`(stx-account '${actual.stxAddress})`))
.toBeTuple({
"locked": Cl.uint(actual.amountLocked),
"unlocked": Cl.uint(actual.ustxBalance),
"unlocked": Cl.uint(actual.amountUnlocked),
"unlock-height": Cl.uint(actual.unlockHeight),
});

Expand All @@ -41,7 +41,7 @@ export class GetStxAccountCommand implements PoxCommand {
} ${"lock-amount".padStart(12, " ")} ${
actual.amountLocked.toString().padStart(13, " ")
} ${"unlocked-amount".padStart(12, " ")} ${
actual.ustxBalance.toString().padStart(15, " ")
actual.amountUnlocked.toString().padStart(15, " ")
} ${"unlocked-height".padStart(12, " ")} ${
actual.unlockHeight.toString().padStart(7, " ")
}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class StackStxCommand implements PoxCommand {
// Update locked, unlocked, and unlock-height fields in the model.
wallet.amountLocked = amountUstx;
wallet.unlockHeight = Number(unlockBurnHeight.value);
wallet.ustxBalance -= amountUstx;
wallet.amountUnlocked -= amountUstx;

// 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.
Expand Down

0 comments on commit 59c0a26

Please sign in to comment.