@fuel-ts/account 0.0.0-rc-1356-20240510142347 → 0.0.0-rc-2037-20240510174704

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 (46) hide show
  1. package/dist/index.global.js +102 -45
  2. package/dist/index.global.js.map +1 -1
  3. package/dist/index.js +442 -363
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +242 -171
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/predicate/predicate.d.ts +9 -2
  8. package/dist/predicate/predicate.d.ts.map +1 -1
  9. package/dist/providers/provider.d.ts +1 -1
  10. package/dist/providers/provider.d.ts.map +1 -1
  11. package/dist/providers/transaction-request/helpers.d.ts +4 -0
  12. package/dist/providers/transaction-request/helpers.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/index.d.ts +1 -0
  14. package/dist/providers/transaction-request/index.d.ts.map +1 -1
  15. package/dist/providers/transaction-request/transaction-request.d.ts +2 -0
  16. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  17. package/dist/providers/transaction-request/utils.d.ts +0 -4
  18. package/dist/providers/transaction-request/utils.d.ts.map +1 -1
  19. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  20. package/dist/providers/utils/index.d.ts +1 -0
  21. package/dist/providers/utils/index.d.ts.map +1 -1
  22. package/dist/providers/utils/sleep.d.ts +3 -0
  23. package/dist/providers/utils/sleep.d.ts.map +1 -0
  24. package/dist/test-utils/index.d.ts +0 -4
  25. package/dist/test-utils/index.d.ts.map +1 -1
  26. package/dist/test-utils/launchNode.d.ts +1 -8
  27. package/dist/test-utils/launchNode.d.ts.map +1 -1
  28. package/dist/test-utils/seedTestWallet.d.ts +1 -1
  29. package/dist/test-utils/seedTestWallet.d.ts.map +1 -1
  30. package/dist/test-utils.global.js +126 -432
  31. package/dist/test-utils.global.js.map +1 -1
  32. package/dist/test-utils.js +427 -642
  33. package/dist/test-utils.js.map +1 -1
  34. package/dist/test-utils.mjs +252 -463
  35. package/dist/test-utils.mjs.map +1 -1
  36. package/dist/wallet/base-wallet-unlocked.d.ts +2 -2
  37. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  38. package/package.json +15 -16
  39. package/dist/test-utils/asset-id.d.ts +0 -8
  40. package/dist/test-utils/asset-id.d.ts.map +0 -1
  41. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
  42. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
  43. package/dist/test-utils/test-message.d.ts +0 -28
  44. package/dist/test-utils/test-message.d.ts.map +0 -1
  45. package/dist/test-utils/wallet-config.d.ts +0 -49
  46. package/dist/test-utils/wallet-config.d.ts.map +0 -1
@@ -32709,13 +32709,6 @@ This unreleased fuel-core build may include features and updates not yet support
32709
32709
  };
32710
32710
  var DateTime = _DateTime;
32711
32711
  __publicField3(DateTime, "TAI64_NULL", "");
32712
- function sleep(time) {
32713
- return new Promise((resolve) => {
32714
- setTimeout(() => {
32715
- resolve(true);
32716
- }, time);
32717
- });
32718
- }
32719
32712
  var chainConfig_default = {
32720
32713
  chain_name: "local_testnet",
32721
32714
  consensus_parameters: {
@@ -33470,9 +33463,9 @@ This unreleased fuel-core build may include features and updates not yet support
33470
33463
  da_block_height: 0
33471
33464
  };
33472
33465
  var defaultSnapshotConfigs = {
33473
- chainConfig: chainConfig_default,
33474
- metadata: metadata_default,
33475
- stateConfig: stateConfig_default
33466
+ chainConfigJson: chainConfig_default,
33467
+ metadataJson: metadata_default,
33468
+ stateConfigJson: stateConfig_default
33476
33469
  };
33477
33470
  var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
33478
33471
  function isDefined(value) {
@@ -34889,72 +34882,11 @@ This unreleased fuel-core build may include features and updates not yet support
34889
34882
  };
34890
34883
  }
34891
34884
 
34892
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
34893
- function _curry2(fn) {
34894
- return function f2(a, b) {
34895
- switch (arguments.length) {
34896
- case 0:
34897
- return f2;
34898
- case 1:
34899
- return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
34900
- return fn(a, _b);
34901
- });
34902
- default:
34903
- return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
34904
- return fn(_a, b);
34905
- }) : _isPlaceholder(b) ? _curry1(function(_b) {
34906
- return fn(a, _b);
34907
- }) : fn(a, b);
34908
- }
34909
- };
34910
- }
34911
-
34912
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
34913
- function _curry3(fn) {
34914
- return function f3(a, b, c) {
34915
- switch (arguments.length) {
34916
- case 0:
34917
- return f3;
34918
- case 1:
34919
- return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
34920
- return fn(a, _b, _c);
34921
- });
34922
- case 2:
34923
- return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
34924
- return fn(_a, b, _c);
34925
- }) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
34926
- return fn(a, _b, _c);
34927
- }) : _curry1(function(_c) {
34928
- return fn(a, b, _c);
34929
- });
34930
- default:
34931
- return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
34932
- return fn(_a, _b, c);
34933
- }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
34934
- return fn(_a, b, _c);
34935
- }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
34936
- return fn(a, _b, _c);
34937
- }) : _isPlaceholder(a) ? _curry1(function(_a) {
34938
- return fn(_a, b, c);
34939
- }) : _isPlaceholder(b) ? _curry1(function(_b) {
34940
- return fn(a, _b, c);
34941
- }) : _isPlaceholder(c) ? _curry1(function(_c) {
34942
- return fn(a, b, _c);
34943
- }) : fn(a, b, c);
34944
- }
34945
- };
34946
- }
34947
-
34948
34885
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
34949
34886
  var isArray_default = Array.isArray || function _isArray(val) {
34950
34887
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
34951
34888
  };
34952
34889
 
34953
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
34954
- function _has(prop, obj) {
34955
- return Object.prototype.hasOwnProperty.call(obj, prop);
34956
- }
34957
-
34958
34890
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
34959
34891
  var type = /* @__PURE__ */ _curry1(function type2(val) {
34960
34892
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -34971,11 +34903,6 @@ This unreleased fuel-core build may include features and updates not yet support
34971
34903
  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";
34972
34904
  };
34973
34905
 
34974
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
34975
- function _isObject(x) {
34976
- return Object.prototype.toString.call(x) === "[object Object]";
34977
- }
34978
-
34979
34906
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
34980
34907
  var isInteger_default = Number.isInteger || function _isInteger(n) {
34981
34908
  return n << 0 === n;
@@ -35089,46 +35016,6 @@ This unreleased fuel-core build may include features and updates not yet support
35089
35016
  });
35090
35017
  var clone_default = clone;
35091
35018
 
35092
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
35093
- var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
35094
- var result = {};
35095
- var k;
35096
- l = l || {};
35097
- r = r || {};
35098
- for (k in l) {
35099
- if (_has(k, l)) {
35100
- result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
35101
- }
35102
- }
35103
- for (k in r) {
35104
- if (_has(k, r) && !_has(k, result)) {
35105
- result[k] = r[k];
35106
- }
35107
- }
35108
- return result;
35109
- });
35110
- var mergeWithKey_default = mergeWithKey;
35111
-
35112
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
35113
- var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
35114
- return mergeWithKey_default(function(k, lVal, rVal) {
35115
- if (_isObject(lVal) && _isObject(rVal)) {
35116
- return mergeDeepWithKey2(fn, lVal, rVal);
35117
- } else {
35118
- return fn(k, lVal, rVal);
35119
- }
35120
- }, lObj, rObj);
35121
- });
35122
- var mergeDeepWithKey_default = mergeDeepWithKey;
35123
-
35124
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
35125
- var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
35126
- return mergeDeepWithKey_default(function(k, lVal, rVal) {
35127
- return rVal;
35128
- }, lObj, rObj);
35129
- });
35130
- var mergeDeepRight_default = mergeDeepRight;
35131
-
35132
35019
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
35133
35020
  var hasProtoTrim = typeof String.prototype.trim === "function";
35134
35021
 
@@ -43207,6 +43094,15 @@ ${MessageCoinFragmentDoc}`;
43207
43094
  return normalize2(clone_default(root));
43208
43095
  }
43209
43096
 
43097
+ // src/providers/utils/sleep.ts
43098
+ function sleep(time) {
43099
+ return new Promise((resolve) => {
43100
+ setTimeout(() => {
43101
+ resolve(true);
43102
+ }, time);
43103
+ });
43104
+ }
43105
+
43210
43106
  // src/providers/utils/extract-tx-error.ts
43211
43107
  var assemblePanicError = (status) => {
43212
43108
  let errorMessage = `The transaction reverted with reason: "${status.reason}".`;
@@ -43285,6 +43181,34 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43285
43181
  name = "NoWitnessAtIndexError";
43286
43182
  };
43287
43183
 
43184
+ // src/providers/transaction-request/helpers.ts
43185
+ var isRequestInputCoin = (input) => input.type === InputType.Coin;
43186
+ var isRequestInputMessage = (input) => input.type === InputType.Message;
43187
+ var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
43188
+ var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
43189
+ if (isRequestInputCoin(input) && input.assetId === assetId) {
43190
+ return acc.add(input.amount);
43191
+ }
43192
+ if (isRequestInputMessage(input) && assetId === baseAsset) {
43193
+ return acc.add(input.amount);
43194
+ }
43195
+ return acc;
43196
+ }, bn(0));
43197
+ var cacheRequestInputsResourcesFromOwner = (inputs, owner) => inputs.reduce(
43198
+ (acc, input) => {
43199
+ if (isRequestInputCoin(input) && input.owner === owner.toB256()) {
43200
+ acc.utxos.push(input.id);
43201
+ } else if (isRequestInputMessage(input) && input.recipient === owner.toB256()) {
43202
+ acc.messages.push(input.nonce);
43203
+ }
43204
+ return acc;
43205
+ },
43206
+ {
43207
+ utxos: [],
43208
+ messages: []
43209
+ }
43210
+ );
43211
+
43288
43212
  // src/providers/transaction-request/witness.ts
43289
43213
  var witnessify = (value) => {
43290
43214
  const data = arrayify(value);
@@ -43522,7 +43446,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43522
43446
  * @param coin - Coin resource.
43523
43447
  */
43524
43448
  addCoinInput(coin) {
43525
- const { assetId, owner, amount } = coin;
43449
+ const { assetId, owner, amount, id, predicate } = coin;
43526
43450
  let witnessIndex;
43527
43451
  if (coin.predicate) {
43528
43452
  witnessIndex = 0;
@@ -43533,13 +43457,14 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43533
43457
  }
43534
43458
  }
43535
43459
  const input = {
43536
- ...coin,
43460
+ id,
43537
43461
  type: InputType.Coin,
43538
43462
  owner: owner.toB256(),
43539
43463
  amount,
43540
43464
  assetId,
43541
43465
  txPointer: "0x00000000000000000000000000000000",
43542
- witnessIndex
43466
+ witnessIndex,
43467
+ predicate
43543
43468
  };
43544
43469
  this.pushInput(input);
43545
43470
  this.addChangeOutput(owner, assetId);
@@ -43551,7 +43476,7 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43551
43476
  * @param message - Message resource.
43552
43477
  */
43553
43478
  addMessageInput(message) {
43554
- const { recipient, sender, amount, assetId } = message;
43479
+ const { recipient, sender, amount, predicate, nonce, assetId } = message;
43555
43480
  let witnessIndex;
43556
43481
  if (message.predicate) {
43557
43482
  witnessIndex = 0;
@@ -43562,12 +43487,13 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43562
43487
  }
43563
43488
  }
43564
43489
  const input = {
43565
- ...message,
43490
+ nonce,
43566
43491
  type: InputType.Message,
43567
43492
  sender: sender.toB256(),
43568
43493
  recipient: recipient.toB256(),
43569
43494
  amount,
43570
- witnessIndex
43495
+ witnessIndex,
43496
+ predicate
43571
43497
  };
43572
43498
  this.pushInput(input);
43573
43499
  this.addChangeOutput(recipient, assetId);
@@ -43757,6 +43683,17 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
43757
43683
  toJSON() {
43758
43684
  return normalizeJSON(this);
43759
43685
  }
43686
+ removeWitness(index) {
43687
+ this.witnesses.splice(index, 1);
43688
+ this.adjustWitnessIndexes(index);
43689
+ }
43690
+ adjustWitnessIndexes(removedIndex) {
43691
+ this.inputs.filter(isRequestInputResource).forEach((input) => {
43692
+ if (input.witnessIndex > removedIndex) {
43693
+ input.witnessIndex -= 1;
43694
+ }
43695
+ });
43696
+ }
43760
43697
  updatePredicateGasUsed(inputs) {
43761
43698
  this.inputs.forEach((i) => {
43762
43699
  let correspondingInput;
@@ -44183,21 +44120,6 @@ ${PANIC_DOC_URL}#variant.${status.reason}`;
44183
44120
  }
44184
44121
  }
44185
44122
  };
44186
- var cacheTxInputsFromOwner = (inputs, owner) => inputs.reduce(
44187
- (acc, input) => {
44188
- if (input.type === InputType.Coin && input.owner === owner.toB256()) {
44189
- acc.utxos.push(input.id);
44190
- }
44191
- if (input.type === InputType.Message && input.recipient === owner.toB256()) {
44192
- acc.messages.push(input.nonce);
44193
- }
44194
- return acc;
44195
- },
44196
- {
44197
- utxos: [],
44198
- messages: []
44199
- }
44200
- );
44201
44123
 
44202
44124
  // src/providers/transaction-summary/calculate-tx-fee-for-summary.ts
44203
44125
  var calculateTXFeeForSummary = (params) => {
@@ -46337,20 +46259,6 @@ Supported fuel-core version: ${supportedVersion}.`
46337
46259
  ];
46338
46260
  var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
46339
46261
 
46340
- // src/providers/transaction-request/helpers.ts
46341
- var isRequestInputCoin = (input) => input.type === InputType.Coin;
46342
- var isRequestInputMessage = (input) => input.type === InputType.Message;
46343
- var isRequestInputResource = (input) => isRequestInputCoin(input) || isRequestInputMessage(input);
46344
- var getAssetAmountInRequestInputs = (inputs, assetId, baseAsset) => inputs.filter(isRequestInputResource).reduce((acc, input) => {
46345
- if (isRequestInputCoin(input) && input.assetId === assetId) {
46346
- return acc.add(input.amount);
46347
- }
46348
- if (isRequestInputMessage(input) && assetId === baseAsset) {
46349
- return acc.add(input.amount);
46350
- }
46351
- return acc;
46352
- }, bn(0));
46353
-
46354
46262
  // src/utils/formatTransferToContractScriptData.ts
46355
46263
  var asm = __toESM(require_node());
46356
46264
  var formatTransferToContractScriptData = (params) => {
@@ -46585,7 +46493,7 @@ Supported fuel-core version: ${supportedVersion}.`
46585
46493
  while (needsToBeFunded && fundingAttempts < MAX_FUNDING_ATTEMPTS) {
46586
46494
  const resources = await this.getResourcesToSpend(
46587
46495
  missingQuantities,
46588
- cacheTxInputsFromOwner(request.inputs, this.address)
46496
+ cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
46589
46497
  );
46590
46498
  request.addResources(resources);
46591
46499
  request.shiftPredicateData();
@@ -51174,16 +51082,18 @@ Supported fuel-core version: ${supportedVersion}.`
51174
51082
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
51175
51083
 
51176
51084
  // src/test-utils/seedTestWallet.ts
51177
- var seedTestWallet = async (wallet, quantities) => {
51178
- const genesisWallet = new WalletUnlocked(
51179
- process.env.GENESIS_SECRET || randomBytes22(32),
51180
- wallet.provider
51181
- );
51085
+ var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
51086
+ const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
51087
+ const [{ provider }] = accountsToBeFunded;
51088
+ const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || randomBytes22(32), provider);
51182
51089
  const request = new ScriptTransactionRequest();
51183
- quantities.forEach((quantity) => {
51184
- const { amount, assetId } = coinQuantityfy(quantity);
51185
- request.addCoinOutput(wallet.address, amount, assetId);
51186
- });
51090
+ quantities.map(coinQuantityfy).forEach(
51091
+ ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
51092
+ for (let i = 0; i < utxosAmount; i++) {
51093
+ request.addCoinOutput(address, amount.div(utxosAmount), assetId);
51094
+ }
51095
+ })
51096
+ );
51187
51097
  const txCost = await genesisWallet.provider.getTransactionCost(request);
51188
51098
  request.gasLimit = txCost.gasUsed;
51189
51099
  request.maxFee = txCost.maxFee;
@@ -51254,40 +51164,6 @@ Supported fuel-core version: ${supportedVersion}.`
51254
51164
  }
51255
51165
  }
51256
51166
  };
51257
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
51258
- const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
51259
- ...coin,
51260
- amount: "18446744073709551615"
51261
- }));
51262
- const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
51263
- ...message,
51264
- amount: "18446744073709551615"
51265
- }));
51266
- 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);
51267
- 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);
51268
- if (!process.env.GENESIS_SECRET) {
51269
- const pk = Signer.generatePrivateKey();
51270
- const signer = new Signer(pk);
51271
- process.env.GENESIS_SECRET = hexlify(pk);
51272
- coins.push({
51273
- tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
51274
- owner: signer.address.toHexString(),
51275
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51276
- amount: "18446744073709551615",
51277
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
51278
- output_index: 0,
51279
- tx_pointer_block_height: 0,
51280
- tx_pointer_tx_idx: 0
51281
- });
51282
- }
51283
- const json = JSON.stringify({
51284
- ...stateConfig,
51285
- coins,
51286
- messages
51287
- });
51288
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
51289
- return json.replace(regexMakeNumber, "$1$2");
51290
- }
51291
51167
  var launchNode = async ({
51292
51168
  ip,
51293
51169
  port,
@@ -51295,8 +51171,7 @@ Supported fuel-core version: ${supportedVersion}.`
51295
51171
  useSystemFuelCore = false,
51296
51172
  loggingEnabled = true,
51297
51173
  debugEnabled = false,
51298
- basePath,
51299
- snapshotConfig = defaultSnapshotConfigs
51174
+ basePath
51300
51175
  }) => (
51301
51176
  // eslint-disable-next-line no-async-promise-executor
51302
51177
  new Promise(async (resolve, reject) => {
@@ -51325,23 +51200,56 @@ Supported fuel-core version: ${supportedVersion}.`
51325
51200
  let snapshotDirToUse;
51326
51201
  const prefix = basePath || import_os.default.tmpdir();
51327
51202
  const suffix = basePath ? "" : (0, import_crypto21.randomUUID)();
51328
- const tempDir = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
51203
+ const tempDirPath = import_path8.default.join(prefix, ".fuels", suffix, "snapshotDir");
51329
51204
  if (snapshotDir) {
51330
51205
  snapshotDirToUse = snapshotDir;
51331
51206
  } else {
51332
- if (!(0, import_fs2.existsSync)(tempDir)) {
51333
- (0, import_fs2.mkdirSync)(tempDir, { recursive: true });
51334
- }
51335
- const { metadata } = snapshotConfig;
51336
- const metadataPath = import_path8.default.join(tempDir, "metadata.json");
51337
- const chainConfigPath = import_path8.default.join(tempDir, metadata.chain_config);
51338
- const stateConfigPath = import_path8.default.join(tempDir, metadata.table_encoding.Json.filepath);
51339
- const stateTransitionPath = import_path8.default.join(tempDir, "state_transition_bytecode.wasm");
51340
- (0, import_fs2.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
51341
- (0, import_fs2.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
51342
- (0, import_fs2.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
51343
- (0, import_fs2.writeFileSync)(stateTransitionPath, JSON.stringify(""));
51344
- snapshotDirToUse = tempDir;
51207
+ if (!(0, import_fs2.existsSync)(tempDirPath)) {
51208
+ (0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
51209
+ }
51210
+ let { stateConfigJson } = defaultSnapshotConfigs;
51211
+ const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
51212
+ stateConfigJson = {
51213
+ ...stateConfigJson,
51214
+ coins: [
51215
+ ...stateConfigJson.coins.map((coin) => ({
51216
+ ...coin,
51217
+ amount: "18446744073709551615"
51218
+ }))
51219
+ ],
51220
+ messages: stateConfigJson.messages.map((message) => ({
51221
+ ...message,
51222
+ amount: "18446744073709551615"
51223
+ }))
51224
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51225
+ };
51226
+ if (!process.env.GENESIS_SECRET) {
51227
+ const pk = Signer.generatePrivateKey();
51228
+ const signer = new Signer(pk);
51229
+ process.env.GENESIS_SECRET = hexlify(pk);
51230
+ stateConfigJson.coins.push({
51231
+ tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
51232
+ owner: signer.address.toHexString(),
51233
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
51234
+ amount: "18446744073709551615",
51235
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
51236
+ output_index: 0,
51237
+ tx_pointer_block_height: 0,
51238
+ tx_pointer_tx_idx: 0
51239
+ });
51240
+ }
51241
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
51242
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
51243
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
51244
+ const chainConfigWritePath = import_path8.default.join(tempDirPath, "chainConfig.json");
51245
+ const stateConfigWritePath = import_path8.default.join(tempDirPath, "stateConfig.json");
51246
+ const metadataWritePath = import_path8.default.join(tempDirPath, "metadata.json");
51247
+ const stateTransitionWritePath = import_path8.default.join(tempDirPath, "state_transition_bytecode.wasm");
51248
+ (0, import_fs2.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
51249
+ (0, import_fs2.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
51250
+ (0, import_fs2.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
51251
+ (0, import_fs2.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
51252
+ snapshotDirToUse = tempDirPath;
51345
51253
  }
51346
51254
  const child = (0, import_child_process.spawn)(
51347
51255
  command,
@@ -51349,7 +51257,7 @@ Supported fuel-core version: ${supportedVersion}.`
51349
51257
  "run",
51350
51258
  ["--ip", ipToUse],
51351
51259
  ["--port", portToUse],
51352
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
51260
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
51353
51261
  ["--min-gas-price", "1"],
51354
51262
  poaInstant ? ["--poa-instant", "true"] : [],
51355
51263
  ["--consensus-key", consensusKey],
@@ -51371,28 +51279,23 @@ Supported fuel-core version: ${supportedVersion}.`
51371
51279
  }
51372
51280
  const cleanupConfig = {
51373
51281
  child,
51374
- configPath: tempDir,
51282
+ configPath: tempDirPath,
51375
51283
  killFn: import_tree_kill.default,
51376
51284
  state: {
51377
51285
  isDead: false
51378
51286
  }
51379
51287
  };
51380
51288
  child.stderr.on("data", (chunk) => {
51381
- const text = typeof chunk === "string" ? chunk : chunk.toString();
51382
- if (text.indexOf(graphQLStartSubstring) !== -1) {
51383
- const rows = text.split("\n");
51384
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
51385
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
51289
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
51386
51290
  resolve({
51387
51291
  cleanup: () => killNode(cleanupConfig),
51388
- ip: realIp,
51389
- port: realPort,
51390
- url: `http://${realIp}:${realPort}/v1/graphql`,
51292
+ ip: ipToUse,
51293
+ port: portToUse,
51391
51294
  snapshotDir: snapshotDirToUse
51392
51295
  });
51393
51296
  }
51394
- if (/error/i.test(text)) {
51395
- reject(text.toString());
51297
+ if (/error/i.test(chunk)) {
51298
+ reject(chunk.toString());
51396
51299
  }
51397
51300
  });
51398
51301
  process.on("exit", () => killNode(cleanupConfig));
@@ -51425,215 +51328,6 @@ Supported fuel-core version: ${supportedVersion}.`
51425
51328
  };
51426
51329
  return { wallets, stop: cleanup, provider };
51427
51330
  };
51428
-
51429
- // src/test-utils/asset-id.ts
51430
- var _AssetId = class {
51431
- constructor(value) {
51432
- this.value = value;
51433
- }
51434
- static random() {
51435
- return new _AssetId(hexlify(randomBytes22(32)));
51436
- }
51437
- };
51438
- var AssetId = _AssetId;
51439
- __publicField(AssetId, "A", new _AssetId(
51440
- "0x0101010101010101010101010101010101010101010101010101010101010101"
51441
- ));
51442
- __publicField(AssetId, "B", new _AssetId(
51443
- "0x0202020202020202020202020202020202020202020202020202020202020202"
51444
- ));
51445
-
51446
- // src/test-utils/wallet-config.ts
51447
- var WalletConfig = class {
51448
- initialState;
51449
- options;
51450
- wallets;
51451
- generateWallets = () => {
51452
- const generatedWallets = [];
51453
- for (let index = 1; index <= this.options.count; index++) {
51454
- generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
51455
- }
51456
- return generatedWallets;
51457
- };
51458
- constructor(baseAssetId, config) {
51459
- const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
51460
- WalletConfig.guard(config);
51461
- this.options = config;
51462
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
51463
- this.wallets = this.generateWallets();
51464
- this.initialState = {
51465
- messages: WalletConfig.createMessages(this.wallets, messages),
51466
- coins: WalletConfig.createCoins(
51467
- this.wallets,
51468
- BASE_ASSET_ID,
51469
- assets2,
51470
- coinsPerAsset,
51471
- amountPerCoin
51472
- )
51473
- };
51474
- }
51475
- apply(snapshotConfig) {
51476
- return {
51477
- ...snapshotConfig,
51478
- stateConfig: {
51479
- ...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs.stateConfig,
51480
- coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
51481
- messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
51482
- }
51483
- };
51484
- }
51485
- static createMessages(wallets, messages) {
51486
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
51487
- }
51488
- static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
51489
- const coins = [];
51490
- let assetIds = [baseAssetId];
51491
- if (Array.isArray(assets2)) {
51492
- assetIds = assetIds.concat(assets2.map((a) => a.value));
51493
- } else {
51494
- for (let index = 0; index < assets2 - 1; index++) {
51495
- assetIds.push(AssetId.random().value);
51496
- }
51497
- }
51498
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
51499
- assetIds.forEach((assetId) => {
51500
- for (let index = 0; index < coinsPerAsset; index++) {
51501
- coins.push({
51502
- amount: amountPerCoin,
51503
- asset_id: assetId,
51504
- owner: walletAddress,
51505
- tx_pointer_block_height: 0,
51506
- tx_pointer_tx_idx: 0,
51507
- output_index: 0,
51508
- tx_id: hexlify(randomBytes22(32))
51509
- });
51510
- }
51511
- });
51512
- });
51513
- return coins;
51514
- }
51515
- static guard({
51516
- count: wallets,
51517
- assets: assets2,
51518
- coinsPerAsset,
51519
- amountPerCoin
51520
- }) {
51521
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
51522
- throw new FuelError(
51523
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
51524
- "Number of wallets must be greater than zero."
51525
- );
51526
- }
51527
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
51528
- throw new FuelError(
51529
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
51530
- "Number of assets per wallet must be greater than zero."
51531
- );
51532
- }
51533
- if (coinsPerAsset <= 0) {
51534
- throw new FuelError(
51535
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
51536
- "Number of coins per asset must be greater than zero."
51537
- );
51538
- }
51539
- if (amountPerCoin <= 0) {
51540
- throw new FuelError(
51541
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
51542
- "Amount per coin must be greater than zero."
51543
- );
51544
- }
51545
- }
51546
- };
51547
-
51548
- // src/test-utils/setup-test-provider-and-wallets.ts
51549
- var defaultWalletConfigOptions = {
51550
- count: 2,
51551
- assets: [AssetId.A, AssetId.B],
51552
- coinsPerAsset: 1,
51553
- amountPerCoin: 1e10,
51554
- messages: []
51555
- };
51556
- async function setupTestProviderAndWallets({
51557
- walletConfig: walletConfigOptions = {},
51558
- providerOptions,
51559
- nodeOptions = {}
51560
- } = {}) {
51561
- Symbol.dispose ??= Symbol("Symbol.dispose");
51562
- const walletConfig = new WalletConfig(
51563
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
51564
- {
51565
- ...defaultWalletConfigOptions,
51566
- ...walletConfigOptions
51567
- }
51568
- );
51569
- const { cleanup, url } = await launchNode({
51570
- loggingEnabled: false,
51571
- ...nodeOptions,
51572
- snapshotConfig: mergeDeepRight_default(
51573
- defaultSnapshotConfigs,
51574
- walletConfig.apply(nodeOptions?.snapshotConfig)
51575
- ),
51576
- port: "0"
51577
- });
51578
- let provider;
51579
- try {
51580
- provider = await Provider.create(url, providerOptions);
51581
- } catch (err) {
51582
- cleanup();
51583
- throw err;
51584
- }
51585
- const wallets = walletConfig.wallets;
51586
- wallets.forEach((wallet) => {
51587
- wallet.connect(provider);
51588
- });
51589
- return {
51590
- provider,
51591
- wallets,
51592
- cleanup,
51593
- [Symbol.dispose]: cleanup
51594
- };
51595
- }
51596
-
51597
- // src/test-utils/test-message.ts
51598
- var TestMessage = class {
51599
- sender;
51600
- recipient;
51601
- nonce;
51602
- amount;
51603
- data;
51604
- da_height;
51605
- /**
51606
- * A helper class to create messages for testing purposes.
51607
- *
51608
- * Used in tandem with `WalletConfig`.
51609
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
51610
- */
51611
- constructor({
51612
- sender = Address.fromRandom(),
51613
- recipient = Address.fromRandom(),
51614
- nonce = hexlify(randomBytes22(32)),
51615
- amount = 1e6,
51616
- data = "02",
51617
- da_height = 0
51618
- } = {}) {
51619
- this.sender = sender;
51620
- this.recipient = recipient;
51621
- this.nonce = nonce;
51622
- this.amount = amount;
51623
- this.data = data;
51624
- this.da_height = da_height;
51625
- }
51626
- toChainMessage(recipient) {
51627
- return {
51628
- sender: this.sender.toB256(),
51629
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
51630
- nonce: this.nonce,
51631
- amount: bn(this.amount).toNumber(),
51632
- data: this.data,
51633
- da_height: this.da_height
51634
- };
51635
- }
51636
- };
51637
51331
  })();
51638
51332
  /*! Bundled license information:
51639
51333