@fuel-ts/account 0.0.0-rc-2395-20240528075431 → 0.0.0-rc-1356-20240528093309

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.

Potentially problematic release.


This version of @fuel-ts/account might be problematic. Click here for more details.

Files changed (38) hide show
  1. package/dist/index.global.js +17 -30
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +126 -147
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +11 -31
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/providers/transaction-response/transaction-response.d.ts.map +1 -1
  8. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts +0 -1
  9. package/dist/providers/transaction-summary/assemble-transaction-summary.d.ts.map +1 -1
  10. package/dist/providers/transaction-summary/get-transaction-summary.d.ts.map +1 -1
  11. package/dist/providers/transaction-summary/operations.d.ts +2 -4
  12. package/dist/providers/transaction-summary/operations.d.ts.map +1 -1
  13. package/dist/providers/transaction-summary/types.d.ts +0 -1
  14. package/dist/providers/transaction-summary/types.d.ts.map +1 -1
  15. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  16. package/dist/providers/utils/index.d.ts +0 -1
  17. package/dist/providers/utils/index.d.ts.map +1 -1
  18. package/dist/test-utils/asset-id.d.ts +8 -0
  19. package/dist/test-utils/asset-id.d.ts.map +1 -0
  20. package/dist/test-utils/index.d.ts +4 -0
  21. package/dist/test-utils/index.d.ts.map +1 -1
  22. package/dist/test-utils/launchNode.d.ts +8 -1
  23. package/dist/test-utils/launchNode.d.ts.map +1 -1
  24. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
  25. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
  26. package/dist/test-utils/test-message.d.ts +29 -0
  27. package/dist/test-utils/test-message.d.ts.map +1 -0
  28. package/dist/test-utils/wallet-config.d.ts +55 -0
  29. package/dist/test-utils/wallet-config.d.ts.map +1 -0
  30. package/dist/test-utils.global.js +401 -79
  31. package/dist/test-utils.global.js.map +1 -1
  32. package/dist/test-utils.js +410 -179
  33. package/dist/test-utils.js.map +1 -1
  34. package/dist/test-utils.mjs +304 -77
  35. package/dist/test-utils.mjs.map +1 -1
  36. package/package.json +16 -15
  37. package/dist/providers/utils/sleep.d.ts +0 -3
  38. package/dist/providers/utils/sleep.d.ts.map +0 -1
@@ -32933,6 +32933,13 @@ This unreleased fuel-core build may include features and updates not yet support
32933
32933
  };
32934
32934
  var DateTime = _DateTime;
32935
32935
  __publicField3(DateTime, "TAI64_NULL", "");
32936
+ function sleep(time) {
32937
+ return new Promise((resolve) => {
32938
+ setTimeout(() => {
32939
+ resolve(true);
32940
+ }, time);
32941
+ });
32942
+ }
32936
32943
  var chainConfig_default = {
32937
32944
  chain_name: "local_testnet",
32938
32945
  consensus_parameters: {
@@ -33687,9 +33694,9 @@ This unreleased fuel-core build may include features and updates not yet support
33687
33694
  da_block_height: 0
33688
33695
  };
33689
33696
  var defaultSnapshotConfigs = {
33690
- chainConfigJson: chainConfig_default,
33691
- metadataJson: metadata_default,
33692
- stateConfigJson: stateConfig_default
33697
+ chainConfig: chainConfig_default,
33698
+ metadata: metadata_default,
33699
+ stateConfig: stateConfig_default
33693
33700
  };
33694
33701
  var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
33695
33702
  function isDefined(value) {
@@ -34429,11 +34436,72 @@ This unreleased fuel-core build may include features and updates not yet support
34429
34436
  };
34430
34437
  }
34431
34438
 
34439
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
34440
+ function _curry2(fn) {
34441
+ return function f2(a, b) {
34442
+ switch (arguments.length) {
34443
+ case 0:
34444
+ return f2;
34445
+ case 1:
34446
+ return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
34447
+ return fn(a, _b);
34448
+ });
34449
+ default:
34450
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
34451
+ return fn(_a, b);
34452
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
34453
+ return fn(a, _b);
34454
+ }) : fn(a, b);
34455
+ }
34456
+ };
34457
+ }
34458
+
34459
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
34460
+ function _curry3(fn) {
34461
+ return function f3(a, b, c) {
34462
+ switch (arguments.length) {
34463
+ case 0:
34464
+ return f3;
34465
+ case 1:
34466
+ return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
34467
+ return fn(a, _b, _c);
34468
+ });
34469
+ case 2:
34470
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
34471
+ return fn(_a, b, _c);
34472
+ }) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
34473
+ return fn(a, _b, _c);
34474
+ }) : _curry1(function(_c) {
34475
+ return fn(a, b, _c);
34476
+ });
34477
+ default:
34478
+ return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
34479
+ return fn(_a, _b, c);
34480
+ }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
34481
+ return fn(_a, b, _c);
34482
+ }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
34483
+ return fn(a, _b, _c);
34484
+ }) : _isPlaceholder(a) ? _curry1(function(_a) {
34485
+ return fn(_a, b, c);
34486
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
34487
+ return fn(a, _b, c);
34488
+ }) : _isPlaceholder(c) ? _curry1(function(_c) {
34489
+ return fn(a, b, _c);
34490
+ }) : fn(a, b, c);
34491
+ }
34492
+ };
34493
+ }
34494
+
34432
34495
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
34433
34496
  var isArray_default = Array.isArray || function _isArray(val) {
34434
34497
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
34435
34498
  };
34436
34499
 
34500
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
34501
+ function _has(prop, obj) {
34502
+ return Object.prototype.hasOwnProperty.call(obj, prop);
34503
+ }
34504
+
34437
34505
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
34438
34506
  var type = /* @__PURE__ */ _curry1(function type2(val) {
34439
34507
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -34450,6 +34518,11 @@ This unreleased fuel-core build may include features and updates not yet support
34450
34518
  return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()) + "T" + pad(d.getUTCHours()) + ":" + pad(d.getUTCMinutes()) + ":" + pad(d.getUTCSeconds()) + "." + (d.getUTCMilliseconds() / 1e3).toFixed(3).slice(2, 5) + "Z";
34451
34519
  };
34452
34520
 
34521
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
34522
+ function _isObject(x) {
34523
+ return Object.prototype.toString.call(x) === "[object Object]";
34524
+ }
34525
+
34453
34526
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
34454
34527
  var isInteger_default = Number.isInteger || function _isInteger(n) {
34455
34528
  return n << 0 === n;
@@ -34563,6 +34636,46 @@ This unreleased fuel-core build may include features and updates not yet support
34563
34636
  });
34564
34637
  var clone_default = clone;
34565
34638
 
34639
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
34640
+ var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
34641
+ var result = {};
34642
+ var k;
34643
+ l = l || {};
34644
+ r = r || {};
34645
+ for (k in l) {
34646
+ if (_has(k, l)) {
34647
+ result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
34648
+ }
34649
+ }
34650
+ for (k in r) {
34651
+ if (_has(k, r) && !_has(k, result)) {
34652
+ result[k] = r[k];
34653
+ }
34654
+ }
34655
+ return result;
34656
+ });
34657
+ var mergeWithKey_default = mergeWithKey;
34658
+
34659
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
34660
+ var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
34661
+ return mergeWithKey_default(function(k, lVal, rVal) {
34662
+ if (_isObject(lVal) && _isObject(rVal)) {
34663
+ return mergeDeepWithKey2(fn, lVal, rVal);
34664
+ } else {
34665
+ return fn(k, lVal, rVal);
34666
+ }
34667
+ }, lObj, rObj);
34668
+ });
34669
+ var mergeDeepWithKey_default = mergeDeepWithKey;
34670
+
34671
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
34672
+ var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
34673
+ return mergeDeepWithKey_default(function(k, lVal, rVal) {
34674
+ return rVal;
34675
+ }, lObj, rObj);
34676
+ });
34677
+ var mergeDeepRight_default = mergeDeepRight;
34678
+
34566
34679
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
34567
34680
  var hasProtoTrim = typeof String.prototype.trim === "function";
34568
34681
 
@@ -41976,15 +42089,6 @@ ${MessageCoinFragmentDoc}`;
41976
42089
  return normalize2(clone_default(root));
41977
42090
  }
41978
42091
 
41979
- // src/providers/utils/sleep.ts
41980
- function sleep(time) {
41981
- return new Promise((resolve) => {
41982
- setTimeout(() => {
41983
- resolve(true);
41984
- }, time);
41985
- });
41986
- }
41987
-
41988
42092
  // src/providers/utils/extract-tx-error.ts
41989
42093
  var assemblePanicError = (statusReason) => {
41990
42094
  let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
@@ -43246,12 +43350,12 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43246
43350
  }
43247
43351
  function getWithdrawFromFuelOperations({
43248
43352
  inputs,
43249
- receipts,
43250
- assetId
43353
+ receipts
43251
43354
  }) {
43252
43355
  const messageOutReceipts = getReceiptsMessageOut(receipts);
43253
43356
  const withdrawFromFuelOperations = messageOutReceipts.reduce(
43254
43357
  (prevWithdrawFromFuelOps, receipt) => {
43358
+ const assetId = "0x0000000000000000000000000000000000000000000000000000000000000000";
43255
43359
  const input = getInputFromAssetId(inputs, assetId);
43256
43360
  if (input) {
43257
43361
  const inputAddress = getInputAccountAddress(input);
@@ -43465,8 +43569,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43465
43569
  receipts,
43466
43570
  abiMap,
43467
43571
  rawPayload,
43468
- maxInputs,
43469
- assetId
43572
+ maxInputs
43470
43573
  }) {
43471
43574
  if (isTypeCreate(transactionType)) {
43472
43575
  return [
@@ -43485,7 +43588,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43485
43588
  rawPayload,
43486
43589
  maxInputs
43487
43590
  }),
43488
- ...getWithdrawFromFuelOperations({ inputs, receipts, assetId })
43591
+ ...getWithdrawFromFuelOperations({ inputs, receipts })
43489
43592
  ];
43490
43593
  }
43491
43594
  return [...getPayProducerOperations(outputs)];
@@ -43618,8 +43721,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43618
43721
  maxInputs,
43619
43722
  gasCosts,
43620
43723
  maxGasPerTx,
43621
- gasPrice,
43622
- assetId
43724
+ gasPrice
43623
43725
  } = params;
43624
43726
  const gasUsed = getGasUsedFromReceipts(receipts);
43625
43727
  const rawPayload = hexlify(transactionBytes);
@@ -43630,8 +43732,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43630
43732
  receipts,
43631
43733
  rawPayload,
43632
43734
  abiMap,
43633
- maxInputs,
43634
- assetId
43735
+ maxInputs
43635
43736
  });
43636
43737
  const typeName = getTransactionTypeName(transaction.type);
43637
43738
  const tip = bn(transaction.policies?.find((policy) => policy.type === PolicyType.Tip)?.data);
@@ -43789,7 +43890,6 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43789
43890
  const { gasPerByte, gasPriceFactor, gasCosts, maxGasPerTx } = this.provider.getGasConfig();
43790
43891
  const gasPrice = await this.provider.getLatestGasPrice();
43791
43892
  const maxInputs = this.provider.getChain().consensusParameters.txParameters.maxInputs;
43792
- const assetId = this.provider.getBaseAssetId();
43793
43893
  const transactionSummary = assembleTransactionSummary({
43794
43894
  id: this.id,
43795
43895
  receipts,
@@ -43802,8 +43902,7 @@ ${PANIC_DOC_URL}#variant.${statusReason}`;
43802
43902
  maxInputs,
43803
43903
  gasCosts,
43804
43904
  maxGasPerTx,
43805
- gasPrice,
43806
- assetId
43905
+ gasPrice
43807
43906
  });
43808
43907
  return transactionSummary;
43809
43908
  }
@@ -50144,6 +50243,40 @@ Supported fuel-core version: ${supportedVersion}.`
50144
50243
  }
50145
50244
  }
50146
50245
  };
50246
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
50247
+ const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
50248
+ ...coin,
50249
+ amount: "18446744073709551615"
50250
+ }));
50251
+ const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
50252
+ ...message,
50253
+ amount: "18446744073709551615"
50254
+ }));
50255
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self2) => self2.findIndex((c) => c.tx_id === coin.tx_id) === index);
50256
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self2) => self2.findIndex((m) => m.nonce === msg.nonce) === index);
50257
+ if (!process.env.GENESIS_SECRET) {
50258
+ const pk = Signer.generatePrivateKey();
50259
+ const signer = new Signer(pk);
50260
+ process.env.GENESIS_SECRET = hexlify(pk);
50261
+ coins.push({
50262
+ tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50263
+ owner: signer.address.toHexString(),
50264
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50265
+ amount: "18446744073709551615",
50266
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
50267
+ output_index: 0,
50268
+ tx_pointer_block_height: 0,
50269
+ tx_pointer_tx_idx: 0
50270
+ });
50271
+ }
50272
+ const json = JSON.stringify({
50273
+ ...stateConfig,
50274
+ coins,
50275
+ messages
50276
+ });
50277
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
50278
+ return json.replace(regexMakeNumber, "$1$2");
50279
+ }
50147
50280
  var launchNode = async ({
50148
50281
  ip,
50149
50282
  port,
@@ -50151,7 +50284,8 @@ Supported fuel-core version: ${supportedVersion}.`
50151
50284
  fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
50152
50285
  loggingEnabled = true,
50153
50286
  debugEnabled = false,
50154
- basePath
50287
+ basePath,
50288
+ snapshotConfig = defaultSnapshotConfigs
50155
50289
  }) => (
50156
50290
  // eslint-disable-next-line no-async-promise-executor
50157
50291
  new Promise(async (resolve, reject) => {
@@ -50179,56 +50313,23 @@ Supported fuel-core version: ${supportedVersion}.`
50179
50313
  let snapshotDirToUse;
50180
50314
  const prefix = basePath || import_os.default.tmpdir();
50181
50315
  const suffix = basePath ? "" : (0, import_crypto19.randomUUID)();
50182
- const tempDirPath = import_path7.default.join(prefix, ".fuels", suffix, "snapshotDir");
50316
+ const tempDir = import_path7.default.join(prefix, ".fuels", suffix, "snapshotDir");
50183
50317
  if (snapshotDir) {
50184
50318
  snapshotDirToUse = snapshotDir;
50185
50319
  } else {
50186
- if (!(0, import_fs.existsSync)(tempDirPath)) {
50187
- (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
50188
- }
50189
- let { stateConfigJson } = defaultSnapshotConfigs;
50190
- const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
50191
- stateConfigJson = {
50192
- ...stateConfigJson,
50193
- coins: [
50194
- ...stateConfigJson.coins.map((coin) => ({
50195
- ...coin,
50196
- amount: "18446744073709551615"
50197
- }))
50198
- ],
50199
- messages: stateConfigJson.messages.map((message) => ({
50200
- ...message,
50201
- amount: "18446744073709551615"
50202
- }))
50203
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50204
- };
50205
- if (!process.env.GENESIS_SECRET) {
50206
- const pk = Signer.generatePrivateKey();
50207
- const signer = new Signer(pk);
50208
- process.env.GENESIS_SECRET = hexlify(pk);
50209
- stateConfigJson.coins.push({
50210
- tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50211
- owner: signer.address.toHexString(),
50212
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50213
- amount: "18446744073709551615",
50214
- asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
50215
- output_index: 0,
50216
- tx_pointer_block_height: 0,
50217
- tx_pointer_tx_idx: 0
50218
- });
50219
- }
50220
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
50221
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
50222
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
50223
- const chainConfigWritePath = import_path7.default.join(tempDirPath, "chainConfig.json");
50224
- const stateConfigWritePath = import_path7.default.join(tempDirPath, "stateConfig.json");
50225
- const metadataWritePath = import_path7.default.join(tempDirPath, "metadata.json");
50226
- const stateTransitionWritePath = import_path7.default.join(tempDirPath, "state_transition_bytecode.wasm");
50227
- (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
50228
- (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
50229
- (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
50230
- (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
50231
- snapshotDirToUse = tempDirPath;
50320
+ if (!(0, import_fs.existsSync)(tempDir)) {
50321
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
50322
+ }
50323
+ const { metadata } = snapshotConfig;
50324
+ const metadataPath = import_path7.default.join(tempDir, "metadata.json");
50325
+ const chainConfigPath = import_path7.default.join(tempDir, metadata.chain_config);
50326
+ const stateConfigPath = import_path7.default.join(tempDir, metadata.table_encoding.Json.filepath);
50327
+ const stateTransitionPath = import_path7.default.join(tempDir, "state_transition_bytecode.wasm");
50328
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
50329
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
50330
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
50331
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
50332
+ snapshotDirToUse = tempDir;
50232
50333
  }
50233
50334
  const child = (0, import_child_process.spawn)(
50234
50335
  command,
@@ -50236,7 +50337,7 @@ Supported fuel-core version: ${supportedVersion}.`
50236
50337
  "run",
50237
50338
  ["--ip", ipToUse],
50238
50339
  ["--port", portToUse],
50239
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
50340
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
50240
50341
  ["--min-gas-price", "1"],
50241
50342
  poaInstant ? ["--poa-instant", "true"] : [],
50242
50343
  ["--consensus-key", consensusKey],
@@ -50258,23 +50359,28 @@ Supported fuel-core version: ${supportedVersion}.`
50258
50359
  }
50259
50360
  const cleanupConfig = {
50260
50361
  child,
50261
- configPath: tempDirPath,
50362
+ configPath: tempDir,
50262
50363
  killFn: import_tree_kill.default,
50263
50364
  state: {
50264
50365
  isDead: false
50265
50366
  }
50266
50367
  };
50267
50368
  child.stderr.on("data", (chunk) => {
50268
- if (chunk.indexOf(graphQLStartSubstring) !== -1) {
50369
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
50370
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
50371
+ const rows = text.split("\n");
50372
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
50373
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
50269
50374
  resolve({
50270
50375
  cleanup: () => killNode(cleanupConfig),
50271
- ip: ipToUse,
50272
- port: portToUse,
50376
+ ip: realIp,
50377
+ port: realPort,
50378
+ url: `http://${realIp}:${realPort}/v1/graphql`,
50273
50379
  snapshotDir: snapshotDirToUse
50274
50380
  });
50275
50381
  }
50276
- if (/error/i.test(chunk)) {
50277
- reject(chunk.toString());
50382
+ if (/error/i.test(text)) {
50383
+ reject(text.toString());
50278
50384
  }
50279
50385
  });
50280
50386
  process.on("exit", () => killNode(cleanupConfig));
@@ -50307,6 +50413,222 @@ Supported fuel-core version: ${supportedVersion}.`
50307
50413
  };
50308
50414
  return { wallets, stop: cleanup, provider };
50309
50415
  };
50416
+
50417
+ // src/test-utils/asset-id.ts
50418
+ var _AssetId = class {
50419
+ constructor(value) {
50420
+ this.value = value;
50421
+ }
50422
+ static random(count = 1) {
50423
+ const assetIds = [];
50424
+ for (let i = 0; i < count; i++) {
50425
+ assetIds.push(new _AssetId(hexlify(randomBytes22(32))));
50426
+ }
50427
+ return assetIds;
50428
+ }
50429
+ };
50430
+ var AssetId = _AssetId;
50431
+ __publicField(AssetId, "A", new _AssetId(
50432
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
50433
+ ));
50434
+ __publicField(AssetId, "B", new _AssetId(
50435
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
50436
+ ));
50437
+
50438
+ // src/test-utils/wallet-config.ts
50439
+ var WalletConfig = class {
50440
+ initialState;
50441
+ options;
50442
+ wallets;
50443
+ generateWallets = () => {
50444
+ const generatedWallets = [];
50445
+ for (let index = 1; index <= this.options.count; index++) {
50446
+ generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
50447
+ }
50448
+ return generatedWallets;
50449
+ };
50450
+ constructor(baseAssetId, config) {
50451
+ WalletConfig.validate(config);
50452
+ this.options = config;
50453
+ const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
50454
+ this.wallets = this.generateWallets();
50455
+ this.initialState = {
50456
+ messages: WalletConfig.createMessages(this.wallets, messages),
50457
+ coins: WalletConfig.createCoins(
50458
+ this.wallets,
50459
+ baseAssetId,
50460
+ assets2,
50461
+ coinsPerAsset,
50462
+ amountPerCoin
50463
+ )
50464
+ };
50465
+ }
50466
+ apply(snapshotConfig) {
50467
+ return {
50468
+ ...snapshotConfig,
50469
+ stateConfig: {
50470
+ ...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs.stateConfig,
50471
+ coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
50472
+ messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
50473
+ }
50474
+ };
50475
+ }
50476
+ /**
50477
+ * Create messages for the wallets in the format that the chain expects.
50478
+ */
50479
+ static createMessages(wallets, messages) {
50480
+ return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
50481
+ }
50482
+ /**
50483
+ * Create coins for the wallets in the format that the chain expects.
50484
+ */
50485
+ static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
50486
+ const coins = [];
50487
+ let assetIds = [baseAssetId];
50488
+ if (Array.isArray(assets2)) {
50489
+ assetIds = assetIds.concat(assets2.map((a) => a.value));
50490
+ } else {
50491
+ assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
50492
+ }
50493
+ wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
50494
+ assetIds.forEach((assetId) => {
50495
+ for (let index = 0; index < coinsPerAsset; index++) {
50496
+ coins.push({
50497
+ amount: amountPerCoin,
50498
+ asset_id: assetId,
50499
+ owner: walletAddress,
50500
+ tx_pointer_block_height: 0,
50501
+ tx_pointer_tx_idx: 0,
50502
+ output_index: 0,
50503
+ tx_id: hexlify(randomBytes22(32))
50504
+ });
50505
+ }
50506
+ });
50507
+ });
50508
+ return coins;
50509
+ }
50510
+ static validate({
50511
+ count: wallets,
50512
+ assets: assets2,
50513
+ coinsPerAsset,
50514
+ amountPerCoin
50515
+ }) {
50516
+ if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
50517
+ throw new FuelError(
50518
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50519
+ "Number of wallets must be greater than zero."
50520
+ );
50521
+ }
50522
+ if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
50523
+ throw new FuelError(
50524
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50525
+ "Number of assets per wallet must be greater than zero."
50526
+ );
50527
+ }
50528
+ if (coinsPerAsset <= 0) {
50529
+ throw new FuelError(
50530
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50531
+ "Number of coins per asset must be greater than zero."
50532
+ );
50533
+ }
50534
+ if (amountPerCoin <= 0) {
50535
+ throw new FuelError(
50536
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50537
+ "Amount per coin must be greater than zero."
50538
+ );
50539
+ }
50540
+ }
50541
+ };
50542
+
50543
+ // src/test-utils/setup-test-provider-and-wallets.ts
50544
+ var defaultWalletConfigOptions = {
50545
+ count: 2,
50546
+ assets: [AssetId.A, AssetId.B],
50547
+ coinsPerAsset: 1,
50548
+ amountPerCoin: 1e10,
50549
+ messages: []
50550
+ };
50551
+ async function setupTestProviderAndWallets({
50552
+ walletConfig: walletConfigOptions = {},
50553
+ providerOptions,
50554
+ nodeOptions = {}
50555
+ } = {}) {
50556
+ Symbol.dispose ??= Symbol("Symbol.dispose");
50557
+ const walletConfig = new WalletConfig(
50558
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
50559
+ {
50560
+ ...defaultWalletConfigOptions,
50561
+ ...walletConfigOptions
50562
+ }
50563
+ );
50564
+ const { cleanup, url } = await launchNode({
50565
+ loggingEnabled: false,
50566
+ ...nodeOptions,
50567
+ snapshotConfig: mergeDeepRight_default(
50568
+ defaultSnapshotConfigs,
50569
+ walletConfig.apply(nodeOptions?.snapshotConfig)
50570
+ ),
50571
+ port: "0"
50572
+ });
50573
+ let provider;
50574
+ try {
50575
+ provider = await Provider.create(url, providerOptions);
50576
+ } catch (err) {
50577
+ cleanup();
50578
+ throw err;
50579
+ }
50580
+ const wallets = walletConfig.wallets;
50581
+ wallets.forEach((wallet) => {
50582
+ wallet.connect(provider);
50583
+ });
50584
+ return {
50585
+ provider,
50586
+ wallets,
50587
+ cleanup,
50588
+ [Symbol.dispose]: cleanup
50589
+ };
50590
+ }
50591
+
50592
+ // src/test-utils/test-message.ts
50593
+ var TestMessage = class {
50594
+ sender;
50595
+ recipient;
50596
+ nonce;
50597
+ amount;
50598
+ data;
50599
+ da_height;
50600
+ /**
50601
+ * A helper class to create messages for testing purposes.
50602
+ *
50603
+ * Used in tandem with `WalletConfig`.
50604
+ * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
50605
+ */
50606
+ constructor({
50607
+ sender = Address.fromRandom(),
50608
+ recipient = Address.fromRandom(),
50609
+ nonce = hexlify(randomBytes22(32)),
50610
+ amount = 1e6,
50611
+ data = "02",
50612
+ da_height = 0
50613
+ } = {}) {
50614
+ this.sender = sender;
50615
+ this.recipient = recipient;
50616
+ this.nonce = nonce;
50617
+ this.amount = amount;
50618
+ this.data = data;
50619
+ this.da_height = da_height;
50620
+ }
50621
+ toChainMessage(recipient) {
50622
+ return {
50623
+ sender: this.sender.toB256(),
50624
+ recipient: recipient?.toB256() ?? this.recipient.toB256(),
50625
+ nonce: this.nonce,
50626
+ amount: bn(this.amount).toNumber(),
50627
+ data: this.data,
50628
+ da_height: this.da_height
50629
+ };
50630
+ }
50631
+ };
50310
50632
  })();
50311
50633
  /*! Bundled license information:
50312
50634