@fuel-ts/account 0.0.0-rc-1356-20240520140225 → 0.0.0-rc-2143-20240520152005

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.

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