@fuel-ts/account 0.0.0-rc-1356-20240322130951 → 0.0.0-rc-1815-20240322131329

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 (39) hide show
  1. package/dist/account.d.ts +7 -0
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/connectors/fuel-connector.d.ts +10 -0
  4. package/dist/connectors/fuel-connector.d.ts.map +1 -1
  5. package/dist/index.global.js +75 -13
  6. package/dist/index.global.js.map +1 -1
  7. package/dist/index.js +178 -108
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +76 -7
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/providers/provider.d.ts +3 -2
  12. package/dist/providers/provider.d.ts.map +1 -1
  13. package/dist/providers/transaction-request/transaction-request.d.ts +20 -1
  14. package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
  15. package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
  16. package/dist/providers/utils/index.d.ts +1 -0
  17. package/dist/providers/utils/index.d.ts.map +1 -1
  18. package/dist/providers/utils/sleep.d.ts +3 -0
  19. package/dist/providers/utils/sleep.d.ts.map +1 -0
  20. package/dist/test-utils/index.d.ts +0 -4
  21. package/dist/test-utils/index.d.ts.map +1 -1
  22. package/dist/test-utils/launchNode.d.ts +1 -8
  23. package/dist/test-utils/launchNode.d.ts.map +1 -1
  24. package/dist/test-utils.global.js +75 -329
  25. package/dist/test-utils.global.js.map +1 -1
  26. package/dist/test-utils.js +169 -333
  27. package/dist/test-utils.js.map +1 -1
  28. package/dist/test-utils.mjs +76 -236
  29. package/dist/test-utils.mjs.map +1 -1
  30. package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
  31. package/package.json +16 -17
  32. package/dist/test-utils/asset-id.d.ts +0 -9
  33. package/dist/test-utils/asset-id.d.ts.map +0 -1
  34. package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
  35. package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
  36. package/dist/test-utils/test-message.d.ts +0 -28
  37. package/dist/test-utils/test-message.d.ts.map +0 -1
  38. package/dist/test-utils/wallet-config.d.ts +0 -49
  39. package/dist/test-utils/wallet-config.d.ts.map +0 -1
@@ -32710,13 +32710,6 @@ This unreleased fuel-core build may include features and updates not yet support
32710
32710
  };
32711
32711
  var defaultChainConfig = chainConfig_default;
32712
32712
  var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
32713
- function sleep(time) {
32714
- return new Promise((resolve) => {
32715
- setTimeout(() => {
32716
- resolve(true);
32717
- }, time);
32718
- });
32719
- }
32720
32713
 
32721
32714
  // ../crypto/dist/index.mjs
32722
32715
  var import_crypto8 = __toESM(__require("crypto"), 1);
@@ -38087,72 +38080,11 @@ This unreleased fuel-core build may include features and updates not yet support
38087
38080
  };
38088
38081
  }
38089
38082
 
38090
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
38091
- function _curry2(fn) {
38092
- return function f2(a, b) {
38093
- switch (arguments.length) {
38094
- case 0:
38095
- return f2;
38096
- case 1:
38097
- return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
38098
- return fn(a, _b);
38099
- });
38100
- default:
38101
- return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
38102
- return fn(_a, b);
38103
- }) : _isPlaceholder(b) ? _curry1(function(_b) {
38104
- return fn(a, _b);
38105
- }) : fn(a, b);
38106
- }
38107
- };
38108
- }
38109
-
38110
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
38111
- function _curry3(fn) {
38112
- return function f3(a, b, c) {
38113
- switch (arguments.length) {
38114
- case 0:
38115
- return f3;
38116
- case 1:
38117
- return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
38118
- return fn(a, _b, _c);
38119
- });
38120
- case 2:
38121
- return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
38122
- return fn(_a, b, _c);
38123
- }) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
38124
- return fn(a, _b, _c);
38125
- }) : _curry1(function(_c) {
38126
- return fn(a, b, _c);
38127
- });
38128
- default:
38129
- return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
38130
- return fn(_a, _b, c);
38131
- }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
38132
- return fn(_a, b, _c);
38133
- }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
38134
- return fn(a, _b, _c);
38135
- }) : _isPlaceholder(a) ? _curry1(function(_a) {
38136
- return fn(_a, b, c);
38137
- }) : _isPlaceholder(b) ? _curry1(function(_b) {
38138
- return fn(a, _b, c);
38139
- }) : _isPlaceholder(c) ? _curry1(function(_c) {
38140
- return fn(a, b, _c);
38141
- }) : fn(a, b, c);
38142
- }
38143
- };
38144
- }
38145
-
38146
38083
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
38147
38084
  var isArray_default = Array.isArray || function _isArray(val) {
38148
38085
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
38149
38086
  };
38150
38087
 
38151
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
38152
- function _has(prop, obj) {
38153
- return Object.prototype.hasOwnProperty.call(obj, prop);
38154
- }
38155
-
38156
38088
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
38157
38089
  var type = /* @__PURE__ */ _curry1(function type2(val) {
38158
38090
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -38169,11 +38101,6 @@ This unreleased fuel-core build may include features and updates not yet support
38169
38101
  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";
38170
38102
  };
38171
38103
 
38172
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
38173
- function _isObject(x) {
38174
- return Object.prototype.toString.call(x) === "[object Object]";
38175
- }
38176
-
38177
38104
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
38178
38105
  var isInteger_default = Number.isInteger || function _isInteger(n) {
38179
38106
  return n << 0 === n;
@@ -38287,46 +38214,6 @@ This unreleased fuel-core build may include features and updates not yet support
38287
38214
  });
38288
38215
  var clone_default = clone2;
38289
38216
 
38290
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
38291
- var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
38292
- var result = {};
38293
- var k;
38294
- l = l || {};
38295
- r = r || {};
38296
- for (k in l) {
38297
- if (_has(k, l)) {
38298
- result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
38299
- }
38300
- }
38301
- for (k in r) {
38302
- if (_has(k, r) && !_has(k, result)) {
38303
- result[k] = r[k];
38304
- }
38305
- }
38306
- return result;
38307
- });
38308
- var mergeWithKey_default = mergeWithKey;
38309
-
38310
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
38311
- var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
38312
- return mergeWithKey_default(function(k, lVal, rVal) {
38313
- if (_isObject(lVal) && _isObject(rVal)) {
38314
- return mergeDeepWithKey2(fn, lVal, rVal);
38315
- } else {
38316
- return fn(k, lVal, rVal);
38317
- }
38318
- }, lObj, rObj);
38319
- });
38320
- var mergeDeepWithKey_default = mergeDeepWithKey;
38321
-
38322
- // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
38323
- var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
38324
- return mergeDeepWithKey_default(function(k, lVal, rVal) {
38325
- return rVal;
38326
- }, lObj, rObj);
38327
- });
38328
- var mergeDeepRight_default = mergeDeepRight;
38329
-
38330
38217
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
38331
38218
  var hasProtoTrim = typeof String.prototype.trim === "function";
38332
38219
 
@@ -42858,6 +42745,15 @@ ${MessageCoinFragmentFragmentDoc}`;
42858
42745
  return normalize2(clone_default(root));
42859
42746
  }
42860
42747
 
42748
+ // src/providers/utils/sleep.ts
42749
+ function sleep(time) {
42750
+ return new Promise((resolve) => {
42751
+ setTimeout(() => {
42752
+ resolve(true);
42753
+ }, time);
42754
+ });
42755
+ }
42756
+
42861
42757
  // src/providers/transaction-request/errors.ts
42862
42758
  var NoWitnessAtIndexError = class extends Error {
42863
42759
  constructor(index) {
@@ -42986,13 +42882,27 @@ ${MessageCoinFragmentFragmentDoc}`;
42986
42882
  this.outputs.push(output3);
42987
42883
  return this.outputs.length - 1;
42988
42884
  }
42885
+ /**
42886
+ * @hidden
42887
+ *
42888
+ * Pushes a witness to the list and returns the index
42889
+ *
42890
+ * @param signature - The signature to add to the witness.
42891
+ * @returns The index of the created witness.
42892
+ */
42893
+ addWitness(signature) {
42894
+ this.witnesses.push(signature);
42895
+ return this.witnesses.length - 1;
42896
+ }
42989
42897
  /**
42990
42898
  * @hidden
42991
42899
  *
42992
42900
  * Creates an empty witness without any side effects and returns the index
42901
+ *
42902
+ * @returns The index of the created witness.
42993
42903
  */
42994
- createWitness() {
42995
- this.witnesses.push(concat([ZeroBytes32, ZeroBytes32]));
42904
+ addEmptyWitness() {
42905
+ this.addWitness(concat([ZeroBytes32, ZeroBytes32]));
42996
42906
  return this.witnesses.length - 1;
42997
42907
  }
42998
42908
  /**
@@ -43021,6 +42931,21 @@ ${MessageCoinFragmentFragmentDoc}`;
43021
42931
  }
43022
42932
  this.witnesses[index] = witness;
43023
42933
  }
42934
+ /**
42935
+ * Helper function to add an external signature to the transaction.
42936
+ *
42937
+ * @param account - The account/s to sign to the transaction.
42938
+ * @returns The transaction with the signature witness added.
42939
+ */
42940
+ async addAccountWitnesses(account) {
42941
+ const accounts = Array.isArray(account) ? account : [account];
42942
+ await Promise.all(
42943
+ accounts.map(async (acc) => {
42944
+ this.addWitness(await acc.signTransaction(this));
42945
+ })
42946
+ );
42947
+ return this;
42948
+ }
43024
42949
  /**
43025
42950
  * Gets the coin inputs for a transaction.
43026
42951
  *
@@ -43086,7 +43011,7 @@ ${MessageCoinFragmentFragmentDoc}`;
43086
43011
  } else {
43087
43012
  witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
43088
43013
  if (typeof witnessIndex !== "number") {
43089
- witnessIndex = this.createWitness();
43014
+ witnessIndex = this.addEmptyWitness();
43090
43015
  }
43091
43016
  }
43092
43017
  const input = {
@@ -43120,7 +43045,7 @@ ${MessageCoinFragmentFragmentDoc}`;
43120
43045
  } else {
43121
43046
  witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
43122
43047
  if (typeof witnessIndex !== "number") {
43123
- witnessIndex = this.createWitness();
43048
+ witnessIndex = this.addEmptyWitness();
43124
43049
  }
43125
43050
  }
43126
43051
  const input = {
@@ -45094,7 +45019,8 @@ ${MessageCoinFragmentFragmentDoc}`;
45094
45019
  async getTransactionCost(transactionRequestLike, forwardingQuantities = [], {
45095
45020
  estimateTxDependencies = true,
45096
45021
  estimatePredicates = true,
45097
- resourcesOwner
45022
+ resourcesOwner,
45023
+ signatureCallback
45098
45024
  } = {}) {
45099
45025
  const txRequestClone = clone_default(transactionRequestify(transactionRequestLike));
45100
45026
  const chainInfo = this.getChain();
@@ -45113,6 +45039,9 @@ ${MessageCoinFragmentFragmentDoc}`;
45113
45039
  }
45114
45040
  await this.estimatePredicates(txRequestClone);
45115
45041
  }
45042
+ if (signatureCallback && isScriptTransaction) {
45043
+ await signatureCallback(txRequestClone);
45044
+ }
45116
45045
  const minGas = txRequestClone.calculateMinGas(chainInfo);
45117
45046
  const maxGas = txRequestClone.calculateMaxGas(chainInfo, minGas);
45118
45047
  let receipts = [];
@@ -45985,6 +45914,21 @@ ${MessageCoinFragmentFragmentDoc}`;
45985
45914
  }
45986
45915
  return this._connector.signMessage(this.address.toString(), message);
45987
45916
  }
45917
+ /**
45918
+ * Signs a transaction with the wallet's private key.
45919
+ *
45920
+ * @param transactionRequestLike - The transaction request to sign.
45921
+ * @returns A promise that resolves to the signature of the transaction.
45922
+ */
45923
+ async signTransaction(transactionRequestLike) {
45924
+ if (!this._connector) {
45925
+ throw new FuelError(
45926
+ ErrorCode.MISSING_CONNECTOR,
45927
+ "A connector is required to sign transactions."
45928
+ );
45929
+ }
45930
+ return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
45931
+ }
45988
45932
  /**
45989
45933
  * Sends a transaction to the network.
45990
45934
  *
@@ -47596,7 +47540,7 @@ ${MessageCoinFragmentFragmentDoc}`;
47596
47540
  */
47597
47541
  async signTransaction(transactionRequestLike) {
47598
47542
  const transactionRequest = transactionRequestify(transactionRequestLike);
47599
- const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
47543
+ const chainId = this.provider.getChainId();
47600
47544
  const hashedTransaction = transactionRequest.getTransactionId(chainId);
47601
47545
  const signature = await this.signer().sign(hashedTransaction);
47602
47546
  return hexlify(signature);
@@ -50460,8 +50404,7 @@ ${MessageCoinFragmentFragmentDoc}`;
50460
50404
  useSystemFuelCore = false,
50461
50405
  loggingEnabled = true,
50462
50406
  debugEnabled = false,
50463
- basePath,
50464
- chainConfig = defaultChainConfig
50407
+ basePath
50465
50408
  }) => (
50466
50409
  // eslint-disable-next-line no-async-promise-executor
50467
50410
  new Promise(async (resolve, reject) => {
@@ -50498,17 +50441,17 @@ ${MessageCoinFragmentFragmentDoc}`;
50498
50441
  (0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
50499
50442
  }
50500
50443
  const tempChainConfigFilePath = import_path8.default.join(tempDirPath, "chainConfig.json");
50501
- let generatedChainConfig = chainConfig;
50444
+ let chainConfig = defaultChainConfig;
50502
50445
  if (!process.env.GENESIS_SECRET) {
50503
50446
  const pk = Signer.generatePrivateKey();
50504
50447
  const signer = new Signer(pk);
50505
50448
  process.env.GENESIS_SECRET = hexlify(pk);
50506
- generatedChainConfig = {
50507
- ...generatedChainConfig,
50449
+ chainConfig = {
50450
+ ...defaultChainConfig,
50508
50451
  initial_state: {
50509
- ...generatedChainConfig.initial_state,
50452
+ ...defaultChainConfig.initial_state,
50510
50453
  coins: [
50511
- ...generatedChainConfig.initial_state.coins,
50454
+ ...defaultChainConfig.initial_state.coins,
50512
50455
  {
50513
50456
  owner: signer.address.toHexString(),
50514
50457
  amount: toHex(1e9),
@@ -50518,7 +50461,7 @@ ${MessageCoinFragmentFragmentDoc}`;
50518
50461
  }
50519
50462
  };
50520
50463
  }
50521
- (0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(generatedChainConfig), "utf8");
50464
+ (0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
50522
50465
  chainConfigPathToUse = tempChainConfigFilePath;
50523
50466
  }
50524
50467
  const child = (0, import_child_process.spawn)(
@@ -50556,21 +50499,16 @@ ${MessageCoinFragmentFragmentDoc}`;
50556
50499
  }
50557
50500
  };
50558
50501
  child.stderr.on("data", (chunk) => {
50559
- const text = typeof chunk === "string" ? chunk : chunk.toString();
50560
- if (text.indexOf(graphQLStartSubstring) !== -1) {
50561
- const rows = text.split("\n");
50562
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
50563
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
50502
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
50564
50503
  resolve({
50565
50504
  cleanup: () => killNode(cleanupConfig),
50566
- ip: realIp,
50567
- port: realPort,
50568
- url: `http://${realIp}:${realPort}/graphql`,
50505
+ ip: ipToUse,
50506
+ port: portToUse,
50569
50507
  chainConfigPath: chainConfigPathToUse
50570
50508
  });
50571
50509
  }
50572
- if (/error/i.test(text)) {
50573
- reject(text.toString());
50510
+ if (/error/i.test(chunk)) {
50511
+ reject(chunk.toString());
50574
50512
  }
50575
50513
  });
50576
50514
  process.on("exit", () => killNode(cleanupConfig));
@@ -50602,198 +50540,6 @@ ${MessageCoinFragmentFragmentDoc}`;
50602
50540
  };
50603
50541
  return { wallets, stop: cleanup, provider };
50604
50542
  };
50605
-
50606
- // src/test-utils/asset-id.ts
50607
- var _AssetId = class {
50608
- constructor(value) {
50609
- this.value = value;
50610
- }
50611
- static random() {
50612
- return new _AssetId(hexlify(randomBytes22(32)));
50613
- }
50614
- };
50615
- var AssetId = _AssetId;
50616
- __publicField(AssetId, "BaseAssetId", new _AssetId(BaseAssetId));
50617
- __publicField(AssetId, "A", new _AssetId(
50618
- "0x0101010101010101010101010101010101010101010101010101010101010101"
50619
- ));
50620
- __publicField(AssetId, "B", new _AssetId(
50621
- "0x0202020202020202020202020202020202020202020202020202020202020202"
50622
- ));
50623
-
50624
- // src/test-utils/wallet-config.ts
50625
- var WalletConfig = class {
50626
- initialState;
50627
- options;
50628
- wallets;
50629
- generateWallets = () => {
50630
- const generatedWallets = [];
50631
- for (let index = 1; index <= this.options.count; index++) {
50632
- generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
50633
- }
50634
- return generatedWallets;
50635
- };
50636
- constructor(config) {
50637
- WalletConfig.guard(config);
50638
- this.options = config;
50639
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
50640
- this.wallets = this.generateWallets();
50641
- this.initialState = {
50642
- messages: WalletConfig.createMessages(this.wallets, messages),
50643
- coins: WalletConfig.createCoins(this.wallets, assets2, coinsPerAsset, amountPerCoin)
50644
- };
50645
- }
50646
- apply(chainConfig) {
50647
- return {
50648
- ...chainConfig,
50649
- initial_state: {
50650
- ...chainConfig?.initial_state,
50651
- coins: this.initialState.coins.concat(chainConfig?.initial_state?.coins || []),
50652
- messages: this.initialState.messages.concat(chainConfig?.initial_state?.messages ?? [])
50653
- }
50654
- };
50655
- }
50656
- static createMessages(wallets, messages) {
50657
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
50658
- }
50659
- static createCoins(wallets, assets2, coinsPerAsset, amountPerCoin) {
50660
- const coins = [];
50661
- let assetIds = [AssetId.BaseAssetId.value];
50662
- if (Array.isArray(assets2)) {
50663
- assetIds = assetIds.concat(assets2.map((a) => a.value));
50664
- } else {
50665
- for (let index = 0; index < assets2 - 1; index++) {
50666
- assetIds.push(AssetId.random().value);
50667
- }
50668
- }
50669
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
50670
- assetIds.forEach((assetId) => {
50671
- for (let index = 0; index < coinsPerAsset; index++) {
50672
- coins.push({
50673
- amount: toHex(amountPerCoin, 8),
50674
- asset_id: assetId,
50675
- owner: walletAddress
50676
- });
50677
- }
50678
- });
50679
- });
50680
- return coins;
50681
- }
50682
- static guard({
50683
- count: wallets,
50684
- assets: assets2,
50685
- coinsPerAsset,
50686
- amountPerCoin
50687
- }) {
50688
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
50689
- throw new FuelError(
50690
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50691
- "Number of wallets must be greater than zero."
50692
- );
50693
- }
50694
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
50695
- throw new FuelError(
50696
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50697
- "Number of assets per wallet must be greater than zero."
50698
- );
50699
- }
50700
- if (coinsPerAsset <= 0) {
50701
- throw new FuelError(
50702
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50703
- "Number of coins per asset must be greater than zero."
50704
- );
50705
- }
50706
- if (amountPerCoin <= 0) {
50707
- throw new FuelError(
50708
- FuelError.CODES.INVALID_INPUT_PARAMETERS,
50709
- "Amount per coin must be greater than zero."
50710
- );
50711
- }
50712
- }
50713
- };
50714
-
50715
- // src/test-utils/setup-test-provider-and-wallets.ts
50716
- var defaultWalletConfigOptions = {
50717
- count: 2,
50718
- assets: [AssetId.A, AssetId.B],
50719
- coinsPerAsset: 1,
50720
- amountPerCoin: 1e10,
50721
- messages: []
50722
- };
50723
- async function setupTestProviderAndWallets({
50724
- walletConfig: walletConfigOptions = {},
50725
- providerOptions,
50726
- nodeOptions = {}
50727
- } = {}) {
50728
- Symbol.dispose ??= Symbol("Symbol.dispose");
50729
- const walletConfig = new WalletConfig({
50730
- ...defaultWalletConfigOptions,
50731
- ...walletConfigOptions
50732
- });
50733
- const { cleanup, url } = await launchNode({
50734
- ...nodeOptions,
50735
- chainConfig: mergeDeepRight_default(defaultChainConfig, walletConfig.apply(nodeOptions?.chainConfig)),
50736
- port: "0"
50737
- });
50738
- let provider;
50739
- try {
50740
- provider = await Provider.create(url, providerOptions);
50741
- } catch (err) {
50742
- cleanup();
50743
- throw err;
50744
- }
50745
- const wallets = walletConfig.wallets;
50746
- wallets.forEach((wallet) => {
50747
- wallet.connect(provider);
50748
- });
50749
- return {
50750
- provider,
50751
- wallets,
50752
- cleanup,
50753
- [Symbol.dispose]: cleanup
50754
- };
50755
- }
50756
-
50757
- // src/test-utils/test-message.ts
50758
- var TestMessage = class {
50759
- sender;
50760
- recipient;
50761
- nonce;
50762
- amount;
50763
- data;
50764
- da_height;
50765
- /**
50766
- * A helper class to create messages for testing purposes.
50767
- *
50768
- * Used in tandem with `WalletConfig`.
50769
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
50770
- */
50771
- constructor({
50772
- sender = Address.fromRandom(),
50773
- recipient = Address.fromRandom(),
50774
- nonce = hexlify(randomBytes22(32)),
50775
- amount = 1e6,
50776
- data = "02",
50777
- da_height = "0x00"
50778
- } = {}) {
50779
- this.sender = sender;
50780
- this.recipient = recipient;
50781
- this.nonce = nonce;
50782
- this.amount = amount;
50783
- this.data = data;
50784
- this.da_height = da_height;
50785
- }
50786
- toChainMessage(recipient) {
50787
- return {
50788
- sender: this.sender.toB256(),
50789
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
50790
- nonce: this.nonce,
50791
- amount: new BN(this.amount).toHex(8),
50792
- data: this.data,
50793
- da_height: this.da_height
50794
- };
50795
- }
50796
- };
50797
50543
  })();
50798
50544
  /*! Bundled license information:
50799
50545