@fuel-ts/account 0.0.0-rc-2037-20240510180649 → 0.0.0-rc-1356-20240513141855
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/hdwallet/hdwallet.d.ts.map +1 -1
- package/dist/index.global.js +1287 -1545
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +118 -129
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -16
- package/dist/index.mjs.map +1 -1
- package/dist/mnemonic/mnemonic.d.ts.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 +8 -1
- 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 +28 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +49 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +1648 -1584
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +400 -172
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +295 -71
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -16
- 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
@@ -1645,15 +1645,6 @@ 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
|
-
|
1657
1648
|
// src/providers/utils/extract-tx-error.ts
|
1658
1649
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1659
1650
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -3625,6 +3616,7 @@ var TransactionResponse = class {
|
|
3625
3616
|
};
|
3626
3617
|
|
3627
3618
|
// src/providers/utils/auto-retry-fetch.ts
|
3619
|
+
import { sleep } from "@fuel-ts/utils";
|
3628
3620
|
function getWaitDelay(options, retryAttemptNum) {
|
3629
3621
|
const duration = options.baseDelay ?? 150;
|
3630
3622
|
switch (options.backoff) {
|
@@ -5698,18 +5690,17 @@ var BaseWalletUnlocked = class extends Account {
|
|
5698
5690
|
__publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
5699
5691
|
|
5700
5692
|
// src/hdwallet/hdwallet.ts
|
5693
|
+
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
5701
5694
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5702
5695
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5703
5696
|
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5704
|
-
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5 } from "@fuel-ts/utils";
|
5705
|
-
import { toBeHex, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58, computeHmac as computeHmac2, ripemd160 } from "ethers";
|
5697
|
+
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
5706
5698
|
|
5707
5699
|
// src/mnemonic/mnemonic.ts
|
5708
|
-
import { randomBytes as randomBytes4 } from "@fuel-ts/crypto";
|
5700
|
+
import { randomBytes as randomBytes4, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
5709
5701
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5710
5702
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5711
|
-
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4 } from "@fuel-ts/utils";
|
5712
|
-
import { dataSlice, pbkdf2, computeHmac, encodeBase58 } from "ethers";
|
5703
|
+
import { arrayify as arrayify17, hexlify as hexlify16, concat as concat4, dataSlice, encodeBase58 } from "@fuel-ts/utils";
|
5713
5704
|
|
5714
5705
|
// src/wordlists/words/english.ts
|
5715
5706
|
var english = [
|
@@ -8232,7 +8223,7 @@ var HDWallet = class {
|
|
8232
8223
|
});
|
8233
8224
|
}
|
8234
8225
|
static fromExtendedKey(extendedKey) {
|
8235
|
-
const decoded =
|
8226
|
+
const decoded = hexlify17(toBytes2(decodeBase58(extendedKey)));
|
8236
8227
|
const bytes = arrayify18(decoded);
|
8237
8228
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8238
8229
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
@@ -8463,7 +8454,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8463
8454
|
// src/test-utils/launchNode.ts
|
8464
8455
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8465
8456
|
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8466
|
-
import {
|
8457
|
+
import { defaultConsensusKey, hexlify as hexlify18, defaultSnapshotConfigs } from "@fuel-ts/utils";
|
8467
8458
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8468
8459
|
import { spawn } from "child_process";
|
8469
8460
|
import { randomUUID } from "crypto";
|
@@ -8503,6 +8494,40 @@ var killNode = (params) => {
|
|
8503
8494
|
}
|
8504
8495
|
}
|
8505
8496
|
};
|
8497
|
+
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8498
|
+
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8499
|
+
...coin,
|
8500
|
+
amount: "18446744073709551615"
|
8501
|
+
}));
|
8502
|
+
const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8503
|
+
...message,
|
8504
|
+
amount: "18446744073709551615"
|
8505
|
+
}));
|
8506
|
+
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);
|
8507
|
+
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);
|
8508
|
+
if (!process.env.GENESIS_SECRET) {
|
8509
|
+
const pk = Signer.generatePrivateKey();
|
8510
|
+
const signer = new Signer(pk);
|
8511
|
+
process.env.GENESIS_SECRET = hexlify18(pk);
|
8512
|
+
coins.push({
|
8513
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8514
|
+
owner: signer.address.toHexString(),
|
8515
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8516
|
+
amount: "18446744073709551615",
|
8517
|
+
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8518
|
+
output_index: 0,
|
8519
|
+
tx_pointer_block_height: 0,
|
8520
|
+
tx_pointer_tx_idx: 0
|
8521
|
+
});
|
8522
|
+
}
|
8523
|
+
const json = JSON.stringify({
|
8524
|
+
...stateConfig,
|
8525
|
+
coins,
|
8526
|
+
messages
|
8527
|
+
});
|
8528
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8529
|
+
return json.replace(regexMakeNumber, "$1$2");
|
8530
|
+
}
|
8506
8531
|
var launchNode = async ({
|
8507
8532
|
ip,
|
8508
8533
|
port,
|
@@ -8510,7 +8535,8 @@ var launchNode = async ({
|
|
8510
8535
|
useSystemFuelCore = false,
|
8511
8536
|
loggingEnabled = true,
|
8512
8537
|
debugEnabled = false,
|
8513
|
-
basePath
|
8538
|
+
basePath,
|
8539
|
+
snapshotConfig = defaultSnapshotConfigs
|
8514
8540
|
}) => (
|
8515
8541
|
// eslint-disable-next-line no-async-promise-executor
|
8516
8542
|
new Promise(async (resolve, reject) => {
|
@@ -8539,56 +8565,23 @@ var launchNode = async ({
|
|
8539
8565
|
let snapshotDirToUse;
|
8540
8566
|
const prefix = basePath || os.tmpdir();
|
8541
8567
|
const suffix = basePath ? "" : randomUUID();
|
8542
|
-
const
|
8568
|
+
const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8543
8569
|
if (snapshotDir) {
|
8544
8570
|
snapshotDirToUse = snapshotDir;
|
8545
8571
|
} else {
|
8546
|
-
if (!existsSync(
|
8547
|
-
mkdirSync(
|
8572
|
+
if (!existsSync(tempDir)) {
|
8573
|
+
mkdirSync(tempDir, { recursive: true });
|
8548
8574
|
}
|
8549
|
-
|
8550
|
-
const
|
8551
|
-
|
8552
|
-
|
8553
|
-
|
8554
|
-
|
8555
|
-
|
8556
|
-
|
8557
|
-
|
8558
|
-
|
8559
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8560
|
-
...message,
|
8561
|
-
amount: "18446744073709551615"
|
8562
|
-
}))
|
8563
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8564
|
-
};
|
8565
|
-
if (!process.env.GENESIS_SECRET) {
|
8566
|
-
const pk = Signer.generatePrivateKey();
|
8567
|
-
const signer = new Signer(pk);
|
8568
|
-
process.env.GENESIS_SECRET = hexlify18(pk);
|
8569
|
-
stateConfigJson.coins.push({
|
8570
|
-
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8571
|
-
owner: signer.address.toHexString(),
|
8572
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8573
|
-
amount: "18446744073709551615",
|
8574
|
-
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8575
|
-
output_index: 0,
|
8576
|
-
tx_pointer_block_height: 0,
|
8577
|
-
tx_pointer_tx_idx: 0
|
8578
|
-
});
|
8579
|
-
}
|
8580
|
-
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8581
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8582
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8583
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8584
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8585
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8586
|
-
const stateTransitionWritePath = path.join(tempDirPath, "state_transition_bytecode.wasm");
|
8587
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8588
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8589
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8590
|
-
writeFileSync(stateTransitionWritePath, JSON.stringify(""));
|
8591
|
-
snapshotDirToUse = tempDirPath;
|
8575
|
+
const { metadata } = snapshotConfig;
|
8576
|
+
const metadataPath = path.join(tempDir, "metadata.json");
|
8577
|
+
const chainConfigPath = path.join(tempDir, metadata.chain_config);
|
8578
|
+
const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
|
8579
|
+
const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
|
8580
|
+
writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
8581
|
+
writeFileSync(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
8582
|
+
writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
|
8583
|
+
writeFileSync(stateTransitionPath, JSON.stringify(""));
|
8584
|
+
snapshotDirToUse = tempDir;
|
8592
8585
|
}
|
8593
8586
|
const child = spawn(
|
8594
8587
|
command,
|
@@ -8596,7 +8589,7 @@ var launchNode = async ({
|
|
8596
8589
|
"run",
|
8597
8590
|
["--ip", ipToUse],
|
8598
8591
|
["--port", portToUse],
|
8599
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8592
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8600
8593
|
["--min-gas-price", "1"],
|
8601
8594
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8602
8595
|
["--consensus-key", consensusKey],
|
@@ -8618,23 +8611,28 @@ var launchNode = async ({
|
|
8618
8611
|
}
|
8619
8612
|
const cleanupConfig = {
|
8620
8613
|
child,
|
8621
|
-
configPath:
|
8614
|
+
configPath: tempDir,
|
8622
8615
|
killFn: treeKill,
|
8623
8616
|
state: {
|
8624
8617
|
isDead: false
|
8625
8618
|
}
|
8626
8619
|
};
|
8627
8620
|
child.stderr.on("data", (chunk) => {
|
8628
|
-
|
8621
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
8622
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8623
|
+
const rows = text.split("\n");
|
8624
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8625
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8629
8626
|
resolve({
|
8630
8627
|
cleanup: () => killNode(cleanupConfig),
|
8631
|
-
ip:
|
8632
|
-
port:
|
8628
|
+
ip: realIp,
|
8629
|
+
port: realPort,
|
8630
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8633
8631
|
snapshotDir: snapshotDirToUse
|
8634
8632
|
});
|
8635
8633
|
}
|
8636
|
-
if (/error/i.test(
|
8637
|
-
reject(
|
8634
|
+
if (/error/i.test(text)) {
|
8635
|
+
reject(text.toString());
|
8638
8636
|
}
|
8639
8637
|
});
|
8640
8638
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8667,11 +8665,237 @@ var launchNodeAndGetWallets = async ({
|
|
8667
8665
|
};
|
8668
8666
|
return { wallets, stop: cleanup, provider };
|
8669
8667
|
};
|
8668
|
+
|
8669
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8670
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
|
8671
|
+
import { mergeDeepRight } from "ramda";
|
8672
|
+
|
8673
|
+
// src/test-utils/asset-id.ts
|
8674
|
+
import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
|
8675
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
8676
|
+
var _AssetId = class {
|
8677
|
+
constructor(value) {
|
8678
|
+
this.value = value;
|
8679
|
+
}
|
8680
|
+
static random() {
|
8681
|
+
return new _AssetId(hexlify19(randomBytes7(32)));
|
8682
|
+
}
|
8683
|
+
};
|
8684
|
+
var AssetId = _AssetId;
|
8685
|
+
__publicField(AssetId, "A", new _AssetId(
|
8686
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8687
|
+
));
|
8688
|
+
__publicField(AssetId, "B", new _AssetId(
|
8689
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8690
|
+
));
|
8691
|
+
|
8692
|
+
// src/test-utils/wallet-config.ts
|
8693
|
+
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
8694
|
+
import { FuelError as FuelError20 } from "@fuel-ts/errors";
|
8695
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify20 } from "@fuel-ts/utils";
|
8696
|
+
var WalletConfig = class {
|
8697
|
+
initialState;
|
8698
|
+
options;
|
8699
|
+
wallets;
|
8700
|
+
generateWallets = () => {
|
8701
|
+
const generatedWallets = [];
|
8702
|
+
for (let index = 1; index <= this.options.count; index++) {
|
8703
|
+
generatedWallets.push(new WalletUnlocked(randomBytes8(32)));
|
8704
|
+
}
|
8705
|
+
return generatedWallets;
|
8706
|
+
};
|
8707
|
+
constructor(baseAssetId, config) {
|
8708
|
+
const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
|
8709
|
+
WalletConfig.guard(config);
|
8710
|
+
this.options = config;
|
8711
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8712
|
+
this.wallets = this.generateWallets();
|
8713
|
+
this.initialState = {
|
8714
|
+
messages: WalletConfig.createMessages(this.wallets, messages),
|
8715
|
+
coins: WalletConfig.createCoins(
|
8716
|
+
this.wallets,
|
8717
|
+
BASE_ASSET_ID,
|
8718
|
+
assets2,
|
8719
|
+
coinsPerAsset,
|
8720
|
+
amountPerCoin
|
8721
|
+
)
|
8722
|
+
};
|
8723
|
+
}
|
8724
|
+
apply(snapshotConfig) {
|
8725
|
+
return {
|
8726
|
+
...snapshotConfig,
|
8727
|
+
stateConfig: {
|
8728
|
+
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
|
8729
|
+
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8730
|
+
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8731
|
+
}
|
8732
|
+
};
|
8733
|
+
}
|
8734
|
+
static createMessages(wallets, messages) {
|
8735
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8736
|
+
}
|
8737
|
+
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8738
|
+
const coins = [];
|
8739
|
+
let assetIds = [baseAssetId];
|
8740
|
+
if (Array.isArray(assets2)) {
|
8741
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8742
|
+
} else {
|
8743
|
+
for (let index = 0; index < assets2 - 1; index++) {
|
8744
|
+
assetIds.push(AssetId.random().value);
|
8745
|
+
}
|
8746
|
+
}
|
8747
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8748
|
+
assetIds.forEach((assetId) => {
|
8749
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
8750
|
+
coins.push({
|
8751
|
+
amount: amountPerCoin,
|
8752
|
+
asset_id: assetId,
|
8753
|
+
owner: walletAddress,
|
8754
|
+
tx_pointer_block_height: 0,
|
8755
|
+
tx_pointer_tx_idx: 0,
|
8756
|
+
output_index: 0,
|
8757
|
+
tx_id: hexlify20(randomBytes8(32))
|
8758
|
+
});
|
8759
|
+
}
|
8760
|
+
});
|
8761
|
+
});
|
8762
|
+
return coins;
|
8763
|
+
}
|
8764
|
+
static guard({
|
8765
|
+
count: wallets,
|
8766
|
+
assets: assets2,
|
8767
|
+
coinsPerAsset,
|
8768
|
+
amountPerCoin
|
8769
|
+
}) {
|
8770
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8771
|
+
throw new FuelError20(
|
8772
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8773
|
+
"Number of wallets must be greater than zero."
|
8774
|
+
);
|
8775
|
+
}
|
8776
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8777
|
+
throw new FuelError20(
|
8778
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8779
|
+
"Number of assets per wallet must be greater than zero."
|
8780
|
+
);
|
8781
|
+
}
|
8782
|
+
if (coinsPerAsset <= 0) {
|
8783
|
+
throw new FuelError20(
|
8784
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8785
|
+
"Number of coins per asset must be greater than zero."
|
8786
|
+
);
|
8787
|
+
}
|
8788
|
+
if (amountPerCoin <= 0) {
|
8789
|
+
throw new FuelError20(
|
8790
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8791
|
+
"Amount per coin must be greater than zero."
|
8792
|
+
);
|
8793
|
+
}
|
8794
|
+
}
|
8795
|
+
};
|
8796
|
+
|
8797
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8798
|
+
var defaultWalletConfigOptions = {
|
8799
|
+
count: 2,
|
8800
|
+
assets: [AssetId.A, AssetId.B],
|
8801
|
+
coinsPerAsset: 1,
|
8802
|
+
amountPerCoin: 1e10,
|
8803
|
+
messages: []
|
8804
|
+
};
|
8805
|
+
async function setupTestProviderAndWallets({
|
8806
|
+
walletConfig: walletConfigOptions = {},
|
8807
|
+
providerOptions,
|
8808
|
+
nodeOptions = {}
|
8809
|
+
} = {}) {
|
8810
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8811
|
+
const walletConfig = new WalletConfig(
|
8812
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
|
8813
|
+
{
|
8814
|
+
...defaultWalletConfigOptions,
|
8815
|
+
...walletConfigOptions
|
8816
|
+
}
|
8817
|
+
);
|
8818
|
+
const { cleanup, url } = await launchNode({
|
8819
|
+
loggingEnabled: false,
|
8820
|
+
...nodeOptions,
|
8821
|
+
snapshotConfig: mergeDeepRight(
|
8822
|
+
defaultSnapshotConfigs3,
|
8823
|
+
walletConfig.apply(nodeOptions?.snapshotConfig)
|
8824
|
+
),
|
8825
|
+
port: "0"
|
8826
|
+
});
|
8827
|
+
let provider;
|
8828
|
+
try {
|
8829
|
+
provider = await Provider.create(url, providerOptions);
|
8830
|
+
} catch (err) {
|
8831
|
+
cleanup();
|
8832
|
+
throw err;
|
8833
|
+
}
|
8834
|
+
const wallets = walletConfig.wallets;
|
8835
|
+
wallets.forEach((wallet) => {
|
8836
|
+
wallet.connect(provider);
|
8837
|
+
});
|
8838
|
+
return {
|
8839
|
+
provider,
|
8840
|
+
wallets,
|
8841
|
+
cleanup,
|
8842
|
+
[Symbol.dispose]: cleanup
|
8843
|
+
};
|
8844
|
+
}
|
8845
|
+
|
8846
|
+
// src/test-utils/test-message.ts
|
8847
|
+
import { Address as Address6 } from "@fuel-ts/address";
|
8848
|
+
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
8849
|
+
import { bn as bn22 } from "@fuel-ts/math";
|
8850
|
+
import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
8851
|
+
var TestMessage = class {
|
8852
|
+
sender;
|
8853
|
+
recipient;
|
8854
|
+
nonce;
|
8855
|
+
amount;
|
8856
|
+
data;
|
8857
|
+
da_height;
|
8858
|
+
/**
|
8859
|
+
* A helper class to create messages for testing purposes.
|
8860
|
+
*
|
8861
|
+
* Used in tandem with `WalletConfig`.
|
8862
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8863
|
+
*/
|
8864
|
+
constructor({
|
8865
|
+
sender = Address6.fromRandom(),
|
8866
|
+
recipient = Address6.fromRandom(),
|
8867
|
+
nonce = hexlify21(randomBytes9(32)),
|
8868
|
+
amount = 1e6,
|
8869
|
+
data = "02",
|
8870
|
+
da_height = 0
|
8871
|
+
} = {}) {
|
8872
|
+
this.sender = sender;
|
8873
|
+
this.recipient = recipient;
|
8874
|
+
this.nonce = nonce;
|
8875
|
+
this.amount = amount;
|
8876
|
+
this.data = data;
|
8877
|
+
this.da_height = da_height;
|
8878
|
+
}
|
8879
|
+
toChainMessage(recipient) {
|
8880
|
+
return {
|
8881
|
+
sender: this.sender.toB256(),
|
8882
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8883
|
+
nonce: this.nonce,
|
8884
|
+
amount: bn22(this.amount).toNumber(),
|
8885
|
+
data: this.data,
|
8886
|
+
da_height: this.da_height
|
8887
|
+
};
|
8888
|
+
}
|
8889
|
+
};
|
8670
8890
|
export {
|
8891
|
+
AssetId,
|
8892
|
+
TestMessage,
|
8893
|
+
WalletConfig,
|
8671
8894
|
generateTestWallet,
|
8672
8895
|
killNode,
|
8673
8896
|
launchNode,
|
8674
8897
|
launchNodeAndGetWallets,
|
8675
|
-
seedTestWallet
|
8898
|
+
seedTestWallet,
|
8899
|
+
setupTestProviderAndWallets
|
8676
8900
|
};
|
8677
8901
|
//# sourceMappingURL=test-utils.mjs.map
|