@fuel-ts/account 0.0.0-rc-2143-20240520152005 → 0.0.0-rc-1356-20240520163254
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.
- package/dist/index.global.js +7 -9
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +115 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -10
- package/dist/index.mjs.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +8 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +4 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +10 -3
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +29 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +55 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +465 -122
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +407 -169
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +301 -67
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -1647,15 +1647,6 @@ 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
|
-
|
1659
1650
|
// src/providers/utils/extract-tx-error.ts
|
1660
1651
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1661
1652
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -3604,6 +3595,7 @@ var TransactionResponse = class {
|
|
3604
3595
|
};
|
3605
3596
|
|
3606
3597
|
// src/providers/utils/auto-retry-fetch.ts
|
3598
|
+
import { sleep } from "@fuel-ts/utils";
|
3607
3599
|
function getWaitDelay(options, retryAttemptNum) {
|
3608
3600
|
const duration = options.baseDelay ?? 150;
|
3609
3601
|
switch (options.backoff) {
|
@@ -8426,7 +8418,8 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8426
8418
|
// src/test-utils/launchNode.ts
|
8427
8419
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8428
8420
|
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8429
|
-
import {
|
8421
|
+
import { defaultConsensusKey, hexlify as hexlify18, defaultSnapshotConfigs } from "@fuel-ts/utils";
|
8422
|
+
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8430
8423
|
import { spawn } from "child_process";
|
8431
8424
|
import { randomUUID } from "crypto";
|
8432
8425
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
@@ -8465,14 +8458,49 @@ var killNode = (params) => {
|
|
8465
8458
|
}
|
8466
8459
|
}
|
8467
8460
|
};
|
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
|
+
}
|
8468
8495
|
var launchNode = async ({
|
8469
8496
|
ip,
|
8470
8497
|
port,
|
8471
8498
|
args = [],
|
8472
|
-
|
8499
|
+
useSystemFuelCore = false,
|
8473
8500
|
loggingEnabled = true,
|
8474
8501
|
debugEnabled = false,
|
8475
|
-
basePath
|
8502
|
+
basePath,
|
8503
|
+
snapshotConfig = defaultSnapshotConfigs
|
8476
8504
|
}) => (
|
8477
8505
|
// eslint-disable-next-line no-async-promise-executor
|
8478
8506
|
new Promise(async (resolve, reject) => {
|
@@ -8489,7 +8517,8 @@ var launchNode = async ({
|
|
8489
8517
|
const poaInstantFlagValue = getFlagValueFromArgs(args, "--poa-instant");
|
8490
8518
|
const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
|
8491
8519
|
const graphQLStartSubstring = "Binding GraphQL provider to";
|
8492
|
-
const
|
8520
|
+
const binPath = findBinPath("fuels-core", __dirname);
|
8521
|
+
const command = useSystemFuelCore ? "fuel-core" : binPath;
|
8493
8522
|
const ipToUse = ip || "0.0.0.0";
|
8494
8523
|
const portToUse = port || (await getPortPromise({
|
8495
8524
|
port: 4e3,
|
@@ -8500,56 +8529,23 @@ var launchNode = async ({
|
|
8500
8529
|
let snapshotDirToUse;
|
8501
8530
|
const prefix = basePath || os.tmpdir();
|
8502
8531
|
const suffix = basePath ? "" : randomUUID();
|
8503
|
-
const
|
8532
|
+
const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8504
8533
|
if (snapshotDir) {
|
8505
8534
|
snapshotDirToUse = snapshotDir;
|
8506
8535
|
} else {
|
8507
|
-
if (!existsSync(
|
8508
|
-
mkdirSync(
|
8536
|
+
if (!existsSync(tempDir)) {
|
8537
|
+
mkdirSync(tempDir, { recursive: true });
|
8509
8538
|
}
|
8510
|
-
|
8511
|
-
const
|
8512
|
-
|
8513
|
-
|
8514
|
-
|
8515
|
-
|
8516
|
-
|
8517
|
-
|
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;
|
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;
|
8553
8549
|
}
|
8554
8550
|
const child = spawn(
|
8555
8551
|
command,
|
@@ -8557,7 +8553,7 @@ var launchNode = async ({
|
|
8557
8553
|
"run",
|
8558
8554
|
["--ip", ipToUse],
|
8559
8555
|
["--port", portToUse],
|
8560
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8556
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8561
8557
|
["--min-gas-price", "1"],
|
8562
8558
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8563
8559
|
["--consensus-key", consensusKey],
|
@@ -8579,23 +8575,28 @@ var launchNode = async ({
|
|
8579
8575
|
}
|
8580
8576
|
const cleanupConfig = {
|
8581
8577
|
child,
|
8582
|
-
configPath:
|
8578
|
+
configPath: tempDir,
|
8583
8579
|
killFn: treeKill,
|
8584
8580
|
state: {
|
8585
8581
|
isDead: false
|
8586
8582
|
}
|
8587
8583
|
};
|
8588
8584
|
child.stderr.on("data", (chunk) => {
|
8589
|
-
|
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(":");
|
8590
8590
|
resolve({
|
8591
8591
|
cleanup: () => killNode(cleanupConfig),
|
8592
|
-
ip:
|
8593
|
-
port:
|
8592
|
+
ip: realIp,
|
8593
|
+
port: realPort,
|
8594
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8594
8595
|
snapshotDir: snapshotDirToUse
|
8595
8596
|
});
|
8596
8597
|
}
|
8597
|
-
if (/error/i.test(
|
8598
|
-
reject(
|
8598
|
+
if (/error/i.test(text)) {
|
8599
|
+
reject(text.toString());
|
8599
8600
|
}
|
8600
8601
|
});
|
8601
8602
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8628,11 +8629,244 @@ var launchNodeAndGetWallets = async ({
|
|
8628
8629
|
};
|
8629
8630
|
return { wallets, stop: cleanup, provider };
|
8630
8631
|
};
|
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
|
+
};
|
8631
8861
|
export {
|
8862
|
+
AssetId,
|
8863
|
+
TestMessage,
|
8864
|
+
WalletConfig,
|
8632
8865
|
generateTestWallet,
|
8633
8866
|
killNode,
|
8634
8867
|
launchNode,
|
8635
8868
|
launchNodeAndGetWallets,
|
8636
|
-
seedTestWallet
|
8869
|
+
seedTestWallet,
|
8870
|
+
setupTestProviderAndWallets
|
8637
8871
|
};
|
8638
8872
|
//# sourceMappingURL=test-utils.mjs.map
|