Skip to content

Commit

Permalink
chore: upgrade stacks.js to v7
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Feb 19, 2025
1 parent 9a8fdfd commit 918ba48
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 183 deletions.
4 changes: 2 additions & 2 deletions components/clarinet-cli/src/generate/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,11 @@ btc_address = "mvZtbibDAAA3WLpY7zXXFqRa3T4XSknBX7"
"license": "ISC",
"dependencies": {{
"@hirosystems/clarinet-sdk": "^2.3.2",
"@stacks/transactions": "^6.12.0",
"@stacks/transactions": "^7.0.0",
"chokidar-cli": "^3.0.0",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vitest": "^1.3.1",
"vitest": "^2.1.4",
"vitest-environment-clarinet": "^2.0.0"
}}
}}
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-sdk/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"readme": "./README.md",
"dependencies": {
"@hirosystems/clarinet-sdk-wasm-browser": "2.14.0",
"@stacks/transactions": "^6.13.0"
"@stacks/transactions": "^7.0.0"
}
}
6 changes: 3 additions & 3 deletions components/clarinet-sdk/browser/src/sdkProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cl } from "@stacks/transactions";
import { Cl, serializeCVBytes } from "@stacks/transactions";
import {
CallFnArgs,
DeployContractArgs,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function getSessionProxy() {
new CallFnArgs(
contract,
method,
args.map((a) => Cl.serialize(a)),
args.map((a) => serializeCVBytes(a)),
sender,
),
);
Expand Down Expand Up @@ -144,7 +144,7 @@ export function getSessionProxy() {

if (prop === "getMapEntry") {
const getMapEntry: GetMapEntry = (contract, mapName, mapKey) => {
const response = session.getMapEntry(contract, mapName, Cl.serialize(mapKey));
const response = session.getMapEntry(contract, mapName, serializeCVBytes(mapKey));
const result = Cl.deserialize(response);
return result;
};
Expand Down
10 changes: 5 additions & 5 deletions components/clarinet-sdk/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@
"readme": "./README.md",
"dependencies": {
"@hirosystems/clarinet-sdk-wasm": "2.14.0",
"@stacks/transactions": "^6.13.0",
"vitest": "^3.0.5",
"@stacks/transactions": "^7.0.0",
"kolorist": "^1.8.0",
"prompts": "^2.4.2",
"vitest": "^3.0.5",
"yargs": "^17.7.2"
},
"devDependencies": {
"@stacks/encryption": "^6.13.0",
"@stacks/network": "^6.13.0",
"@stacks/stacking": "^6.13.0"
"@stacks/encryption": "^7.0.0",
"@stacks/network": "^7.0.0",
"@stacks/stacking": "^7.0.0"
}
}
6 changes: 3 additions & 3 deletions components/clarinet-sdk/node/src/sdkProxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Cl } from "@stacks/transactions";
import { Cl, serializeCVBytes } from "@stacks/transactions";
import {
CallFnArgs,
DeployContractArgs,
Expand Down Expand Up @@ -66,7 +66,7 @@ export function getSessionProxy() {
new CallFnArgs(
contract,
method,
args.map((a) => Cl.serialize(a)),
args.map((a) => serializeCVBytes(a)),
sender,
),
);
Expand Down Expand Up @@ -144,7 +144,7 @@ export function getSessionProxy() {

if (prop === "getMapEntry") {
const getMapEntry: GetMapEntry = (contract, mapName, mapKey) => {
const response = session.getMapEntry(contract, mapName, Cl.serialize(mapKey));
const response = session.getMapEntry(contract, mapName, serializeCVBytes(mapKey));
const result = Cl.deserialize(response);
return result;
};
Expand Down
6 changes: 3 additions & 3 deletions components/clarinet-sdk/node/templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"@hirosystems/clarinet-sdk": "^2.3.2",
"@stacks/transactions": "^6.12.0",
"@hirosystems/clarinet-sdk": "2.11.0",
"@stacks/transactions": "^7.0.0",
"chokidar-cli": "^3.0.0",
"typescript": "^5.3.3",
"vite": "^5.1.4",
"vitest": "^1.3.1",
"vitest": "^2.1.4",
"vitest-environment-clarinet": "^2.0.0"
}
}
32 changes: 14 additions & 18 deletions components/clarinet-sdk/node/tests/pox-locking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import crypto from "crypto";
import { describe, expect, it, beforeEach } from "vitest";

import { Pox4SignatureTopic, StackingClient, poxAddressToTuple } from "@stacks/stacking";
import { StacksDevnet } from "@stacks/network";
import { STACKS_DEVNET } from "@stacks/network";
import { getPublicKeyFromPrivate, publicKeyToBtcAddress } from "@stacks/encryption";
import {
Cl,
ClarityType,
getAddressFromPrivateKey,
TransactionVersion,
createStacksPrivateKey,
} from "@stacks/transactions";
import { Cl, ClarityType, getAddressFromPrivateKey } from "@stacks/transactions";

// test the built package and not the source code
// makes it simpler to handle wasm build
Expand Down Expand Up @@ -158,21 +152,20 @@ describe("test pox-4", () => {
];

const accounts = stackingKeys.map((privKey) => {
const network = new StacksDevnet();
const network = STACKS_DEVNET;

const pubKey = getPublicKeyFromPrivate(privKey);
const stxAddress = getAddressFromPrivateKey(privKey, TransactionVersion.Testnet);
const signerPrivKey = createStacksPrivateKey(privKey);
const signerPubKey = getPublicKeyFromPrivate(signerPrivKey.data);
const stxAddress = getAddressFromPrivateKey(privKey, network);
const signerPubKey = getPublicKeyFromPrivate(privKey);

return {
privKey,
pubKey,
stxAddress,
btcAddr: publicKeyToBtcAddress(pubKey),
signerPrivKey: signerPrivKey,
signerPrivKey: privKey,
signerPubKey: signerPubKey,
client: new StackingClient(stxAddress, network),
client: new StackingClient({ address: stxAddress, network }),
};
});

Expand All @@ -183,12 +176,12 @@ describe("test pox-4", () => {
simnet.setEpoch("3.0");
});

it("can call get-pox-info", async () => {
it("can call get-pox-info", () => {
const poxInfo = simnet.callReadOnlyFn(poxContract, "get-pox-info", [], address1);
expect(poxInfo.result.type).toBe(ClarityType.ResponseOk);
});

it("can call get-pox-info", async () => {
it("can call get-pox-info", () => {
const account = accounts[0];
const rewardCycle = 0;
const burnBlockHeight = 0;
Expand All @@ -198,8 +191,11 @@ describe("test pox-4", () => {

expect(poxInfo.result.type).toBe(ClarityType.ResponseOk);

expect(poxInfo.result).toHaveProperty("value.data.min-amount-ustx", Cl.uint(stackingThreshold));
expect(poxInfo.result).toHaveProperty("value.data.reward-cycle-id", Cl.uint(rewardCycle));
expect(poxInfo.result).toHaveProperty(
"value.value.min-amount-ustx",
Cl.uint(stackingThreshold),
);
expect(poxInfo.result).toHaveProperty("value.value.reward-cycle-id", Cl.uint(rewardCycle));

const sigArgs = {
authId,
Expand Down
3 changes: 1 addition & 2 deletions components/clarinet-sdk/node/tests/simnet-usage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,7 @@ describe("the simnet can execute commands", () => {

describe("the sdk handles multiple manifests project", () => {
it("handle invalid project", async () => {
// the lsp displays paths with the unix notation, hence why we are hardcoding the contract path with `/`
const manifestPath = `${process.cwd()}/tests/fixtures/contracts/invalid.clar`;
const manifestPath = path.join(process.cwd(), "tests/fixtures/contracts/invalid.clar");
const expectedErr = `error: unexpected ')'\n--> ${manifestPath}:5:2\n)) ;; extra \`)\`\n`;

await expect(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import {
ListCV,
TupleCV,
BufferCV,
principalToString,
TrueCV,
FalseCV,
BooleanCV,
cvToString,
} from "@stacks/transactions";

import { MatcherState } from "@vitest/expect";
Expand Down Expand Up @@ -69,6 +69,8 @@ type ClarityTypetoValue = {
[ClarityType.Buffer]: BufferCV;
};

const ClarityTypeReversed = Object.fromEntries(Object.entries(ClarityType).map(([k, v]) => [v, k]));

// the "simple clarity values" are CVs that can't be nested and have `value` property
type SimpleCV = BooleanCV | IntCV | UIntCV | StringAsciiCV | StringUtf8CV;
type SimpleCVTypes =
Expand All @@ -79,11 +81,13 @@ type SimpleCVTypes =
| ClarityType.StringASCII
| ClarityType.StringUTF8;

const validClarityTypes = Object.values(ClarityType).filter((t) => typeof t === "number");
const validClarityTypes = Object.values(ClarityType).filter(
(t) => typeof t === "string",
) as string[];

function isClarityValue(input: unknown): input is ClarityValue {
if (!input || typeof input !== "object") return false;
if (!("type" in input) || typeof input.type !== "number") return false;
if (!("type" in input) || typeof input.type !== "string") return false;
if (!validClarityTypes.includes(input.type)) return false;

return true;
Expand All @@ -109,7 +113,7 @@ function checkCVType<T extends ClarityType>(
if (!isCV) {
throw new ClarityTypeError({
message: `actual value must ${notStr(isNot)}be a Clarity "${
ClarityType[expectedType]
ClarityTypeReversed[expectedType]
}", received "${typeof actual}"`,
});
}
Expand All @@ -126,10 +130,10 @@ function checkCVType<T extends ClarityType>(
throw new ClarityTypeError({
// generic and short message
message: `actual value must ${notStr(isNot)}be a Clarity "${
ClarityType[expectedType]
}", received "${ClarityType[actual.type]}"${errorCode}`,
actual: ClarityType[actual.type],
expected: ClarityType[expectedType],
ClarityTypeReversed[expectedType]
}", received "${ClarityTypeReversed[actual.type]}"${errorCode}`,
actual: ClarityTypeReversed[actual.type],
expected: ClarityTypeReversed[expectedType],
});
}

Expand Down Expand Up @@ -219,7 +223,7 @@ expect.extend({
return {
pass: true,
message: () =>
`actual value must ${notStr(this.isNot)}be a Clarity "${ClarityType[expectedType]}"`,
`actual value must ${notStr(this.isNot)}be a Clarity "${ClarityTypeReversed[expectedType]}"`,
};
},

Expand Down Expand Up @@ -286,7 +290,7 @@ expect.extend({
return errorToAssertionResult.call(this, e);
}

const actualString = principalToString(actual);
const actualString = cvToString(actual, "tryAscii");

try {
expected = isStandard
Expand Down Expand Up @@ -341,7 +345,7 @@ expect.extend({
const expected = isListArray ? Cl.prettyPrint(Cl.list(expectedItems), 2) : expectedItems;

return {
pass: this.equals(actual.list, expectedItems, undefined, true),
pass: this.equals(actual.value, expectedItems, undefined, true),
// note: throw a simple message and rely on `actual` and `expected` to display the diff
message: () => `the received List does ${this.isNot ? "" : "not "}match the expected one`,
actual: Cl.prettyPrint(actual, 2),
Expand All @@ -362,7 +366,7 @@ expect.extend({
const expected = isTupleData ? Cl.prettyPrint(Cl.tuple(expectedData), 2) : expectedData;

return {
pass: this.equals(actual.data, expectedData, undefined, true),
pass: this.equals(actual.value, expectedData, undefined, true),
// note: throw a simple message and rely on `actual` and `expected` to display the diff
message: () => `the received Tuple does ${this.isNot ? "" : "not "}match the expected one`,
actual: Cl.prettyPrint(actual, 2),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ describe("test nested types", () => {
expect(complexTuple).toEqual(complexTuple);

// toBeTuple with a Cl.tuple
expect(complexTuple).toBeTuple(complexTuple.data);
expect(complexTuple).toBeTuple(complexTuple.value);

// toBeTuple asymmetric matched
expect(complexTuple).toBeTuple({
Expand Down
Loading

0 comments on commit 918ba48

Please sign in to comment.