@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.

@@ -1486,6 +1486,15 @@ function normalizeJSON(root) {
1486
1486
  return normalize(clone(root));
1487
1487
  }
1488
1488
 
1489
+ // src/providers/utils/sleep.ts
1490
+ function sleep(time) {
1491
+ return new Promise((resolve) => {
1492
+ setTimeout(() => {
1493
+ resolve(true);
1494
+ }, time);
1495
+ });
1496
+ }
1497
+
1489
1498
  // src/providers/transaction-request/errors.ts
1490
1499
  var NoWitnessAtIndexError = class extends Error {
1491
1500
  constructor(index) {
@@ -3271,7 +3280,6 @@ import { BigNumberCoder } from "@fuel-ts/abi-coder";
3271
3280
  import { ReceiptType as ReceiptType5 } from "@fuel-ts/transactions";
3272
3281
 
3273
3282
  // src/providers/utils/auto-retry-fetch.ts
3274
- import { sleep } from "@fuel-ts/utils";
3275
3283
  function getWaitDelay(options, retryAttemptNum) {
3276
3284
  const duration = options.baseDelay ?? 150;
3277
3285
  switch (options.backoff) {
@@ -7862,8 +7870,7 @@ var launchNode = async ({
7862
7870
  useSystemFuelCore = false,
7863
7871
  loggingEnabled = true,
7864
7872
  debugEnabled = false,
7865
- basePath,
7866
- chainConfig = defaultChainConfig
7873
+ basePath
7867
7874
  }) => (
7868
7875
  // eslint-disable-next-line no-async-promise-executor
7869
7876
  new Promise(async (resolve, reject) => {
@@ -7900,17 +7907,17 @@ var launchNode = async ({
7900
7907
  mkdirSync(tempDirPath, { recursive: true });
7901
7908
  }
7902
7909
  const tempChainConfigFilePath = path.join(tempDirPath, "chainConfig.json");
7903
- let generatedChainConfig = chainConfig;
7910
+ let chainConfig = defaultChainConfig;
7904
7911
  if (!process.env.GENESIS_SECRET) {
7905
7912
  const pk = Signer.generatePrivateKey();
7906
7913
  const signer = new Signer(pk);
7907
7914
  process.env.GENESIS_SECRET = hexlify18(pk);
7908
- generatedChainConfig = {
7909
- ...generatedChainConfig,
7915
+ chainConfig = {
7916
+ ...defaultChainConfig,
7910
7917
  initial_state: {
7911
- ...generatedChainConfig.initial_state,
7918
+ ...defaultChainConfig.initial_state,
7912
7919
  coins: [
7913
- ...generatedChainConfig.initial_state.coins,
7920
+ ...defaultChainConfig.initial_state.coins,
7914
7921
  {
7915
7922
  owner: signer.address.toHexString(),
7916
7923
  amount: toHex2(1e9),
@@ -7920,7 +7927,7 @@ var launchNode = async ({
7920
7927
  }
7921
7928
  };
7922
7929
  }
7923
- writeFileSync(tempChainConfigFilePath, JSON.stringify(generatedChainConfig), "utf8");
7930
+ writeFileSync(tempChainConfigFilePath, JSON.stringify(chainConfig), "utf8");
7924
7931
  chainConfigPathToUse = tempChainConfigFilePath;
7925
7932
  }
7926
7933
  const child = spawn(
@@ -7958,21 +7965,16 @@ var launchNode = async ({
7958
7965
  }
7959
7966
  };
7960
7967
  child.stderr.on("data", (chunk) => {
7961
- const text = typeof chunk === "string" ? chunk : chunk.toString();
7962
- if (text.indexOf(graphQLStartSubstring) !== -1) {
7963
- const rows = text.split("\n");
7964
- const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
7965
- const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
7968
+ if (chunk.indexOf(graphQLStartSubstring) !== -1) {
7966
7969
  resolve({
7967
7970
  cleanup: () => killNode(cleanupConfig),
7968
- ip: realIp,
7969
- port: realPort,
7970
- url: `http://${realIp}:${realPort}/graphql`,
7971
+ ip: ipToUse,
7972
+ port: portToUse,
7971
7973
  chainConfigPath: chainConfigPathToUse
7972
7974
  });
7973
7975
  }
7974
- if (/error/i.test(text)) {
7975
- reject(text.toString());
7976
+ if (/error/i.test(chunk)) {
7977
+ reject(chunk.toString());
7976
7978
  }
7977
7979
  });
7978
7980
  process.on("exit", () => killNode(cleanupConfig));
@@ -8004,221 +8006,11 @@ var launchNodeAndGetWallets = async ({
8004
8006
  };
8005
8007
  return { wallets, stop: cleanup, provider };
8006
8008
  };
8007
-
8008
- // src/test-utils/setup-test-provider-and-wallets.ts
8009
- import { defaultChainConfig as defaultChainConfig2 } from "@fuel-ts/utils";
8010
- import { mergeDeepRight } from "ramda";
8011
-
8012
- // src/test-utils/asset-id.ts
8013
- import { BaseAssetId as BaseAssetId5 } from "@fuel-ts/address/configs";
8014
- import { randomBytes as randomBytes5 } from "@fuel-ts/crypto";
8015
- import { hexlify as hexlify19 } from "@fuel-ts/utils";
8016
- var _AssetId = class {
8017
- constructor(value) {
8018
- this.value = value;
8019
- }
8020
- static random() {
8021
- return new _AssetId(hexlify19(randomBytes5(32)));
8022
- }
8023
- };
8024
- var AssetId = _AssetId;
8025
- __publicField(AssetId, "BaseAssetId", new _AssetId(BaseAssetId5));
8026
- __publicField(AssetId, "A", new _AssetId(
8027
- "0x0101010101010101010101010101010101010101010101010101010101010101"
8028
- ));
8029
- __publicField(AssetId, "B", new _AssetId(
8030
- "0x0202020202020202020202020202020202020202020202020202020202020202"
8031
- ));
8032
-
8033
- // src/test-utils/wallet-config.ts
8034
- import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
8035
- import { FuelError as FuelError19 } from "@fuel-ts/errors";
8036
- import { toHex as toHex3 } from "@fuel-ts/math";
8037
- var WalletConfig = class {
8038
- initialState;
8039
- options;
8040
- wallets;
8041
- generateWallets = () => {
8042
- const generatedWallets = [];
8043
- for (let index = 1; index <= this.options.count; index++) {
8044
- generatedWallets.push(new WalletUnlocked(randomBytes6(32)));
8045
- }
8046
- return generatedWallets;
8047
- };
8048
- constructor(config) {
8049
- WalletConfig.guard(config);
8050
- this.options = config;
8051
- const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
8052
- this.wallets = this.generateWallets();
8053
- this.initialState = {
8054
- messages: WalletConfig.createMessages(this.wallets, messages),
8055
- coins: WalletConfig.createCoins(this.wallets, assets2, coinsPerAsset, amountPerCoin)
8056
- };
8057
- }
8058
- apply(chainConfig) {
8059
- return {
8060
- ...chainConfig,
8061
- initial_state: {
8062
- ...chainConfig?.initial_state,
8063
- coins: this.initialState.coins.concat(chainConfig?.initial_state?.coins || []),
8064
- messages: this.initialState.messages.concat(chainConfig?.initial_state?.messages ?? [])
8065
- }
8066
- };
8067
- }
8068
- static createMessages(wallets, messages) {
8069
- return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
8070
- }
8071
- static createCoins(wallets, assets2, coinsPerAsset, amountPerCoin) {
8072
- const coins = [];
8073
- let assetIds = [AssetId.BaseAssetId.value];
8074
- if (Array.isArray(assets2)) {
8075
- assetIds = assetIds.concat(assets2.map((a) => a.value));
8076
- } else {
8077
- for (let index = 0; index < assets2 - 1; index++) {
8078
- assetIds.push(AssetId.random().value);
8079
- }
8080
- }
8081
- wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
8082
- assetIds.forEach((assetId) => {
8083
- for (let index = 0; index < coinsPerAsset; index++) {
8084
- coins.push({
8085
- amount: toHex3(amountPerCoin, 8),
8086
- asset_id: assetId,
8087
- owner: walletAddress
8088
- });
8089
- }
8090
- });
8091
- });
8092
- return coins;
8093
- }
8094
- static guard({
8095
- count: wallets,
8096
- assets: assets2,
8097
- coinsPerAsset,
8098
- amountPerCoin
8099
- }) {
8100
- if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
8101
- throw new FuelError19(
8102
- FuelError19.CODES.INVALID_INPUT_PARAMETERS,
8103
- "Number of wallets must be greater than zero."
8104
- );
8105
- }
8106
- if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
8107
- throw new FuelError19(
8108
- FuelError19.CODES.INVALID_INPUT_PARAMETERS,
8109
- "Number of assets per wallet must be greater than zero."
8110
- );
8111
- }
8112
- if (coinsPerAsset <= 0) {
8113
- throw new FuelError19(
8114
- FuelError19.CODES.INVALID_INPUT_PARAMETERS,
8115
- "Number of coins per asset must be greater than zero."
8116
- );
8117
- }
8118
- if (amountPerCoin <= 0) {
8119
- throw new FuelError19(
8120
- FuelError19.CODES.INVALID_INPUT_PARAMETERS,
8121
- "Amount per coin must be greater than zero."
8122
- );
8123
- }
8124
- }
8125
- };
8126
-
8127
- // src/test-utils/setup-test-provider-and-wallets.ts
8128
- var defaultWalletConfigOptions = {
8129
- count: 2,
8130
- assets: [AssetId.A, AssetId.B],
8131
- coinsPerAsset: 1,
8132
- amountPerCoin: 1e10,
8133
- messages: []
8134
- };
8135
- async function setupTestProviderAndWallets({
8136
- walletConfig: walletConfigOptions = {},
8137
- providerOptions,
8138
- nodeOptions = {}
8139
- } = {}) {
8140
- Symbol.dispose ??= Symbol("Symbol.dispose");
8141
- const walletConfig = new WalletConfig({
8142
- ...defaultWalletConfigOptions,
8143
- ...walletConfigOptions
8144
- });
8145
- const { cleanup, url } = await launchNode({
8146
- ...nodeOptions,
8147
- chainConfig: mergeDeepRight(defaultChainConfig2, walletConfig.apply(nodeOptions?.chainConfig)),
8148
- port: "0"
8149
- });
8150
- let provider;
8151
- try {
8152
- provider = await Provider.create(url, providerOptions);
8153
- } catch (err) {
8154
- cleanup();
8155
- throw err;
8156
- }
8157
- const wallets = walletConfig.wallets;
8158
- wallets.forEach((wallet) => {
8159
- wallet.connect(provider);
8160
- });
8161
- return {
8162
- provider,
8163
- wallets,
8164
- cleanup,
8165
- [Symbol.dispose]: cleanup
8166
- };
8167
- }
8168
-
8169
- // src/test-utils/test-message.ts
8170
- import { Address as Address6 } from "@fuel-ts/address";
8171
- import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
8172
- import { BN as BN3 } from "@fuel-ts/math";
8173
- import { hexlify as hexlify20 } from "@fuel-ts/utils";
8174
- var TestMessage = class {
8175
- sender;
8176
- recipient;
8177
- nonce;
8178
- amount;
8179
- data;
8180
- da_height;
8181
- /**
8182
- * A helper class to create messages for testing purposes.
8183
- *
8184
- * Used in tandem with `WalletConfig`.
8185
- * It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
8186
- */
8187
- constructor({
8188
- sender = Address6.fromRandom(),
8189
- recipient = Address6.fromRandom(),
8190
- nonce = hexlify20(randomBytes7(32)),
8191
- amount = 1e6,
8192
- data = "02",
8193
- da_height = "0x00"
8194
- } = {}) {
8195
- this.sender = sender;
8196
- this.recipient = recipient;
8197
- this.nonce = nonce;
8198
- this.amount = amount;
8199
- this.data = data;
8200
- this.da_height = da_height;
8201
- }
8202
- toChainMessage(recipient) {
8203
- return {
8204
- sender: this.sender.toB256(),
8205
- recipient: recipient?.toB256() ?? this.recipient.toB256(),
8206
- nonce: this.nonce,
8207
- amount: new BN3(this.amount).toHex(8),
8208
- data: this.data,
8209
- da_height: this.da_height
8210
- };
8211
- }
8212
- };
8213
8009
  export {
8214
- AssetId,
8215
- TestMessage,
8216
- WalletConfig,
8217
8010
  generateTestWallet,
8218
8011
  killNode,
8219
8012
  launchNode,
8220
8013
  launchNodeAndGetWallets,
8221
- seedTestWallet,
8222
- setupTestProviderAndWallets
8014
+ seedTestWallet
8223
8015
  };
8224
8016
  //# sourceMappingURL=test-utils.mjs.map