@stacks/clarinet-sdk 3.23.1 → 3.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/common/src/sdkProxy.d.ts +32 -0
- package/dist/cjs/common/src/sdkProxy.js +88 -0
- package/dist/cjs/common/src/sdkProxy.js.map +1 -0
- package/dist/cjs/common/src/sdkProxyHelpers.d.ts +34 -12
- package/dist/cjs/common/src/sdkProxyHelpers.js +40 -8
- package/dist/cjs/common/src/sdkProxyHelpers.js.map +1 -1
- package/dist/cjs/node/src/debugClient.d.ts +78 -0
- package/dist/cjs/node/src/debugClient.js +242 -0
- package/dist/cjs/node/src/debugClient.js.map +1 -0
- package/dist/cjs/node/src/index.d.ts +3 -1
- package/dist/cjs/node/src/index.js +21 -1
- package/dist/cjs/node/src/index.js.map +1 -1
- package/dist/cjs/node/src/sdkProxy.d.ts +3 -10
- package/dist/cjs/node/src/sdkProxy.js +7 -98
- package/dist/cjs/node/src/sdkProxy.js.map +1 -1
- package/dist/cjs/node/src/syncDebugSimnet.d.ts +46 -0
- package/dist/cjs/node/src/syncDebugSimnet.js +180 -0
- package/dist/cjs/node/src/syncDebugSimnet.js.map +1 -0
- package/dist/cjs/node/src/syncDebugSocket.d.ts +12 -0
- package/dist/cjs/node/src/syncDebugSocket.js +281 -0
- package/dist/cjs/node/src/syncDebugSocket.js.map +1 -0
- package/dist/cjs/node/src/vfs.d.ts +2 -2
- package/dist/cjs/node/src/vfs.js.map +1 -1
- package/dist/cjs/node/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/common/src/sdkProxy.d.ts +32 -0
- package/dist/esm/common/src/sdkProxy.js +85 -0
- package/dist/esm/common/src/sdkProxy.js.map +1 -0
- package/dist/esm/common/src/sdkProxyHelpers.d.ts +34 -12
- package/dist/esm/common/src/sdkProxyHelpers.js +40 -9
- package/dist/esm/common/src/sdkProxyHelpers.js.map +1 -1
- package/dist/esm/node/src/debugClient.d.ts +78 -0
- package/dist/esm/node/src/debugClient.js +204 -0
- package/dist/esm/node/src/debugClient.js.map +1 -0
- package/dist/esm/node/src/index.d.ts +3 -1
- package/dist/esm/node/src/index.js +18 -0
- package/dist/esm/node/src/index.js.map +1 -1
- package/dist/esm/node/src/sdkProxy.d.ts +3 -10
- package/dist/esm/node/src/sdkProxy.js +8 -99
- package/dist/esm/node/src/sdkProxy.js.map +1 -1
- package/dist/esm/node/src/syncDebugSimnet.d.ts +46 -0
- package/dist/esm/node/src/syncDebugSimnet.js +177 -0
- package/dist/esm/node/src/syncDebugSimnet.js.map +1 -0
- package/dist/esm/node/src/syncDebugSocket.d.ts +12 -0
- package/dist/esm/node/src/syncDebugSocket.js +276 -0
- package/dist/esm/node/src/syncDebugSocket.js.map +1 -0
- package/dist/esm/node/src/vfs.d.ts +2 -2
- package/dist/esm/node/src/vitest/index.d.ts +20 -20
- package/dist/esm/node/src/vitest/index.js +4 -7
- package/dist/esm/node/src/vitest/index.js.map +1 -1
- package/dist/esm/node/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -10
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.initSimnet = exports.tx = void 0;
|
|
3
|
+
exports.DebugClient = exports.startDebugServer = exports.initSimnet = exports.tx = void 0;
|
|
4
4
|
exports.getSDK = getSDK;
|
|
5
5
|
exports.generateDeployement = generateDeployement;
|
|
6
6
|
var sdkProxyHelpers_js_1 = require("../../common/src/sdkProxyHelpers.js");
|
|
7
7
|
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return sdkProxyHelpers_js_1.tx; } });
|
|
8
8
|
const vfs_js_1 = require("./vfs.js");
|
|
9
9
|
const sdkProxy_js_1 = require("./sdkProxy.js");
|
|
10
|
+
const syncDebugSocket_js_1 = require("./syncDebugSocket.js");
|
|
11
|
+
const syncDebugSimnet_js_1 = require("./syncDebugSimnet.js");
|
|
10
12
|
const wasmModule = import("@stacks/clarinet-sdk-wasm");
|
|
11
13
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json
|
|
12
14
|
// @ts-ignore
|
|
@@ -34,7 +36,22 @@ async function generateDeployement(manifestPath = "./Clarinet.toml") {
|
|
|
34
36
|
// load wasm only once and memoize it
|
|
35
37
|
function memoizedInit() {
|
|
36
38
|
let simnet = null;
|
|
39
|
+
// When CLARINET_DEBUG_PORT is set, a single debug proxy is shared across all calls.
|
|
40
|
+
let debugSimnet = null;
|
|
37
41
|
return async (manifestPath = "./Clarinet.toml", noCache = false, options) => {
|
|
42
|
+
const debugPort = process.env["CLARINET_DEBUG_PORT"]
|
|
43
|
+
? Number(process.env["CLARINET_DEBUG_PORT"])
|
|
44
|
+
: undefined;
|
|
45
|
+
if (debugPort != null) {
|
|
46
|
+
// Connect to the debug server (no-op if already connected).
|
|
47
|
+
await (0, syncDebugSocket_js_1.connectSyncSocket)(debugPort);
|
|
48
|
+
if (!debugSimnet || noCache) {
|
|
49
|
+
debugSimnet = (0, syncDebugSimnet_js_1.createSyncDebugSimnet)();
|
|
50
|
+
}
|
|
51
|
+
// Tell the server to reinitialise its session (mirrors initSession semantics).
|
|
52
|
+
await debugSimnet.initSession(process.cwd(), manifestPath, options);
|
|
53
|
+
return debugSimnet;
|
|
54
|
+
}
|
|
38
55
|
if (noCache || !simnet) {
|
|
39
56
|
simnet = await getSDK(options);
|
|
40
57
|
}
|
|
@@ -44,4 +61,7 @@ function memoizedInit() {
|
|
|
44
61
|
};
|
|
45
62
|
}
|
|
46
63
|
exports.initSimnet = memoizedInit();
|
|
64
|
+
var debugClient_js_1 = require("./debugClient.js");
|
|
65
|
+
Object.defineProperty(exports, "startDebugServer", { enumerable: true, get: function () { return debugClient_js_1.startDebugServer; } });
|
|
66
|
+
Object.defineProperty(exports, "DebugClient", { enumerable: true, get: function () { return debugClient_js_1.DebugClient; } });
|
|
47
67
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0EAO6C;AAN3C,wGAAA,EAAE,OAAA;AAUJ,qCAA+B;AAC/B,+CAAwD;AACxD,6DAAyD;AAEzD,6DAA6D;AAI7D,MAAM,UAAU,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAEvD,0GAA0G;AAC1G,aAAa;AACb,MAAM,CAAC,SAAS,CAAC,MAAM,GAAG;IACxB,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;AACzB,CAAC,CAAC;AAQK,KAAK,iBAAiB,OAAiB;IAC5C,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC;IAChC,IAAI,UAAU,GAAG,IAAI,MAAM,CAAC,UAAU,CACpC,CAAC,CAAC,OAAO,EAAE,UAAU,EACrB,CAAC,CAAC,OAAO,EAAE,aAAa,EACxB,CAAC,CAAC,OAAO,EAAE,gBAAgB,CAC5B,CAAC;IAEF,MAAM,MAAM,GAAG,IAAI,KAAK,CACtB,IAAI,MAAM,CAAC,GAAG,CAAC,YAAG,EAAE,UAAU,CAAC,EAC/B,IAAA,6BAAe,GAAuB,CAClB,CAAC;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,0FAA0F;AACnF,KAAK,8BAA8B,YAAY,GAAG,iBAAiB;IACxE,MAAM,MAAM,GAAG,MAAM,MAAM,EAAE,CAAC;IAE9B,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACf,OAAO,KAAK,CAAC;IACf,CAAC;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sdk-wasm";
|
|
2
|
-
import { type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export type Simnet = {
|
|
6
|
-
[K in keyof SDK]: K extends "callReadOnlyFn" | "callPublicFn" | "callPrivateFn" ? CallFn : K extends "execute" ? Execute : K extends "runSnippet" ? RunSnippet : K extends "deployContract" ? DeployContract : K extends "transferSTX" ? TransferSTX : K extends "mineBlock" ? MineBlock : K extends "getDataVar" ? GetDataVar : K extends "getMapEntry" ? GetMapEntry : SDK[K];
|
|
7
|
-
};
|
|
8
|
-
export declare function getSessionProxy(): {
|
|
9
|
-
get(session: SDK, prop: keyof SDK, receiver: any): string | number | CallFn | DeployContract | TransferSTX | MineBlock | GetMapEntry | ((include_boot_contracts: boolean, boot_contracts_path: string) => import("@stacks/clarinet-sdk-wasm").SessionReport) | ((cost_field: string) => void) | ((cwd: string, manifest_path: string, api_base_url: any) => Promise<void>) | ((count?: number | null) => number) | ((token: string, recipient: string, amount: bigint) => string) | ((recipient: string, amount: bigint) => string) | ((addresses: string[]) => void);
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
2
|
+
import { type ProxiedSimnet } from "../../common/src/sdkProxy.js";
|
|
3
|
+
export type Simnet = ProxiedSimnet<SDK>;
|
|
4
|
+
export declare function getSessionProxy(): ProxyHandler<SDK>;
|
|
@@ -1,105 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSessionProxy = getSessionProxy;
|
|
4
|
-
const transactions_1 = require("@stacks/transactions");
|
|
5
4
|
const clarinet_sdk_wasm_1 = require("@stacks/clarinet-sdk-wasm");
|
|
6
|
-
const
|
|
7
|
-
function parseTxResponse(response) {
|
|
8
|
-
return {
|
|
9
|
-
result: transactions_1.Cl.deserialize(response.result),
|
|
10
|
-
events: (0, sdkProxyHelpers_js_1.parseEvents)(response.events),
|
|
11
|
-
costs: (0, sdkProxyHelpers_js_1.parseCosts)(response.costs),
|
|
12
|
-
performance: response.performance,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
5
|
+
const sdkProxy_js_1 = require("../../common/src/sdkProxy.js");
|
|
15
6
|
function getSessionProxy() {
|
|
16
|
-
return {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const callFn = (contract, method, args, sender) => {
|
|
23
|
-
const response = session[prop](new clarinet_sdk_wasm_1.CallFnArgs(contract, method, args.map(transactions_1.serializeCVBytes), sender));
|
|
24
|
-
return parseTxResponse(response);
|
|
25
|
-
};
|
|
26
|
-
return callFn;
|
|
27
|
-
}
|
|
28
|
-
if (prop === "execute") {
|
|
29
|
-
const execute = (snippet) => {
|
|
30
|
-
const response = session.execute(snippet);
|
|
31
|
-
return parseTxResponse(response);
|
|
32
|
-
};
|
|
33
|
-
return execute;
|
|
34
|
-
}
|
|
35
|
-
if (prop === "deployContract") {
|
|
36
|
-
const callDeployContract = (name, content, options, sender) => {
|
|
37
|
-
const rustOptions = options
|
|
38
|
-
? new clarinet_sdk_wasm_1.ContractOptions(options.clarityVersion)
|
|
39
|
-
: new clarinet_sdk_wasm_1.ContractOptions();
|
|
40
|
-
const response = session.deployContract(new clarinet_sdk_wasm_1.DeployContractArgs(name, content, rustOptions, sender));
|
|
41
|
-
return parseTxResponse(response);
|
|
42
|
-
};
|
|
43
|
-
return callDeployContract;
|
|
44
|
-
}
|
|
45
|
-
if (prop === "transferSTX") {
|
|
46
|
-
const callTransferSTX = (amount, ...args) => {
|
|
47
|
-
const response = session.transferSTX(new clarinet_sdk_wasm_1.TransferSTXArgs(BigInt(amount), ...args));
|
|
48
|
-
return parseTxResponse(response);
|
|
49
|
-
};
|
|
50
|
-
return callTransferSTX;
|
|
51
|
-
}
|
|
52
|
-
if (prop === "mineBlock") {
|
|
53
|
-
const callMineBlock = (txs) => {
|
|
54
|
-
const serializedTxs = txs.map((tx) => {
|
|
55
|
-
if (tx.callPublicFn) {
|
|
56
|
-
return {
|
|
57
|
-
callPublicFn: {
|
|
58
|
-
...tx.callPublicFn,
|
|
59
|
-
args_maps: tx.callPublicFn.args.map(transactions_1.serializeCVBytes),
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
if (tx.callPrivateFn) {
|
|
64
|
-
return {
|
|
65
|
-
callPrivateFn: {
|
|
66
|
-
...tx.callPrivateFn,
|
|
67
|
-
args_maps: tx.callPrivateFn.args.map(transactions_1.serializeCVBytes),
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (tx.deployContract) {
|
|
72
|
-
return {
|
|
73
|
-
deployContract: {
|
|
74
|
-
...tx.deployContract,
|
|
75
|
-
},
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
return tx;
|
|
79
|
-
});
|
|
80
|
-
const responses = session.mineBlock(serializedTxs);
|
|
81
|
-
return responses.map(parseTxResponse);
|
|
82
|
-
};
|
|
83
|
-
return callMineBlock;
|
|
84
|
-
}
|
|
85
|
-
if (prop === "getDataVar") {
|
|
86
|
-
const getDataVar = (...args) => {
|
|
87
|
-
const response = session.getDataVar(...args);
|
|
88
|
-
const result = transactions_1.Cl.deserialize(response);
|
|
89
|
-
return result;
|
|
90
|
-
};
|
|
91
|
-
return getDataVar;
|
|
92
|
-
}
|
|
93
|
-
if (prop === "getMapEntry") {
|
|
94
|
-
const getMapEntry = (contract, mapName, mapKey) => {
|
|
95
|
-
const response = session.getMapEntry(contract, mapName, (0, transactions_1.serializeCVBytes)(mapKey));
|
|
96
|
-
const result = transactions_1.Cl.deserialize(response);
|
|
97
|
-
return result;
|
|
98
|
-
};
|
|
99
|
-
return getMapEntry;
|
|
100
|
-
}
|
|
101
|
-
return Reflect.get(session, prop, receiver);
|
|
102
|
-
},
|
|
103
|
-
};
|
|
7
|
+
return (0, sdkProxy_js_1.createSessionProxy)({
|
|
8
|
+
CallFnArgs: clarinet_sdk_wasm_1.CallFnArgs,
|
|
9
|
+
ContractOptions: clarinet_sdk_wasm_1.ContractOptions,
|
|
10
|
+
DeployContractArgs: clarinet_sdk_wasm_1.DeployContractArgs,
|
|
11
|
+
TransferSTXArgs: clarinet_sdk_wasm_1.TransferSTXArgs,
|
|
12
|
+
});
|
|
104
13
|
}
|
|
105
14
|
//# sourceMappingURL=sdkProxy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../src/sdkProxy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sdkProxy.js","sourceRoot":"","sources":["../../../../src/sdkProxy.ts"],"names":[],"mappings":";;;AAAA,iEAMmC;AAEnC,8DAAsF;AAItF;IACE,OAAO,IAAA,gCAAkB,EAAuB;QAC9C,UAAU,EAAV,8BAAU;QACV,eAAe,EAAf,mCAAe;QACf,kBAAkB,EAAlB,sCAAkB;QAClB,eAAe,EAAf,mCAAe;KAChB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous simnet proxy that routes all calls to a `clarinet dap` debug server
|
|
3
|
+
* via a SharedArrayBuffer + Atomics.wait worker (see syncDebugSocket.ts).
|
|
4
|
+
*
|
|
5
|
+
* When CLARINET_DEBUG_PORT is set, initSimnet() returns one of these instead of
|
|
6
|
+
* the WASM simnet. The API surface is identical, so existing tests run unchanged
|
|
7
|
+
* while breakpoints in .clar files fire in VSCode (or any DAP-capable editor).
|
|
8
|
+
*/
|
|
9
|
+
import { type ClarityValue } from "@stacks/transactions";
|
|
10
|
+
import { type ParsedTransactionResult, type Tx } from "../../common/src/sdkProxyHelpers.js";
|
|
11
|
+
export type SyncDebugSimnet = {
|
|
12
|
+
readonly deployer: string;
|
|
13
|
+
readonly blockHeight: number;
|
|
14
|
+
readonly burnBlockHeight: number;
|
|
15
|
+
readonly stacksBlockHeight: number;
|
|
16
|
+
getAccounts(): Map<string, string>;
|
|
17
|
+
mineBlock(txs: Tx[]): ParsedTransactionResult[];
|
|
18
|
+
mineEmptyBlock(count?: number): number;
|
|
19
|
+
mineEmptyStacksBlock(): number;
|
|
20
|
+
callPublicFn(contract: string, method: string, args: ClarityValue[], sender: string): ParsedTransactionResult;
|
|
21
|
+
callReadOnlyFn(contract: string, method: string, args: ClarityValue[], sender: string): ParsedTransactionResult;
|
|
22
|
+
callPrivateFn(contract: string, method: string, args: ClarityValue[], sender: string): ParsedTransactionResult;
|
|
23
|
+
execute(snippet: string): ParsedTransactionResult;
|
|
24
|
+
runSnippet(snippet: string): string;
|
|
25
|
+
getAssetsMap(): Map<string, Map<string, bigint>>;
|
|
26
|
+
getLastContractCallTrace(): string | undefined;
|
|
27
|
+
setCurrentTestName(name: string): void;
|
|
28
|
+
collectReport(includeBootContracts: boolean, bootContractsPath: string): {
|
|
29
|
+
coverage: string;
|
|
30
|
+
costs: string;
|
|
31
|
+
};
|
|
32
|
+
initSession(cwd: string, manifestPath: string, options?: {
|
|
33
|
+
trackCosts: boolean;
|
|
34
|
+
trackCoverage: boolean;
|
|
35
|
+
trackPerformance?: boolean;
|
|
36
|
+
performanceCostField?: string;
|
|
37
|
+
apiUrl?: string;
|
|
38
|
+
}): Promise<void>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Create a synchronous debug simnet proxy connected to the debug server at the
|
|
42
|
+
* given port. The caller must have already called `connectSyncSocket(port)`.
|
|
43
|
+
*
|
|
44
|
+
* `deployer` is fetched immediately (synchronously) from the server.
|
|
45
|
+
*/
|
|
46
|
+
export declare function createSyncDebugSimnet(): SyncDebugSimnet;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSyncDebugSimnet = createSyncDebugSimnet;
|
|
4
|
+
/**
|
|
5
|
+
* Synchronous simnet proxy that routes all calls to a `clarinet dap` debug server
|
|
6
|
+
* via a SharedArrayBuffer + Atomics.wait worker (see syncDebugSocket.ts).
|
|
7
|
+
*
|
|
8
|
+
* When CLARINET_DEBUG_PORT is set, initSimnet() returns one of these instead of
|
|
9
|
+
* the WASM simnet. The API surface is identical, so existing tests run unchanged
|
|
10
|
+
* while breakpoints in .clar files fire in VSCode (or any DAP-capable editor).
|
|
11
|
+
*/
|
|
12
|
+
const transactions_1 = require("@stacks/transactions");
|
|
13
|
+
const syncDebugSocket_js_1 = require("./syncDebugSocket.js");
|
|
14
|
+
const sdkProxyHelpers_js_1 = require("../../common/src/sdkProxyHelpers.js");
|
|
15
|
+
function parseTxResult(r) {
|
|
16
|
+
if (!r.result) {
|
|
17
|
+
throw new Error(r.error ?? "transaction failed with no result");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
result: transactions_1.Cl.deserialize(r.result),
|
|
21
|
+
events: (0, sdkProxyHelpers_js_1.parseEvents)(r.events),
|
|
22
|
+
costs: (0, sdkProxyHelpers_js_1.parseCosts)(r.costs),
|
|
23
|
+
performance: undefined,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Call syncSend and throw if the server responded with an error. */
|
|
27
|
+
function send(request) {
|
|
28
|
+
const raw = (0, syncDebugSocket_js_1.syncSend)(request);
|
|
29
|
+
const resp = JSON.parse(raw);
|
|
30
|
+
if (resp.error)
|
|
31
|
+
throw new Error(resp.error);
|
|
32
|
+
return resp.result ?? {};
|
|
33
|
+
}
|
|
34
|
+
/** Serialize a ClarityValue to a Clarity syntax string for use in snippets. */
|
|
35
|
+
function argString(v) {
|
|
36
|
+
return transactions_1.Cl.stringify(v);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a synchronous debug simnet proxy connected to the debug server at the
|
|
40
|
+
* given port. The caller must have already called `connectSyncSocket(port)`.
|
|
41
|
+
*
|
|
42
|
+
* `deployer` is fetched immediately (synchronously) from the server.
|
|
43
|
+
*/
|
|
44
|
+
function createSyncDebugSimnet() {
|
|
45
|
+
// Fetch deployer and accounts at construction time (sync, server is connected).
|
|
46
|
+
const initData = send({ method: "getAccounts" });
|
|
47
|
+
const accountsRecord = initData.accounts ?? {};
|
|
48
|
+
const deployer = accountsRecord["deployer"] ?? "";
|
|
49
|
+
return {
|
|
50
|
+
deployer,
|
|
51
|
+
get blockHeight() {
|
|
52
|
+
const resp = send({ method: "getBlockHeight" });
|
|
53
|
+
return resp.blockHeight;
|
|
54
|
+
},
|
|
55
|
+
get burnBlockHeight() {
|
|
56
|
+
const resp = send({ method: "getBurnBlockHeight" });
|
|
57
|
+
return resp.burnBlockHeight;
|
|
58
|
+
},
|
|
59
|
+
get stacksBlockHeight() {
|
|
60
|
+
const resp = send({ method: "getBlockHeight" });
|
|
61
|
+
return resp.blockHeight;
|
|
62
|
+
},
|
|
63
|
+
getAccounts() {
|
|
64
|
+
return new Map(Object.entries(accountsRecord));
|
|
65
|
+
},
|
|
66
|
+
mineEmptyBlock(count = 1) {
|
|
67
|
+
const resp = send({ method: "mineEmptyBlock", count });
|
|
68
|
+
return resp.blockHeight;
|
|
69
|
+
},
|
|
70
|
+
mineEmptyStacksBlock() {
|
|
71
|
+
const resp = send({ method: "mineEmptyBlock", count: 1 });
|
|
72
|
+
return resp.blockHeight;
|
|
73
|
+
},
|
|
74
|
+
setCurrentTestName(_name) {
|
|
75
|
+
// No-op in debug mode: coverage tracking is not supported.
|
|
76
|
+
},
|
|
77
|
+
collectReport(_includeBootContracts, _bootContractsPath) {
|
|
78
|
+
// Debug mode does not support coverage/cost reports.
|
|
79
|
+
throw new Error("collectReport: coverage and cost reports are not supported in debug mode");
|
|
80
|
+
},
|
|
81
|
+
runSnippet(snippet) {
|
|
82
|
+
const resp = send({ method: "execute", snippet });
|
|
83
|
+
return transactions_1.Cl.stringify(transactions_1.Cl.deserialize(resp.result));
|
|
84
|
+
},
|
|
85
|
+
mineBlock(txs) {
|
|
86
|
+
const serialized = txs.map((tx) => {
|
|
87
|
+
if (tx.callPublicFn) {
|
|
88
|
+
return {
|
|
89
|
+
type: "callPublicFn",
|
|
90
|
+
contract: tx.callPublicFn.contract,
|
|
91
|
+
function: tx.callPublicFn.method,
|
|
92
|
+
args: tx.callPublicFn.args.map(argString),
|
|
93
|
+
sender: tx.callPublicFn.sender,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (tx.callPrivateFn) {
|
|
97
|
+
return {
|
|
98
|
+
type: "callPrivateFn",
|
|
99
|
+
contract: tx.callPrivateFn.contract,
|
|
100
|
+
function: tx.callPrivateFn.method,
|
|
101
|
+
args: tx.callPrivateFn.args.map(argString),
|
|
102
|
+
sender: tx.callPrivateFn.sender,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (tx.deployContract) {
|
|
106
|
+
return {
|
|
107
|
+
type: "deployContract",
|
|
108
|
+
name: tx.deployContract.name,
|
|
109
|
+
content: tx.deployContract.content,
|
|
110
|
+
sender: tx.deployContract.sender,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (tx.transferSTX) {
|
|
114
|
+
return {
|
|
115
|
+
type: "transferSTX",
|
|
116
|
+
amount: tx.transferSTX.amount,
|
|
117
|
+
recipient: tx.transferSTX.recipient,
|
|
118
|
+
sender: tx.transferSTX.sender,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { type: "unknown" };
|
|
122
|
+
});
|
|
123
|
+
const resp = send({ method: "mineBlock", txs: serialized });
|
|
124
|
+
return (resp.results ?? []).map(parseTxResult);
|
|
125
|
+
},
|
|
126
|
+
callPublicFn(contract, method, args, sender) {
|
|
127
|
+
const resp = send({
|
|
128
|
+
method: "callPublicFn",
|
|
129
|
+
contract,
|
|
130
|
+
function: method,
|
|
131
|
+
args: args.map(argString),
|
|
132
|
+
sender,
|
|
133
|
+
});
|
|
134
|
+
return parseTxResult(resp);
|
|
135
|
+
},
|
|
136
|
+
callReadOnlyFn(contract, method, args, sender) {
|
|
137
|
+
const resp = send({
|
|
138
|
+
method: "callReadOnlyFn",
|
|
139
|
+
contract,
|
|
140
|
+
function: method,
|
|
141
|
+
args: args.map(argString),
|
|
142
|
+
sender,
|
|
143
|
+
});
|
|
144
|
+
return parseTxResult(resp);
|
|
145
|
+
},
|
|
146
|
+
callPrivateFn(contract, method, args, sender) {
|
|
147
|
+
const resp = send({
|
|
148
|
+
method: "callPrivateFn",
|
|
149
|
+
contract,
|
|
150
|
+
function: method,
|
|
151
|
+
args: args.map(argString),
|
|
152
|
+
sender,
|
|
153
|
+
});
|
|
154
|
+
return parseTxResult(resp);
|
|
155
|
+
},
|
|
156
|
+
execute(snippet) {
|
|
157
|
+
const resp = send({ method: "execute", snippet });
|
|
158
|
+
return parseTxResult(resp);
|
|
159
|
+
},
|
|
160
|
+
getAssetsMap() {
|
|
161
|
+
const resp = send({ method: "getAssetsMap" });
|
|
162
|
+
const outer = new Map();
|
|
163
|
+
for (const [asset, holders] of Object.entries(resp.assetsMap ?? {})) {
|
|
164
|
+
const inner = new Map();
|
|
165
|
+
for (const [addr, bal] of Object.entries(holders)) {
|
|
166
|
+
inner.set(addr, BigInt(bal));
|
|
167
|
+
}
|
|
168
|
+
outer.set(asset, inner);
|
|
169
|
+
}
|
|
170
|
+
return outer;
|
|
171
|
+
},
|
|
172
|
+
getLastContractCallTrace() {
|
|
173
|
+
return undefined;
|
|
174
|
+
},
|
|
175
|
+
async initSession(cwd, manifestPath, options) {
|
|
176
|
+
send({ method: "initSession", cwd, manifestPath, options });
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=syncDebugSimnet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syncDebugSimnet.js","sourceRoot":"","sources":["../../../../src/syncDebugSimnet.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,uDAA6D;AAC7D,6DAAgD;AAChD,4EAO6C;AAS7C,SAAS,aAAa,CAAC,CAAiB;IACtC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,C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,IAAI,CAAC,CAAC;QAC7B,CAAC;QAED,YAAY;YACV,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAE3C,CAAC;YACF,MAAM,KAAK,GAAG,IAAI,GAAG,EAA+B,CAAC;YACrD,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC;gBACpE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;gBACxC,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC/B,CAAC;gBACD,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,wBAAwB;YACtB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,KAAK,CAAC,WAAW,CACf,GAAW,EACX,YAAoB,EACpB,OAMC;YAED,IAAI,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC;QAC9D,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Spawn the worker and wait for its TCP socket to connect.
|
|
3
|
+
* Must be called (and awaited) before any `syncSend` call.
|
|
4
|
+
*/
|
|
5
|
+
export declare function connectSyncSocket(port: number): Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* Send a JSON request to the debug server synchronously (blocks via Atomics.wait).
|
|
8
|
+
* Returns the raw JSON response string.
|
|
9
|
+
*/
|
|
10
|
+
export declare function syncSend(request: Record<string, unknown>): string;
|
|
11
|
+
/** Terminate the worker and release the socket. */
|
|
12
|
+
export declare function closeSyncSocket(): void;
|