@fuel-ts/account 0.89.2 → 0.90.0
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/account.d.ts +8 -0
- package/dist/account.d.ts.map +1 -1
- package/dist/configs.d.ts +3 -1
- package/dist/configs.d.ts.map +1 -1
- package/dist/configs.global.js +4 -2
- package/dist/configs.global.js.map +1 -1
- package/dist/configs.js +10 -4
- package/dist/configs.js.map +1 -1
- package/dist/configs.mjs +7 -3
- package/dist/configs.mjs.map +1 -1
- package/dist/index.global.js +3328 -3275
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +217 -169
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -72
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts +8 -0
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/__generated__/operations.d.ts +58 -0
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/chains.d.ts +1 -1
- package/dist/providers/provider.d.ts +12 -2
- package/dist/providers/provider.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/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 +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.d.ts +8 -0
- package/dist/test-utils.d.ts.map +1 -0
- package/dist/test-utils.global.js +2275 -1900
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +491 -210
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +398 -121
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +1 -1
- package/package.json +18 -17
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -20,14 +20,16 @@ var __privateMethod = (obj, member, method) => {
|
|
20
20
|
|
21
21
|
// src/wallet/base-wallet-unlocked.ts
|
22
22
|
import { hashMessage } from "@fuel-ts/hasher";
|
23
|
-
import { hexlify as
|
23
|
+
import { hexlify as hexlify16 } from "@fuel-ts/utils";
|
24
24
|
|
25
25
|
// src/account.ts
|
26
|
+
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
26
27
|
import { Address as Address3 } from "@fuel-ts/address";
|
28
|
+
import { randomBytes as randomBytes2 } from "@fuel-ts/crypto";
|
27
29
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
30
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
31
|
import { bn as bn19 } from "@fuel-ts/math";
|
30
|
-
import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
|
32
|
+
import { arrayify as arrayify14, hexlify as hexlify13, isDefined as isDefined2 } from "@fuel-ts/utils";
|
31
33
|
import { clone as clone4 } from "ramda";
|
32
34
|
|
33
35
|
// src/providers/coin-quantity.ts
|
@@ -302,6 +304,7 @@ var MessageProofFragmentDoc = gql`
|
|
302
304
|
proofIndex
|
303
305
|
}
|
304
306
|
messageBlockHeader {
|
307
|
+
version
|
305
308
|
id
|
306
309
|
daHeight
|
307
310
|
consensusParametersVersion
|
@@ -317,6 +320,7 @@ var MessageProofFragmentDoc = gql`
|
|
317
320
|
applicationHash
|
318
321
|
}
|
319
322
|
commitBlockHeader {
|
323
|
+
version
|
320
324
|
id
|
321
325
|
daHeight
|
322
326
|
consensusParametersVersion
|
@@ -503,6 +507,9 @@ var GasCostsFragmentDoc = gql`
|
|
503
507
|
wqmm
|
504
508
|
xor
|
505
509
|
xori
|
510
|
+
alocDependentCost {
|
511
|
+
...DependentCostFragment
|
512
|
+
}
|
506
513
|
call {
|
507
514
|
...DependentCostFragment
|
508
515
|
}
|
@@ -687,9 +694,13 @@ var GetTransactionsDocument = gql`
|
|
687
694
|
...transactionFragment
|
688
695
|
}
|
689
696
|
}
|
697
|
+
pageInfo {
|
698
|
+
...pageInfoFragment
|
699
|
+
}
|
690
700
|
}
|
691
701
|
}
|
692
|
-
${TransactionFragmentDoc}
|
702
|
+
${TransactionFragmentDoc}
|
703
|
+
${PageInfoFragmentDoc}`;
|
693
704
|
var GetTransactionsByOwnerDocument = gql`
|
694
705
|
query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
695
706
|
transactionsByOwner(
|
@@ -881,8 +892,12 @@ var GetRelayedTransactionStatusDocument = gql`
|
|
881
892
|
}
|
882
893
|
${RelayedTransactionStatusFragmentDoc}`;
|
883
894
|
var DryRunDocument = gql`
|
884
|
-
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
885
|
-
dryRun(
|
895
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
896
|
+
dryRun(
|
897
|
+
txs: $encodedTransactions
|
898
|
+
utxoValidation: $utxoValidation
|
899
|
+
gasPrice: $gasPrice
|
900
|
+
) {
|
886
901
|
...dryRunTransactionExecutionStatusFragment
|
887
902
|
}
|
888
903
|
}
|
@@ -1647,15 +1662,6 @@ function normalizeJSON(root) {
|
|
1647
1662
|
return normalize(clone(root));
|
1648
1663
|
}
|
1649
1664
|
|
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
1665
|
// src/providers/utils/extract-tx-error.ts
|
1660
1666
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1661
1667
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -3610,6 +3616,7 @@ var TransactionResponse = class {
|
|
3610
3616
|
};
|
3611
3617
|
|
3612
3618
|
// src/providers/utils/auto-retry-fetch.ts
|
3619
|
+
import { sleep } from "@fuel-ts/utils";
|
3613
3620
|
function getWaitDelay(options, retryAttemptNum) {
|
3614
3621
|
const duration = options.baseDelay ?? 150;
|
3615
3622
|
switch (options.backoff) {
|
@@ -4036,7 +4043,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4036
4043
|
* @param sendTransactionParams - The provider call parameters (optional).
|
4037
4044
|
* @returns A promise that resolves to the call result object.
|
4038
4045
|
*/
|
4039
|
-
async
|
4046
|
+
async dryRun(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4040
4047
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4041
4048
|
if (estimateTxDependencies) {
|
4042
4049
|
return this.estimateTxDependencies(transactionRequest);
|
@@ -4575,6 +4582,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4575
4582
|
0
|
4576
4583
|
)?.[0];
|
4577
4584
|
}
|
4585
|
+
/**
|
4586
|
+
* Retrieves transactions based on the provided pagination arguments.
|
4587
|
+
* @param paginationArgs - The pagination arguments for retrieving transactions.
|
4588
|
+
* @returns A promise that resolves to an object containing the retrieved transactions and pagination information.
|
4589
|
+
*/
|
4590
|
+
async getTransactions(paginationArgs) {
|
4591
|
+
const {
|
4592
|
+
transactions: { edges, pageInfo }
|
4593
|
+
} = await this.operations.getTransactions(paginationArgs);
|
4594
|
+
const coder = new TransactionCoder5();
|
4595
|
+
const transactions = edges.map(
|
4596
|
+
({ node: { rawPayload } }) => coder.decode(arrayify11(rawPayload), 0)[0]
|
4597
|
+
);
|
4598
|
+
return { transactions, pageInfo };
|
4599
|
+
}
|
4578
4600
|
/**
|
4579
4601
|
* Get deployed contract with the given ID.
|
4580
4602
|
*
|
@@ -4892,8 +4914,8 @@ var CHAIN_IDS = {
|
|
4892
4914
|
foundry: 31337
|
4893
4915
|
},
|
4894
4916
|
fuel: {
|
4895
|
-
|
4896
|
-
|
4917
|
+
devnet: 0,
|
4918
|
+
testnet: 0
|
4897
4919
|
}
|
4898
4920
|
};
|
4899
4921
|
|
@@ -4941,15 +4963,15 @@ var rawAssets = [
|
|
4941
4963
|
},
|
4942
4964
|
{
|
4943
4965
|
type: "fuel",
|
4944
|
-
chainId: CHAIN_IDS.fuel.
|
4966
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4945
4967
|
decimals: 9,
|
4946
|
-
assetId: "
|
4968
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4947
4969
|
},
|
4948
4970
|
{
|
4949
4971
|
type: "fuel",
|
4950
|
-
chainId: CHAIN_IDS.fuel.
|
4972
|
+
chainId: CHAIN_IDS.fuel.testnet,
|
4951
4973
|
decimals: 9,
|
4952
|
-
assetId: "
|
4974
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4953
4975
|
}
|
4954
4976
|
]
|
4955
4977
|
}
|
@@ -5463,6 +5485,21 @@ var Account = class extends AbstractAccount {
|
|
5463
5485
|
}
|
5464
5486
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5465
5487
|
}
|
5488
|
+
/**
|
5489
|
+
* Generates an array of fake resources based on the provided coins.
|
5490
|
+
*
|
5491
|
+
* @param coins - An array of `FakeResources` objects representing the coins.
|
5492
|
+
* @returns An array of `Resource` objects with generated properties.
|
5493
|
+
*/
|
5494
|
+
generateFakeResources(coins) {
|
5495
|
+
return coins.map((coin) => ({
|
5496
|
+
id: hexlify13(randomBytes2(UTXO_ID_LEN3)),
|
5497
|
+
owner: this.address,
|
5498
|
+
blockCreated: bn19(1),
|
5499
|
+
txCreatedIdx: bn19(1),
|
5500
|
+
...coin
|
5501
|
+
}));
|
5502
|
+
}
|
5466
5503
|
/** @hidden * */
|
5467
5504
|
validateTransferAmount(amount) {
|
5468
5505
|
if (bn19(amount).lte(0)) {
|
@@ -5517,10 +5554,10 @@ var Account = class extends AbstractAccount {
|
|
5517
5554
|
|
5518
5555
|
// src/signer/signer.ts
|
5519
5556
|
import { Address as Address4 } from "@fuel-ts/address";
|
5520
|
-
import { randomBytes as
|
5557
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5521
5558
|
import { hash } from "@fuel-ts/hasher";
|
5522
5559
|
import { toBytes } from "@fuel-ts/math";
|
5523
|
-
import { hexlify as
|
5560
|
+
import { hexlify as hexlify14, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
5524
5561
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
5525
5562
|
var Signer = class {
|
5526
5563
|
address;
|
@@ -5540,9 +5577,9 @@ var Signer = class {
|
|
5540
5577
|
}
|
5541
5578
|
}
|
5542
5579
|
const privateKeyBytes = toBytes(privateKey, 32);
|
5543
|
-
this.privateKey =
|
5544
|
-
this.publicKey =
|
5545
|
-
this.compressedPublicKey =
|
5580
|
+
this.privateKey = hexlify14(privateKeyBytes);
|
5581
|
+
this.publicKey = hexlify14(secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5582
|
+
this.compressedPublicKey = hexlify14(secp256k1.getPublicKey(privateKeyBytes, true));
|
5546
5583
|
this.address = Address4.fromPublicKey(this.publicKey);
|
5547
5584
|
}
|
5548
5585
|
/**
|
@@ -5560,7 +5597,7 @@ var Signer = class {
|
|
5560
5597
|
const r = toBytes(`0x${signature.r.toString(16)}`, 32);
|
5561
5598
|
const s = toBytes(`0x${signature.s.toString(16)}`, 32);
|
5562
5599
|
s[0] |= (signature.recovery || 0) << 7;
|
5563
|
-
return
|
5600
|
+
return hexlify14(concat3([r, s]));
|
5564
5601
|
}
|
5565
5602
|
/**
|
5566
5603
|
* Add point on the current elliptic curve
|
@@ -5587,11 +5624,11 @@ var Signer = class {
|
|
5587
5624
|
const s = signedMessageBytes.slice(32, 64);
|
5588
5625
|
const recoveryParam = (s[0] & 128) >> 7;
|
5589
5626
|
s[0] &= 127;
|
5590
|
-
const sig = new secp256k1.Signature(BigInt(
|
5627
|
+
const sig = new secp256k1.Signature(BigInt(hexlify14(r)), BigInt(hexlify14(s))).addRecoveryBit(
|
5591
5628
|
recoveryParam
|
5592
5629
|
);
|
5593
5630
|
const publicKey = sig.recoverPublicKey(arrayify15(data)).toRawBytes(false).slice(1);
|
5594
|
-
return
|
5631
|
+
return hexlify14(publicKey);
|
5595
5632
|
}
|
5596
5633
|
/**
|
5597
5634
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5610,7 +5647,7 @@ var Signer = class {
|
|
5610
5647
|
* @returns random 32-byte hashed
|
5611
5648
|
*/
|
5612
5649
|
static generatePrivateKey(entropy) {
|
5613
|
-
return entropy ? hash(concat3([
|
5650
|
+
return entropy ? hash(concat3([randomBytes3(32), arrayify15(entropy)])) : randomBytes3(32);
|
5614
5651
|
}
|
5615
5652
|
/**
|
5616
5653
|
* Extended publicKey from a compact publicKey
|
@@ -5620,7 +5657,7 @@ var Signer = class {
|
|
5620
5657
|
*/
|
5621
5658
|
static extendPublicKey(publicKey) {
|
5622
5659
|
const point = secp256k1.ProjectivePoint.fromHex(arrayify15(publicKey));
|
5623
|
-
return
|
5660
|
+
return hexlify14(point.toRawBytes(false).slice(1));
|
5624
5661
|
}
|
5625
5662
|
};
|
5626
5663
|
|
@@ -5629,14 +5666,14 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5629
5666
|
import {
|
5630
5667
|
bufferFromString,
|
5631
5668
|
keccak256,
|
5632
|
-
randomBytes as
|
5669
|
+
randomBytes as randomBytes4,
|
5633
5670
|
scrypt,
|
5634
5671
|
stringFromBuffer,
|
5635
5672
|
decryptJsonWalletData,
|
5636
5673
|
encryptJsonWalletData
|
5637
5674
|
} from "@fuel-ts/crypto";
|
5638
5675
|
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
5639
|
-
import { hexlify as
|
5676
|
+
import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
5640
5677
|
import { v4 as uuidv4 } from "uuid";
|
5641
5678
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5642
5679
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5652,7 +5689,7 @@ var removeHexPrefix = (hexString) => {
|
|
5652
5689
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5653
5690
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5654
5691
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5655
|
-
const salt =
|
5692
|
+
const salt = randomBytes4(DEFAULT_KEY_SIZE);
|
5656
5693
|
const key = scrypt({
|
5657
5694
|
password: bufferFromString(password),
|
5658
5695
|
salt,
|
@@ -5661,7 +5698,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5661
5698
|
r: DEFAULT_KDF_PARAMS_R,
|
5662
5699
|
p: DEFAULT_KDF_PARAMS_P
|
5663
5700
|
});
|
5664
|
-
const iv =
|
5701
|
+
const iv = randomBytes4(DEFAULT_IV_SIZE);
|
5665
5702
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5666
5703
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5667
5704
|
const macHashUint8Array = keccak256(data);
|
@@ -5719,7 +5756,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5719
5756
|
);
|
5720
5757
|
}
|
5721
5758
|
const buffer = await decryptJsonWalletData(ciphertextBuffer, key, ivBuffer);
|
5722
|
-
const privateKey =
|
5759
|
+
const privateKey = hexlify15(buffer);
|
5723
5760
|
return privateKey;
|
5724
5761
|
}
|
5725
5762
|
|
@@ -5764,7 +5801,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5764
5801
|
*/
|
5765
5802
|
async signMessage(message) {
|
5766
5803
|
const signedMessage = await this.signer().sign(hashMessage(message));
|
5767
|
-
return
|
5804
|
+
return hexlify16(signedMessage);
|
5768
5805
|
}
|
5769
5806
|
/**
|
5770
5807
|
* Signs a transaction with the wallet's private key.
|
@@ -5777,7 +5814,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5777
5814
|
const chainId = this.provider.getChainId();
|
5778
5815
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5779
5816
|
const signature = await this.signer().sign(hashedTransaction);
|
5780
|
-
return
|
5817
|
+
return hexlify16(signature);
|
5781
5818
|
}
|
5782
5819
|
/**
|
5783
5820
|
* Populates a transaction with the witnesses signature.
|
@@ -5810,7 +5847,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5810
5847
|
);
|
5811
5848
|
}
|
5812
5849
|
/**
|
5813
|
-
* Populates the witness signature for a transaction and sends a call to the network using `provider.
|
5850
|
+
* Populates the witness signature for a transaction and sends a call to the network using `provider.dryRun`.
|
5814
5851
|
*
|
5815
5852
|
* @param transactionRequestLike - The transaction request to simulate.
|
5816
5853
|
* @returns A promise that resolves to the CallResult object.
|
@@ -5820,7 +5857,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5820
5857
|
if (estimateTxDependencies) {
|
5821
5858
|
await this.provider.estimateTxDependencies(transactionRequest);
|
5822
5859
|
}
|
5823
|
-
return this.provider.
|
5860
|
+
return this.provider.dryRun(
|
5824
5861
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
5825
5862
|
{
|
5826
5863
|
utxoValidation: true,
|
@@ -5848,13 +5885,13 @@ import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
|
5848
5885
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5849
5886
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5850
5887
|
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5851
|
-
import { arrayify as arrayify18, hexlify as
|
5888
|
+
import { arrayify as arrayify18, hexlify as hexlify18, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
5852
5889
|
|
5853
5890
|
// src/mnemonic/mnemonic.ts
|
5854
|
-
import { randomBytes as
|
5891
|
+
import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
5855
5892
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5856
5893
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5857
|
-
import { arrayify as arrayify17, hexlify as
|
5894
|
+
import { arrayify as arrayify17, hexlify as hexlify17, concat as concat4, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
5858
5895
|
|
5859
5896
|
// src/wordlists/words/english.ts
|
5860
5897
|
var english = [
|
@@ -8048,7 +8085,7 @@ var Mnemonic = class {
|
|
8048
8085
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8049
8086
|
const words = getWords(phrase);
|
8050
8087
|
assertMnemonic(words);
|
8051
|
-
return
|
8088
|
+
return hexlify17(mnemonicWordsToEntropy(words, wordlist));
|
8052
8089
|
}
|
8053
8090
|
/**
|
8054
8091
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8173,7 +8210,7 @@ var Mnemonic = class {
|
|
8173
8210
|
* @returns A randomly generated mnemonic
|
8174
8211
|
*/
|
8175
8212
|
static generate(size = 32, extraEntropy = "") {
|
8176
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
8213
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes5(size), arrayify17(extraEntropy)])) : randomBytes5(size);
|
8177
8214
|
return Mnemonic.entropyToMnemonic(entropy);
|
8178
8215
|
}
|
8179
8216
|
};
|
@@ -8181,10 +8218,10 @@ var mnemonic_default = Mnemonic;
|
|
8181
8218
|
|
8182
8219
|
// src/hdwallet/hdwallet.ts
|
8183
8220
|
var HARDENED_INDEX = 2147483648;
|
8184
|
-
var MainnetPRV2 =
|
8185
|
-
var MainnetPUB =
|
8186
|
-
var TestnetPRV2 =
|
8187
|
-
var TestnetPUB =
|
8221
|
+
var MainnetPRV2 = hexlify18("0x0488ade4");
|
8222
|
+
var MainnetPUB = hexlify18("0x0488b21e");
|
8223
|
+
var TestnetPRV2 = hexlify18("0x04358394");
|
8224
|
+
var TestnetPUB = hexlify18("0x043587cf");
|
8188
8225
|
function base58check(data) {
|
8189
8226
|
return encodeBase582(concat5([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
8190
8227
|
}
|
@@ -8195,11 +8232,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8195
8232
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8196
8233
|
}
|
8197
8234
|
function isPublicExtendedKey(extendedKey) {
|
8198
|
-
return [MainnetPUB, TestnetPUB].includes(
|
8235
|
+
return [MainnetPUB, TestnetPUB].includes(hexlify18(extendedKey.slice(0, 4)));
|
8199
8236
|
}
|
8200
8237
|
function isValidExtendedKey(extendedKey) {
|
8201
8238
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8202
|
-
|
8239
|
+
hexlify18(extendedKey.slice(0, 4))
|
8203
8240
|
);
|
8204
8241
|
}
|
8205
8242
|
function parsePath(path2, depth = 0) {
|
@@ -8217,8 +8254,8 @@ function parsePath(path2, depth = 0) {
|
|
8217
8254
|
var HDWallet = class {
|
8218
8255
|
depth = 0;
|
8219
8256
|
index = 0;
|
8220
|
-
fingerprint =
|
8221
|
-
parentFingerprint =
|
8257
|
+
fingerprint = hexlify18("0x00000000");
|
8258
|
+
parentFingerprint = hexlify18("0x00000000");
|
8222
8259
|
privateKey;
|
8223
8260
|
publicKey;
|
8224
8261
|
chainCode;
|
@@ -8230,8 +8267,8 @@ var HDWallet = class {
|
|
8230
8267
|
constructor(config) {
|
8231
8268
|
if (config.privateKey) {
|
8232
8269
|
const signer = new Signer(config.privateKey);
|
8233
|
-
this.publicKey =
|
8234
|
-
this.privateKey =
|
8270
|
+
this.publicKey = hexlify18(signer.compressedPublicKey);
|
8271
|
+
this.privateKey = hexlify18(config.privateKey);
|
8235
8272
|
} else {
|
8236
8273
|
if (!config.publicKey) {
|
8237
8274
|
throw new FuelError19(
|
@@ -8239,7 +8276,7 @@ var HDWallet = class {
|
|
8239
8276
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8240
8277
|
);
|
8241
8278
|
}
|
8242
|
-
this.publicKey =
|
8279
|
+
this.publicKey = hexlify18(config.publicKey);
|
8243
8280
|
}
|
8244
8281
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8245
8282
|
this.fingerprint = dataSlice2(ripemd160(sha2564(this.publicKey)), 0, 4);
|
@@ -8288,7 +8325,7 @@ var HDWallet = class {
|
|
8288
8325
|
parentFingerprint: this.fingerprint
|
8289
8326
|
});
|
8290
8327
|
}
|
8291
|
-
const signer = new Signer(
|
8328
|
+
const signer = new Signer(hexlify18(IL));
|
8292
8329
|
const Ki = signer.addPoint(publicKey);
|
8293
8330
|
return new HDWallet({
|
8294
8331
|
publicKey: Ki,
|
@@ -8323,7 +8360,7 @@ var HDWallet = class {
|
|
8323
8360
|
);
|
8324
8361
|
}
|
8325
8362
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8326
|
-
const depth =
|
8363
|
+
const depth = hexlify18(Uint8Array.from([this.depth]));
|
8327
8364
|
const parentFingerprint = this.parentFingerprint;
|
8328
8365
|
const index = toHex(this.index, 4);
|
8329
8366
|
const chainCode = this.chainCode;
|
@@ -8345,7 +8382,7 @@ var HDWallet = class {
|
|
8345
8382
|
});
|
8346
8383
|
}
|
8347
8384
|
static fromExtendedKey(extendedKey) {
|
8348
|
-
const decoded =
|
8385
|
+
const decoded = hexlify18(toBytes2(decodeBase58(extendedKey)));
|
8349
8386
|
const bytes = arrayify18(decoded);
|
8350
8387
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8351
8388
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
@@ -8355,9 +8392,9 @@ var HDWallet = class {
|
|
8355
8392
|
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8356
8393
|
}
|
8357
8394
|
const depth = bytes[4];
|
8358
|
-
const parentFingerprint =
|
8359
|
-
const index = parseInt(
|
8360
|
-
const chainCode =
|
8395
|
+
const parentFingerprint = hexlify18(bytes.slice(5, 9));
|
8396
|
+
const index = parseInt(hexlify18(bytes.slice(9, 13)).substring(2), 16);
|
8397
|
+
const chainCode = hexlify18(bytes.slice(13, 45));
|
8361
8398
|
const key = bytes.slice(45, 78);
|
8362
8399
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8363
8400
|
throw new FuelError19(
|
@@ -8544,11 +8581,11 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8544
8581
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8545
8582
|
|
8546
8583
|
// src/test-utils/seedTestWallet.ts
|
8547
|
-
import { randomBytes as
|
8584
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8548
8585
|
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
8549
8586
|
const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
|
8550
8587
|
const [{ provider }] = accountsToBeFunded;
|
8551
|
-
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET ||
|
8588
|
+
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || randomBytes6(32), provider);
|
8552
8589
|
const request = new ScriptTransactionRequest();
|
8553
8590
|
quantities.map(coinQuantityfy).forEach(
|
8554
8591
|
({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
|
@@ -8575,8 +8612,8 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8575
8612
|
|
8576
8613
|
// src/test-utils/launchNode.ts
|
8577
8614
|
import { BYTES_32 as BYTES_322 } from "@fuel-ts/abi-coder";
|
8578
|
-
import { randomBytes as
|
8579
|
-
import {
|
8615
|
+
import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
|
8616
|
+
import { defaultConsensusKey, hexlify as hexlify19, defaultSnapshotConfigs } from "@fuel-ts/utils";
|
8580
8617
|
import { spawn } from "child_process";
|
8581
8618
|
import { randomUUID } from "crypto";
|
8582
8619
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
@@ -8615,6 +8652,40 @@ var killNode = (params) => {
|
|
8615
8652
|
}
|
8616
8653
|
}
|
8617
8654
|
};
|
8655
|
+
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8656
|
+
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8657
|
+
...coin,
|
8658
|
+
amount: "18446744073709551615"
|
8659
|
+
}));
|
8660
|
+
const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8661
|
+
...message,
|
8662
|
+
amount: "18446744073709551615"
|
8663
|
+
}));
|
8664
|
+
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);
|
8665
|
+
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);
|
8666
|
+
if (!process.env.GENESIS_SECRET) {
|
8667
|
+
const pk = Signer.generatePrivateKey();
|
8668
|
+
const signer = new Signer(pk);
|
8669
|
+
process.env.GENESIS_SECRET = hexlify19(pk);
|
8670
|
+
coins.push({
|
8671
|
+
tx_id: hexlify19(randomBytes7(BYTES_322)),
|
8672
|
+
owner: signer.address.toHexString(),
|
8673
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8674
|
+
amount: "18446744073709551615",
|
8675
|
+
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8676
|
+
output_index: 0,
|
8677
|
+
tx_pointer_block_height: 0,
|
8678
|
+
tx_pointer_tx_idx: 0
|
8679
|
+
});
|
8680
|
+
}
|
8681
|
+
const json = JSON.stringify({
|
8682
|
+
...stateConfig,
|
8683
|
+
coins,
|
8684
|
+
messages
|
8685
|
+
});
|
8686
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8687
|
+
return json.replace(regexMakeNumber, "$1$2");
|
8688
|
+
}
|
8618
8689
|
var launchNode = async ({
|
8619
8690
|
ip,
|
8620
8691
|
port,
|
@@ -8622,7 +8693,8 @@ var launchNode = async ({
|
|
8622
8693
|
fuelCorePath = process.env.FUEL_CORE_PATH ?? void 0,
|
8623
8694
|
loggingEnabled = true,
|
8624
8695
|
debugEnabled = false,
|
8625
|
-
basePath
|
8696
|
+
basePath,
|
8697
|
+
snapshotConfig = defaultSnapshotConfigs
|
8626
8698
|
}) => (
|
8627
8699
|
// eslint-disable-next-line no-async-promise-executor
|
8628
8700
|
new Promise(async (resolve, reject) => {
|
@@ -8651,56 +8723,23 @@ var launchNode = async ({
|
|
8651
8723
|
let snapshotDirToUse;
|
8652
8724
|
const prefix = basePath || os.tmpdir();
|
8653
8725
|
const suffix = basePath ? "" : randomUUID();
|
8654
|
-
const
|
8726
|
+
const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8655
8727
|
if (snapshotDir) {
|
8656
8728
|
snapshotDirToUse = snapshotDir;
|
8657
8729
|
} else {
|
8658
|
-
if (!existsSync(
|
8659
|
-
mkdirSync(
|
8730
|
+
if (!existsSync(tempDir)) {
|
8731
|
+
mkdirSync(tempDir, { recursive: true });
|
8660
8732
|
}
|
8661
|
-
|
8662
|
-
const
|
8663
|
-
|
8664
|
-
|
8665
|
-
|
8666
|
-
|
8667
|
-
|
8668
|
-
|
8669
|
-
|
8670
|
-
|
8671
|
-
messages: stateConfigJson.messages.map((message) => ({
|
8672
|
-
...message,
|
8673
|
-
amount: "18446744073709551615"
|
8674
|
-
}))
|
8675
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8676
|
-
};
|
8677
|
-
if (!process.env.GENESIS_SECRET) {
|
8678
|
-
const pk = Signer.generatePrivateKey();
|
8679
|
-
const signer = new Signer(pk);
|
8680
|
-
process.env.GENESIS_SECRET = hexlify18(pk);
|
8681
|
-
stateConfigJson.coins.push({
|
8682
|
-
tx_id: hexlify18(randomBytes6(BYTES_322)),
|
8683
|
-
owner: signer.address.toHexString(),
|
8684
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8685
|
-
amount: "18446744073709551615",
|
8686
|
-
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8687
|
-
output_index: 0,
|
8688
|
-
tx_pointer_block_height: 0,
|
8689
|
-
tx_pointer_tx_idx: 0
|
8690
|
-
});
|
8691
|
-
}
|
8692
|
-
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8693
|
-
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8694
|
-
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8695
|
-
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8696
|
-
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8697
|
-
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8698
|
-
const stateTransitionWritePath = path.join(tempDirPath, "state_transition_bytecode.wasm");
|
8699
|
-
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8700
|
-
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8701
|
-
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8702
|
-
writeFileSync(stateTransitionWritePath, JSON.stringify(""));
|
8703
|
-
snapshotDirToUse = tempDirPath;
|
8733
|
+
const { metadata } = snapshotConfig;
|
8734
|
+
const metadataPath = path.join(tempDir, "metadata.json");
|
8735
|
+
const chainConfigPath = path.join(tempDir, metadata.chain_config);
|
8736
|
+
const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
|
8737
|
+
const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
|
8738
|
+
writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
8739
|
+
writeFileSync(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
8740
|
+
writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
|
8741
|
+
writeFileSync(stateTransitionPath, JSON.stringify(""));
|
8742
|
+
snapshotDirToUse = tempDir;
|
8704
8743
|
}
|
8705
8744
|
const child = spawn(
|
8706
8745
|
command,
|
@@ -8708,7 +8747,7 @@ var launchNode = async ({
|
|
8708
8747
|
"run",
|
8709
8748
|
["--ip", ipToUse],
|
8710
8749
|
["--port", portToUse],
|
8711
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8750
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8712
8751
|
["--min-gas-price", "1"],
|
8713
8752
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8714
8753
|
["--native-executor-version", nativeExecutorVersion],
|
@@ -8731,23 +8770,28 @@ var launchNode = async ({
|
|
8731
8770
|
}
|
8732
8771
|
const cleanupConfig = {
|
8733
8772
|
child,
|
8734
|
-
configPath:
|
8773
|
+
configPath: tempDir,
|
8735
8774
|
killFn: treeKill,
|
8736
8775
|
state: {
|
8737
8776
|
isDead: false
|
8738
8777
|
}
|
8739
8778
|
};
|
8740
8779
|
child.stderr.on("data", (chunk) => {
|
8741
|
-
|
8780
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
8781
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8782
|
+
const rows = text.split("\n");
|
8783
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8784
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8742
8785
|
resolve({
|
8743
8786
|
cleanup: () => killNode(cleanupConfig),
|
8744
|
-
ip:
|
8745
|
-
port:
|
8787
|
+
ip: realIp,
|
8788
|
+
port: realPort,
|
8789
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8746
8790
|
snapshotDir: snapshotDirToUse
|
8747
8791
|
});
|
8748
8792
|
}
|
8749
|
-
if (/error/i.test(
|
8750
|
-
reject(
|
8793
|
+
if (/error/i.test(text)) {
|
8794
|
+
reject(text.toString());
|
8751
8795
|
}
|
8752
8796
|
});
|
8753
8797
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8780,11 +8824,244 @@ var launchNodeAndGetWallets = async ({
|
|
8780
8824
|
};
|
8781
8825
|
return { wallets, stop: cleanup, provider };
|
8782
8826
|
};
|
8827
|
+
|
8828
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8829
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
|
8830
|
+
import { mergeDeepRight } from "ramda";
|
8831
|
+
|
8832
|
+
// src/test-utils/asset-id.ts
|
8833
|
+
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
8834
|
+
import { hexlify as hexlify20 } from "@fuel-ts/utils";
|
8835
|
+
var _AssetId = class {
|
8836
|
+
constructor(value) {
|
8837
|
+
this.value = value;
|
8838
|
+
}
|
8839
|
+
static random(count = 1) {
|
8840
|
+
const assetIds = [];
|
8841
|
+
for (let i = 0; i < count; i++) {
|
8842
|
+
assetIds.push(new _AssetId(hexlify20(randomBytes8(32))));
|
8843
|
+
}
|
8844
|
+
return assetIds;
|
8845
|
+
}
|
8846
|
+
};
|
8847
|
+
var AssetId = _AssetId;
|
8848
|
+
__publicField(AssetId, "A", new _AssetId(
|
8849
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8850
|
+
));
|
8851
|
+
__publicField(AssetId, "B", new _AssetId(
|
8852
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8853
|
+
));
|
8854
|
+
|
8855
|
+
// src/test-utils/wallet-config.ts
|
8856
|
+
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
8857
|
+
import { FuelError as FuelError20 } from "@fuel-ts/errors";
|
8858
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify21 } from "@fuel-ts/utils";
|
8859
|
+
var WalletsConfig = class {
|
8860
|
+
initialState;
|
8861
|
+
options;
|
8862
|
+
wallets;
|
8863
|
+
generateWallets = () => {
|
8864
|
+
const generatedWallets = [];
|
8865
|
+
for (let index = 1; index <= this.options.count; index++) {
|
8866
|
+
generatedWallets.push(new WalletUnlocked(randomBytes9(32)));
|
8867
|
+
}
|
8868
|
+
return generatedWallets;
|
8869
|
+
};
|
8870
|
+
constructor(baseAssetId, config) {
|
8871
|
+
WalletsConfig.validate(config);
|
8872
|
+
this.options = config;
|
8873
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8874
|
+
this.wallets = this.generateWallets();
|
8875
|
+
this.initialState = {
|
8876
|
+
messages: WalletsConfig.createMessages(this.wallets, messages),
|
8877
|
+
coins: WalletsConfig.createCoins(
|
8878
|
+
this.wallets,
|
8879
|
+
baseAssetId,
|
8880
|
+
assets2,
|
8881
|
+
coinsPerAsset,
|
8882
|
+
amountPerCoin
|
8883
|
+
)
|
8884
|
+
};
|
8885
|
+
}
|
8886
|
+
apply(snapshotConfig) {
|
8887
|
+
return {
|
8888
|
+
...snapshotConfig,
|
8889
|
+
stateConfig: {
|
8890
|
+
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
|
8891
|
+
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8892
|
+
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8893
|
+
}
|
8894
|
+
};
|
8895
|
+
}
|
8896
|
+
/**
|
8897
|
+
* Create messages for the wallets in the format that the chain expects.
|
8898
|
+
*/
|
8899
|
+
static createMessages(wallets, messages) {
|
8900
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8901
|
+
}
|
8902
|
+
/**
|
8903
|
+
* Create coins for the wallets in the format that the chain expects.
|
8904
|
+
*/
|
8905
|
+
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8906
|
+
const coins = [];
|
8907
|
+
let assetIds = [baseAssetId];
|
8908
|
+
if (Array.isArray(assets2)) {
|
8909
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8910
|
+
} else {
|
8911
|
+
assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
|
8912
|
+
}
|
8913
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8914
|
+
assetIds.forEach((assetId) => {
|
8915
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
8916
|
+
coins.push({
|
8917
|
+
amount: amountPerCoin,
|
8918
|
+
asset_id: assetId,
|
8919
|
+
owner: walletAddress,
|
8920
|
+
tx_pointer_block_height: 0,
|
8921
|
+
tx_pointer_tx_idx: 0,
|
8922
|
+
output_index: 0,
|
8923
|
+
tx_id: hexlify21(randomBytes9(32))
|
8924
|
+
});
|
8925
|
+
}
|
8926
|
+
});
|
8927
|
+
});
|
8928
|
+
return coins;
|
8929
|
+
}
|
8930
|
+
static validate({
|
8931
|
+
count: wallets,
|
8932
|
+
assets: assets2,
|
8933
|
+
coinsPerAsset,
|
8934
|
+
amountPerCoin
|
8935
|
+
}) {
|
8936
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8937
|
+
throw new FuelError20(
|
8938
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8939
|
+
"Number of wallets must be greater than zero."
|
8940
|
+
);
|
8941
|
+
}
|
8942
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8943
|
+
throw new FuelError20(
|
8944
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8945
|
+
"Number of assets per wallet must be greater than zero."
|
8946
|
+
);
|
8947
|
+
}
|
8948
|
+
if (coinsPerAsset <= 0) {
|
8949
|
+
throw new FuelError20(
|
8950
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8951
|
+
"Number of coins per asset must be greater than zero."
|
8952
|
+
);
|
8953
|
+
}
|
8954
|
+
if (amountPerCoin <= 0) {
|
8955
|
+
throw new FuelError20(
|
8956
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8957
|
+
"Amount per coin must be greater than zero."
|
8958
|
+
);
|
8959
|
+
}
|
8960
|
+
}
|
8961
|
+
};
|
8962
|
+
|
8963
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8964
|
+
var defaultWalletConfigOptions = {
|
8965
|
+
count: 2,
|
8966
|
+
assets: [AssetId.A, AssetId.B],
|
8967
|
+
coinsPerAsset: 1,
|
8968
|
+
amountPerCoin: 1e10,
|
8969
|
+
messages: []
|
8970
|
+
};
|
8971
|
+
async function setupTestProviderAndWallets({
|
8972
|
+
walletsConfig: walletsConfigOptions = {},
|
8973
|
+
providerOptions,
|
8974
|
+
nodeOptions = {}
|
8975
|
+
} = {}) {
|
8976
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8977
|
+
const walletsConfig = new WalletsConfig(
|
8978
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
|
8979
|
+
{
|
8980
|
+
...defaultWalletConfigOptions,
|
8981
|
+
...walletsConfigOptions
|
8982
|
+
}
|
8983
|
+
);
|
8984
|
+
const { cleanup, url } = await launchNode({
|
8985
|
+
loggingEnabled: false,
|
8986
|
+
...nodeOptions,
|
8987
|
+
snapshotConfig: mergeDeepRight(
|
8988
|
+
defaultSnapshotConfigs3,
|
8989
|
+
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
8990
|
+
),
|
8991
|
+
port: "0"
|
8992
|
+
});
|
8993
|
+
let provider;
|
8994
|
+
try {
|
8995
|
+
provider = await Provider.create(url, providerOptions);
|
8996
|
+
} catch (err) {
|
8997
|
+
cleanup();
|
8998
|
+
throw err;
|
8999
|
+
}
|
9000
|
+
const wallets = walletsConfig.wallets;
|
9001
|
+
wallets.forEach((wallet) => {
|
9002
|
+
wallet.connect(provider);
|
9003
|
+
});
|
9004
|
+
return {
|
9005
|
+
provider,
|
9006
|
+
wallets,
|
9007
|
+
cleanup,
|
9008
|
+
[Symbol.dispose]: cleanup
|
9009
|
+
};
|
9010
|
+
}
|
9011
|
+
|
9012
|
+
// src/test-utils/test-message.ts
|
9013
|
+
import { Address as Address6 } from "@fuel-ts/address";
|
9014
|
+
import { randomBytes as randomBytes10 } from "@fuel-ts/crypto";
|
9015
|
+
import { bn as bn21 } from "@fuel-ts/math";
|
9016
|
+
import { hexlify as hexlify22 } from "@fuel-ts/utils";
|
9017
|
+
var TestMessage = class {
|
9018
|
+
sender;
|
9019
|
+
recipient;
|
9020
|
+
nonce;
|
9021
|
+
amount;
|
9022
|
+
data;
|
9023
|
+
da_height;
|
9024
|
+
/**
|
9025
|
+
* A helper class to create messages for testing purposes.
|
9026
|
+
*
|
9027
|
+
* Used in tandem with `WalletsConfig`.
|
9028
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
9029
|
+
*/
|
9030
|
+
constructor({
|
9031
|
+
sender = Address6.fromRandom(),
|
9032
|
+
recipient = Address6.fromRandom(),
|
9033
|
+
nonce = hexlify22(randomBytes10(32)),
|
9034
|
+
amount = 1e6,
|
9035
|
+
data = "02",
|
9036
|
+
da_height = 0
|
9037
|
+
} = {}) {
|
9038
|
+
this.sender = sender;
|
9039
|
+
this.recipient = recipient;
|
9040
|
+
this.nonce = nonce;
|
9041
|
+
this.amount = amount;
|
9042
|
+
this.data = data;
|
9043
|
+
this.da_height = da_height;
|
9044
|
+
}
|
9045
|
+
toChainMessage(recipient) {
|
9046
|
+
return {
|
9047
|
+
sender: this.sender.toB256(),
|
9048
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
9049
|
+
nonce: this.nonce,
|
9050
|
+
amount: bn21(this.amount).toNumber(),
|
9051
|
+
data: this.data,
|
9052
|
+
da_height: this.da_height
|
9053
|
+
};
|
9054
|
+
}
|
9055
|
+
};
|
8783
9056
|
export {
|
9057
|
+
AssetId,
|
9058
|
+
TestMessage,
|
9059
|
+
WalletsConfig,
|
8784
9060
|
generateTestWallet,
|
8785
9061
|
killNode,
|
8786
9062
|
launchNode,
|
8787
9063
|
launchNodeAndGetWallets,
|
8788
|
-
seedTestWallet
|
9064
|
+
seedTestWallet,
|
9065
|
+
setupTestProviderAndWallets
|
8789
9066
|
};
|
8790
9067
|
//# sourceMappingURL=test-utils.mjs.map
|