@fuel-ts/account 0.89.2 → 0.91.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (53) hide show
  1. package/dist/account.d.ts +8 -0
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/configs.d.ts +3 -1
  4. package/dist/configs.d.ts.map +1 -1
  5. package/dist/configs.global.js +4 -2
  6. package/dist/configs.global.js.map +1 -1
  7. package/dist/configs.js +10 -4
  8. package/dist/configs.js.map +1 -1
  9. package/dist/configs.mjs +7 -3
  10. package/dist/configs.mjs.map +1 -1
  11. package/dist/index.global.js +3228 -2762
  12. package/dist/index.global.js.map +1 -1
  13. package/dist/index.js +246 -178
  14. package/dist/index.js.map +1 -1
  15. package/dist/index.mjs +150 -81
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/predicate/predicate.d.ts +8 -0
  18. package/dist/predicate/predicate.d.ts.map +1 -1
  19. package/dist/providers/__generated__/operations.d.ts +711 -505
  20. package/dist/providers/__generated__/operations.d.ts.map +1 -1
  21. package/dist/providers/assets/utils/network.d.ts.map +1 -1
  22. package/dist/providers/chains.d.ts +1 -1
  23. package/dist/providers/provider.d.ts +12 -2
  24. package/dist/providers/provider.d.ts.map +1 -1
  25. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  26. package/dist/providers/utils/extract-tx-error.d.ts +2 -8
  27. package/dist/providers/utils/extract-tx-error.d.ts.map +1 -1
  28. package/dist/providers/utils/index.d.ts +0 -1
  29. package/dist/providers/utils/index.d.ts.map +1 -1
  30. package/dist/test-utils/asset-id.d.ts +8 -0
  31. package/dist/test-utils/asset-id.d.ts.map +1 -0
  32. package/dist/test-utils/launchNode.d.ts +10 -5
  33. package/dist/test-utils/launchNode.d.ts.map +1 -1
  34. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +34 -0
  35. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
  36. package/dist/test-utils/test-message.d.ts +29 -0
  37. package/dist/test-utils/test-message.d.ts.map +1 -0
  38. package/dist/test-utils/wallet-config.d.ts +55 -0
  39. package/dist/test-utils/wallet-config.d.ts.map +1 -0
  40. package/dist/test-utils.d.ts +8 -0
  41. package/dist/test-utils.d.ts.map +1 -0
  42. package/dist/test-utils.global.js +2277 -1467
  43. package/dist/test-utils.global.js.map +1 -1
  44. package/dist/test-utils.js +546 -234
  45. package/dist/test-utils.js.map +1 -1
  46. package/dist/test-utils.mjs +452 -144
  47. package/dist/test-utils.mjs.map +1 -1
  48. package/dist/wallet/base-wallet-unlocked.d.ts +1 -1
  49. package/package.json +26 -25
  50. package/dist/providers/utils/sleep.d.ts +0 -3
  51. package/dist/providers/utils/sleep.d.ts.map +0 -1
  52. package/dist/test-utils/index.d.ts +0 -4
  53. package/dist/test-utils/index.d.ts.map +0 -1
@@ -45,27 +45,33 @@ var __privateMethod = (obj, member, method) => {
45
45
  return method;
46
46
  };
47
47
 
48
- // src/test-utils/index.ts
48
+ // src/test-utils.ts
49
49
  var test_utils_exports = {};
50
50
  __export(test_utils_exports, {
51
+ AssetId: () => AssetId,
52
+ TestMessage: () => TestMessage,
53
+ WalletsConfig: () => WalletsConfig,
51
54
  generateTestWallet: () => generateTestWallet,
52
55
  killNode: () => killNode,
53
56
  launchNode: () => launchNode,
54
57
  launchNodeAndGetWallets: () => launchNodeAndGetWallets,
55
- seedTestWallet: () => seedTestWallet
58
+ seedTestWallet: () => seedTestWallet,
59
+ setupTestProviderAndWallets: () => setupTestProviderAndWallets
56
60
  });
57
61
  module.exports = __toCommonJS(test_utils_exports);
58
62
 
59
63
  // src/wallet/base-wallet-unlocked.ts
60
64
  var import_hasher3 = require("@fuel-ts/hasher");
61
- var import_utils31 = require("@fuel-ts/utils");
65
+ var import_utils32 = require("@fuel-ts/utils");
62
66
 
63
67
  // src/account.ts
68
+ var import_abi_coder7 = require("@fuel-ts/abi-coder");
64
69
  var import_address4 = require("@fuel-ts/address");
70
+ var import_crypto2 = require("@fuel-ts/crypto");
65
71
  var import_errors16 = require("@fuel-ts/errors");
66
72
  var import_interfaces = require("@fuel-ts/interfaces");
67
73
  var import_math20 = require("@fuel-ts/math");
68
- var import_utils28 = require("@fuel-ts/utils");
74
+ var import_utils29 = require("@fuel-ts/utils");
69
75
  var import_ramda4 = require("ramda");
70
76
 
71
77
  // src/providers/coin-quantity.ts
@@ -108,9 +114,9 @@ var import_address3 = require("@fuel-ts/address");
108
114
  var import_errors14 = require("@fuel-ts/errors");
109
115
  var import_math17 = require("@fuel-ts/math");
110
116
  var import_transactions20 = require("@fuel-ts/transactions");
111
- var import_utils22 = require("@fuel-ts/utils");
117
+ var import_utils23 = require("@fuel-ts/utils");
112
118
  var import_versions = require("@fuel-ts/versions");
113
- var import_utils23 = require("@noble/curves/abstract/utils");
119
+ var import_utils24 = require("@noble/curves/abstract/utils");
114
120
  var import_graphql_request = require("graphql-request");
115
121
  var import_ramda3 = require("ramda");
116
122
 
@@ -335,6 +341,7 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
335
341
  proofIndex
336
342
  }
337
343
  messageBlockHeader {
344
+ version
338
345
  id
339
346
  daHeight
340
347
  consensusParametersVersion
@@ -350,6 +357,7 @@ var MessageProofFragmentDoc = import_graphql_tag.default`
350
357
  applicationHash
351
358
  }
352
359
  commitBlockHeader {
360
+ version
353
361
  id
354
362
  daHeight
355
363
  consensusParametersVersion
@@ -536,6 +544,15 @@ var GasCostsFragmentDoc = import_graphql_tag.default`
536
544
  wqmm
537
545
  xor
538
546
  xori
547
+ alocDependentCost {
548
+ ...DependentCostFragment
549
+ }
550
+ cfe {
551
+ ...DependentCostFragment
552
+ }
553
+ cfeiDependentCost {
554
+ ...DependentCostFragment
555
+ }
539
556
  call {
540
557
  ...DependentCostFragment
541
558
  }
@@ -720,9 +737,13 @@ var GetTransactionsDocument = import_graphql_tag.default`
720
737
  ...transactionFragment
721
738
  }
722
739
  }
740
+ pageInfo {
741
+ ...pageInfoFragment
742
+ }
723
743
  }
724
744
  }
725
- ${TransactionFragmentDoc}`;
745
+ ${TransactionFragmentDoc}
746
+ ${PageInfoFragmentDoc}`;
726
747
  var GetTransactionsByOwnerDocument = import_graphql_tag.default`
727
748
  query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
728
749
  transactionsByOwner(
@@ -914,8 +935,12 @@ var GetRelayedTransactionStatusDocument = import_graphql_tag.default`
914
935
  }
915
936
  ${RelayedTransactionStatusFragmentDoc}`;
916
937
  var DryRunDocument = import_graphql_tag.default`
917
- mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
918
- dryRun(txs: $encodedTransactions, utxoValidation: $utxoValidation) {
938
+ mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
939
+ dryRun(
940
+ txs: $encodedTransactions
941
+ utxoValidation: $utxoValidation
942
+ gasPrice: $gasPrice
943
+ ) {
919
944
  ...dryRunTransactionExecutionStatusFragment
920
945
  }
921
946
  }
@@ -1669,21 +1694,12 @@ function normalizeJSON(root) {
1669
1694
  return normalize((0, import_ramda.clone)(root));
1670
1695
  }
1671
1696
 
1672
- // src/providers/utils/sleep.ts
1673
- function sleep(time) {
1674
- return new Promise((resolve) => {
1675
- setTimeout(() => {
1676
- resolve(true);
1677
- }, time);
1678
- });
1679
- }
1680
-
1681
1697
  // src/providers/utils/extract-tx-error.ts
1682
1698
  var import_errors7 = require("@fuel-ts/errors");
1683
1699
  var import_math6 = require("@fuel-ts/math");
1684
1700
  var import_transactions5 = require("@fuel-ts/transactions");
1685
1701
  var import_configs5 = require("@fuel-ts/transactions/configs");
1686
- var assemblePanicError = (statusReason) => {
1702
+ var assemblePanicError = (statusReason, metadata) => {
1687
1703
  let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
1688
1704
  if (import_configs5.PANIC_REASONS.includes(statusReason)) {
1689
1705
  errorMessage = `${errorMessage}
@@ -1692,10 +1708,13 @@ You can read more about this error at:
1692
1708
 
1693
1709
  ${import_configs5.PANIC_DOC_URL}#variant.${statusReason}`;
1694
1710
  }
1695
- return { errorMessage, reason: statusReason };
1711
+ return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1712
+ ...metadata,
1713
+ reason: statusReason
1714
+ });
1696
1715
  };
1697
1716
  var stringify = (obj) => JSON.stringify(obj, null, 2);
1698
- var assembleRevertError = (receipts, logs) => {
1717
+ var assembleRevertError = (receipts, logs, metadata) => {
1699
1718
  let errorMessage = "The transaction reverted with an unknown reason.";
1700
1719
  const revertReceipt = receipts.find(({ type }) => type === import_transactions5.ReceiptType.Revert);
1701
1720
  let reason = "";
@@ -1728,25 +1747,36 @@ var assembleRevertError = (receipts, logs) => {
1728
1747
  errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
1729
1748
  break;
1730
1749
  default:
1731
- reason = "unknown";
1732
- errorMessage = `The transaction reverted with an unknown reason: ${revertReceipt.val}`;
1750
+ throw new import_errors7.FuelError(
1751
+ import_errors7.ErrorCode.UNKNOWN,
1752
+ `The transaction reverted with an unknown reason: ${revertReceipt.val}`,
1753
+ {
1754
+ ...metadata,
1755
+ reason: "unknown"
1756
+ }
1757
+ );
1733
1758
  }
1734
1759
  }
1735
- return { errorMessage, reason };
1760
+ return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, {
1761
+ ...metadata,
1762
+ reason
1763
+ });
1736
1764
  };
1737
1765
  var extractTxError = (params) => {
1738
1766
  const { receipts, statusReason, logs } = params;
1739
1767
  const isPanic = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Panic);
1740
1768
  const isRevert = receipts.some(({ type }) => type === import_transactions5.ReceiptType.Revert);
1741
- const { errorMessage, reason } = isPanic ? assemblePanicError(statusReason) : assembleRevertError(receipts, logs);
1742
1769
  const metadata = {
1743
1770
  logs,
1744
1771
  receipts,
1745
1772
  panic: isPanic,
1746
1773
  revert: isRevert,
1747
- reason
1774
+ reason: ""
1748
1775
  };
1749
- return new import_errors7.FuelError(import_errors7.ErrorCode.SCRIPT_REVERTED, errorMessage, metadata);
1776
+ if (isPanic) {
1777
+ return assemblePanicError(statusReason, metadata);
1778
+ }
1779
+ return assembleRevertError(receipts, logs, metadata);
1750
1780
  };
1751
1781
 
1752
1782
  // src/providers/transaction-request/errors.ts
@@ -3624,6 +3654,7 @@ var TransactionResponse = class {
3624
3654
  };
3625
3655
 
3626
3656
  // src/providers/utils/auto-retry-fetch.ts
3657
+ var import_utils22 = require("@fuel-ts/utils");
3627
3658
  function getWaitDelay(options, retryAttemptNum) {
3628
3659
  const duration = options.baseDelay ?? 150;
3629
3660
  switch (options.backoff) {
@@ -3653,7 +3684,7 @@ function autoRetryFetch(fetchFn, options, retryAttemptNum = 0) {
3653
3684
  throw error;
3654
3685
  }
3655
3686
  const delay = getWaitDelay(options, retryNum);
3656
- await sleep(delay);
3687
+ await (0, import_utils22.sleep)(delay);
3657
3688
  return autoRetryFetch(fetchFn, options, retryNum)(...args);
3658
3689
  }
3659
3690
  };
@@ -4012,7 +4043,7 @@ Supported fuel-core version: ${supportedVersion}.`
4012
4043
  if (estimateTxDependencies) {
4013
4044
  await this.estimateTxDependencies(transactionRequest);
4014
4045
  }
4015
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4046
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4016
4047
  let abis;
4017
4048
  if (transactionRequest.type === import_transactions20.TransactionType.Script) {
4018
4049
  abis = transactionRequest.abis;
@@ -4050,12 +4081,12 @@ Supported fuel-core version: ${supportedVersion}.`
4050
4081
  * @param sendTransactionParams - The provider call parameters (optional).
4051
4082
  * @returns A promise that resolves to the call result object.
4052
4083
  */
4053
- async call(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
4084
+ async dryRun(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
4054
4085
  const transactionRequest = transactionRequestify(transactionRequestLike);
4055
4086
  if (estimateTxDependencies) {
4056
4087
  return this.estimateTxDependencies(transactionRequest);
4057
4088
  }
4058
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4089
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4059
4090
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4060
4091
  encodedTransactions: encodedTransaction,
4061
4092
  utxoValidation: utxoValidation || false
@@ -4075,13 +4106,13 @@ Supported fuel-core version: ${supportedVersion}.`
4075
4106
  async estimatePredicates(transactionRequest) {
4076
4107
  const shouldEstimatePredicates = Boolean(
4077
4108
  transactionRequest.inputs.find(
4078
- (input) => "predicate" in input && input.predicate && !(0, import_utils23.equalBytes)((0, import_utils22.arrayify)(input.predicate), (0, import_utils22.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4109
+ (input) => "predicate" in input && input.predicate && !(0, import_utils24.equalBytes)((0, import_utils23.arrayify)(input.predicate), (0, import_utils23.arrayify)("0x")) && new import_math17.BN(input.predicateGasUsed).isZero()
4079
4110
  )
4080
4111
  );
4081
4112
  if (!shouldEstimatePredicates) {
4082
4113
  return transactionRequest;
4083
4114
  }
4084
- const encodedTransaction = (0, import_utils22.hexlify)(transactionRequest.toTransactionBytes());
4115
+ const encodedTransaction = (0, import_utils23.hexlify)(transactionRequest.toTransactionBytes());
4085
4116
  const response = await this.operations.estimatePredicates({
4086
4117
  encodedTransaction
4087
4118
  });
@@ -4122,7 +4153,7 @@ Supported fuel-core version: ${supportedVersion}.`
4122
4153
  const {
4123
4154
  dryRun: [{ receipts: rawReceipts, status }]
4124
4155
  } = await this.operations.dryRun({
4125
- encodedTransactions: [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())],
4156
+ encodedTransactions: [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())],
4126
4157
  utxoValidation: false
4127
4158
  });
4128
4159
  receipts = rawReceipts.map(processGqlReceipt);
@@ -4172,7 +4203,7 @@ Supported fuel-core version: ${supportedVersion}.`
4172
4203
  const serializedTransactionsMap = /* @__PURE__ */ new Map();
4173
4204
  allRequests.forEach((req, index) => {
4174
4205
  if (req.type === import_transactions20.TransactionType.Script) {
4175
- serializedTransactionsMap.set(index, (0, import_utils22.hexlify)(req.toTransactionBytes()));
4206
+ serializedTransactionsMap.set(index, (0, import_utils23.hexlify)(req.toTransactionBytes()));
4176
4207
  }
4177
4208
  });
4178
4209
  let transactionsToProcess = Array.from(serializedTransactionsMap.keys());
@@ -4208,7 +4239,7 @@ Supported fuel-core version: ${supportedVersion}.`
4208
4239
  transactionRequest: request
4209
4240
  });
4210
4241
  request.maxFee = maxFee;
4211
- serializedTransactionsMap.set(requestIdx, (0, import_utils22.hexlify)(request.toTransactionBytes()));
4242
+ serializedTransactionsMap.set(requestIdx, (0, import_utils23.hexlify)(request.toTransactionBytes()));
4212
4243
  nextRoundTransactions.push(requestIdx);
4213
4244
  }
4214
4245
  }
@@ -4229,7 +4260,7 @@ Supported fuel-core version: ${supportedVersion}.`
4229
4260
  if (estimateTxDependencies) {
4230
4261
  return this.estimateMultipleTxDependencies(transactionRequests);
4231
4262
  }
4232
- const encodedTransactions = transactionRequests.map((tx) => (0, import_utils22.hexlify)(tx.toTransactionBytes()));
4263
+ const encodedTransactions = transactionRequests.map((tx) => (0, import_utils23.hexlify)(tx.toTransactionBytes()));
4233
4264
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4234
4265
  encodedTransactions,
4235
4266
  utxoValidation: utxoValidation || false
@@ -4303,7 +4334,7 @@ Supported fuel-core version: ${supportedVersion}.`
4303
4334
  if (estimateTxDependencies) {
4304
4335
  return this.estimateTxDependencies(transactionRequest);
4305
4336
  }
4306
- const encodedTransactions = [(0, import_utils22.hexlify)(transactionRequest.toTransactionBytes())];
4337
+ const encodedTransactions = [(0, import_utils23.hexlify)(transactionRequest.toTransactionBytes())];
4307
4338
  const { dryRun: dryRunStatuses } = await this.operations.dryRun({
4308
4339
  encodedTransactions,
4309
4340
  utxoValidation: true
@@ -4432,7 +4463,7 @@ Supported fuel-core version: ${supportedVersion}.`
4432
4463
  const result = await this.operations.getCoins({
4433
4464
  first: 10,
4434
4465
  ...paginationArgs,
4435
- filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils22.hexlify)(assetId) }
4466
+ filter: { owner: ownerAddress.toB256(), assetId: assetId && (0, import_utils23.hexlify)(assetId) }
4436
4467
  });
4437
4468
  const coins = result.coins.edges.map((edge) => edge.node);
4438
4469
  return coins.map((coin) => ({
@@ -4455,19 +4486,19 @@ Supported fuel-core version: ${supportedVersion}.`
4455
4486
  async getResourcesToSpend(owner, quantities, excludedIds) {
4456
4487
  const ownerAddress = import_address3.Address.fromAddressOrString(owner);
4457
4488
  const excludeInput = {
4458
- messages: excludedIds?.messages?.map((nonce) => (0, import_utils22.hexlify)(nonce)) || [],
4459
- utxos: excludedIds?.utxos?.map((id) => (0, import_utils22.hexlify)(id)) || []
4489
+ messages: excludedIds?.messages?.map((nonce) => (0, import_utils23.hexlify)(nonce)) || [],
4490
+ utxos: excludedIds?.utxos?.map((id) => (0, import_utils23.hexlify)(id)) || []
4460
4491
  };
4461
4492
  if (this.cache) {
4462
4493
  const uniqueUtxos = new Set(
4463
- excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils22.hexlify)(id)))
4494
+ excludeInput.utxos.concat(this.cache?.getActiveData().map((id) => (0, import_utils23.hexlify)(id)))
4464
4495
  );
4465
4496
  excludeInput.utxos = Array.from(uniqueUtxos);
4466
4497
  }
4467
4498
  const coinsQuery = {
4468
4499
  owner: ownerAddress.toB256(),
4469
4500
  queryPerAsset: quantities.map(coinQuantityfy).map(({ assetId, amount, max: maxPerAsset }) => ({
4470
- assetId: (0, import_utils22.hexlify)(assetId),
4501
+ assetId: (0, import_utils23.hexlify)(assetId),
4471
4502
  amount: amount.toString(10),
4472
4503
  max: maxPerAsset ? maxPerAsset.toString(10) : void 0
4473
4504
  })),
@@ -4569,7 +4600,7 @@ Supported fuel-core version: ${supportedVersion}.`
4569
4600
  time: block.header.time,
4570
4601
  transactionIds: block.transactions.map((tx) => tx.id),
4571
4602
  transactions: block.transactions.map(
4572
- (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils22.arrayify)(tx.rawPayload), 0)?.[0]
4603
+ (tx) => new import_transactions20.TransactionCoder().decode((0, import_utils23.arrayify)(tx.rawPayload), 0)?.[0]
4573
4604
  )
4574
4605
  };
4575
4606
  }
@@ -4585,10 +4616,25 @@ Supported fuel-core version: ${supportedVersion}.`
4585
4616
  return null;
4586
4617
  }
4587
4618
  return new import_transactions20.TransactionCoder().decode(
4588
- (0, import_utils22.arrayify)(transaction.rawPayload),
4619
+ (0, import_utils23.arrayify)(transaction.rawPayload),
4589
4620
  0
4590
4621
  )?.[0];
4591
4622
  }
4623
+ /**
4624
+ * Retrieves transactions based on the provided pagination arguments.
4625
+ * @param paginationArgs - The pagination arguments for retrieving transactions.
4626
+ * @returns A promise that resolves to an object containing the retrieved transactions and pagination information.
4627
+ */
4628
+ async getTransactions(paginationArgs) {
4629
+ const {
4630
+ transactions: { edges, pageInfo }
4631
+ } = await this.operations.getTransactions(paginationArgs);
4632
+ const coder = new import_transactions20.TransactionCoder();
4633
+ const transactions = edges.map(
4634
+ ({ node: { rawPayload } }) => coder.decode((0, import_utils23.arrayify)(rawPayload), 0)[0]
4635
+ );
4636
+ return { transactions, pageInfo };
4637
+ }
4592
4638
  /**
4593
4639
  * Get deployed contract with the given ID.
4594
4640
  *
@@ -4612,7 +4658,7 @@ Supported fuel-core version: ${supportedVersion}.`
4612
4658
  async getContractBalance(contractId, assetId) {
4613
4659
  const { contractBalance } = await this.operations.getContractBalance({
4614
4660
  contract: import_address3.Address.fromAddressOrString(contractId).toB256(),
4615
- asset: (0, import_utils22.hexlify)(assetId)
4661
+ asset: (0, import_utils23.hexlify)(assetId)
4616
4662
  });
4617
4663
  return (0, import_math17.bn)(contractBalance.amount, 10);
4618
4664
  }
@@ -4626,7 +4672,7 @@ Supported fuel-core version: ${supportedVersion}.`
4626
4672
  async getBalance(owner, assetId) {
4627
4673
  const { balance } = await this.operations.getBalance({
4628
4674
  owner: import_address3.Address.fromAddressOrString(owner).toB256(),
4629
- assetId: (0, import_utils22.hexlify)(assetId)
4675
+ assetId: (0, import_utils23.hexlify)(assetId)
4630
4676
  });
4631
4677
  return (0, import_math17.bn)(balance.amount, 10);
4632
4678
  }
@@ -4814,7 +4860,7 @@ Supported fuel-core version: ${supportedVersion}.`
4814
4860
  async produceBlocks(amount, startTime) {
4815
4861
  const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
4816
4862
  blocksToProduce: (0, import_math17.bn)(amount).toString(10),
4817
- startTimestamp: startTime ? import_utils22.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4863
+ startTimestamp: startTime ? import_utils23.DateTime.fromUnixMilliseconds(startTime).toTai64() : void 0
4818
4864
  });
4819
4865
  return (0, import_math17.bn)(latestBlockHeight);
4820
4866
  }
@@ -4897,7 +4943,7 @@ __publicField(Provider, "nodeInfoCache", {});
4897
4943
  var import_errors15 = require("@fuel-ts/errors");
4898
4944
  var import_math18 = require("@fuel-ts/math");
4899
4945
  var import_transactions21 = require("@fuel-ts/transactions");
4900
- var import_utils25 = require("@fuel-ts/utils");
4946
+ var import_utils26 = require("@fuel-ts/utils");
4901
4947
 
4902
4948
  // src/providers/chains.ts
4903
4949
  var CHAIN_IDS = {
@@ -4906,8 +4952,8 @@ var CHAIN_IDS = {
4906
4952
  foundry: 31337
4907
4953
  },
4908
4954
  fuel: {
4909
- beta5: 0,
4910
- devnet: 10
4955
+ devnet: 0,
4956
+ testnet: 0
4911
4957
  }
4912
4958
  };
4913
4959
 
@@ -4955,15 +5001,15 @@ var rawAssets = [
4955
5001
  },
4956
5002
  {
4957
5003
  type: "fuel",
4958
- chainId: CHAIN_IDS.fuel.beta5,
5004
+ chainId: CHAIN_IDS.fuel.devnet,
4959
5005
  decimals: 9,
4960
- assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
5006
+ assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
4961
5007
  },
4962
5008
  {
4963
5009
  type: "fuel",
4964
- chainId: CHAIN_IDS.fuel.devnet,
5010
+ chainId: CHAIN_IDS.fuel.testnet,
4965
5011
  decimals: 9,
4966
- assetId: "0x0000000000000000000000000000000000000000000000000000000000000000"
5012
+ assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
4967
5013
  }
4968
5014
  ]
4969
5015
  }
@@ -4973,16 +5019,16 @@ var assets = resolveIconPaths(rawAssets, fuelAssetsBaseUrl);
4973
5019
  // src/utils/formatTransferToContractScriptData.ts
4974
5020
  var import_abi_coder6 = require("@fuel-ts/abi-coder");
4975
5021
  var import_math19 = require("@fuel-ts/math");
4976
- var import_utils27 = require("@fuel-ts/utils");
5022
+ var import_utils28 = require("@fuel-ts/utils");
4977
5023
  var asm = __toESM(require("@fuels/vm-asm"));
4978
5024
  var formatTransferToContractScriptData = (params) => {
4979
5025
  const { assetId, amountToTransfer, hexlifiedContractId } = params;
4980
5026
  const numberCoder = new import_abi_coder6.BigNumberCoder("u64");
4981
5027
  const encoded = numberCoder.encode(new import_math19.BN(amountToTransfer).toNumber());
4982
5028
  const scriptData = Uint8Array.from([
4983
- ...(0, import_utils27.arrayify)(hexlifiedContractId),
5029
+ ...(0, import_utils28.arrayify)(hexlifiedContractId),
4984
5030
  ...encoded,
4985
- ...(0, import_utils27.arrayify)(assetId)
5031
+ ...(0, import_utils28.arrayify)(assetId)
4986
5032
  ]);
4987
5033
  return scriptData;
4988
5034
  };
@@ -5387,14 +5433,14 @@ var Account = class extends import_interfaces.AbstractAccount {
5387
5433
  */
5388
5434
  async withdrawToBaseLayer(recipient, amount, txParams = {}) {
5389
5435
  const recipientAddress = import_address4.Address.fromAddressOrString(recipient);
5390
- const recipientDataArray = (0, import_utils28.arrayify)(
5436
+ const recipientDataArray = (0, import_utils29.arrayify)(
5391
5437
  "0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
5392
5438
  );
5393
- const amountDataArray = (0, import_utils28.arrayify)(
5439
+ const amountDataArray = (0, import_utils29.arrayify)(
5394
5440
  "0x".concat((0, import_math20.bn)(amount).toHex().substring(2).padStart(16, "0"))
5395
5441
  );
5396
5442
  const script = new Uint8Array([
5397
- ...(0, import_utils28.arrayify)(withdrawScript.bytes),
5443
+ ...(0, import_utils29.arrayify)(withdrawScript.bytes),
5398
5444
  ...recipientDataArray,
5399
5445
  ...amountDataArray
5400
5446
  ]);
@@ -5477,6 +5523,21 @@ var Account = class extends import_interfaces.AbstractAccount {
5477
5523
  }
5478
5524
  return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
5479
5525
  }
5526
+ /**
5527
+ * Generates an array of fake resources based on the provided coins.
5528
+ *
5529
+ * @param coins - An array of `FakeResources` objects representing the coins.
5530
+ * @returns An array of `Resource` objects with generated properties.
5531
+ */
5532
+ generateFakeResources(coins) {
5533
+ return coins.map((coin) => ({
5534
+ id: (0, import_utils29.hexlify)((0, import_crypto2.randomBytes)(import_abi_coder7.UTXO_ID_LEN)),
5535
+ owner: this.address,
5536
+ blockCreated: (0, import_math20.bn)(1),
5537
+ txCreatedIdx: (0, import_math20.bn)(1),
5538
+ ...coin
5539
+ }));
5540
+ }
5480
5541
  /** @hidden * */
5481
5542
  validateTransferAmount(amount) {
5482
5543
  if ((0, import_math20.bn)(amount).lte(0)) {
@@ -5509,7 +5570,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5509
5570
  txParams: { gasLimit: setGasLimit, maxFee: setMaxFee }
5510
5571
  }) {
5511
5572
  const request = transactionRequestify(transactionRequest);
5512
- if (!(0, import_utils28.isDefined)(setGasLimit)) {
5573
+ if (!(0, import_utils29.isDefined)(setGasLimit)) {
5513
5574
  request.gasLimit = gasUsed;
5514
5575
  } else if (gasUsed.gt(setGasLimit)) {
5515
5576
  throw new import_errors16.FuelError(
@@ -5517,7 +5578,7 @@ var Account = class extends import_interfaces.AbstractAccount {
5517
5578
  `Gas limit '${setGasLimit}' is lower than the required: '${gasUsed}'.`
5518
5579
  );
5519
5580
  }
5520
- if (!(0, import_utils28.isDefined)(setMaxFee)) {
5581
+ if (!(0, import_utils29.isDefined)(setMaxFee)) {
5521
5582
  request.maxFee = maxFee;
5522
5583
  } else if (maxFee.gt(setMaxFee)) {
5523
5584
  throw new import_errors16.FuelError(
@@ -5531,10 +5592,10 @@ var Account = class extends import_interfaces.AbstractAccount {
5531
5592
 
5532
5593
  // src/signer/signer.ts
5533
5594
  var import_address5 = require("@fuel-ts/address");
5534
- var import_crypto2 = require("@fuel-ts/crypto");
5595
+ var import_crypto3 = require("@fuel-ts/crypto");
5535
5596
  var import_hasher2 = require("@fuel-ts/hasher");
5536
5597
  var import_math21 = require("@fuel-ts/math");
5537
- var import_utils29 = require("@fuel-ts/utils");
5598
+ var import_utils30 = require("@fuel-ts/utils");
5538
5599
  var import_secp256k1 = require("@noble/curves/secp256k1");
5539
5600
  var Signer = class {
5540
5601
  address;
@@ -5554,9 +5615,9 @@ var Signer = class {
5554
5615
  }
5555
5616
  }
5556
5617
  const privateKeyBytes = (0, import_math21.toBytes)(privateKey, 32);
5557
- this.privateKey = (0, import_utils29.hexlify)(privateKeyBytes);
5558
- this.publicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5559
- this.compressedPublicKey = (0, import_utils29.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5618
+ this.privateKey = (0, import_utils30.hexlify)(privateKeyBytes);
5619
+ this.publicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
5620
+ this.compressedPublicKey = (0, import_utils30.hexlify)(import_secp256k1.secp256k1.getPublicKey(privateKeyBytes, true));
5560
5621
  this.address = import_address5.Address.fromPublicKey(this.publicKey);
5561
5622
  }
5562
5623
  /**
@@ -5570,11 +5631,11 @@ var Signer = class {
5570
5631
  * @returns hashed signature
5571
5632
  */
5572
5633
  sign(data) {
5573
- const signature = import_secp256k1.secp256k1.sign((0, import_utils29.arrayify)(data), (0, import_utils29.arrayify)(this.privateKey));
5634
+ const signature = import_secp256k1.secp256k1.sign((0, import_utils30.arrayify)(data), (0, import_utils30.arrayify)(this.privateKey));
5574
5635
  const r = (0, import_math21.toBytes)(`0x${signature.r.toString(16)}`, 32);
5575
5636
  const s = (0, import_math21.toBytes)(`0x${signature.s.toString(16)}`, 32);
5576
5637
  s[0] |= (signature.recovery || 0) << 7;
5577
- return (0, import_utils29.hexlify)((0, import_utils29.concat)([r, s]));
5638
+ return (0, import_utils30.hexlify)((0, import_utils30.concat)([r, s]));
5578
5639
  }
5579
5640
  /**
5580
5641
  * Add point on the current elliptic curve
@@ -5583,8 +5644,8 @@ var Signer = class {
5583
5644
  * @returns compressed point on the curve
5584
5645
  */
5585
5646
  addPoint(point) {
5586
- const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(this.compressedPublicKey));
5587
- const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(point));
5647
+ const p0 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(this.compressedPublicKey));
5648
+ const p1 = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(point));
5588
5649
  const result = p0.add(p1);
5589
5650
  return `0x${result.toHex(true)}`;
5590
5651
  }
@@ -5596,16 +5657,16 @@ var Signer = class {
5596
5657
  * @returns public key from signature from the
5597
5658
  */
5598
5659
  static recoverPublicKey(data, signature) {
5599
- const signedMessageBytes = (0, import_utils29.arrayify)(signature);
5660
+ const signedMessageBytes = (0, import_utils30.arrayify)(signature);
5600
5661
  const r = signedMessageBytes.slice(0, 32);
5601
5662
  const s = signedMessageBytes.slice(32, 64);
5602
5663
  const recoveryParam = (s[0] & 128) >> 7;
5603
5664
  s[0] &= 127;
5604
- const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils29.hexlify)(r)), BigInt((0, import_utils29.hexlify)(s))).addRecoveryBit(
5665
+ const sig = new import_secp256k1.secp256k1.Signature(BigInt((0, import_utils30.hexlify)(r)), BigInt((0, import_utils30.hexlify)(s))).addRecoveryBit(
5605
5666
  recoveryParam
5606
5667
  );
5607
- const publicKey = sig.recoverPublicKey((0, import_utils29.arrayify)(data)).toRawBytes(false).slice(1);
5608
- return (0, import_utils29.hexlify)(publicKey);
5668
+ const publicKey = sig.recoverPublicKey((0, import_utils30.arrayify)(data)).toRawBytes(false).slice(1);
5669
+ return (0, import_utils30.hexlify)(publicKey);
5609
5670
  }
5610
5671
  /**
5611
5672
  * Recover the address from a signature performed with [`sign`](#sign).
@@ -5624,7 +5685,7 @@ var Signer = class {
5624
5685
  * @returns random 32-byte hashed
5625
5686
  */
5626
5687
  static generatePrivateKey(entropy) {
5627
- return entropy ? (0, import_hasher2.hash)((0, import_utils29.concat)([(0, import_crypto2.randomBytes)(32), (0, import_utils29.arrayify)(entropy)])) : (0, import_crypto2.randomBytes)(32);
5688
+ return entropy ? (0, import_hasher2.hash)((0, import_utils30.concat)([(0, import_crypto3.randomBytes)(32), (0, import_utils30.arrayify)(entropy)])) : (0, import_crypto3.randomBytes)(32);
5628
5689
  }
5629
5690
  /**
5630
5691
  * Extended publicKey from a compact publicKey
@@ -5633,16 +5694,16 @@ var Signer = class {
5633
5694
  * @returns extended publicKey
5634
5695
  */
5635
5696
  static extendPublicKey(publicKey) {
5636
- const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils29.arrayify)(publicKey));
5637
- return (0, import_utils29.hexlify)(point.toRawBytes(false).slice(1));
5697
+ const point = import_secp256k1.secp256k1.ProjectivePoint.fromHex((0, import_utils30.arrayify)(publicKey));
5698
+ return (0, import_utils30.hexlify)(point.toRawBytes(false).slice(1));
5638
5699
  }
5639
5700
  };
5640
5701
 
5641
5702
  // src/wallet/keystore-wallet.ts
5642
5703
  var import_address6 = require("@fuel-ts/address");
5643
- var import_crypto3 = require("@fuel-ts/crypto");
5704
+ var import_crypto4 = require("@fuel-ts/crypto");
5644
5705
  var import_errors17 = require("@fuel-ts/errors");
5645
- var import_utils30 = require("@fuel-ts/utils");
5706
+ var import_utils31 = require("@fuel-ts/utils");
5646
5707
  var import_uuid = require("uuid");
5647
5708
  var DEFAULT_KDF_PARAMS_LOG_N = 13;
5648
5709
  var DEFAULT_KDF_PARAMS_R = 8;
@@ -5656,22 +5717,22 @@ var removeHexPrefix = (hexString) => {
5656
5717
  return hexString;
5657
5718
  };
5658
5719
  async function encryptKeystoreWallet(privateKey, address, password) {
5659
- const privateKeyBuffer = (0, import_crypto3.bufferFromString)(removeHexPrefix(privateKey), "hex");
5720
+ const privateKeyBuffer = (0, import_crypto4.bufferFromString)(removeHexPrefix(privateKey), "hex");
5660
5721
  const ownerAddress = import_address6.Address.fromAddressOrString(address);
5661
- const salt = (0, import_crypto3.randomBytes)(DEFAULT_KEY_SIZE);
5662
- const key = (0, import_crypto3.scrypt)({
5663
- password: (0, import_crypto3.bufferFromString)(password),
5722
+ const salt = (0, import_crypto4.randomBytes)(DEFAULT_KEY_SIZE);
5723
+ const key = (0, import_crypto4.scrypt)({
5724
+ password: (0, import_crypto4.bufferFromString)(password),
5664
5725
  salt,
5665
5726
  dklen: DEFAULT_KEY_SIZE,
5666
5727
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5667
5728
  r: DEFAULT_KDF_PARAMS_R,
5668
5729
  p: DEFAULT_KDF_PARAMS_P
5669
5730
  });
5670
- const iv = (0, import_crypto3.randomBytes)(DEFAULT_IV_SIZE);
5671
- const ciphertext = await (0, import_crypto3.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5731
+ const iv = (0, import_crypto4.randomBytes)(DEFAULT_IV_SIZE);
5732
+ const ciphertext = await (0, import_crypto4.encryptJsonWalletData)(privateKeyBuffer, key, iv);
5672
5733
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
5673
- const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5674
- const mac = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5734
+ const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5735
+ const mac = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
5675
5736
  const keystore = {
5676
5737
  id: (0, import_uuid.v4)(),
5677
5738
  version: 3,
@@ -5679,15 +5740,15 @@ async function encryptKeystoreWallet(privateKey, address, password) {
5679
5740
  crypto: {
5680
5741
  cipher: "aes-128-ctr",
5681
5742
  mac,
5682
- cipherparams: { iv: (0, import_crypto3.stringFromBuffer)(iv, "hex") },
5683
- ciphertext: (0, import_crypto3.stringFromBuffer)(ciphertext, "hex"),
5743
+ cipherparams: { iv: (0, import_crypto4.stringFromBuffer)(iv, "hex") },
5744
+ ciphertext: (0, import_crypto4.stringFromBuffer)(ciphertext, "hex"),
5684
5745
  kdf: "scrypt",
5685
5746
  kdfparams: {
5686
5747
  dklen: DEFAULT_KEY_SIZE,
5687
5748
  n: 2 ** DEFAULT_KDF_PARAMS_LOG_N,
5688
5749
  p: DEFAULT_KDF_PARAMS_P,
5689
5750
  r: DEFAULT_KDF_PARAMS_R,
5690
- salt: (0, import_crypto3.stringFromBuffer)(salt, "hex")
5751
+ salt: (0, import_crypto4.stringFromBuffer)(salt, "hex")
5691
5752
  }
5692
5753
  }
5693
5754
  };
@@ -5703,11 +5764,11 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5703
5764
  kdfparams: { dklen, n, r, p, salt }
5704
5765
  }
5705
5766
  } = keystoreWallet;
5706
- const ciphertextBuffer = (0, import_crypto3.bufferFromString)(ciphertext, "hex");
5707
- const ivBuffer = (0, import_crypto3.bufferFromString)(iv, "hex");
5708
- const saltBuffer = (0, import_crypto3.bufferFromString)(salt, "hex");
5709
- const passwordBuffer = (0, import_crypto3.bufferFromString)(password);
5710
- const key = (0, import_crypto3.scrypt)({
5767
+ const ciphertextBuffer = (0, import_crypto4.bufferFromString)(ciphertext, "hex");
5768
+ const ivBuffer = (0, import_crypto4.bufferFromString)(iv, "hex");
5769
+ const saltBuffer = (0, import_crypto4.bufferFromString)(salt, "hex");
5770
+ const passwordBuffer = (0, import_crypto4.bufferFromString)(password);
5771
+ const key = (0, import_crypto4.scrypt)({
5711
5772
  password: passwordBuffer,
5712
5773
  salt: saltBuffer,
5713
5774
  n,
@@ -5716,16 +5777,16 @@ async function decryptKeystoreWallet(jsonWallet, password) {
5716
5777
  dklen
5717
5778
  });
5718
5779
  const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertextBuffer]);
5719
- const macHashUint8Array = (0, import_crypto3.keccak256)(data);
5720
- const macHash = (0, import_crypto3.stringFromBuffer)(macHashUint8Array, "hex");
5780
+ const macHashUint8Array = (0, import_crypto4.keccak256)(data);
5781
+ const macHash = (0, import_crypto4.stringFromBuffer)(macHashUint8Array, "hex");
5721
5782
  if (mac !== macHash) {
5722
5783
  throw new import_errors17.FuelError(
5723
5784
  import_errors17.ErrorCode.INVALID_PASSWORD,
5724
5785
  "Failed to decrypt the keystore wallet, the provided password is incorrect."
5725
5786
  );
5726
5787
  }
5727
- const buffer = await (0, import_crypto3.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5728
- const privateKey = (0, import_utils30.hexlify)(buffer);
5788
+ const buffer = await (0, import_crypto4.decryptJsonWalletData)(ciphertextBuffer, key, ivBuffer);
5789
+ const privateKey = (0, import_utils31.hexlify)(buffer);
5729
5790
  return privateKey;
5730
5791
  }
5731
5792
 
@@ -5770,7 +5831,7 @@ var BaseWalletUnlocked = class extends Account {
5770
5831
  */
5771
5832
  async signMessage(message) {
5772
5833
  const signedMessage = await this.signer().sign((0, import_hasher3.hashMessage)(message));
5773
- return (0, import_utils31.hexlify)(signedMessage);
5834
+ return (0, import_utils32.hexlify)(signedMessage);
5774
5835
  }
5775
5836
  /**
5776
5837
  * Signs a transaction with the wallet's private key.
@@ -5783,7 +5844,7 @@ var BaseWalletUnlocked = class extends Account {
5783
5844
  const chainId = this.provider.getChainId();
5784
5845
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
5785
5846
  const signature = await this.signer().sign(hashedTransaction);
5786
- return (0, import_utils31.hexlify)(signature);
5847
+ return (0, import_utils32.hexlify)(signature);
5787
5848
  }
5788
5849
  /**
5789
5850
  * Populates a transaction with the witnesses signature.
@@ -5816,7 +5877,7 @@ var BaseWalletUnlocked = class extends Account {
5816
5877
  );
5817
5878
  }
5818
5879
  /**
5819
- * Populates the witness signature for a transaction and sends a call to the network using `provider.call`.
5880
+ * Populates the witness signature for a transaction and sends a call to the network using `provider.dryRun`.
5820
5881
  *
5821
5882
  * @param transactionRequestLike - The transaction request to simulate.
5822
5883
  * @returns A promise that resolves to the CallResult object.
@@ -5826,7 +5887,7 @@ var BaseWalletUnlocked = class extends Account {
5826
5887
  if (estimateTxDependencies) {
5827
5888
  await this.provider.estimateTxDependencies(transactionRequest);
5828
5889
  }
5829
- return this.provider.call(
5890
+ return this.provider.dryRun(
5830
5891
  await this.populateTransactionWitnessesSignature(transactionRequest),
5831
5892
  {
5832
5893
  utxoValidation: true,
@@ -5850,17 +5911,17 @@ var BaseWalletUnlocked = class extends Account {
5850
5911
  __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
5851
5912
 
5852
5913
  // src/hdwallet/hdwallet.ts
5853
- var import_crypto5 = require("@fuel-ts/crypto");
5914
+ var import_crypto6 = require("@fuel-ts/crypto");
5854
5915
  var import_errors20 = require("@fuel-ts/errors");
5855
5916
  var import_hasher6 = require("@fuel-ts/hasher");
5856
5917
  var import_math22 = require("@fuel-ts/math");
5857
- var import_utils35 = require("@fuel-ts/utils");
5918
+ var import_utils36 = require("@fuel-ts/utils");
5858
5919
 
5859
5920
  // src/mnemonic/mnemonic.ts
5860
- var import_crypto4 = require("@fuel-ts/crypto");
5921
+ var import_crypto5 = require("@fuel-ts/crypto");
5861
5922
  var import_errors19 = require("@fuel-ts/errors");
5862
5923
  var import_hasher5 = require("@fuel-ts/hasher");
5863
- var import_utils33 = require("@fuel-ts/utils");
5924
+ var import_utils34 = require("@fuel-ts/utils");
5864
5925
 
5865
5926
  // src/wordlists/words/english.ts
5866
5927
  var english = [
@@ -7917,7 +7978,7 @@ var english = [
7917
7978
  // src/mnemonic/utils.ts
7918
7979
  var import_errors18 = require("@fuel-ts/errors");
7919
7980
  var import_hasher4 = require("@fuel-ts/hasher");
7920
- var import_utils32 = require("@fuel-ts/utils");
7981
+ var import_utils33 = require("@fuel-ts/utils");
7921
7982
  function getLowerMask(bits) {
7922
7983
  return (1 << bits) - 1;
7923
7984
  }
@@ -7952,14 +8013,14 @@ function entropyToMnemonicIndices(entropy) {
7952
8013
  }
7953
8014
  }
7954
8015
  const checksumBits = entropy.length / 4;
7955
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
8016
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy))[0] & getUpperMask(checksumBits);
7956
8017
  indices[indices.length - 1] <<= checksumBits;
7957
8018
  indices[indices.length - 1] |= checksum >> 8 - checksumBits;
7958
8019
  return indices;
7959
8020
  }
7960
8021
  function mnemonicWordsToEntropy(words, wordlist) {
7961
8022
  const size = Math.ceil(11 * words.length / 8);
7962
- const entropy = (0, import_utils32.arrayify)(new Uint8Array(size));
8023
+ const entropy = (0, import_utils33.arrayify)(new Uint8Array(size));
7963
8024
  let offset = 0;
7964
8025
  for (let i = 0; i < words.length; i += 1) {
7965
8026
  const index = wordlist.indexOf(words[i].normalize("NFKD"));
@@ -7979,7 +8040,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7979
8040
  const entropyBits = 32 * words.length / 3;
7980
8041
  const checksumBits = words.length / 3;
7981
8042
  const checksumMask = getUpperMask(checksumBits);
7982
- const checksum = (0, import_utils32.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
8043
+ const checksum = (0, import_utils33.arrayify)((0, import_hasher4.sha256)(entropy.slice(0, entropyBits / 8)))[0] & checksumMask;
7983
8044
  if (checksum !== (entropy[entropy.length - 1] & checksumMask)) {
7984
8045
  throw new import_errors18.FuelError(
7985
8046
  import_errors18.ErrorCode.INVALID_CHECKSUM,
@@ -7990,7 +8051,7 @@ function mnemonicWordsToEntropy(words, wordlist) {
7990
8051
  }
7991
8052
 
7992
8053
  // src/mnemonic/mnemonic.ts
7993
- var MasterSecret = (0, import_utils33.toUtf8Bytes)("Bitcoin seed");
8054
+ var MasterSecret = (0, import_utils34.toUtf8Bytes)("Bitcoin seed");
7994
8055
  var MainnetPRV = "0x0488ade4";
7995
8056
  var TestnetPRV = "0x04358394";
7996
8057
  var MNEMONIC_SIZES = [12, 15, 18, 21, 24];
@@ -8054,7 +8115,7 @@ var Mnemonic = class {
8054
8115
  static mnemonicToEntropy(phrase, wordlist = english) {
8055
8116
  const words = getWords(phrase);
8056
8117
  assertMnemonic(words);
8057
- return (0, import_utils33.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8118
+ return (0, import_utils34.hexlify)(mnemonicWordsToEntropy(words, wordlist));
8058
8119
  }
8059
8120
  /**
8060
8121
  * @param entropy - Entropy source to the mnemonic phrase.
@@ -8062,7 +8123,7 @@ var Mnemonic = class {
8062
8123
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8063
8124
  */
8064
8125
  static entropyToMnemonic(entropy, wordlist = english) {
8065
- const entropyBytes = (0, import_utils33.arrayify)(entropy);
8126
+ const entropyBytes = (0, import_utils34.arrayify)(entropy);
8066
8127
  assertWordList(wordlist);
8067
8128
  assertEntropy(entropyBytes);
8068
8129
  return entropyToMnemonicIndices(entropyBytes).map((i) => wordlist[i]).join(" ");
@@ -8074,9 +8135,9 @@ var Mnemonic = class {
8074
8135
  */
8075
8136
  static mnemonicToSeed(phrase, passphrase = "") {
8076
8137
  assertMnemonic(getWords(phrase));
8077
- const phraseBytes = (0, import_utils33.toUtf8Bytes)(getPhrase(phrase));
8078
- const salt = (0, import_utils33.toUtf8Bytes)(`mnemonic${passphrase}`);
8079
- return (0, import_crypto4.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8138
+ const phraseBytes = (0, import_utils34.toUtf8Bytes)(getPhrase(phrase));
8139
+ const salt = (0, import_utils34.toUtf8Bytes)(`mnemonic${passphrase}`);
8140
+ return (0, import_crypto5.pbkdf2)(phraseBytes, salt, 2048, 64, "sha512");
8080
8141
  }
8081
8142
  /**
8082
8143
  * @param phrase - Mnemonic phrase composed by words from the provided wordlist
@@ -8131,14 +8192,14 @@ var Mnemonic = class {
8131
8192
  * @returns 64-byte array contains privateKey and chainCode as described on BIP39
8132
8193
  */
8133
8194
  static masterKeysFromSeed(seed) {
8134
- const seedArray = (0, import_utils33.arrayify)(seed);
8195
+ const seedArray = (0, import_utils34.arrayify)(seed);
8135
8196
  if (seedArray.length < 16 || seedArray.length > 64) {
8136
8197
  throw new import_errors19.FuelError(
8137
8198
  import_errors19.ErrorCode.INVALID_SEED,
8138
8199
  `Seed length should be between 16 and 64 bytes, but received ${seedArray.length} bytes.`
8139
8200
  );
8140
8201
  }
8141
- return (0, import_utils33.arrayify)((0, import_crypto4.computeHmac)("sha512", MasterSecret, seedArray));
8202
+ return (0, import_utils34.arrayify)((0, import_crypto5.computeHmac)("sha512", MasterSecret, seedArray));
8142
8203
  }
8143
8204
  /**
8144
8205
  * Get the extendKey as defined on BIP-32 from the provided seed
@@ -8149,22 +8210,22 @@ var Mnemonic = class {
8149
8210
  */
8150
8211
  static seedToExtendedKey(seed, testnet = false) {
8151
8212
  const masterKey = Mnemonic.masterKeysFromSeed(seed);
8152
- const prefix = (0, import_utils33.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8213
+ const prefix = (0, import_utils34.arrayify)(testnet ? TestnetPRV : MainnetPRV);
8153
8214
  const depth = "0x00";
8154
8215
  const fingerprint = "0x00000000";
8155
8216
  const index = "0x00000000";
8156
8217
  const chainCode = masterKey.slice(32);
8157
8218
  const privateKey = masterKey.slice(0, 32);
8158
- const extendedKey = (0, import_utils33.concat)([
8219
+ const extendedKey = (0, import_utils34.concat)([
8159
8220
  prefix,
8160
8221
  depth,
8161
8222
  fingerprint,
8162
8223
  index,
8163
8224
  chainCode,
8164
- (0, import_utils33.concat)(["0x00", privateKey])
8225
+ (0, import_utils34.concat)(["0x00", privateKey])
8165
8226
  ]);
8166
- const checksum = (0, import_utils33.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8167
- return (0, import_utils33.encodeBase58)((0, import_utils33.concat)([extendedKey, checksum]));
8227
+ const checksum = (0, import_utils34.dataSlice)((0, import_hasher5.sha256)((0, import_hasher5.sha256)(extendedKey)), 0, 4);
8228
+ return (0, import_utils34.encodeBase58)((0, import_utils34.concat)([extendedKey, checksum]));
8168
8229
  }
8169
8230
  /**
8170
8231
  * Create a new mnemonic using a randomly generated number as entropy.
@@ -8179,7 +8240,7 @@ var Mnemonic = class {
8179
8240
  * @returns A randomly generated mnemonic
8180
8241
  */
8181
8242
  static generate(size = 32, extraEntropy = "") {
8182
- const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils33.concat)([(0, import_crypto4.randomBytes)(size), (0, import_utils33.arrayify)(extraEntropy)])) : (0, import_crypto4.randomBytes)(size);
8243
+ const entropy = extraEntropy ? (0, import_hasher5.sha256)((0, import_utils34.concat)([(0, import_crypto5.randomBytes)(size), (0, import_utils34.arrayify)(extraEntropy)])) : (0, import_crypto5.randomBytes)(size);
8183
8244
  return Mnemonic.entropyToMnemonic(entropy);
8184
8245
  }
8185
8246
  };
@@ -8187,12 +8248,12 @@ var mnemonic_default = Mnemonic;
8187
8248
 
8188
8249
  // src/hdwallet/hdwallet.ts
8189
8250
  var HARDENED_INDEX = 2147483648;
8190
- var MainnetPRV2 = (0, import_utils35.hexlify)("0x0488ade4");
8191
- var MainnetPUB = (0, import_utils35.hexlify)("0x0488b21e");
8192
- var TestnetPRV2 = (0, import_utils35.hexlify)("0x04358394");
8193
- var TestnetPUB = (0, import_utils35.hexlify)("0x043587cf");
8251
+ var MainnetPRV2 = (0, import_utils36.hexlify)("0x0488ade4");
8252
+ var MainnetPUB = (0, import_utils36.hexlify)("0x0488b21e");
8253
+ var TestnetPRV2 = (0, import_utils36.hexlify)("0x04358394");
8254
+ var TestnetPUB = (0, import_utils36.hexlify)("0x043587cf");
8194
8255
  function base58check(data) {
8195
- return (0, import_utils35.encodeBase58)((0, import_utils35.concat)([data, (0, import_utils35.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8256
+ return (0, import_utils36.encodeBase58)((0, import_utils36.concat)([data, (0, import_utils36.dataSlice)((0, import_hasher6.sha256)((0, import_hasher6.sha256)(data)), 0, 4)]));
8196
8257
  }
8197
8258
  function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8198
8259
  if (isPublic) {
@@ -8201,11 +8262,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
8201
8262
  return testnet ? TestnetPRV2 : MainnetPRV2;
8202
8263
  }
8203
8264
  function isPublicExtendedKey(extendedKey) {
8204
- return [MainnetPUB, TestnetPUB].includes((0, import_utils35.hexlify)(extendedKey.slice(0, 4)));
8265
+ return [MainnetPUB, TestnetPUB].includes((0, import_utils36.hexlify)(extendedKey.slice(0, 4)));
8205
8266
  }
8206
8267
  function isValidExtendedKey(extendedKey) {
8207
8268
  return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
8208
- (0, import_utils35.hexlify)(extendedKey.slice(0, 4))
8269
+ (0, import_utils36.hexlify)(extendedKey.slice(0, 4))
8209
8270
  );
8210
8271
  }
8211
8272
  function parsePath(path2, depth = 0) {
@@ -8223,8 +8284,8 @@ function parsePath(path2, depth = 0) {
8223
8284
  var HDWallet = class {
8224
8285
  depth = 0;
8225
8286
  index = 0;
8226
- fingerprint = (0, import_utils35.hexlify)("0x00000000");
8227
- parentFingerprint = (0, import_utils35.hexlify)("0x00000000");
8287
+ fingerprint = (0, import_utils36.hexlify)("0x00000000");
8288
+ parentFingerprint = (0, import_utils36.hexlify)("0x00000000");
8228
8289
  privateKey;
8229
8290
  publicKey;
8230
8291
  chainCode;
@@ -8236,8 +8297,8 @@ var HDWallet = class {
8236
8297
  constructor(config) {
8237
8298
  if (config.privateKey) {
8238
8299
  const signer = new Signer(config.privateKey);
8239
- this.publicKey = (0, import_utils35.hexlify)(signer.compressedPublicKey);
8240
- this.privateKey = (0, import_utils35.hexlify)(config.privateKey);
8300
+ this.publicKey = (0, import_utils36.hexlify)(signer.compressedPublicKey);
8301
+ this.privateKey = (0, import_utils36.hexlify)(config.privateKey);
8241
8302
  } else {
8242
8303
  if (!config.publicKey) {
8243
8304
  throw new import_errors20.FuelError(
@@ -8245,10 +8306,10 @@ var HDWallet = class {
8245
8306
  "Both public and private Key cannot be missing. At least one should be provided."
8246
8307
  );
8247
8308
  }
8248
- this.publicKey = (0, import_utils35.hexlify)(config.publicKey);
8309
+ this.publicKey = (0, import_utils36.hexlify)(config.publicKey);
8249
8310
  }
8250
8311
  this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
8251
- this.fingerprint = (0, import_utils35.dataSlice)((0, import_crypto5.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8312
+ this.fingerprint = (0, import_utils36.dataSlice)((0, import_crypto6.ripemd160)((0, import_hasher6.sha256)(this.publicKey)), 0, 4);
8252
8313
  this.depth = config.depth || this.depth;
8253
8314
  this.index = config.index || this.index;
8254
8315
  this.chainCode = config.chainCode;
@@ -8264,9 +8325,9 @@ var HDWallet = class {
8264
8325
  * @returns A new instance of HDWallet on the derived index
8265
8326
  */
8266
8327
  deriveIndex(index) {
8267
- const privateKey = this.privateKey && (0, import_utils35.arrayify)(this.privateKey);
8268
- const publicKey = (0, import_utils35.arrayify)(this.publicKey);
8269
- const chainCode = (0, import_utils35.arrayify)(this.chainCode);
8328
+ const privateKey = this.privateKey && (0, import_utils36.arrayify)(this.privateKey);
8329
+ const publicKey = (0, import_utils36.arrayify)(this.publicKey);
8330
+ const chainCode = (0, import_utils36.arrayify)(this.chainCode);
8270
8331
  const data = new Uint8Array(37);
8271
8332
  if (index & HARDENED_INDEX) {
8272
8333
  if (!privateKey) {
@@ -8277,10 +8338,10 @@ var HDWallet = class {
8277
8338
  }
8278
8339
  data.set(privateKey, 1);
8279
8340
  } else {
8280
- data.set((0, import_utils35.arrayify)(this.publicKey));
8341
+ data.set((0, import_utils36.arrayify)(this.publicKey));
8281
8342
  }
8282
8343
  data.set((0, import_math22.toBytes)(index, 4), 33);
8283
- const bytes = (0, import_utils35.arrayify)((0, import_crypto5.computeHmac)("sha512", chainCode, data));
8344
+ const bytes = (0, import_utils36.arrayify)((0, import_crypto6.computeHmac)("sha512", chainCode, data));
8284
8345
  const IL = bytes.slice(0, 32);
8285
8346
  const IR = bytes.slice(32);
8286
8347
  if (privateKey) {
@@ -8294,7 +8355,7 @@ var HDWallet = class {
8294
8355
  parentFingerprint: this.fingerprint
8295
8356
  });
8296
8357
  }
8297
- const signer = new Signer((0, import_utils35.hexlify)(IL));
8358
+ const signer = new Signer((0, import_utils36.hexlify)(IL));
8298
8359
  const Ki = signer.addPoint(publicKey);
8299
8360
  return new HDWallet({
8300
8361
  publicKey: Ki,
@@ -8329,12 +8390,12 @@ var HDWallet = class {
8329
8390
  );
8330
8391
  }
8331
8392
  const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
8332
- const depth = (0, import_utils35.hexlify)(Uint8Array.from([this.depth]));
8393
+ const depth = (0, import_utils36.hexlify)(Uint8Array.from([this.depth]));
8333
8394
  const parentFingerprint = this.parentFingerprint;
8334
8395
  const index = (0, import_math22.toHex)(this.index, 4);
8335
8396
  const chainCode = this.chainCode;
8336
- const key = this.privateKey != null && !isPublic ? (0, import_utils35.concat)(["0x00", this.privateKey]) : this.publicKey;
8337
- const extendedKey = (0, import_utils35.arrayify)((0, import_utils35.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8397
+ const key = this.privateKey != null && !isPublic ? (0, import_utils36.concat)(["0x00", this.privateKey]) : this.publicKey;
8398
+ const extendedKey = (0, import_utils36.arrayify)((0, import_utils36.concat)([prefix, depth, parentFingerprint, index, chainCode, key]));
8338
8399
  return base58check(extendedKey);
8339
8400
  }
8340
8401
  /**
@@ -8346,13 +8407,13 @@ var HDWallet = class {
8346
8407
  static fromSeed(seed) {
8347
8408
  const masterKey = mnemonic_default.masterKeysFromSeed(seed);
8348
8409
  return new HDWallet({
8349
- chainCode: (0, import_utils35.arrayify)(masterKey.slice(32)),
8350
- privateKey: (0, import_utils35.arrayify)(masterKey.slice(0, 32))
8410
+ chainCode: (0, import_utils36.arrayify)(masterKey.slice(32)),
8411
+ privateKey: (0, import_utils36.arrayify)(masterKey.slice(0, 32))
8351
8412
  });
8352
8413
  }
8353
8414
  static fromExtendedKey(extendedKey) {
8354
- const decoded = (0, import_utils35.hexlify)((0, import_math22.toBytes)((0, import_utils35.decodeBase58)(extendedKey)));
8355
- const bytes = (0, import_utils35.arrayify)(decoded);
8415
+ const decoded = (0, import_utils36.hexlify)((0, import_math22.toBytes)((0, import_utils36.decodeBase58)(extendedKey)));
8416
+ const bytes = (0, import_utils36.arrayify)(decoded);
8356
8417
  const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
8357
8418
  if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
8358
8419
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key is not a valid extended key.");
@@ -8361,9 +8422,9 @@ var HDWallet = class {
8361
8422
  throw new import_errors20.FuelError(import_errors20.ErrorCode.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
8362
8423
  }
8363
8424
  const depth = bytes[4];
8364
- const parentFingerprint = (0, import_utils35.hexlify)(bytes.slice(5, 9));
8365
- const index = parseInt((0, import_utils35.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8366
- const chainCode = (0, import_utils35.hexlify)(bytes.slice(13, 45));
8425
+ const parentFingerprint = (0, import_utils36.hexlify)(bytes.slice(5, 9));
8426
+ const index = parseInt((0, import_utils36.hexlify)(bytes.slice(9, 13)).substring(2), 16);
8427
+ const chainCode = (0, import_utils36.hexlify)(bytes.slice(13, 45));
8367
8428
  const key = bytes.slice(45, 78);
8368
8429
  if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
8369
8430
  throw new import_errors20.FuelError(
@@ -8550,11 +8611,11 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
8550
8611
  __publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
8551
8612
 
8552
8613
  // src/test-utils/seedTestWallet.ts
8553
- var import_crypto6 = require("@fuel-ts/crypto");
8614
+ var import_crypto7 = require("@fuel-ts/crypto");
8554
8615
  var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
8555
8616
  const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
8556
8617
  const [{ provider }] = accountsToBeFunded;
8557
- const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto6.randomBytes)(32), provider);
8618
+ const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || (0, import_crypto7.randomBytes)(32), provider);
8558
8619
  const request = new ScriptTransactionRequest();
8559
8620
  quantities.map(coinQuantityfy).forEach(
8560
8621
  ({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
@@ -8580,11 +8641,11 @@ var generateTestWallet = async (provider, quantities) => {
8580
8641
  };
8581
8642
 
8582
8643
  // src/test-utils/launchNode.ts
8583
- var import_abi_coder7 = require("@fuel-ts/abi-coder");
8584
- var import_crypto7 = require("@fuel-ts/crypto");
8585
- var import_utils36 = require("@fuel-ts/utils");
8586
- var import_child_process = require("child_process");
8587
- var import_crypto8 = require("crypto");
8644
+ var import_abi_coder8 = require("@fuel-ts/abi-coder");
8645
+ var import_crypto8 = require("@fuel-ts/crypto");
8646
+ var import_errors21 = require("@fuel-ts/errors");
8647
+ var import_utils37 = require("@fuel-ts/utils");
8648
+ var import_crypto9 = require("crypto");
8588
8649
  var import_fs = require("fs");
8589
8650
  var import_os = __toESM(require("os"));
8590
8651
  var import_path = __toESM(require("path"));
@@ -8614,22 +8675,55 @@ var killNode = (params) => {
8614
8675
  state.isDead = true;
8615
8676
  killFn(Number(child.pid));
8616
8677
  }
8617
- child.stdout.removeAllListeners();
8618
8678
  child.stderr.removeAllListeners();
8619
8679
  if ((0, import_fs.existsSync)(configPath)) {
8620
8680
  (0, import_fs.rmSync)(configPath, { recursive: true });
8621
8681
  }
8622
8682
  }
8623
8683
  };
8684
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8685
+ const defaultCoins = import_utils37.defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8686
+ ...coin,
8687
+ amount: "18446744073709551615"
8688
+ }));
8689
+ const defaultMessages = import_utils37.defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8690
+ ...message,
8691
+ amount: "18446744073709551615"
8692
+ }));
8693
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
8694
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
8695
+ if (!process.env.GENESIS_SECRET) {
8696
+ const pk = Signer.generatePrivateKey();
8697
+ const signer = new Signer(pk);
8698
+ process.env.GENESIS_SECRET = (0, import_utils37.hexlify)(pk);
8699
+ coins.push({
8700
+ tx_id: (0, import_utils37.hexlify)((0, import_crypto8.randomBytes)(import_abi_coder8.BYTES_32)),
8701
+ owner: signer.address.toHexString(),
8702
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8703
+ amount: "18446744073709551615",
8704
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8705
+ output_index: 0,
8706
+ tx_pointer_block_height: 0,
8707
+ tx_pointer_tx_idx: 0
8708
+ });
8709
+ }
8710
+ const json = JSON.stringify({
8711
+ ...stateConfig,
8712
+ coins,
8713
+ messages
8714
+ });
8715
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8716
+ return json.replace(regexMakeNumber, "$1$2");
8717
+ }
8624
8718
  var launchNode = async ({
8625
8719
  ip,
8626
8720
  port,
8627
8721
  args = [],
8628
- fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
8722
+ fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
8629
8723
  loggingEnabled = true,
8630
- debugEnabled = false,
8631
- basePath
8632
- }) => (
8724
+ basePath,
8725
+ snapshotConfig = import_utils37.defaultSnapshotConfigs
8726
+ } = {}) => (
8633
8727
  // eslint-disable-next-line no-async-promise-executor
8634
8728
  new Promise(async (resolve, reject) => {
8635
8729
  const remainingArgs = extractRemainingArgs(args, [
@@ -8639,14 +8733,14 @@ var launchNode = async ({
8639
8733
  "--poa-instant"
8640
8734
  ]);
8641
8735
  const snapshotDir = getFlagValueFromArgs(args, "--snapshot");
8642
- const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils36.defaultConsensusKey;
8736
+ const consensusKey = getFlagValueFromArgs(args, "--consensus-key") || import_utils37.defaultConsensusKey;
8643
8737
  const dbTypeFlagValue = getFlagValueFromArgs(args, "--db-type");
8644
8738
  const useInMemoryDb = dbTypeFlagValue === "in-memory" || dbTypeFlagValue === void 0;
8645
8739
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8646
8740
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8647
8741
  const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
8648
8742
  const graphQLStartSubstring = "Binding GraphQL provider to";
8649
- const command = fuelCorePath ?? "fuel-core";
8743
+ const command = fuelCorePath || "fuel-core";
8650
8744
  const ipToUse = ip || "0.0.0.0";
8651
8745
  const portToUse = port || (await (0, import_portfinder.getPortPromise)({
8652
8746
  port: 4e3,
@@ -8656,65 +8750,33 @@ var launchNode = async ({
8656
8750
  })).toString();
8657
8751
  let snapshotDirToUse;
8658
8752
  const prefix = basePath || import_os.default.tmpdir();
8659
- const suffix = basePath ? "" : (0, import_crypto8.randomUUID)();
8660
- const tempDirPath = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8753
+ const suffix = basePath ? "" : (0, import_crypto9.randomUUID)();
8754
+ const tempDir = import_path.default.join(prefix, ".fuels", suffix, "snapshotDir");
8661
8755
  if (snapshotDir) {
8662
8756
  snapshotDirToUse = snapshotDir;
8663
8757
  } else {
8664
- if (!(0, import_fs.existsSync)(tempDirPath)) {
8665
- (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
8666
- }
8667
- let { stateConfigJson } = import_utils36.defaultSnapshotConfigs;
8668
- const { chainConfigJson, metadataJson } = import_utils36.defaultSnapshotConfigs;
8669
- stateConfigJson = {
8670
- ...stateConfigJson,
8671
- coins: [
8672
- ...stateConfigJson.coins.map((coin) => ({
8673
- ...coin,
8674
- amount: "18446744073709551615"
8675
- }))
8676
- ],
8677
- messages: stateConfigJson.messages.map((message) => ({
8678
- ...message,
8679
- amount: "18446744073709551615"
8680
- }))
8681
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8682
- };
8683
- if (!process.env.GENESIS_SECRET) {
8684
- const pk = Signer.generatePrivateKey();
8685
- const signer = new Signer(pk);
8686
- process.env.GENESIS_SECRET = (0, import_utils36.hexlify)(pk);
8687
- stateConfigJson.coins.push({
8688
- tx_id: (0, import_utils36.hexlify)((0, import_crypto7.randomBytes)(import_abi_coder7.BYTES_32)),
8689
- owner: signer.address.toHexString(),
8690
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8691
- amount: "18446744073709551615",
8692
- asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8693
- output_index: 0,
8694
- tx_pointer_block_height: 0,
8695
- tx_pointer_tx_idx: 0
8696
- });
8758
+ if (!(0, import_fs.existsSync)(tempDir)) {
8759
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
8697
8760
  }
8698
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8699
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8700
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8701
- const chainConfigWritePath = import_path.default.join(tempDirPath, "chainConfig.json");
8702
- const stateConfigWritePath = import_path.default.join(tempDirPath, "stateConfig.json");
8703
- const metadataWritePath = import_path.default.join(tempDirPath, "metadata.json");
8704
- const stateTransitionWritePath = import_path.default.join(tempDirPath, "state_transition_bytecode.wasm");
8705
- (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8706
- (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8707
- (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8708
- (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
8709
- snapshotDirToUse = tempDirPath;
8710
- }
8711
- const child = (0, import_child_process.spawn)(
8761
+ const { metadata } = snapshotConfig;
8762
+ const metadataPath = import_path.default.join(tempDir, "metadata.json");
8763
+ const chainConfigPath = import_path.default.join(tempDir, metadata.chain_config);
8764
+ const stateConfigPath = import_path.default.join(tempDir, metadata.table_encoding.Json.filepath);
8765
+ const stateTransitionPath = import_path.default.join(tempDir, "state_transition_bytecode.wasm");
8766
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8767
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8768
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
8769
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
8770
+ snapshotDirToUse = tempDir;
8771
+ }
8772
+ const { spawn } = await import("child_process");
8773
+ const child = spawn(
8712
8774
  command,
8713
8775
  [
8714
8776
  "run",
8715
8777
  ["--ip", ipToUse],
8716
8778
  ["--port", portToUse],
8717
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8779
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8718
8780
  ["--min-gas-price", "1"],
8719
8781
  poaInstant ? ["--poa-instant", "true"] : [],
8720
8782
  ["--native-executor-version", nativeExecutorVersion],
@@ -8725,35 +8787,38 @@ var launchNode = async ({
8725
8787
  "--debug",
8726
8788
  ...remainingArgs
8727
8789
  ].flat(),
8728
- {
8729
- stdio: "pipe"
8730
- }
8790
+ { stdio: "pipe" }
8731
8791
  );
8732
8792
  if (loggingEnabled) {
8733
- child.stderr.pipe(process.stderr);
8734
- }
8735
- if (debugEnabled) {
8736
- child.stdout.pipe(process.stdout);
8793
+ child.stderr.on("data", (chunk) => {
8794
+ console.log(chunk.toString());
8795
+ });
8737
8796
  }
8738
8797
  const cleanupConfig = {
8739
8798
  child,
8740
- configPath: tempDirPath,
8799
+ configPath: tempDir,
8741
8800
  killFn: import_tree_kill.default,
8742
8801
  state: {
8743
8802
  isDead: false
8744
8803
  }
8745
8804
  };
8746
8805
  child.stderr.on("data", (chunk) => {
8747
- if (chunk.indexOf(graphQLStartSubstring) !== -1) {
8806
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
8807
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
8808
+ const rows = text.split("\n");
8809
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8810
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8748
8811
  resolve({
8749
8812
  cleanup: () => killNode(cleanupConfig),
8750
- ip: ipToUse,
8751
- port: portToUse,
8813
+ ip: realIp,
8814
+ port: realPort,
8815
+ url: `http://${realIp}:${realPort}/v1/graphql`,
8752
8816
  snapshotDir: snapshotDirToUse
8753
8817
  });
8754
8818
  }
8755
- if (/error/i.test(chunk)) {
8756
- reject(chunk.toString());
8819
+ if (/error/i.test(text)) {
8820
+ console.log(text);
8821
+ reject(new import_errors21.FuelError(import_errors21.FuelError.CODES.NODE_LAUNCH_FAILED, text));
8757
8822
  }
8758
8823
  });
8759
8824
  process.on("exit", () => killNode(cleanupConfig));
@@ -8786,12 +8851,259 @@ var launchNodeAndGetWallets = async ({
8786
8851
  };
8787
8852
  return { wallets, stop: cleanup, provider };
8788
8853
  };
8854
+
8855
+ // src/test-utils/setup-test-provider-and-wallets.ts
8856
+ var import_utils40 = require("@fuel-ts/utils");
8857
+ var import_ramda5 = require("ramda");
8858
+
8859
+ // src/test-utils/asset-id.ts
8860
+ var import_crypto10 = require("@fuel-ts/crypto");
8861
+ var import_utils38 = require("@fuel-ts/utils");
8862
+ var _AssetId = class {
8863
+ constructor(value) {
8864
+ this.value = value;
8865
+ }
8866
+ static random(count = 1) {
8867
+ const assetIds = [];
8868
+ for (let i = 0; i < count; i++) {
8869
+ assetIds.push(new _AssetId((0, import_utils38.hexlify)((0, import_crypto10.randomBytes)(32))));
8870
+ }
8871
+ return assetIds;
8872
+ }
8873
+ };
8874
+ var AssetId = _AssetId;
8875
+ __publicField(AssetId, "A", new _AssetId(
8876
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
8877
+ ));
8878
+ __publicField(AssetId, "B", new _AssetId(
8879
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
8880
+ ));
8881
+
8882
+ // src/test-utils/wallet-config.ts
8883
+ var import_crypto11 = require("@fuel-ts/crypto");
8884
+ var import_errors22 = require("@fuel-ts/errors");
8885
+ var import_utils39 = require("@fuel-ts/utils");
8886
+ var WalletsConfig = class {
8887
+ initialState;
8888
+ options;
8889
+ wallets;
8890
+ generateWallets = () => {
8891
+ const generatedWallets = [];
8892
+ for (let index = 1; index <= this.options.count; index++) {
8893
+ generatedWallets.push(new WalletUnlocked((0, import_crypto11.randomBytes)(32)));
8894
+ }
8895
+ return generatedWallets;
8896
+ };
8897
+ constructor(baseAssetId, config) {
8898
+ WalletsConfig.validate(config);
8899
+ this.options = config;
8900
+ const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8901
+ this.wallets = this.generateWallets();
8902
+ this.initialState = {
8903
+ messages: WalletsConfig.createMessages(this.wallets, messages),
8904
+ coins: WalletsConfig.createCoins(
8905
+ this.wallets,
8906
+ baseAssetId,
8907
+ assets2,
8908
+ coinsPerAsset,
8909
+ amountPerCoin
8910
+ )
8911
+ };
8912
+ }
8913
+ apply(snapshotConfig) {
8914
+ return {
8915
+ ...snapshotConfig,
8916
+ stateConfig: {
8917
+ ...snapshotConfig?.stateConfig ?? import_utils39.defaultSnapshotConfigs.stateConfig,
8918
+ coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8919
+ messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8920
+ }
8921
+ };
8922
+ }
8923
+ /**
8924
+ * Create messages for the wallets in the format that the chain expects.
8925
+ */
8926
+ static createMessages(wallets, messages) {
8927
+ return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8928
+ }
8929
+ /**
8930
+ * Create coins for the wallets in the format that the chain expects.
8931
+ */
8932
+ static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
8933
+ const coins = [];
8934
+ let assetIds = [baseAssetId];
8935
+ if (Array.isArray(assets2)) {
8936
+ assetIds = assetIds.concat(assets2.map((a) => a.value));
8937
+ } else {
8938
+ assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
8939
+ }
8940
+ wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8941
+ assetIds.forEach((assetId) => {
8942
+ for (let index = 0; index < coinsPerAsset; index++) {
8943
+ coins.push({
8944
+ amount: amountPerCoin,
8945
+ asset_id: assetId,
8946
+ owner: walletAddress,
8947
+ tx_pointer_block_height: 0,
8948
+ tx_pointer_tx_idx: 0,
8949
+ output_index: 0,
8950
+ tx_id: (0, import_utils39.hexlify)((0, import_crypto11.randomBytes)(32))
8951
+ });
8952
+ }
8953
+ });
8954
+ });
8955
+ return coins;
8956
+ }
8957
+ static validate({
8958
+ count: wallets,
8959
+ assets: assets2,
8960
+ coinsPerAsset,
8961
+ amountPerCoin
8962
+ }) {
8963
+ if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8964
+ throw new import_errors22.FuelError(
8965
+ import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8966
+ "Number of wallets must be greater than zero."
8967
+ );
8968
+ }
8969
+ if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8970
+ throw new import_errors22.FuelError(
8971
+ import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8972
+ "Number of assets per wallet must be greater than zero."
8973
+ );
8974
+ }
8975
+ if (coinsPerAsset <= 0) {
8976
+ throw new import_errors22.FuelError(
8977
+ import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8978
+ "Number of coins per asset must be greater than zero."
8979
+ );
8980
+ }
8981
+ if (amountPerCoin <= 0) {
8982
+ throw new import_errors22.FuelError(
8983
+ import_errors22.FuelError.CODES.INVALID_INPUT_PARAMETERS,
8984
+ "Amount per coin must be greater than zero."
8985
+ );
8986
+ }
8987
+ }
8988
+ };
8989
+
8990
+ // src/test-utils/setup-test-provider-and-wallets.ts
8991
+ var defaultWalletConfigOptions = {
8992
+ count: 2,
8993
+ assets: [AssetId.A, AssetId.B],
8994
+ coinsPerAsset: 1,
8995
+ amountPerCoin: 1e10,
8996
+ messages: []
8997
+ };
8998
+ async function setupTestProviderAndWallets({
8999
+ walletsConfig: walletsConfigOptions = {},
9000
+ providerOptions,
9001
+ nodeOptions = {},
9002
+ launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || void 0
9003
+ } = {}) {
9004
+ Symbol.dispose ??= Symbol("Symbol.dispose");
9005
+ const walletsConfig = new WalletsConfig(
9006
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? import_utils40.defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
9007
+ {
9008
+ ...defaultWalletConfigOptions,
9009
+ ...walletsConfigOptions
9010
+ }
9011
+ );
9012
+ const launchNodeOptions = {
9013
+ loggingEnabled: false,
9014
+ ...nodeOptions,
9015
+ snapshotConfig: (0, import_ramda5.mergeDeepRight)(
9016
+ import_utils40.defaultSnapshotConfigs,
9017
+ walletsConfig.apply(nodeOptions?.snapshotConfig)
9018
+ ),
9019
+ port: "0"
9020
+ };
9021
+ let cleanup;
9022
+ let url;
9023
+ if (launchNodeServerPort) {
9024
+ const serverUrl = `http://localhost:${launchNodeServerPort}`;
9025
+ url = await (await fetch(serverUrl, { method: "POST", body: JSON.stringify(launchNodeOptions) })).text();
9026
+ cleanup = () => {
9027
+ fetch(`${serverUrl}/cleanup/${url}`);
9028
+ };
9029
+ } else {
9030
+ const settings = await launchNode(launchNodeOptions);
9031
+ url = settings.url;
9032
+ cleanup = settings.cleanup;
9033
+ }
9034
+ let provider;
9035
+ try {
9036
+ provider = await Provider.create(url, providerOptions);
9037
+ } catch (err) {
9038
+ cleanup();
9039
+ throw err;
9040
+ }
9041
+ const wallets = walletsConfig.wallets;
9042
+ wallets.forEach((wallet) => {
9043
+ wallet.connect(provider);
9044
+ });
9045
+ return {
9046
+ provider,
9047
+ wallets,
9048
+ cleanup,
9049
+ [Symbol.dispose]: cleanup
9050
+ };
9051
+ }
9052
+
9053
+ // src/test-utils/test-message.ts
9054
+ var import_address7 = require("@fuel-ts/address");
9055
+ var import_crypto12 = require("@fuel-ts/crypto");
9056
+ var import_math23 = require("@fuel-ts/math");
9057
+ var import_utils41 = require("@fuel-ts/utils");
9058
+ var TestMessage = class {
9059
+ sender;
9060
+ recipient;
9061
+ nonce;
9062
+ amount;
9063
+ data;
9064
+ da_height;
9065
+ /**
9066
+ * A helper class to create messages for testing purposes.
9067
+ *
9068
+ * Used in tandem with `WalletsConfig`.
9069
+ * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
9070
+ */
9071
+ constructor({
9072
+ sender = import_address7.Address.fromRandom(),
9073
+ recipient = import_address7.Address.fromRandom(),
9074
+ nonce = (0, import_utils41.hexlify)((0, import_crypto12.randomBytes)(32)),
9075
+ amount = 1e6,
9076
+ data = "02",
9077
+ da_height = 0
9078
+ } = {}) {
9079
+ this.sender = sender;
9080
+ this.recipient = recipient;
9081
+ this.nonce = nonce;
9082
+ this.amount = amount;
9083
+ this.data = data;
9084
+ this.da_height = da_height;
9085
+ }
9086
+ toChainMessage(recipient) {
9087
+ return {
9088
+ sender: this.sender.toB256(),
9089
+ recipient: recipient?.toB256() ?? this.recipient.toB256(),
9090
+ nonce: this.nonce,
9091
+ amount: (0, import_math23.bn)(this.amount).toNumber(),
9092
+ data: this.data,
9093
+ da_height: this.da_height
9094
+ };
9095
+ }
9096
+ };
8789
9097
  // Annotate the CommonJS export names for ESM import in node:
8790
9098
  0 && (module.exports = {
9099
+ AssetId,
9100
+ TestMessage,
9101
+ WalletsConfig,
8791
9102
  generateTestWallet,
8792
9103
  killNode,
8793
9104
  launchNode,
8794
9105
  launchNodeAndGetWallets,
8795
- seedTestWallet
9106
+ seedTestWallet,
9107
+ setupTestProviderAndWallets
8796
9108
  });
8797
9109
  //# sourceMappingURL=test-utils.js.map