@fuel-ts/account 0.0.0-rc-2333-20240521114009 → 0.0.0-rc-1356-20240521154745

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

Potentially problematic release.


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

@@ -32933,6 +32933,13 @@ This unreleased fuel-core build may include features and updates not yet support
32933
32933
  };
32934
32934
  var DateTime = _DateTime;
32935
32935
  __publicField3(DateTime, "TAI64_NULL", "");
32936
+ function sleep(time) {
32937
+ return new Promise((resolve) => {
32938
+ setTimeout(() => {
32939
+ resolve(true);
32940
+ }, time);
32941
+ });
32942
+ }
32936
32943
  var chainConfig_default = {
32937
32944
  chain_name: "local_testnet",
32938
32945
  consensus_parameters: {
@@ -33687,9 +33694,9 @@ This unreleased fuel-core build may include features and updates not yet support
33687
33694
  da_block_height: 0
33688
33695
  };
33689
33696
  var defaultSnapshotConfigs = {
33690
- chainConfigJson: chainConfig_default,
33691
- metadataJson: metadata_default,
33692
- stateConfigJson: stateConfig_default
33697
+ chainConfig: chainConfig_default,
33698
+ metadata: metadata_default,
33699
+ stateConfig: stateConfig_default
33693
33700
  };
33694
33701
  var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
33695
33702
  function isDefined(value) {
@@ -34429,11 +34436,72 @@ This unreleased fuel-core build may include features and updates not yet support
34429
34436
  };
34430
34437
  }
34431
34438
 
34439
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
34440
+ function _curry2(fn) {
34441
+ return function f2(a, b) {
34442
+ switch (arguments.length) {
34443
+ case 0:
34444
+ return f2;
34445
+ case 1:
34446
+ return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
34447
+ return fn(a, _b);
34448
+ });
34449
+ default:
34450
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
34451
+ return fn(_a, b);
34452
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
34453
+ return fn(a, _b);
34454
+ }) : fn(a, b);
34455
+ }
34456
+ };
34457
+ }
34458
+
34459
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
34460
+ function _curry3(fn) {
34461
+ return function f3(a, b, c) {
34462
+ switch (arguments.length) {
34463
+ case 0:
34464
+ return f3;
34465
+ case 1:
34466
+ return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
34467
+ return fn(a, _b, _c);
34468
+ });
34469
+ case 2:
34470
+ return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
34471
+ return fn(_a, b, _c);
34472
+ }) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
34473
+ return fn(a, _b, _c);
34474
+ }) : _curry1(function(_c) {
34475
+ return fn(a, b, _c);
34476
+ });
34477
+ default:
34478
+ return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
34479
+ return fn(_a, _b, c);
34480
+ }) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
34481
+ return fn(_a, b, _c);
34482
+ }) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
34483
+ return fn(a, _b, _c);
34484
+ }) : _isPlaceholder(a) ? _curry1(function(_a) {
34485
+ return fn(_a, b, c);
34486
+ }) : _isPlaceholder(b) ? _curry1(function(_b) {
34487
+ return fn(a, _b, c);
34488
+ }) : _isPlaceholder(c) ? _curry1(function(_c) {
34489
+ return fn(a, b, _c);
34490
+ }) : fn(a, b, c);
34491
+ }
34492
+ };
34493
+ }
34494
+
34432
34495
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
34433
34496
  var isArray_default = Array.isArray || function _isArray(val) {
34434
34497
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
34435
34498
  };
34436
34499
 
34500
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
34501
+ function _has(prop, obj) {
34502
+ return Object.prototype.hasOwnProperty.call(obj, prop);
34503
+ }
34504
+
34437
34505
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
34438
34506
  var type = /* @__PURE__ */ _curry1(function type2(val) {
34439
34507
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -34450,6 +34518,11 @@ This unreleased fuel-core build may include features and updates not yet support
34450
34518
  return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()) + "T" + pad(d.getUTCHours()) + ":" + pad(d.getUTCMinutes()) + ":" + pad(d.getUTCSeconds()) + "." + (d.getUTCMilliseconds() / 1e3).toFixed(3).slice(2, 5) + "Z";
34451
34519
  };
34452
34520
 
34521
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
34522
+ function _isObject(x) {
34523
+ return Object.prototype.toString.call(x) === "[object Object]";
34524
+ }
34525
+
34453
34526
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
34454
34527
  var isInteger_default = Number.isInteger || function _isInteger(n) {
34455
34528
  return n << 0 === n;
@@ -34563,6 +34636,46 @@ This unreleased fuel-core build may include features and updates not yet support
34563
34636
  });
34564
34637
  var clone_default = clone;
34565
34638
 
34639
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
34640
+ var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
34641
+ var result = {};
34642
+ var k;
34643
+ l = l || {};
34644
+ r = r || {};
34645
+ for (k in l) {
34646
+ if (_has(k, l)) {
34647
+ result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
34648
+ }
34649
+ }
34650
+ for (k in r) {
34651
+ if (_has(k, r) && !_has(k, result)) {
34652
+ result[k] = r[k];
34653
+ }
34654
+ }
34655
+ return result;
34656
+ });
34657
+ var mergeWithKey_default = mergeWithKey;
34658
+
34659
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
34660
+ var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
34661
+ return mergeWithKey_default(function(k, lVal, rVal) {
34662
+ if (_isObject(lVal) && _isObject(rVal)) {
34663
+ return mergeDeepWithKey2(fn, lVal, rVal);
34664
+ } else {
34665
+ return fn(k, lVal, rVal);
34666
+ }
34667
+ }, lObj, rObj);
34668
+ });
34669
+ var mergeDeepWithKey_default = mergeDeepWithKey;
34670
+
34671
+ // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
34672
+ var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
34673
+ return mergeDeepWithKey_default(function(k, lVal, rVal) {
34674
+ return rVal;
34675
+ }, lObj, rObj);
34676
+ });
34677
+ var mergeDeepRight_default = mergeDeepRight;
34678
+
34566
34679
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
34567
34680
  var hasProtoTrim = typeof String.prototype.trim === "function";
34568
34681
 
@@ -41970,15 +42083,6 @@ ${MessageCoinFragmentDoc}`;
41970
42083
  return normalize2(clone_default(root));
41971
42084
  }
41972
42085
 
41973
- // src/providers/utils/sleep.ts
41974
- function sleep(time) {
41975
- return new Promise((resolve) => {
41976
- setTimeout(() => {
41977
- resolve(true);
41978
- }, time);
41979
- });
41980
- }
41981
-
41982
42086
  // src/providers/utils/extract-tx-error.ts
41983
42087
  var assemblePanicError = (statusReason) => {
41984
42088
  let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
@@ -50044,6 +50148,40 @@ Supported fuel-core version: ${supportedVersion}.`
50044
50148
  }
50045
50149
  }
50046
50150
  };
50151
+ function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
50152
+ const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
50153
+ ...coin,
50154
+ amount: "18446744073709551615"
50155
+ }));
50156
+ const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
50157
+ ...message,
50158
+ amount: "18446744073709551615"
50159
+ }));
50160
+ const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self2) => self2.findIndex((c) => c.tx_id === coin.tx_id) === index);
50161
+ const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self2) => self2.findIndex((m) => m.nonce === msg.nonce) === index);
50162
+ if (!process.env.GENESIS_SECRET) {
50163
+ const pk = Signer.generatePrivateKey();
50164
+ const signer = new Signer(pk);
50165
+ process.env.GENESIS_SECRET = hexlify(pk);
50166
+ coins.push({
50167
+ tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50168
+ owner: signer.address.toHexString(),
50169
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50170
+ amount: "18446744073709551615",
50171
+ asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
50172
+ output_index: 0,
50173
+ tx_pointer_block_height: 0,
50174
+ tx_pointer_tx_idx: 0
50175
+ });
50176
+ }
50177
+ const json = JSON.stringify({
50178
+ ...stateConfig,
50179
+ coins,
50180
+ messages
50181
+ });
50182
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
50183
+ return json.replace(regexMakeNumber, "$1$2");
50184
+ }
50047
50185
  var launchNode = async ({
50048
50186
  ip,
50049
50187
  port,
@@ -50051,7 +50189,8 @@ Supported fuel-core version: ${supportedVersion}.`
50051
50189
  fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
50052
50190
  loggingEnabled = true,
50053
50191
  debugEnabled = false,
50054
- basePath
50192
+ basePath,
50193
+ snapshotConfig = defaultSnapshotConfigs
50055
50194
  }) => (
50056
50195
  // eslint-disable-next-line no-async-promise-executor
50057
50196
  new Promise(async (resolve, reject) => {
@@ -50079,56 +50218,23 @@ Supported fuel-core version: ${supportedVersion}.`
50079
50218
  let snapshotDirToUse;
50080
50219
  const prefix = basePath || import_os.default.tmpdir();
50081
50220
  const suffix = basePath ? "" : (0, import_crypto19.randomUUID)();
50082
- const tempDirPath = import_path7.default.join(prefix, ".fuels", suffix, "snapshotDir");
50221
+ const tempDir = import_path7.default.join(prefix, ".fuels", suffix, "snapshotDir");
50083
50222
  if (snapshotDir) {
50084
50223
  snapshotDirToUse = snapshotDir;
50085
50224
  } else {
50086
- if (!(0, import_fs.existsSync)(tempDirPath)) {
50087
- (0, import_fs.mkdirSync)(tempDirPath, { recursive: true });
50088
- }
50089
- let { stateConfigJson } = defaultSnapshotConfigs;
50090
- const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
50091
- stateConfigJson = {
50092
- ...stateConfigJson,
50093
- coins: [
50094
- ...stateConfigJson.coins.map((coin) => ({
50095
- ...coin,
50096
- amount: "18446744073709551615"
50097
- }))
50098
- ],
50099
- messages: stateConfigJson.messages.map((message) => ({
50100
- ...message,
50101
- amount: "18446744073709551615"
50102
- }))
50103
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50104
- };
50105
- if (!process.env.GENESIS_SECRET) {
50106
- const pk = Signer.generatePrivateKey();
50107
- const signer = new Signer(pk);
50108
- process.env.GENESIS_SECRET = hexlify(pk);
50109
- stateConfigJson.coins.push({
50110
- tx_id: hexlify(randomBytes22(UTXO_ID_LEN)),
50111
- owner: signer.address.toHexString(),
50112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
50113
- amount: "18446744073709551615",
50114
- asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
50115
- output_index: 0,
50116
- tx_pointer_block_height: 0,
50117
- tx_pointer_tx_idx: 0
50118
- });
50119
- }
50120
- let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
50121
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
50122
- fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
50123
- const chainConfigWritePath = import_path7.default.join(tempDirPath, "chainConfig.json");
50124
- const stateConfigWritePath = import_path7.default.join(tempDirPath, "stateConfig.json");
50125
- const metadataWritePath = import_path7.default.join(tempDirPath, "metadata.json");
50126
- const stateTransitionWritePath = import_path7.default.join(tempDirPath, "state_transition_bytecode.wasm");
50127
- (0, import_fs.writeFileSync)(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
50128
- (0, import_fs.writeFileSync)(stateConfigWritePath, fixedStateConfigJSON, "utf8");
50129
- (0, import_fs.writeFileSync)(metadataWritePath, JSON.stringify(metadataJson), "utf8");
50130
- (0, import_fs.writeFileSync)(stateTransitionWritePath, JSON.stringify(""));
50131
- snapshotDirToUse = tempDirPath;
50225
+ if (!(0, import_fs.existsSync)(tempDir)) {
50226
+ (0, import_fs.mkdirSync)(tempDir, { recursive: true });
50227
+ }
50228
+ const { metadata } = snapshotConfig;
50229
+ const metadataPath = import_path7.default.join(tempDir, "metadata.json");
50230
+ const chainConfigPath = import_path7.default.join(tempDir, metadata.chain_config);
50231
+ const stateConfigPath = import_path7.default.join(tempDir, metadata.table_encoding.Json.filepath);
50232
+ const stateTransitionPath = import_path7.default.join(tempDir, "state_transition_bytecode.wasm");
50233
+ (0, import_fs.writeFileSync)(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
50234
+ (0, import_fs.writeFileSync)(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
50235
+ (0, import_fs.writeFileSync)(metadataPath, JSON.stringify(metadata), "utf8");
50236
+ (0, import_fs.writeFileSync)(stateTransitionPath, JSON.stringify(""));
50237
+ snapshotDirToUse = tempDir;
50132
50238
  }
50133
50239
  const child = (0, import_child_process.spawn)(
50134
50240
  command,
@@ -50136,7 +50242,7 @@ Supported fuel-core version: ${supportedVersion}.`
50136
50242
  "run",
50137
50243
  ["--ip", ipToUse],
50138
50244
  ["--port", portToUse],
50139
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
50245
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
50140
50246
  ["--min-gas-price", "1"],
50141
50247
  poaInstant ? ["--poa-instant", "true"] : [],
50142
50248
  ["--consensus-key", consensusKey],
@@ -50158,23 +50264,28 @@ Supported fuel-core version: ${supportedVersion}.`
50158
50264
  }
50159
50265
  const cleanupConfig = {
50160
50266
  child,
50161
- configPath: tempDirPath,
50267
+ configPath: tempDir,
50162
50268
  killFn: import_tree_kill.default,
50163
50269
  state: {
50164
50270
  isDead: false
50165
50271
  }
50166
50272
  };
50167
50273
  child.stderr.on("data", (chunk) => {
50168
- if (chunk.indexOf(graphQLStartSubstring) !== -1) {
50274
+ const text = typeof chunk === "string" ? chunk : chunk.toString();
50275
+ if (text.indexOf(graphQLStartSubstring) !== -1) {
50276
+ const rows = text.split("\n");
50277
+ const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
50278
+ const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
50169
50279
  resolve({
50170
50280
  cleanup: () => killNode(cleanupConfig),
50171
- ip: ipToUse,
50172
- port: portToUse,
50281
+ ip: realIp,
50282
+ port: realPort,
50283
+ url: `http://${realIp}:${realPort}/v1/graphql`,
50173
50284
  snapshotDir: snapshotDirToUse
50174
50285
  });
50175
50286
  }
50176
- if (/error/i.test(chunk)) {
50177
- reject(chunk.toString());
50287
+ if (/error/i.test(text)) {
50288
+ reject(text.toString());
50178
50289
  }
50179
50290
  });
50180
50291
  process.on("exit", () => killNode(cleanupConfig));
@@ -50207,6 +50318,223 @@ Supported fuel-core version: ${supportedVersion}.`
50207
50318
  };
50208
50319
  return { wallets, stop: cleanup, provider };
50209
50320
  };
50321
+
50322
+ // src/test-utils/asset-id.ts
50323
+ var _AssetId = class {
50324
+ constructor(value) {
50325
+ this.value = value;
50326
+ }
50327
+ static random(count = 1) {
50328
+ const assetIds = [];
50329
+ for (let i = 0; i < count; i++) {
50330
+ assetIds.push(new _AssetId(hexlify(randomBytes22(32))));
50331
+ }
50332
+ return assetIds;
50333
+ }
50334
+ };
50335
+ var AssetId = _AssetId;
50336
+ __publicField(AssetId, "A", new _AssetId(
50337
+ "0x0101010101010101010101010101010101010101010101010101010101010101"
50338
+ ));
50339
+ __publicField(AssetId, "B", new _AssetId(
50340
+ "0x0202020202020202020202020202020202020202020202020202020202020202"
50341
+ ));
50342
+
50343
+ // src/test-utils/wallet-config.ts
50344
+ var WalletConfig = class {
50345
+ initialState;
50346
+ options;
50347
+ wallets;
50348
+ generateWallets = () => {
50349
+ const generatedWallets = [];
50350
+ for (let index = 1; index <= this.options.count; index++) {
50351
+ generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
50352
+ }
50353
+ return generatedWallets;
50354
+ };
50355
+ constructor(baseAssetId, config) {
50356
+ WalletConfig.validate(config);
50357
+ this.options = config;
50358
+ const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
50359
+ this.wallets = this.generateWallets();
50360
+ this.initialState = {
50361
+ messages: WalletConfig.createMessages(this.wallets, messages),
50362
+ coins: WalletConfig.createCoins(
50363
+ this.wallets,
50364
+ baseAssetId,
50365
+ assets2,
50366
+ coinsPerAsset,
50367
+ amountPerCoin
50368
+ )
50369
+ };
50370
+ }
50371
+ apply(snapshotConfig) {
50372
+ return {
50373
+ ...snapshotConfig,
50374
+ stateConfig: {
50375
+ ...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs.stateConfig,
50376
+ coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
50377
+ messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
50378
+ }
50379
+ };
50380
+ }
50381
+ /**
50382
+ * Create messages for the wallets in the format that the chain expects.
50383
+ */
50384
+ static createMessages(wallets, messages) {
50385
+ return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
50386
+ }
50387
+ /**
50388
+ * Create coins for the wallets in the format that the chain expects.
50389
+ */
50390
+ static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
50391
+ const coins = [];
50392
+ let assetIds = [baseAssetId];
50393
+ if (Array.isArray(assets2)) {
50394
+ assetIds = assetIds.concat(assets2.map((a) => a.value));
50395
+ } else {
50396
+ assetIds = assetIds.concat(AssetId.random(assets2).map((a) => a.value));
50397
+ }
50398
+ console.log("assetIds", assets2, assetIds);
50399
+ wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
50400
+ assetIds.forEach((assetId) => {
50401
+ for (let index = 0; index < coinsPerAsset; index++) {
50402
+ coins.push({
50403
+ amount: amountPerCoin,
50404
+ asset_id: assetId,
50405
+ owner: walletAddress,
50406
+ tx_pointer_block_height: 0,
50407
+ tx_pointer_tx_idx: 0,
50408
+ output_index: 0,
50409
+ tx_id: hexlify(randomBytes22(32))
50410
+ });
50411
+ }
50412
+ });
50413
+ });
50414
+ return coins;
50415
+ }
50416
+ static validate({
50417
+ count: wallets,
50418
+ assets: assets2,
50419
+ coinsPerAsset,
50420
+ amountPerCoin
50421
+ }) {
50422
+ if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
50423
+ throw new FuelError(
50424
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50425
+ "Number of wallets must be greater than zero."
50426
+ );
50427
+ }
50428
+ if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
50429
+ throw new FuelError(
50430
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50431
+ "Number of assets per wallet must be greater than zero."
50432
+ );
50433
+ }
50434
+ if (coinsPerAsset <= 0) {
50435
+ throw new FuelError(
50436
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50437
+ "Number of coins per asset must be greater than zero."
50438
+ );
50439
+ }
50440
+ if (amountPerCoin <= 0) {
50441
+ throw new FuelError(
50442
+ FuelError.CODES.INVALID_INPUT_PARAMETERS,
50443
+ "Amount per coin must be greater than zero."
50444
+ );
50445
+ }
50446
+ }
50447
+ };
50448
+
50449
+ // src/test-utils/setup-test-provider-and-wallets.ts
50450
+ var defaultWalletConfigOptions = {
50451
+ count: 2,
50452
+ assets: [AssetId.A, AssetId.B],
50453
+ coinsPerAsset: 1,
50454
+ amountPerCoin: 1e10,
50455
+ messages: []
50456
+ };
50457
+ async function setupTestProviderAndWallets({
50458
+ walletConfig: walletConfigOptions = {},
50459
+ providerOptions,
50460
+ nodeOptions = {}
50461
+ } = {}) {
50462
+ Symbol.dispose ??= Symbol("Symbol.dispose");
50463
+ const walletConfig = new WalletConfig(
50464
+ nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs.chainConfig.consensus_parameters.V1.base_asset_id,
50465
+ {
50466
+ ...defaultWalletConfigOptions,
50467
+ ...walletConfigOptions
50468
+ }
50469
+ );
50470
+ const { cleanup, url } = await launchNode({
50471
+ loggingEnabled: false,
50472
+ ...nodeOptions,
50473
+ snapshotConfig: mergeDeepRight_default(
50474
+ defaultSnapshotConfigs,
50475
+ walletConfig.apply(nodeOptions?.snapshotConfig)
50476
+ ),
50477
+ port: "0"
50478
+ });
50479
+ let provider;
50480
+ try {
50481
+ provider = await Provider.create(url, providerOptions);
50482
+ } catch (err) {
50483
+ cleanup();
50484
+ throw err;
50485
+ }
50486
+ const wallets = walletConfig.wallets;
50487
+ wallets.forEach((wallet) => {
50488
+ wallet.connect(provider);
50489
+ });
50490
+ return {
50491
+ provider,
50492
+ wallets,
50493
+ cleanup,
50494
+ [Symbol.dispose]: cleanup
50495
+ };
50496
+ }
50497
+
50498
+ // src/test-utils/test-message.ts
50499
+ var TestMessage = class {
50500
+ sender;
50501
+ recipient;
50502
+ nonce;
50503
+ amount;
50504
+ data;
50505
+ da_height;
50506
+ /**
50507
+ * A helper class to create messages for testing purposes.
50508
+ *
50509
+ * Used in tandem with `WalletConfig`.
50510
+ * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
50511
+ */
50512
+ constructor({
50513
+ sender = Address.fromRandom(),
50514
+ recipient = Address.fromRandom(),
50515
+ nonce = hexlify(randomBytes22(32)),
50516
+ amount = 1e6,
50517
+ data = "02",
50518
+ da_height = 0
50519
+ } = {}) {
50520
+ this.sender = sender;
50521
+ this.recipient = recipient;
50522
+ this.nonce = nonce;
50523
+ this.amount = amount;
50524
+ this.data = data;
50525
+ this.da_height = da_height;
50526
+ }
50527
+ toChainMessage(recipient) {
50528
+ return {
50529
+ sender: this.sender.toB256(),
50530
+ recipient: recipient?.toB256() ?? this.recipient.toB256(),
50531
+ nonce: this.nonce,
50532
+ amount: bn(this.amount).toNumber(),
50533
+ data: this.data,
50534
+ da_height: this.da_height
50535
+ };
50536
+ }
50537
+ };
50210
50538
  })();
50211
50539
  /*! Bundled license information:
50212
50540