@stacks/rendezvous 0.7.0 → 0.7.1

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/citizen.js CHANGED
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getTestContractSource = exports.buildRendezvousData = exports.getContractSource = exports.groupContractsByEpochFromSimnetPlan = exports.issueFirstClassCitizenship = void 0;
15
+ exports.getSbtcBalancesFromSimnet = exports.getTestContractSource = exports.buildRendezvousData = exports.getContractSource = exports.groupContractsByEpochFromSimnetPlan = exports.issueFirstClassCitizenship = void 0;
16
16
  exports.scheduleRendezvous = scheduleRendezvous;
17
17
  const fs_1 = require("fs");
18
18
  const path_1 = require("path");
@@ -48,18 +48,7 @@ const issueFirstClassCitizenship = (manifestDir, manifestPath, remoteDataSetting
48
48
  const balanceHex = simnet.runSnippet(`(stx-get-balance '${address})`);
49
49
  return [address, (0, transactions_1.cvToValue)((0, transactions_1.hexToCV)(balanceHex))];
50
50
  }));
51
- const sbtcBalancesMap = new Map(simnetAddresses.map((address) => {
52
- try {
53
- const { result: getBalanceResult } = simnet.callReadOnlyFn("SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token", "get-balance", [transactions_1.Cl.principal(address)], address);
54
- // If the previous read-only call works, the user is working with
55
- // sBTC. This means we can proceed with restoring sBTC balances.
56
- const sbtcBalance = (0, transactions_1.cvToJSON)(getBalanceResult).value.value;
57
- return [address, sbtcBalance];
58
- }
59
- catch (e) {
60
- return [address, 0];
61
- }
62
- }));
51
+ const sbtcBalancesMap = (0, exports.getSbtcBalancesFromSimnet)(simnet);
63
52
  yield simnet.initEmptySession(remoteDataSettings);
64
53
  simnetAddresses.forEach((address) => {
65
54
  simnet.mintSTX(address, stxBalancesMap.get(address));
@@ -260,6 +249,31 @@ function scheduleRendezvous(targetContractSource, tests) {
260
249
  (ok (map-set context function-name {called: called})))`;
261
250
  return `${targetContractSource}\n\n${context}\n\n${tests}`;
262
251
  }
252
+ /**
253
+ * Maps the simnet accounts to their sBTC balances. The function tries to call
254
+ * the `get-balance` function of the `sbtc-token` contract for each address. If
255
+ * the call fails, it returns a balance of 0 for that address. The call fails
256
+ * if the user is not working with sBTC.
257
+ * @param simnet The simnet instance.
258
+ * @returns A map of addresses to their sBTC balances.
259
+ */
260
+ const getSbtcBalancesFromSimnet = (simnet) => new Map([...simnet.getAccounts().values()].map((address) => {
261
+ try {
262
+ const { result: getBalanceResult } = simnet.callReadOnlyFn("SM3VDXK3WZZSA84XXFKAFAF15NNZX32CTSG82JFQ4.sbtc-token", "get-balance", [transactions_1.Cl.principal(address)], address);
263
+ // If the previous read-only call works, the user is working with
264
+ // sBTC. This means we can proceed with restoring sBTC balances.
265
+ const sbtcBalanceJSON = (0, transactions_1.cvToJSON)(getBalanceResult);
266
+ // The `get-balance` function returns a response containing the uint
267
+ // balance of the address. In the JSON representation, the balance is
268
+ // represented as a string. We need to parse it to an integer.
269
+ const sbtcBalance = parseInt(sbtcBalanceJSON.value.value, 10);
270
+ return [address, sbtcBalance];
271
+ }
272
+ catch (e) {
273
+ return [address, 0];
274
+ }
275
+ }));
276
+ exports.getSbtcBalancesFromSimnet = getSbtcBalancesFromSimnet;
263
277
  /**
264
278
  * Utility function that restores the test wallets' initial sBTC balances in
265
279
  * the re-initialized first-class citizenship simnet.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/rendezvous",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Meet your contract's vulnerabilities head-on.",
5
5
  "main": "app.js",
6
6
  "bin": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacks/rendezvous",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "Meet your contract's vulnerabilities head-on.",
5
5
  "main": "app.js",
6
6
  "bin": {