@fuel-ts/account 0.0.0-rc-1356-20240322130951 → 0.0.0-rc-1832-20240322144804

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.

@@ -31914,7 +31914,7 @@ spurious results.`);
31914
31914
  // ../versions/dist/index.mjs
31915
31915
  function getBuiltinVersions() {
31916
31916
  return {
31917
- FORC: "0.51.1",
31917
+ FORC: "git:xunilrj/encoding-contract-call",
31918
31918
  FUEL_CORE: "0.22.1",
31919
31919
  FUELS: "0.77.0"
31920
31920
  };
@@ -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);
@@ -35390,9 +35383,6 @@ This unreleased fuel-core build may include features and updates not yet support
35390
35383
  __privateAdd2(this, _getPaddedData);
35391
35384
  }
35392
35385
  encode(value) {
35393
- if (!Array.isArray(value)) {
35394
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
35395
- }
35396
35386
  const parts = [];
35397
35387
  const pointer = new BigNumberCoder("u64").encode(BASE_VECTOR_OFFSET);
35398
35388
  const data = __privateMethod2(this, _getPaddedData, getPaddedData_fn).call(this, value);
@@ -35419,7 +35409,8 @@ This unreleased fuel-core build may include features and updates not yet support
35419
35409
  };
35420
35410
  _getPaddedData = /* @__PURE__ */ new WeakSet();
35421
35411
  getPaddedData_fn = function(value) {
35422
- const data = [Uint8Array.from(value)];
35412
+ const bytes3 = value instanceof Uint8Array ? value : new Uint8Array(value);
35413
+ const data = [Uint8Array.from(bytes3)];
35423
35414
  const paddingLength = (WORD_SIZE - value.length % WORD_SIZE) % WORD_SIZE;
35424
35415
  if (paddingLength) {
35425
35416
  data.push(new Uint8Array(paddingLength));
@@ -35512,7 +35503,7 @@ This unreleased fuel-core build may include features and updates not yet support
35512
35503
  return { None: [] };
35513
35504
  }
35514
35505
  decode(data, offset) {
35515
- if (data.length < this.encodedLength - 1) {
35506
+ if (data.length < this.encodedLength) {
35516
35507
  throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid option data size.`);
35517
35508
  }
35518
35509
  const [decoded, newOffset] = super.decode(data, offset);
@@ -36095,11 +36086,8 @@ This unreleased fuel-core build may include features and updates not yet support
36095
36086
  super("struct", "struct Bytes", WORD_SIZE);
36096
36087
  }
36097
36088
  encode(value) {
36098
- if (!Array.isArray(value)) {
36099
- throw new FuelError(ErrorCode.ENCODE_ERROR, `Expected array value.`);
36100
- }
36101
- const bytes3 = new Uint8Array(value);
36102
- const lengthBytes = new BigNumberCoder("u64").encode(value.length);
36089
+ const bytes3 = value instanceof Uint8Array ? value : new Uint8Array(value);
36090
+ const lengthBytes = new BigNumberCoder("u64").encode(bytes3.length);
36103
36091
  return new Uint8Array([...lengthBytes, ...bytes3]);
36104
36092
  }
36105
36093
  decode(data, offset) {
@@ -36230,6 +36218,28 @@ This unreleased fuel-core build may include features and updates not yet support
36230
36218
  return [toNumber2(bytes3), offset + this.length];
36231
36219
  }
36232
36220
  };
36221
+ var OptionCoder2 = class extends EnumCoder2 {
36222
+ encode(value) {
36223
+ const result = super.encode(this.toSwayOption(value));
36224
+ return result;
36225
+ }
36226
+ toSwayOption(input) {
36227
+ if (input !== void 0) {
36228
+ return { Some: input };
36229
+ }
36230
+ return { None: [] };
36231
+ }
36232
+ decode(data, offset) {
36233
+ const [decoded, newOffset] = super.decode(data, offset);
36234
+ return [this.toOption(decoded), newOffset];
36235
+ }
36236
+ toOption(output3) {
36237
+ if (output3 && "Some" in output3) {
36238
+ return output3.Some;
36239
+ }
36240
+ return void 0;
36241
+ }
36242
+ };
36233
36243
  var RawSliceCoder2 = class extends Coder {
36234
36244
  constructor() {
36235
36245
  super("raw untyped slice", "raw untyped slice", WORD_SIZE);
@@ -36283,6 +36293,30 @@ This unreleased fuel-core build may include features and updates not yet support
36283
36293
  }
36284
36294
  };
36285
36295
  __publicField4(StdStringCoder2, "memorySize", 1);
36296
+ var StrSliceCoder = class extends Coder {
36297
+ constructor() {
36298
+ super("strSlice", "str", WORD_SIZE);
36299
+ }
36300
+ encode(value) {
36301
+ const bytes3 = toUtf8Bytes(value);
36302
+ const lengthBytes = new BigNumberCoder("u64").encode(value.length);
36303
+ return new Uint8Array([...lengthBytes, ...bytes3]);
36304
+ }
36305
+ decode(data, offset) {
36306
+ if (data.length < this.encodedLength) {
36307
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice data size.`);
36308
+ }
36309
+ const offsetAndLength = offset + WORD_SIZE;
36310
+ const lengthBytes = data.slice(offset, offsetAndLength);
36311
+ const length = bn(new BigNumberCoder("u64").decode(lengthBytes, 0)[0]).toNumber();
36312
+ const bytes3 = data.slice(offsetAndLength, offsetAndLength + length);
36313
+ if (bytes3.length !== length) {
36314
+ throw new FuelError(ErrorCode.DECODE_ERROR, `Invalid string slice byte data size.`);
36315
+ }
36316
+ return [toUtf8String(bytes3), offsetAndLength + length];
36317
+ }
36318
+ };
36319
+ __publicField4(StrSliceCoder, "memorySize", 1);
36286
36320
  var StringCoder2 = class extends Coder {
36287
36321
  constructor(length) {
36288
36322
  super("string", `str[${length}]`, length);
@@ -36321,7 +36355,7 @@ This unreleased fuel-core build may include features and updates not yet support
36321
36355
  Object.keys(this.coders).map((fieldName) => {
36322
36356
  const fieldCoder = this.coders[fieldName];
36323
36357
  const fieldValue = value[fieldName];
36324
- if (!(fieldCoder instanceof OptionCoder) && fieldValue == null) {
36358
+ if (!(fieldCoder instanceof OptionCoder2) && fieldValue == null) {
36325
36359
  throw new FuelError(
36326
36360
  ErrorCode.ENCODE_ERROR,
36327
36361
  `Invalid ${this.type}. Field "${fieldName}" not present.`
@@ -36429,6 +36463,8 @@ This unreleased fuel-core build may include features and updates not yet support
36429
36463
  return new ByteCoder2();
36430
36464
  case STD_STRING_CODER_TYPE:
36431
36465
  return new StdStringCoder2();
36466
+ case STR_SLICE_CODER_TYPE:
36467
+ return new StrSliceCoder();
36432
36468
  default:
36433
36469
  break;
36434
36470
  }
@@ -36473,7 +36509,7 @@ This unreleased fuel-core build may include features and updates not yet support
36473
36509
  const coders = getCoders(components, { getCoder: getCoder2 });
36474
36510
  const isOptionEnum = resolvedAbiType.type === OPTION_CODER_TYPE;
36475
36511
  if (isOptionEnum) {
36476
- return new OptionCoder(enumMatch.name, coders);
36512
+ return new OptionCoder2(enumMatch.name, coders);
36477
36513
  }
36478
36514
  return new EnumCoder2(enumMatch.name, coders);
36479
36515
  }
@@ -36484,12 +36520,6 @@ This unreleased fuel-core build may include features and updates not yet support
36484
36520
  );
36485
36521
  return new TupleCoder2(coders);
36486
36522
  }
36487
- if (resolvedAbiType.type === STR_SLICE_CODER_TYPE) {
36488
- throw new FuelError(
36489
- ErrorCode.INVALID_DATA,
36490
- "String slices can not be decoded from logs. Convert the slice to `str[N]` with `__to_str_array`"
36491
- );
36492
- }
36493
36523
  throw new FuelError(
36494
36524
  ErrorCode.CODER_NOT_FOUND,
36495
36525
  `Coder not found: ${JSON.stringify(resolvedAbiType)}.`
@@ -36525,6 +36555,8 @@ This unreleased fuel-core build may include features and updates not yet support
36525
36555
  var FunctionFragment = class {
36526
36556
  signature;
36527
36557
  selector;
36558
+ selectorBytes;
36559
+ encoding;
36528
36560
  name;
36529
36561
  jsonFn;
36530
36562
  attributes;
@@ -36537,6 +36569,8 @@ This unreleased fuel-core build may include features and updates not yet support
36537
36569
  this.name = name;
36538
36570
  this.signature = FunctionFragment.getSignature(this.jsonAbi, this.jsonFn);
36539
36571
  this.selector = FunctionFragment.getFunctionSelector(this.signature);
36572
+ this.selectorBytes = new StdStringCoder2().encode(name);
36573
+ this.encoding = this.jsonAbi.encoding;
36540
36574
  this.isInputDataPointer = this.#isInputDataPointer();
36541
36575
  this.outputMetadata = {
36542
36576
  isHeapType: this.#isOutputDataHeap(),
@@ -36590,11 +36624,14 @@ This unreleased fuel-core build may include features and updates not yet support
36590
36624
  }
36591
36625
  const coders = nonEmptyInputs.map(
36592
36626
  (t) => AbiCoder.getCoder(this.jsonAbi, t, {
36593
- isRightPadded: nonEmptyInputs.length > 1
36627
+ isRightPadded: nonEmptyInputs.length > 1,
36628
+ encoding: this.encoding
36594
36629
  })
36595
36630
  );
36596
- const coder = new TupleCoder(coders);
36597
- const results = coder.encode(shallowCopyValues);
36631
+ if (this.encoding === ENCODING_V1) {
36632
+ return new TupleCoder2(coders).encode(shallowCopyValues);
36633
+ }
36634
+ const results = new TupleCoder(coders).encode(shallowCopyValues);
36598
36635
  return unpackDynamicData(results, offset, results.byteLength);
36599
36636
  }
36600
36637
  static verifyArgsAndInputsAlign(args, inputs, abi) {
@@ -36641,7 +36678,7 @@ This unreleased fuel-core build may include features and updates not yet support
36641
36678
  }
36642
36679
  const result = nonEmptyInputs.reduce(
36643
36680
  (obj, input) => {
36644
- const coder = AbiCoder.getCoder(this.jsonAbi, input);
36681
+ const coder = AbiCoder.getCoder(this.jsonAbi, input, { encoding: this.encoding });
36645
36682
  const [decodedValue, decodedValueByteSize] = coder.decode(bytes3, obj.offset);
36646
36683
  return {
36647
36684
  decoded: [...obj.decoded, decodedValue],
@@ -36661,7 +36698,9 @@ This unreleased fuel-core build may include features and updates not yet support
36661
36698
  return [void 0, 0];
36662
36699
  }
36663
36700
  const bytes3 = arrayify(data);
36664
- const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output);
36701
+ const coder = AbiCoder.getCoder(this.jsonAbi, this.jsonFn.output, {
36702
+ encoding: this.encoding
36703
+ });
36665
36704
  return coder.decode(bytes3, 0);
36666
36705
  }
36667
36706
  };
@@ -36746,7 +36785,8 @@ This unreleased fuel-core build may include features and updates not yet support
36746
36785
  }
36747
36786
  );
36748
36787
  return AbiCoder.encode(this.jsonAbi, configurable.configurableType, value, {
36749
- isRightPadded: true
36788
+ isRightPadded: true,
36789
+ encoding: this.jsonAbi.encoding
36750
36790
  });
36751
36791
  }
36752
36792
  getTypeById(typeId) {
@@ -38087,72 +38127,11 @@ This unreleased fuel-core build may include features and updates not yet support
38087
38127
  };
38088
38128
  }
38089
38129
 
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
38130
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
38147
38131
  var isArray_default = Array.isArray || function _isArray(val) {
38148
38132
  return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
38149
38133
  };
38150
38134
 
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
38135
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
38157
38136
  var type = /* @__PURE__ */ _curry1(function type2(val) {
38158
38137
  return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
@@ -38169,11 +38148,6 @@ This unreleased fuel-core build may include features and updates not yet support
38169
38148
  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
38149
  };
38171
38150
 
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
38151
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
38178
38152
  var isInteger_default = Number.isInteger || function _isInteger(n) {
38179
38153
  return n << 0 === n;
@@ -38287,46 +38261,6 @@ This unreleased fuel-core build may include features and updates not yet support
38287
38261
  });
38288
38262
  var clone_default = clone2;
38289
38263
 
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
38264
  // ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
38331
38265
  var hasProtoTrim = typeof String.prototype.trim === "function";
38332
38266
 
@@ -42858,6 +42792,15 @@ ${MessageCoinFragmentFragmentDoc}`;
42858
42792
  return normalize2(clone_default(root));
42859
42793
  }
42860
42794
 
42795
+ // src/providers/utils/sleep.ts
42796
+ function sleep(time) {
42797
+ return new Promise((resolve) => {
42798
+ setTimeout(() => {
42799
+ resolve(true);
42800
+ }, time);
42801
+ });
42802
+ }
42803
+
42861
42804
  // src/providers/transaction-request/errors.ts
42862
42805
  var NoWitnessAtIndexError = class extends Error {
42863
42806
  constructor(index) {
@@ -50460,8 +50403,7 @@ ${MessageCoinFragmentFragmentDoc}`;
50460
50403
  useSystemFuelCore = false,
50461
50404
  loggingEnabled = true,
50462
50405
  debugEnabled = false,
50463
- basePath,
50464
- chainConfig = defaultChainConfig
50406
+ basePath
50465
50407
  }) => (
50466
50408
  // eslint-disable-next-line no-async-promise-executor
50467
50409
  new Promise(async (resolve, reject) => {
@@ -50498,17 +50440,17 @@ ${MessageCoinFragmentFragmentDoc}`;
50498
50440
  (0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
50499
50441
  }
50500
50442
  const tempChainConfigFilePath = import_path8.default.join(tempDirPath, "chainConfig.json");
50501
- let generatedChainConfig = chainConfig;
50443
+ let chainConfig = defaultChainConfig;
50502
50444
  if (!process.env.GENESIS_SECRET) {
50503
50445
  const pk = Signer.generatePrivateKey();
50504
50446
  const signer = new Signer(pk);
50505
50447
  process.env.GENESIS_SECRET = hexlify(pk);
50506
- generatedChainConfig = {
50507
- ...generatedChainConfig,
50448
+ chainConfig = {
50449
+ ...defaultChainConfig,
50508
50450
  initial_state: {
50509
- ...generatedChainConfig.initial_state,
50451
+ ...defaultChainConfig.initial_state,
50510
50452
  coins: [
50511
- ...generatedChainConfig.initial_state.coins,
50453
+ ...defaultChainConfig.initial_state.coins,
50512
50454
  {
50513
50455
  owner: signer.address.toHexString(),
50514
50456
  amount: toHex(1e9),
@@ -50518,7 +50460,7 @@ ${MessageCoinFragmentFragmentDoc}`;
50518
50460
  }
50519
50461
  };
50520
50462
  }
50521
- (0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(generatedChainConfig), "utf8");
50463
+ (0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
50522
50464
  chainConfigPathToUse = tempChainConfigFilePath;
50523
50465
  }
50524
50466
  const child = (0, import_child_process.spawn)(
@@ -50556,21 +50498,16 @@ ${MessageCoinFragmentFragmentDoc}`;
50556
50498
  }
50557
50499
  };
50558
50500
  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(":");
50501
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
50564
50502
  resolve({
50565
50503
  cleanup: () => killNode(cleanupConfig),
50566
- ip: realIp,
50567
- port: realPort,
50568
- url: `http://${realIp}:${realPort}/graphql`,
50504
+ ip: ipToUse,
50505
+ port: portToUse,
50569
50506
  chainConfigPath: chainConfigPathToUse
50570
50507
  });
50571
50508
  }
50572
- if (/error/i.test(text)) {
50573
- reject(text.toString());
50509
+ if (/error/i.test(chunk)) {
50510
+ reject(chunk.toString());
50574
50511
  }
50575
50512
  });
50576
50513
  process.on("exit", () => killNode(cleanupConfig));
@@ -50602,198 +50539,6 @@ ${MessageCoinFragmentFragmentDoc}`;
50602
50539
  };
50603
50540
  return { wallets, stop: cleanup, provider };
50604
50541
  };
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
50542
  })();
50798
50543
  /*! Bundled license information:
50799
50544