@fuel-ts/account 0.0.0-rc-1356-20240520180710 → 0.0.0-rc-2333-20240520180734

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.

@@ -32933,13 +32933,6 @@ 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
- }
32943
32936
  var chainConfig_default = {
32944
32937
  chain_name: "local_testnet",
32945
32938
  consensus_parameters: {
@@ -33694,9 +33687,9 @@ This unreleased fuel-core build may include features and updates not yet support
33694
33687
  da_block_height: 0
33695
33688
  };
33696
33689
  var defaultSnapshotConfigs = {
33697
- chainConfig: chainConfig_default,
33698
- metadata: metadata_default,
33699
- stateConfig: stateConfig_default
33690
+ chainConfigJson: chainConfig_default,
33691
+ metadataJson: metadata_default,
33692
+ stateConfigJson: stateConfig_default
33700
33693
  };
33701
33694
  var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
33702
33695
  function isDefined(value) {
@@ -34436,72 +34429,11 @@ This unreleased fuel-core build may include features and updates not yet support
34436
34429
  };
34437
34430
  }
34438
34431
 
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
-
34495
34432
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
34496
34433
  var isArray_default = Array.isArray || function _isArray(val) {
34497
34434
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
34498
34435
  };
34499
34436
 
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
-
34505
34437
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
34506
34438
  var type = /* @__PURE__ */ _curry1(function type2(val) {
34507
34439
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -34518,11 +34450,6 @@ This unreleased fuel-core build may include features and updates not yet support
34518
34450
  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";
34519
34451
  };
34520
34452
 
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
-
34526
34453
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
34527
34454
  var isInteger_default = Number.isInteger || function _isInteger(n) {
34528
34455
  return n << 0 === n;
@@ -34636,46 +34563,6 @@ This unreleased fuel-core build may include features and updates not yet support
34636
34563
  });
34637
34564
  var clone_default = clone;
34638
34565
 
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
-
34679
34566
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
34680
34567
  var hasProtoTrim = typeof String.prototype.trim === "function";
34681
34568
 
@@ -42083,6 +41970,15 @@ ${MessageCoinFragmentDoc}`;
42083
41970
  return normalize2(clone_default(root));
42084
41971
  }
42085
41972
 
41973
+ // src/providers/utils/sleep.ts
41974
+ function sleep(time) {
41975
+ return new Promise((resolve) => {
41976
+ setTimeout(() => {
41977
+ resolve(true);
41978
+ }, time);
41979
+ });
41980
+ }
41981
+
42086
41982
  // src/providers/utils/extract-tx-error.ts
42087
41983
  var assemblePanicError = (statusReason) => {
42088
41984
  let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
@@ -45529,19 +45425,8 @@ Supported fuel-core version: ${supportedVersion}.`
45529
45425
  */
45530
45426
  async createTransfer(destination, amount, assetId, txParams = {}) {
45531
45427
  let request = new ScriptTransactionRequest(txParams);
45532
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
45533
- request.addCoinOutput(Address.fromAddressOrString(destination), amount, assetIdToTransfer);
45534
- const txCost = await this.provider.getTransactionCost(request, {
45535
- estimateTxDependencies: true,
45536
- resourcesOwner: this
45537
- });
45538
- request = this.validateGasLimitAndMaxFee({
45539
- transactionRequest: request,
45540
- gasUsed: txCost.gasUsed,
45541
- maxFee: txCost.maxFee,
45542
- txParams
45543
- });
45544
- await this.fund(request, txCost);
45428
+ request = this.addTransfer(request, { destination, amount, assetId });
45429
+ request = await this.estimateAndFundTransaction(request, txParams);
45545
45430
  return request;
45546
45431
  }
45547
45432
  /**
@@ -45554,16 +45439,57 @@ Supported fuel-core version: ${supportedVersion}.`
45554
45439
  * @returns A promise that resolves to the transaction response.
45555
45440
  */
45556
45441
  async transfer(destination, amount, assetId, txParams = {}) {
45557
- if (bn(amount).lte(0)) {
45558
- throw new FuelError(
45559
- ErrorCode.INVALID_TRANSFER_AMOUNT,
45560
- "Transfer amount must be a positive number."
45561
- );
45562
- }
45563
- const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
45564
- const request = await this.createTransfer(destination, amount, assetIdToTransfer, txParams);
45442
+ const request = await this.createTransfer(destination, amount, assetId, txParams);
45443
+ return this.sendTransaction(request, { estimateTxDependencies: false });
45444
+ }
45445
+ /**
45446
+ * Transfers multiple amounts of a token to multiple recipients.
45447
+ *
45448
+ * @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
45449
+ * @param txParams - Optional transaction parameters.
45450
+ * @returns A promise that resolves to a `TransactionResponse` object representing the transaction result.
45451
+ */
45452
+ async batchTransfer(transferParams, txParams = {}) {
45453
+ let request = new ScriptTransactionRequest(txParams);
45454
+ request = this.addBatchTransfer(request, transferParams);
45455
+ request = await this.estimateAndFundTransaction(request, txParams);
45565
45456
  return this.sendTransaction(request, { estimateTxDependencies: false });
45566
45457
  }
45458
+ /**
45459
+ * Adds a transfer to the given transaction request.
45460
+ *
45461
+ * @param request - The script transaction request to add transfers to.
45462
+ * @param transferParams - The object representing the transfer to be made.
45463
+ * @returns The updated transaction request with the added transfer.
45464
+ */
45465
+ addTransfer(request, transferParams) {
45466
+ const { destination, amount, assetId } = transferParams;
45467
+ this.validateTransferAmount(amount);
45468
+ request.addCoinOutput(
45469
+ Address.fromAddressOrString(destination),
45470
+ amount,
45471
+ assetId ?? this.provider.getBaseAssetId()
45472
+ );
45473
+ return request;
45474
+ }
45475
+ /**
45476
+ * Adds multiple transfers to a script transaction request.
45477
+ *
45478
+ * @param request - The script transaction request to add transfers to.
45479
+ * @param transferParams - An array of `TransferParams` objects representing the transfers to be made.
45480
+ * @returns The updated script transaction request.
45481
+ */
45482
+ addBatchTransfer(request, transferParams) {
45483
+ const baseAssetId = this.provider.getBaseAssetId();
45484
+ transferParams.forEach(({ destination, amount, assetId }) => {
45485
+ this.addTransfer(request, {
45486
+ destination,
45487
+ amount,
45488
+ assetId: assetId ?? baseAssetId
45489
+ });
45490
+ });
45491
+ return request;
45492
+ }
45567
45493
  /**
45568
45494
  * Transfers coins to a contract address.
45569
45495
  *
@@ -45641,6 +45567,7 @@ Supported fuel-core version: ${supportedVersion}.`
45641
45567
  await this.fund(request, txCost);
45642
45568
  return this.sendTransaction(request);
45643
45569
  }
45570
+ /** @hidden * */
45644
45571
  async signMessage(message) {
45645
45572
  if (!this._connector) {
45646
45573
  throw new FuelError(ErrorCode.MISSING_CONNECTOR, "A connector is required to sign messages.");
@@ -45696,6 +45623,31 @@ Supported fuel-core version: ${supportedVersion}.`
45696
45623
  }
45697
45624
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
45698
45625
  }
45626
+ /** @hidden * */
45627
+ validateTransferAmount(amount) {
45628
+ if (bn(amount).lte(0)) {
45629
+ throw new FuelError(
45630
+ ErrorCode.INVALID_TRANSFER_AMOUNT,
45631
+ "Transfer amount must be a positive number."
45632
+ );
45633
+ }
45634
+ }
45635
+ /** @hidden * */
45636
+ async estimateAndFundTransaction(transactionRequest, txParams) {
45637
+ let request = transactionRequest;
45638
+ const txCost = await this.provider.getTransactionCost(request, {
45639
+ resourcesOwner: this
45640
+ });
45641
+ request = this.validateGasLimitAndMaxFee({
45642
+ transactionRequest: request,
45643
+ gasUsed: txCost.gasUsed,
45644
+ maxFee: txCost.maxFee,
45645
+ txParams
45646
+ });
45647
+ request = await this.fund(request, txCost);
45648
+ return request;
45649
+ }
45650
+ /** @hidden * */
45699
45651
  validateGasLimitAndMaxFee({
45700
45652
  gasUsed,
45701
45653
  maxFee,
@@ -50107,40 +50059,6 @@ Supported fuel-core version: ${supportedVersion}.`
50107
50059
  }
50108
50060
  }
50109
50061
  };
50110
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
50111
- const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
50112
- ...coin,
50113
- amount: "18446744073709551615"
50114
- }));
50115
- const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
50116
- ...message,
50117
- amount: "18446744073709551615"
50118
- }));
50119
- 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);
50120
- 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);
50121
- if (!process.env.GENESIS_SECRET) {
50122
- const pk = Signer.generatePrivateKey();
50123
- const signer = new Signer(pk);
50124
- process.env.GENESIS_SECRET = hexlify(pk);
50125
- coins.push({
50126
- tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50127
- owner: signer.address.toHexString(),
50128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50129
- amount: "18446744073709551615",
50130
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
50131
- output_index: 0,
50132
- tx_pointer_block_height: 0,
50133
- tx_pointer_tx_idx: 0
50134
- });
50135
- }
50136
- const json = JSON.stringify({
50137
- ...stateConfig,
50138
- coins,
50139
- messages
50140
- });
50141
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
50142
- return json.replace(regexMakeNumber, "$1$2");
50143
- }
50144
50062
  var launchNode = async ({
50145
50063
  ip,
50146
50064
  port,
@@ -50148,8 +50066,7 @@ Supported fuel-core version: ${supportedVersion}.`
50148
50066
  useSystemFuelCore = false,
50149
50067
  loggingEnabled = true,
50150
50068
  debugEnabled = false,
50151
- basePath,
50152
- snapshotConfig = defaultSnapshotConfigs
50069
+ basePath
50153
50070
  }) => (
50154
50071
  // eslint-disable-next-line no-async-promise-executor
50155
50072
  new Promise(async (resolve, reject) => {
@@ -50178,23 +50095,56 @@ Supported fuel-core version: ${supportedVersion}.`
50178
50095
  let snapshotDirToUse;
50179
50096
  const prefix = basePath || import_os.default.tmpdir();
50180
50097
  const suffix = basePath ? "" : (0, import_crypto19.randomUUID)();
50181
- const tempDir = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
50098
+ const tempDirPath = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
50182
50099
  if (snapshotDir) {
50183
50100
  snapshotDirToUse = snapshotDir;
50184
50101
  } else {
50185
- if (!(0, import_fs2.existsSync)(tempDir)) {
50186
- (0, import_fs2.mkdirSync)(tempDir, { recursive: true });
50187
- }
50188
- const { metadata } = snapshotConfig;
50189
- const metadataPath = import_path8.default.join(tempDir, "metadata.json");
50190
- const chainConfigPath = import_path8.default.join(tempDir, metadata.chain_config);
50191
- const stateConfigPath = import_path8.default.join(tempDir, metadata.table_encoding.Json.filepath);
50192
- const stateTransitionPath = import_path8.default.join(tempDir, "state_transition_bytecode.wasm");
50193
- (0, import_fs2.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
50194
- (0, import_fs2.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
50195
- (0, import_fs2.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
50196
- (0, import_fs2.writeFileSync)(stateTransitionPath, JSON.stringify(""));
50197
- snapshotDirToUse = tempDir;
50102
+ if (!(0, import_fs2.existsSync)(tempDirPath)) {
50103
+ (0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
50104
+ }
50105
+ let { stateConfigJson } = defaultSnapshotConfigs;
50106
+ const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
50107
+ stateConfigJson = {
50108
+ ...stateConfigJson,
50109
+ coins: [
50110
+ ...stateConfigJson.coins.map((coin) => ({
50111
+ ...coin,
50112
+ amount: "18446744073709551615"
50113
+ }))
50114
+ ],
50115
+ messages: stateConfigJson.messages.map((message) => ({
50116
+ ...message,
50117
+ amount: "18446744073709551615"
50118
+ }))
50119
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50120
+ };
50121
+ if (!process.env.GENESIS_SECRET) {
50122
+ const pk = Signer.generatePrivateKey();
50123
+ const signer = new Signer(pk);
50124
+ process.env.GENESIS_SECRET = hexlify(pk);
50125
+ stateConfigJson.coins.push({
50126
+ tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50127
+ owner: signer.address.toHexString(),
50128
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50129
+ amount: "18446744073709551615",
50130
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
50131
+ output_index: 0,
50132
+ tx_pointer_block_height: 0,
50133
+ tx_pointer_tx_idx: 0
50134
+ });
50135
+ }
50136
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
50137
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
50138
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
50139
+ const chainConfigWritePath = import_path8.default.join(tempDirPath, "chainConfig.json");
50140
+ const stateConfigWritePath = import_path8.default.join(tempDirPath, "stateConfig.json");
50141
+ const metadataWritePath = import_path8.default.join(tempDirPath, "metadata.json");
50142
+ const stateTransitionWritePath = import_path8.default.join(tempDirPath, "state_transition_bytecode.wasm");
50143
+ (0, import_fs2.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
50144
+ (0, import_fs2.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
50145
+ (0, import_fs2.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
50146
+ (0, import_fs2.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
50147
+ snapshotDirToUse = tempDirPath;
50198
50148
  }
50199
50149
  const child = (0, import_child_process.spawn)(
50200
50150
  command,
@@ -50202,7 +50152,7 @@ Supported fuel-core version: ${supportedVersion}.`
50202
50152
  "run",
50203
50153
  ["--ip", ipToUse],
50204
50154
  ["--port", portToUse],
50205
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
50155
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
50206
50156
  ["--min-gas-price", "1"],
50207
50157
  poaInstant ? ["--poa-instant", "true"] : [],
50208
50158
  ["--consensus-key", consensusKey],
@@ -50224,28 +50174,23 @@ Supported fuel-core version: ${supportedVersion}.`
50224
50174
  }
50225
50175
  const cleanupConfig = {
50226
50176
  child,
50227
- configPath: tempDir,
50177
+ configPath: tempDirPath,
50228
50178
  killFn: import_tree_kill.default,
50229
50179
  state: {
50230
50180
  isDead: false
50231
50181
  }
50232
50182
  };
50233
50183
  child.stderr.on("data", (chunk) => {
50234
- const text = typeof chunk === "string" ? chunk : chunk.toString();
50235
- if (text.indexOf(graphQLStartSubstring) !== -1) {
50236
- const rows = text.split("\n");
50237
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
50238
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
50184
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
50239
50185
  resolve({
50240
50186
  cleanup: () => killNode(cleanupConfig),
50241
- ip: realIp,
50242
- port: realPort,
50243
- url: `http://${realIp}:${realPort}/v1/graphql`,
50187
+ ip: ipToUse,
50188
+ port: portToUse,
50244
50189
  snapshotDir: snapshotDirToUse
50245
50190
  });
50246
50191
  }
50247
- if (/error/i.test(text)) {
50248
- reject(text.toString());
50192
+ if (/error/i.test(chunk)) {
50193
+ reject(chunk.toString());
50249
50194
  }
50250
50195
  });
50251
50196
  process.on("exit", () => killNode(cleanupConfig));
@@ -50278,222 +50223,6 @@ Supported fuel-core version: ${supportedVersion}.`
50278
50223
  };
50279
50224
  return { wallets, stop: cleanup, provider };
50280
50225
  };
50281
-
50282
- // src/test-utils/asset-id.ts
50283
- var _AssetId = class {
50284
- constructor(value) {
50285
- this.value = value;
50286
- }
50287
- static random(count = 1) {
50288
- const assetIds = [];
50289
- for (let i = 0; i < count; i++) {
50290
- assetIds.push(new _AssetId(hexlify(randomBytes22(32))));
50291
- }
50292
- return assetIds;
50293
- }
50294
- };
50295
- var AssetId = _AssetId;
50296
- __publicField(AssetId, "A", new _AssetId(
50297
- "0x0101010101010101010101010101010101010101010101010101010101010101"
50298
- ));
50299
- __publicField(AssetId, "B", new _AssetId(
50300
- "0x0202020202020202020202020202020202020202020202020202020202020202"
50301
- ));
50302
-
50303
- // src/test-utils/wallet-config.ts
50304
- var WalletConfig = class {
50305
- initialState;
50306
- options;
50307
- wallets;
50308
- generateWallets = () => {
50309
- const generatedWallets = [];
50310
- for (let index = 1; index <= this.options.count; index++) {
50311
- generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
50312
- }
50313
- return generatedWallets;
50314
- };
50315
- constructor(baseAssetId, config) {
50316
- WalletConfig.validate(config);
50317
- this.options = config;
50318
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
50319
- this.wallets = this.generateWallets();
50320
- this.initialState = {
50321
- messages: WalletConfig.createMessages(this.wallets, messages),
50322
- coins: WalletConfig.createCoins(
50323
- this.wallets,
50324
- baseAssetId,
50325
- assets2,
50326
- coinsPerAsset,
50327
- amountPerCoin
50328
- )
50329
- };
50330
- }
50331
- apply(snapshotConfig) {
50332
- return {
50333
- ...snapshotConfig,
50334
- stateConfig: {
50335
- ...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs.stateConfig,
50336
- coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
50337
- messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
50338
- }
50339
- };
50340
- }
50341
- /**
50342
- * Create messages for the wallets in the format that the chain expects.
50343
- */
50344
- static createMessages(wallets, messages) {
50345
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
50346
- }
50347
- /**
50348
- * Create coins for the wallets in the format that the chain expects.
50349
- */
50350
- static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
50351
- const coins = [];
50352
- let assetIds = [baseAssetId];
50353
- if (Array.isArray(assets2)) {
50354
- assetIds = assetIds.concat(assets2.map((a) => a.value));
50355
- } else {
50356
- assetIds.concat(AssetId.random(assets2).map((a) => a.value));
50357
- }
50358
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
50359
- assetIds.forEach((assetId) => {
50360
- for (let index = 0; index < coinsPerAsset; index++) {
50361
- coins.push({
50362
- amount: amountPerCoin,
50363
- asset_id: assetId,
50364
- owner: walletAddress,
50365
- tx_pointer_block_height: 0,
50366
- tx_pointer_tx_idx: 0,
50367
- output_index: 0,
50368
- tx_id: hexlify(randomBytes22(32))
50369
- });
50370
- }
50371
- });
50372
- });
50373
- return coins;
50374
- }
50375
- static validate({
50376
- count: wallets,
50377
- assets: assets2,
50378
- coinsPerAsset,
50379
- amountPerCoin
50380
- }) {
50381
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
50382
- throw new FuelError(
50383
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50384
- "Number of wallets must be greater than zero."
50385
- );
50386
- }
50387
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
50388
- throw new FuelError(
50389
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50390
- "Number of assets per wallet must be greater than zero."
50391
- );
50392
- }
50393
- if (coinsPerAsset <= 0) {
50394
- throw new FuelError(
50395
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50396
- "Number of coins per asset must be greater than zero."
50397
- );
50398
- }
50399
- if (amountPerCoin <= 0) {
50400
- throw new FuelError(
50401
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50402
- "Amount per coin must be greater than zero."
50403
- );
50404
- }
50405
- }
50406
- };
50407
-
50408
- // src/test-utils/setup-test-provider-and-wallets.ts
50409
- var defaultWalletConfigOptions = {
50410
- count: 2,
50411
- assets: [AssetId.A, AssetId.B],
50412
- coinsPerAsset: 1,
50413
- amountPerCoin: 1e10,
50414
- messages: []
50415
- };
50416
- async function setupTestProviderAndWallets({
50417
- walletConfig: walletConfigOptions = {},
50418
- providerOptions,
50419
- nodeOptions = {}
50420
- } = {}) {
50421
- Symbol.dispose ??= Symbol("Symbol.dispose");
50422
- const walletConfig = new WalletConfig(
50423
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
50424
- {
50425
- ...defaultWalletConfigOptions,
50426
- ...walletConfigOptions
50427
- }
50428
- );
50429
- const { cleanup, url } = await launchNode({
50430
- loggingEnabled: false,
50431
- ...nodeOptions,
50432
- snapshotConfig: mergeDeepRight_default(
50433
- defaultSnapshotConfigs,
50434
- walletConfig.apply(nodeOptions?.snapshotConfig)
50435
- ),
50436
- port: "0"
50437
- });
50438
- let provider;
50439
- try {
50440
- provider = await Provider.create(url, providerOptions);
50441
- } catch (err) {
50442
- cleanup();
50443
- throw err;
50444
- }
50445
- const wallets = walletConfig.wallets;
50446
- wallets.forEach((wallet) => {
50447
- wallet.connect(provider);
50448
- });
50449
- return {
50450
- provider,
50451
- wallets,
50452
- cleanup,
50453
- [Symbol.dispose]: cleanup
50454
- };
50455
- }
50456
-
50457
- // src/test-utils/test-message.ts
50458
- var TestMessage = class {
50459
- sender;
50460
- recipient;
50461
- nonce;
50462
- amount;
50463
- data;
50464
- da_height;
50465
- /**
50466
- * A helper class to create messages for testing purposes.
50467
- *
50468
- * Used in tandem with `WalletConfig`.
50469
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
50470
- */
50471
- constructor({
50472
- sender = Address.fromRandom(),
50473
- recipient = Address.fromRandom(),
50474
- nonce = hexlify(randomBytes22(32)),
50475
- amount = 1e6,
50476
- data = "02",
50477
- da_height = 0
50478
- } = {}) {
50479
- this.sender = sender;
50480
- this.recipient = recipient;
50481
- this.nonce = nonce;
50482
- this.amount = amount;
50483
- this.data = data;
50484
- this.da_height = da_height;
50485
- }
50486
- toChainMessage(recipient) {
50487
- return {
50488
- sender: this.sender.toB256(),
50489
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
50490
- nonce: this.nonce,
50491
- amount: bn(this.amount).toNumber(),
50492
- data: this.data,
50493
- da_height: this.da_height
50494
- };
50495
- }
50496
- };
50497
50226
  })();
50498
50227
  /*! Bundled license information:
50499
50228