@stacks/rendezvous 0.4.0 → 0.5.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/app.js CHANGED
@@ -9,11 +9,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  step((generator = generator.apply(thisArg, _arguments || [])).next());
10
10
  });
11
11
  };
12
+ var __importDefault = (this && this.__importDefault) || function (mod) {
13
+ return (mod && mod.__esModule) ? mod : { "default": mod };
14
+ };
12
15
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.getManifestFileName = void 0;
16
+ exports.tryParseRemoteDataSettings = exports.getManifestFileName = exports.invalidRemoteDataErrorMessage = exports.noRemoteData = void 0;
14
17
  exports.main = main;
15
18
  const path_1 = require("path");
16
19
  const events_1 = require("events");
20
+ const toml_1 = __importDefault(require("toml"));
17
21
  const property_1 = require("./property");
18
22
  const invariant_1 = require("./invariant");
19
23
  const shared_1 = require("./shared");
@@ -25,6 +29,16 @@ const dialer_1 = require("./dialer");
25
29
  const logger = (log, logLevel = "log") => {
26
30
  console[logLevel](log);
27
31
  };
32
+ /**
33
+ * The object used to initialize an empty simnet session with, when no remote
34
+ * data is enabled in the `Clarinet.toml` file.
35
+ */
36
+ exports.noRemoteData = {
37
+ enabled: false,
38
+ api_url: "",
39
+ initial_height: 1,
40
+ };
41
+ exports.invalidRemoteDataErrorMessage = `Remote data settings not properly setup in Clarinet.toml! To use remote data, please provide the "api_url", "initial_height", and "enabled" fields under the "repl.remote_data" section in the Clarinet.toml file.`;
28
42
  /**
29
43
  * Gets the manifest file name for a Clarinet project.
30
44
  * If a custom manifest exists (`Clarinet-<contract-name>.toml`), it is used.
@@ -41,6 +55,22 @@ const getManifestFileName = (manifestDir, targetContractName) => {
41
55
  return "Clarinet.toml";
42
56
  };
43
57
  exports.getManifestFileName = getManifestFileName;
58
+ const tryParseRemoteDataSettings = (manifestPath, radio) => {
59
+ var _a, _b;
60
+ const clarinetToml = toml_1.default.parse((0, fs_1.readFileSync)((0, path_1.resolve)(manifestPath), "utf-8"));
61
+ const remoteDataUserSettings = (_b = (_a = clarinetToml.repl) === null || _a === void 0 ? void 0 : _a["remote_data"]) !== null && _b !== void 0 ? _b : undefined;
62
+ if (remoteDataUserSettings !== undefined &&
63
+ (!(remoteDataUserSettings === null || remoteDataUserSettings === void 0 ? void 0 : remoteDataUserSettings["api_url"]) ||
64
+ !(remoteDataUserSettings === null || remoteDataUserSettings === void 0 ? void 0 : remoteDataUserSettings["enabled"]) ||
65
+ !(remoteDataUserSettings === null || remoteDataUserSettings === void 0 ? void 0 : remoteDataUserSettings["initial_height"]))) {
66
+ throw new Error(exports.invalidRemoteDataErrorMessage);
67
+ }
68
+ if (remoteDataUserSettings) {
69
+ radio.emit("logMessage", (0, ansicolor_1.yellow)("\nUsing remote data. Setting up the environment can take up to a minute..."));
70
+ }
71
+ return remoteDataUserSettings || exports.noRemoteData;
72
+ };
73
+ exports.tryParseRemoteDataSettings = tryParseRemoteDataSettings;
44
74
  const helpMessage = `
45
75
  rv v${package_json_1.version}
46
76
 
@@ -130,7 +160,8 @@ function main() {
130
160
  if (dialerRegistry !== undefined) {
131
161
  dialerRegistry.registerDialers();
132
162
  }
133
- const simnet = yield (0, citizen_1.issueFirstClassCitizenship)(manifestDir, manifestPath, sutContractName);
163
+ const remoteDataSettings = (0, exports.tryParseRemoteDataSettings)(manifestPath, radio);
164
+ const simnet = yield (0, citizen_1.issueFirstClassCitizenship)(manifestDir, manifestPath, remoteDataSettings, sutContractName);
134
165
  /**
135
166
  * The list of contract IDs for the SUT contract names, as per the simnet.
136
167
  */
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/citizen.js CHANGED
@@ -18,6 +18,7 @@ const fs_1 = require("fs");
18
18
  const path_1 = require("path");
19
19
  const yaml_1 = __importDefault(require("yaml"));
20
20
  const clarinet_sdk_1 = require("@hirosystems/clarinet-sdk");
21
+ const transactions_1 = require("@stacks/transactions");
21
22
  /**
22
23
  * Prepares the simnet instance and assures the target contract's corresponding
23
24
  * test contract is treated as a first-class citizen, relying on their
@@ -28,11 +29,12 @@ const clarinet_sdk_1 = require("@hirosystems/clarinet-sdk");
28
29
  *
29
30
  * @param manifestDir The relative path to the manifest directory.
30
31
  * @param manifestPath The absolute path to the manifest file.
32
+ * @param remoteDataSettings The remote data settings.
31
33
  * @param sutContractName The target contract name.
32
34
  * @returns The initialized simnet instance with all contracts deployed, with
33
35
  * the test contract treated as a first-class citizen of the target contract.
34
36
  */
35
- const issueFirstClassCitizenship = (manifestDir, manifestPath, sutContractName) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const issueFirstClassCitizenship = (manifestDir, manifestPath, remoteDataSettings, sutContractName) => __awaiter(void 0, void 0, void 0, function* () {
36
38
  // Initialize the simnet, to generate the simnet plan and instance. The empty
37
39
  // session will be set up, and contracts will be deployed in the correct
38
40
  // order based on the simnet plan a few lines below.
@@ -41,7 +43,15 @@ const issueFirstClassCitizenship = (manifestDir, manifestPath, sutContractName)
41
43
  encoding: "utf-8",
42
44
  }));
43
45
  const sortedContractsByEpoch = (0, exports.groupContractsByEpochFromSimnetPlan)(simnetPlan);
44
- yield simnet.initEmptySession();
46
+ const simnetAddresses = [...simnet.getAccounts().values()];
47
+ const balancesMap = new Map(Array.from(simnetAddresses, (address) => {
48
+ const balanceHex = simnet.runSnippet(`(stx-get-balance '${address})`);
49
+ return [address, (0, transactions_1.cvToValue)((0, transactions_1.hexToCV)(balanceHex))];
50
+ }));
51
+ yield simnet.initEmptySession(remoteDataSettings);
52
+ simnetAddresses.forEach((address) => {
53
+ simnet.mintSTX(address, balancesMap.get(address));
54
+ });
45
55
  // Combine the target contract with its tests into a single contract. The
46
56
  // resulting contract will replace the target contract in the simnet.
47
57
  /** The contract names mapped to the concatenated source code. */
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/rendezvous",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Meet your contract's vulnerabilities head-on.",
5
5
  "main": "app.js",
6
6
  "bin": {
@@ -30,14 +30,15 @@
30
30
  "url": "https://github.com/stacks-network/rendezvous.git"
31
31
  },
32
32
  "dependencies": {
33
- "@hirosystems/clarinet-sdk": "2.12.0",
33
+ "@hirosystems/clarinet-sdk": "2.14.0",
34
34
  "@stacks/transactions": "^6.16.1",
35
35
  "ansicolor": "^2.0.3",
36
36
  "fast-check": "^3.20.0",
37
+ "toml": "^3.0.0",
37
38
  "yaml": "^2.6.1"
38
39
  },
39
40
  "devDependencies": {
40
- "@hirosystems/clarinet-sdk-wasm": "2.12.0",
41
+ "@hirosystems/clarinet-sdk-wasm": "2.14.0",
41
42
  "@types/jest": "^29.5.12",
42
43
  "jest": "^29.7.0",
43
44
  "ts-jest": "^29.2.5",
package/dist/property.js CHANGED
@@ -171,10 +171,21 @@ const checkProperties = (simnet, targetContractName, rendezvousList, rendezvousA
171
171
  }
172
172
  }
173
173
  else {
174
- throw new Error(`Test failed for ${targetContractName} contract: "${r.selectedTestFunction.name}" returned ${testFunctionCallResultJson.value.value}`);
174
+ // The function call did not result in (ok true) or (ok false).
175
+ // Either the test failed or the test function returned an
176
+ // unexpected value i.e. `(ok 1)`.
177
+ const displayedError = (0, transactions_1.cvToString)(testFunctionCallResult);
178
+ throw new PropertyTestError(`Test failed for ${targetContractName} contract: "${r.selectedTestFunction.name}" returned ${displayedError}`, displayedError);
175
179
  }
176
180
  }
177
181
  catch (error) {
182
+ const displayedError = error instanceof PropertyTestError
183
+ ? error.clarityError
184
+ : error &&
185
+ typeof error === "string" &&
186
+ error.toLowerCase().includes("runtime")
187
+ ? "(runtime)"
188
+ : "(unknown)";
178
189
  // Capture the error and log the test failure.
179
190
  radio.emit("logMessage", (0, ansicolor_1.red)(`₿ ${simnet.burnBlockHeight.toString().padStart(8)} ` +
180
191
  `Ӿ ${simnet.blockHeight.toString().padStart(8)} ` +
@@ -182,7 +193,8 @@ const checkProperties = (simnet, targetContractName, rendezvousList, rendezvousA
182
193
  `[FAIL] ` +
183
194
  `${targetContractName} ` +
184
195
  `${(0, ansicolor_1.underline)(r.selectedTestFunction.name)} ` +
185
- printedTestFunctionArgs));
196
+ `${printedTestFunctionArgs} ` +
197
+ displayedError));
186
198
  // Re-throw the error for fast-check to catch and process.
187
199
  throw error;
188
200
  }
@@ -269,3 +281,9 @@ exports.isParamsMatch = isParamsMatch;
269
281
  */
270
282
  const isReturnTypeBoolean = (discardFunctionInterface) => discardFunctionInterface.outputs.type === "bool";
271
283
  exports.isReturnTypeBoolean = isReturnTypeBoolean;
284
+ class PropertyTestError extends Error {
285
+ constructor(message, clarityError) {
286
+ super(message);
287
+ this.clarityError = clarityError;
288
+ }
289
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/rendezvous",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Meet your contract's vulnerabilities head-on.",
5
5
  "main": "app.js",
6
6
  "bin": {
@@ -30,14 +30,15 @@
30
30
  "url": "https://github.com/stacks-network/rendezvous.git"
31
31
  },
32
32
  "dependencies": {
33
- "@hirosystems/clarinet-sdk": "2.12.0",
33
+ "@hirosystems/clarinet-sdk": "2.14.0",
34
34
  "@stacks/transactions": "^6.16.1",
35
35
  "ansicolor": "^2.0.3",
36
36
  "fast-check": "^3.20.0",
37
+ "toml": "^3.0.0",
37
38
  "yaml": "^2.6.1"
38
39
  },
39
40
  "devDependencies": {
40
- "@hirosystems/clarinet-sdk-wasm": "2.12.0",
41
+ "@hirosystems/clarinet-sdk-wasm": "2.14.0",
41
42
  "@types/jest": "^29.5.12",
42
43
  "jest": "^29.7.0",
43
44
  "ts-jest": "^29.2.5",