@fuel-ts/account 0.0.0-rc-1356-20240515090957 → 0.0.0-rc-2143-20240515092103
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 +9 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +125 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -1
- 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 +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/sleep.d.ts +3 -0
- package/dist/providers/utils/sleep.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +4 -9
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +2409 -509
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +169 -403
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +67 -297
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -16
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
- package/dist/test-utils/test-message.d.ts +0 -28
- package/dist/test-utils/test-message.d.ts.map +0 -1
- package/dist/test-utils/wallet-config.d.ts +0 -55
- package/dist/test-utils/wallet-config.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -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
|
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
|
8488
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8515
8489
|
if (snapshotDir) {
|
8516
8490
|
snapshotDirToUse = snapshotDir;
|
8517
8491
|
} else {
|
8518
|
-
if (!existsSync(
|
8519
|
-
mkdirSync(
|
8492
|
+
if (!existsSync(tempDirPath)) {
|
8493
|
+
mkdirSync(tempDirPath, { recursive: true });
|
8520
8494
|
}
|
8521
|
-
|
8522
|
-
const
|
8523
|
-
|
8524
|
-
|
8525
|
-
|
8526
|
-
|
8527
|
-
|
8528
|
-
|
8529
|
-
|
8530
|
-
|
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",
|
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:
|
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
|
-
|
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:
|
8575
|
-
port:
|
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(
|
8581
|
-
reject(
|
8582
|
+
if (/error/i.test(chunk)) {
|
8583
|
+
reject(chunk.toString());
|
8582
8584
|
}
|
8583
8585
|
});
|
8584
8586
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8611,243 +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
|
-
const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
|
8655
|
-
WalletConfig.validate(config);
|
8656
|
-
this.options = config;
|
8657
|
-
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8658
|
-
this.wallets = this.generateWallets();
|
8659
|
-
this.initialState = {
|
8660
|
-
messages: WalletConfig.createMessages(this.wallets, messages),
|
8661
|
-
coins: WalletConfig.createCoins(
|
8662
|
-
this.wallets,
|
8663
|
-
BASE_ASSET_ID,
|
8664
|
-
assets2,
|
8665
|
-
coinsPerAsset,
|
8666
|
-
amountPerCoin
|
8667
|
-
)
|
8668
|
-
};
|
8669
|
-
}
|
8670
|
-
apply(snapshotConfig) {
|
8671
|
-
return {
|
8672
|
-
...snapshotConfig,
|
8673
|
-
stateConfig: {
|
8674
|
-
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
|
8675
|
-
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8676
|
-
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8677
|
-
}
|
8678
|
-
};
|
8679
|
-
}
|
8680
|
-
/**
|
8681
|
-
* Create messages for the wallets in the format that the chain expects.
|
8682
|
-
*/
|
8683
|
-
static createMessages(wallets, messages) {
|
8684
|
-
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8685
|
-
}
|
8686
|
-
/**
|
8687
|
-
* Create coins for the wallets in the format that the chain expects.
|
8688
|
-
*/
|
8689
|
-
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8690
|
-
const coins = [];
|
8691
|
-
let assetIds = [baseAssetId];
|
8692
|
-
if (Array.isArray(assets2)) {
|
8693
|
-
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8694
|
-
} else {
|
8695
|
-
for (let index = 0; index < assets2 - 1; index++) {
|
8696
|
-
assetIds.push(AssetId.random().value);
|
8697
|
-
}
|
8698
|
-
}
|
8699
|
-
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8700
|
-
assetIds.forEach((assetId) => {
|
8701
|
-
for (let index = 0; index < coinsPerAsset; index++) {
|
8702
|
-
coins.push({
|
8703
|
-
amount: amountPerCoin,
|
8704
|
-
asset_id: assetId,
|
8705
|
-
owner: walletAddress,
|
8706
|
-
tx_pointer_block_height: 0,
|
8707
|
-
tx_pointer_tx_idx: 0,
|
8708
|
-
output_index: 0,
|
8709
|
-
tx_id: hexlify20(randomBytes8(32))
|
8710
|
-
});
|
8711
|
-
}
|
8712
|
-
});
|
8713
|
-
});
|
8714
|
-
return coins;
|
8715
|
-
}
|
8716
|
-
static validate({
|
8717
|
-
count: wallets,
|
8718
|
-
assets: assets2,
|
8719
|
-
coinsPerAsset,
|
8720
|
-
amountPerCoin
|
8721
|
-
}) {
|
8722
|
-
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8723
|
-
throw new FuelError20(
|
8724
|
-
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8725
|
-
"Number of wallets must be greater than zero."
|
8726
|
-
);
|
8727
|
-
}
|
8728
|
-
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8729
|
-
throw new FuelError20(
|
8730
|
-
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8731
|
-
"Number of assets per wallet must be greater than zero."
|
8732
|
-
);
|
8733
|
-
}
|
8734
|
-
if (coinsPerAsset <= 0) {
|
8735
|
-
throw new FuelError20(
|
8736
|
-
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8737
|
-
"Number of coins per asset must be greater than zero."
|
8738
|
-
);
|
8739
|
-
}
|
8740
|
-
if (amountPerCoin <= 0) {
|
8741
|
-
throw new FuelError20(
|
8742
|
-
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8743
|
-
"Amount per coin must be greater than zero."
|
8744
|
-
);
|
8745
|
-
}
|
8746
|
-
}
|
8747
|
-
};
|
8748
|
-
|
8749
|
-
// src/test-utils/setup-test-provider-and-wallets.ts
|
8750
|
-
var defaultWalletConfigOptions = {
|
8751
|
-
count: 2,
|
8752
|
-
assets: [AssetId.A, AssetId.B],
|
8753
|
-
coinsPerAsset: 1,
|
8754
|
-
amountPerCoin: 1e10,
|
8755
|
-
messages: []
|
8756
|
-
};
|
8757
|
-
async function setupTestProviderAndWallets({
|
8758
|
-
walletConfig: walletConfigOptions = {},
|
8759
|
-
providerOptions,
|
8760
|
-
nodeOptions = {}
|
8761
|
-
} = {}) {
|
8762
|
-
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8763
|
-
const walletConfig = new WalletConfig(
|
8764
|
-
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
|
8765
|
-
{
|
8766
|
-
...defaultWalletConfigOptions,
|
8767
|
-
...walletConfigOptions
|
8768
|
-
}
|
8769
|
-
);
|
8770
|
-
const { cleanup, url } = await launchNode({
|
8771
|
-
loggingEnabled: false,
|
8772
|
-
...nodeOptions,
|
8773
|
-
snapshotConfig: mergeDeepRight(
|
8774
|
-
defaultSnapshotConfigs3,
|
8775
|
-
walletConfig.apply(nodeOptions?.snapshotConfig)
|
8776
|
-
),
|
8777
|
-
port: "0"
|
8778
|
-
});
|
8779
|
-
let provider;
|
8780
|
-
try {
|
8781
|
-
provider = await Provider.create(url, providerOptions);
|
8782
|
-
} catch (err) {
|
8783
|
-
cleanup();
|
8784
|
-
throw err;
|
8785
|
-
}
|
8786
|
-
const wallets = walletConfig.wallets;
|
8787
|
-
wallets.forEach((wallet) => {
|
8788
|
-
wallet.connect(provider);
|
8789
|
-
});
|
8790
|
-
return {
|
8791
|
-
provider,
|
8792
|
-
wallets,
|
8793
|
-
cleanup,
|
8794
|
-
[Symbol.dispose]: cleanup
|
8795
|
-
};
|
8796
|
-
}
|
8797
|
-
|
8798
|
-
// src/test-utils/test-message.ts
|
8799
|
-
import { Address as Address6 } from "@fuel-ts/address";
|
8800
|
-
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
8801
|
-
import { bn as bn21 } from "@fuel-ts/math";
|
8802
|
-
import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
8803
|
-
var TestMessage = class {
|
8804
|
-
sender;
|
8805
|
-
recipient;
|
8806
|
-
nonce;
|
8807
|
-
amount;
|
8808
|
-
data;
|
8809
|
-
da_height;
|
8810
|
-
/**
|
8811
|
-
* A helper class to create messages for testing purposes.
|
8812
|
-
*
|
8813
|
-
* Used in tandem with `WalletConfig`.
|
8814
|
-
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8815
|
-
*/
|
8816
|
-
constructor({
|
8817
|
-
sender = Address6.fromRandom(),
|
8818
|
-
recipient = Address6.fromRandom(),
|
8819
|
-
nonce = hexlify21(randomBytes9(32)),
|
8820
|
-
amount = 1e6,
|
8821
|
-
data = "02",
|
8822
|
-
da_height = 0
|
8823
|
-
} = {}) {
|
8824
|
-
this.sender = sender;
|
8825
|
-
this.recipient = recipient;
|
8826
|
-
this.nonce = nonce;
|
8827
|
-
this.amount = amount;
|
8828
|
-
this.data = data;
|
8829
|
-
this.da_height = da_height;
|
8830
|
-
}
|
8831
|
-
toChainMessage(recipient) {
|
8832
|
-
return {
|
8833
|
-
sender: this.sender.toB256(),
|
8834
|
-
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8835
|
-
nonce: this.nonce,
|
8836
|
-
amount: bn21(this.amount).toNumber(),
|
8837
|
-
data: this.data,
|
8838
|
-
da_height: this.da_height
|
8839
|
-
};
|
8840
|
-
}
|
8841
|
-
};
|
8842
8616
|
export {
|
8843
|
-
AssetId,
|
8844
|
-
TestMessage,
|
8845
|
-
WalletConfig,
|
8846
8617
|
generateTestWallet,
|
8847
8618
|
killNode,
|
8848
8619
|
launchNode,
|
8849
8620
|
launchNodeAndGetWallets,
|
8850
|
-
seedTestWallet
|
8851
|
-
setupTestProviderAndWallets
|
8621
|
+
seedTestWallet
|
8852
8622
|
};
|
8853
8623
|
//# sourceMappingURL=test-utils.mjs.map
|