@fuel-ts/account 0.0.0-rc-1356-20240515091838 → 0.0.0-rc-2143-20240515092507

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.

@@ -1645,6 +1645,15 @@ function normalizeJSON(root) {
1645
1645
  return normalize(clone(root));
1646
1646
  }
1647
1647
 
1648
+ // src/providers/utils/sleep.ts
1649
+ function sleep(time) {
1650
+ return new Promise((resolve) => {
1651
+ setTimeout(() => {
1652
+ resolve(true);
1653
+ }, time);
1654
+ });
1655
+ }
1656
+
1648
1657
  // src/providers/utils/extract-tx-error.ts
1649
1658
  import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
1650
1659
  import { bn as bn6 } from "@fuel-ts/math";
@@ -3596,7 +3605,6 @@ var TransactionResponse = class {
3596
3605
  };
3597
3606
 
3598
3607
  // src/providers/utils/auto-retry-fetch.ts
3599
- import { sleep } from "@fuel-ts/utils";
3600
3608
  function getWaitDelay(options, retryAttemptNum) {
3601
3609
  const duration = options.baseDelay ?? 150;
3602
3610
  switch (options.backoff) {
@@ -8400,7 +8408,7 @@ var generateTestWallet = async (provider, quantities) => {
8400
8408
  // src/test-utils/launchNode.ts
8401
8409
  import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
8402
8410
  import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
8403
- import { defaultConsensusKey, hexlify as hexlify18, defaultSnapshotConfigs } from "@fuel-ts/utils";
8411
+ import { defaultSnapshotConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
8404
8412
  import { findBinPath } from "@fuel-ts/utils/cli-utils";
8405
8413
  import { spawn } from "child_process";
8406
8414
  import { randomUUID } from "crypto";
@@ -8440,49 +8448,15 @@ var killNode = (params) => {
8440
8448
  }
8441
8449
  }
8442
8450
  };
8443
- function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
8444
- const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
8445
- ...coin,
8446
- amount: "18446744073709551615"
8447
- }));
8448
- const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
8449
- ...message,
8450
- amount: "18446744073709551615"
8451
- }));
8452
- 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);
8453
- 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);
8454
- if (!process.env.GENESIS_SECRET) {
8455
- const pk = Signer.generatePrivateKey();
8456
- const signer = new Signer(pk);
8457
- process.env.GENESIS_SECRET = hexlify18(pk);
8458
- coins.push({
8459
- tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
8460
- owner: signer.address.toHexString(),
8461
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8462
- amount: "18446744073709551615",
8463
- asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
8464
- output_index: 0,
8465
- tx_pointer_block_height: 0,
8466
- tx_pointer_tx_idx: 0
8467
- });
8468
- }
8469
- const json = JSON.stringify({
8470
- ...stateConfig,
8471
- coins,
8472
- messages
8473
- });
8474
- const regexMakeNumber = /("amount":)"(\d+)"/gm;
8475
- return json.replace(regexMakeNumber, "$1$2");
8476
- }
8477
8451
  var launchNode = async ({
8478
8452
  ip,
8479
8453
  port,
8480
8454
  args = [],
8455
+ fuelCorePath = void 0,
8481
8456
  useSystemFuelCore = false,
8482
8457
  loggingEnabled = true,
8483
8458
  debugEnabled = false,
8484
- basePath,
8485
- snapshotConfig = defaultSnapshotConfigs
8459
+ basePath
8486
8460
  }) => (
8487
8461
  // eslint-disable-next-line no-async-promise-executor
8488
8462
  new Promise(async (resolve, reject) => {
@@ -8499,7 +8473,7 @@ var launchNode = async ({
8499
8473
  const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
8500
8474
  const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
8501
8475
  const graphQLStartSubstring = "Binding GraphQL provider to";
8502
- const binPath = findBinPath("fuels-core", __dirname);
8476
+ const binPath = fuelCorePath ?? findBinPath("fuels-core", __dirname);
8503
8477
  const command = useSystemFuelCore ? "fuel-core" : binPath;
8504
8478
  const ipToUse = ip || "0.0.0.0";
8505
8479
  const portToUse = port || (await getPortPromise({
@@ -8511,23 +8485,56 @@ var launchNode = async ({
8511
8485
  let snapshotDirToUse;
8512
8486
  const prefix = basePath || os.tmpdir();
8513
8487
  const suffix = basePath ? "" : randomUUID();
8514
- const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
8488
+ const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
8515
8489
  if (snapshotDir) {
8516
8490
  snapshotDirToUse = snapshotDir;
8517
8491
  } else {
8518
- if (!existsSync(tempDir)) {
8519
- mkdirSync(tempDir, { recursive: true });
8492
+ if (!existsSync(tempDirPath)) {
8493
+ mkdirSync(tempDirPath, { recursive: true });
8520
8494
  }
8521
- const { metadata } = snapshotConfig;
8522
- const metadataPath = path.join(tempDir, "metadata.json");
8523
- const chainConfigPath = path.join(tempDir, metadata.chain_config);
8524
- const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
8525
- const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
8526
- writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
8527
- writeFileSync(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
8528
- writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
8529
- writeFileSync(stateTransitionPath, JSON.stringify(""));
8530
- snapshotDirToUse = tempDir;
8495
+ let { stateConfigJson } = defaultSnapshotConfigs;
8496
+ const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
8497
+ stateConfigJson = {
8498
+ ...stateConfigJson,
8499
+ coins: [
8500
+ ...stateConfigJson.coins.map((coin) => ({
8501
+ ...coin,
8502
+ amount: "18446744073709551615"
8503
+ }))
8504
+ ],
8505
+ messages: stateConfigJson.messages.map((message) => ({
8506
+ ...message,
8507
+ amount: "18446744073709551615"
8508
+ }))
8509
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8510
+ };
8511
+ if (!process.env.GENESIS_SECRET) {
8512
+ const pk = Signer.generatePrivateKey();
8513
+ const signer = new Signer(pk);
8514
+ process.env.GENESIS_SECRET = hexlify18(pk);
8515
+ stateConfigJson.coins.push({
8516
+ tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
8517
+ owner: signer.address.toHexString(),
8518
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
8519
+ amount: "18446744073709551615",
8520
+ asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
8521
+ output_index: 0,
8522
+ tx_pointer_block_height: 0,
8523
+ tx_pointer_tx_idx: 0
8524
+ });
8525
+ }
8526
+ let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
8527
+ const regexMakeNumber = /("amount":)"(\d+)"/gm;
8528
+ fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
8529
+ const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
8530
+ const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
8531
+ const metadataWritePath = path.join(tempDirPath, "metadata.json");
8532
+ const stateTransitionWritePath = path.join(tempDirPath, "state_transition_bytecode.wasm");
8533
+ writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
8534
+ writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
8535
+ writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
8536
+ writeFileSync(stateTransitionWritePath, JSON.stringify(""));
8537
+ snapshotDirToUse = tempDirPath;
8531
8538
  }
8532
8539
  const child = spawn(
8533
8540
  command,
@@ -8535,7 +8542,7 @@ var launchNode = async ({
8535
8542
  "run",
8536
8543
  ["--ip", ipToUse],
8537
8544
  ["--port", portToUse],
8538
- useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
8545
+ useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
8539
8546
  ["--min-gas-price", "1"],
8540
8547
  poaInstant ? ["--poa-instant", "true"] : [],
8541
8548
  ["--consensus-key", consensusKey],
@@ -8557,28 +8564,23 @@ var launchNode = async ({
8557
8564
  }
8558
8565
  const cleanupConfig = {
8559
8566
  child,
8560
- configPath: tempDir,
8567
+ configPath: tempDirPath,
8561
8568
  killFn: treeKill,
8562
8569
  state: {
8563
8570
  isDead: false
8564
8571
  }
8565
8572
  };
8566
8573
  child.stderr.on("data", (chunk) => {
8567
- const text = typeof chunk === "string" ? chunk : chunk.toString();
8568
- if (text.indexOf(graphQLStartSubstring) !== -1) {
8569
- const rows = text.split("\n");
8570
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
8571
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
8574
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
8572
8575
  resolve({
8573
8576
  cleanup: () => killNode(cleanupConfig),
8574
- ip: realIp,
8575
- port: realPort,
8576
- url: `http://${realIp}:${realPort}/v1/graphql`,
8577
+ ip: ipToUse,
8578
+ port: portToUse,
8577
8579
  snapshotDir: snapshotDirToUse
8578
8580
  });
8579
8581
  }
8580
- if (/error/i.test(text)) {
8581
- reject(text.toString());
8582
+ if (/error/i.test(chunk)) {
8583
+ reject(chunk.toString());
8582
8584
  }
8583
8585
  });
8584
8586
  process.on("exit", () => killNode(cleanupConfig));
@@ -8611,242 +8613,11 @@ var launchNodeAndGetWallets = async ({
8611
8613
  };
8612
8614
  return { wallets, stop: cleanup, provider };
8613
8615
  };
8614
-
8615
- // src/test-utils/setup-test-provider-and-wallets.ts
8616
- import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
8617
- import { mergeDeepRight } from "ramda";
8618
-
8619
- // src/test-utils/asset-id.ts
8620
- import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
8621
- import { hexlify as hexlify19 } from "@fuel-ts/utils";
8622
- var _AssetId = class {
8623
- constructor(value) {
8624
- this.value = value;
8625
- }
8626
- static random() {
8627
- return new _AssetId(hexlify19(randomBytes7(32)));
8628
- }
8629
- };
8630
- var AssetId = _AssetId;
8631
- __publicField(AssetId, "A", new _AssetId(
8632
- "0x0101010101010101010101010101010101010101010101010101010101010101"
8633
- ));
8634
- __publicField(AssetId, "B", new _AssetId(
8635
- "0x0202020202020202020202020202020202020202020202020202020202020202"
8636
- ));
8637
-
8638
- // src/test-utils/wallet-config.ts
8639
- import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
8640
- import { FuelError as FuelError20 } from "@fuel-ts/errors";
8641
- import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify20 } from "@fuel-ts/utils";
8642
- var WalletConfig = class {
8643
- initialState;
8644
- options;
8645
- wallets;
8646
- generateWallets = () => {
8647
- const generatedWallets = [];
8648
- for (let index = 1; index <= this.options.count; index++) {
8649
- generatedWallets.push(new WalletUnlocked(randomBytes8(32)));
8650
- }
8651
- return generatedWallets;
8652
- };
8653
- constructor(baseAssetId, config) {
8654
- WalletConfig.validate(config);
8655
- this.options = config;
8656
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8657
- this.wallets = this.generateWallets();
8658
- this.initialState = {
8659
- messages: WalletConfig.createMessages(this.wallets, messages),
8660
- coins: WalletConfig.createCoins(
8661
- this.wallets,
8662
- baseAssetId,
8663
- assets2,
8664
- coinsPerAsset,
8665
- amountPerCoin
8666
- )
8667
- };
8668
- }
8669
- apply(snapshotConfig) {
8670
- return {
8671
- ...snapshotConfig,
8672
- stateConfig: {
8673
- ...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
8674
- coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
8675
- messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
8676
- }
8677
- };
8678
- }
8679
- /**
8680
- * Create messages for the wallets in the format that the chain expects.
8681
- */
8682
- static createMessages(wallets, messages) {
8683
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8684
- }
8685
- /**
8686
- * Create coins for the wallets in the format that the chain expects.
8687
- */
8688
- static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
8689
- const coins = [];
8690
- let assetIds = [baseAssetId];
8691
- if (Array.isArray(assets2)) {
8692
- assetIds = assetIds.concat(assets2.map((a) => a.value));
8693
- } else {
8694
- for (let index = 0; index < assets2 - 1; index++) {
8695
- assetIds.push(AssetId.random().value);
8696
- }
8697
- }
8698
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8699
- assetIds.forEach((assetId) => {
8700
- for (let index = 0; index < coinsPerAsset; index++) {
8701
- coins.push({
8702
- amount: amountPerCoin,
8703
- asset_id: assetId,
8704
- owner: walletAddress,
8705
- tx_pointer_block_height: 0,
8706
- tx_pointer_tx_idx: 0,
8707
- output_index: 0,
8708
- tx_id: hexlify20(randomBytes8(32))
8709
- });
8710
- }
8711
- });
8712
- });
8713
- return coins;
8714
- }
8715
- static validate({
8716
- count: wallets,
8717
- assets: assets2,
8718
- coinsPerAsset,
8719
- amountPerCoin
8720
- }) {
8721
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8722
- throw new FuelError20(
8723
- FuelError20.CODES.INVALID_INPUT_PARAMETERS,
8724
- "Number of wallets must be greater than zero."
8725
- );
8726
- }
8727
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8728
- throw new FuelError20(
8729
- FuelError20.CODES.INVALID_INPUT_PARAMETERS,
8730
- "Number of assets per wallet must be greater than zero."
8731
- );
8732
- }
8733
- if (coinsPerAsset <= 0) {
8734
- throw new FuelError20(
8735
- FuelError20.CODES.INVALID_INPUT_PARAMETERS,
8736
- "Number of coins per asset must be greater than zero."
8737
- );
8738
- }
8739
- if (amountPerCoin <= 0) {
8740
- throw new FuelError20(
8741
- FuelError20.CODES.INVALID_INPUT_PARAMETERS,
8742
- "Amount per coin must be greater than zero."
8743
- );
8744
- }
8745
- }
8746
- };
8747
-
8748
- // src/test-utils/setup-test-provider-and-wallets.ts
8749
- var defaultWalletConfigOptions = {
8750
- count: 2,
8751
- assets: [AssetId.A, AssetId.B],
8752
- coinsPerAsset: 1,
8753
- amountPerCoin: 1e10,
8754
- messages: []
8755
- };
8756
- async function setupTestProviderAndWallets({
8757
- walletConfig: walletConfigOptions = {},
8758
- providerOptions,
8759
- nodeOptions = {}
8760
- } = {}) {
8761
- Symbol.dispose ??= Symbol("Symbol.dispose");
8762
- const walletConfig = new WalletConfig(
8763
- nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
8764
- {
8765
- ...defaultWalletConfigOptions,
8766
- ...walletConfigOptions
8767
- }
8768
- );
8769
- const { cleanup, url } = await launchNode({
8770
- loggingEnabled: false,
8771
- ...nodeOptions,
8772
- snapshotConfig: mergeDeepRight(
8773
- defaultSnapshotConfigs3,
8774
- walletConfig.apply(nodeOptions?.snapshotConfig)
8775
- ),
8776
- port: "0"
8777
- });
8778
- let provider;
8779
- try {
8780
- provider = await Provider.create(url, providerOptions);
8781
- } catch (err) {
8782
- cleanup();
8783
- throw err;
8784
- }
8785
- const wallets = walletConfig.wallets;
8786
- wallets.forEach((wallet) => {
8787
- wallet.connect(provider);
8788
- });
8789
- return {
8790
- provider,
8791
- wallets,
8792
- cleanup,
8793
- [Symbol.dispose]: cleanup
8794
- };
8795
- }
8796
-
8797
- // src/test-utils/test-message.ts
8798
- import { Address as Address6 } from "@fuel-ts/address";
8799
- import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
8800
- import { bn as bn21 } from "@fuel-ts/math";
8801
- import { hexlify as hexlify21 } from "@fuel-ts/utils";
8802
- var TestMessage = class {
8803
- sender;
8804
- recipient;
8805
- nonce;
8806
- amount;
8807
- data;
8808
- da_height;
8809
- /**
8810
- * A helper class to create messages for testing purposes.
8811
- *
8812
- * Used in tandem with `WalletConfig`.
8813
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
8814
- */
8815
- constructor({
8816
- sender = Address6.fromRandom(),
8817
- recipient = Address6.fromRandom(),
8818
- nonce = hexlify21(randomBytes9(32)),
8819
- amount = 1e6,
8820
- data = "02",
8821
- da_height = 0
8822
- } = {}) {
8823
- this.sender = sender;
8824
- this.recipient = recipient;
8825
- this.nonce = nonce;
8826
- this.amount = amount;
8827
- this.data = data;
8828
- this.da_height = da_height;
8829
- }
8830
- toChainMessage(recipient) {
8831
- return {
8832
- sender: this.sender.toB256(),
8833
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
8834
- nonce: this.nonce,
8835
- amount: bn21(this.amount).toNumber(),
8836
- data: this.data,
8837
- da_height: this.da_height
8838
- };
8839
- }
8840
- };
8841
8616
  export {
8842
- AssetId,
8843
- TestMessage,
8844
- WalletConfig,
8845
8617
  generateTestWallet,
8846
8618
  killNode,
8847
8619
  launchNode,
8848
8620
  launchNodeAndGetWallets,
8849
- seedTestWallet,
8850
- setupTestProviderAndWallets
8621
+ seedTestWallet
8851
8622
  };
8852
8623
  //# sourceMappingURL=test-utils.mjs.map