@fuel-ts/account 0.89.2 → 0.91.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 +3228 -2762
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +246 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -81
- 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 +711 -505
- package/dist/providers/__generated__/operations.d.ts.map +1 -1
- package/dist/providers/assets/utils/network.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/extract-tx-error.d.ts +2 -8
- package/dist/providers/utils/extract-tx-error.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 +10 -5
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +34 -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 +2277 -1467
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +546 -234
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +452 -144
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts +1 -1
- package/package.json +26 -25
- 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,15 @@ var GasCostsFragmentDoc = gql`
|
|
503
507
|
wqmm
|
504
508
|
xor
|
505
509
|
xori
|
510
|
+
alocDependentCost {
|
511
|
+
...DependentCostFragment
|
512
|
+
}
|
513
|
+
cfe {
|
514
|
+
...DependentCostFragment
|
515
|
+
}
|
516
|
+
cfeiDependentCost {
|
517
|
+
...DependentCostFragment
|
518
|
+
}
|
506
519
|
call {
|
507
520
|
...DependentCostFragment
|
508
521
|
}
|
@@ -687,9 +700,13 @@ var GetTransactionsDocument = gql`
|
|
687
700
|
...transactionFragment
|
688
701
|
}
|
689
702
|
}
|
703
|
+
pageInfo {
|
704
|
+
...pageInfoFragment
|
705
|
+
}
|
690
706
|
}
|
691
707
|
}
|
692
|
-
${TransactionFragmentDoc}
|
708
|
+
${TransactionFragmentDoc}
|
709
|
+
${PageInfoFragmentDoc}`;
|
693
710
|
var GetTransactionsByOwnerDocument = gql`
|
694
711
|
query getTransactionsByOwner($owner: Address!, $after: String, $before: String, $first: Int, $last: Int) {
|
695
712
|
transactionsByOwner(
|
@@ -881,8 +898,12 @@ var GetRelayedTransactionStatusDocument = gql`
|
|
881
898
|
}
|
882
899
|
${RelayedTransactionStatusFragmentDoc}`;
|
883
900
|
var DryRunDocument = gql`
|
884
|
-
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean) {
|
885
|
-
dryRun(
|
901
|
+
mutation dryRun($encodedTransactions: [HexString!]!, $utxoValidation: Boolean, $gasPrice: U64) {
|
902
|
+
dryRun(
|
903
|
+
txs: $encodedTransactions
|
904
|
+
utxoValidation: $utxoValidation
|
905
|
+
gasPrice: $gasPrice
|
906
|
+
) {
|
886
907
|
...dryRunTransactionExecutionStatusFragment
|
887
908
|
}
|
888
909
|
}
|
@@ -1647,15 +1668,6 @@ function normalizeJSON(root) {
|
|
1647
1668
|
return normalize(clone(root));
|
1648
1669
|
}
|
1649
1670
|
|
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
1671
|
// src/providers/utils/extract-tx-error.ts
|
1660
1672
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1661
1673
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -1669,7 +1681,7 @@ import {
|
|
1669
1681
|
PANIC_REASONS,
|
1670
1682
|
PANIC_DOC_URL
|
1671
1683
|
} from "@fuel-ts/transactions/configs";
|
1672
|
-
var assemblePanicError = (statusReason) => {
|
1684
|
+
var assemblePanicError = (statusReason, metadata) => {
|
1673
1685
|
let errorMessage = `The transaction reverted with reason: "${statusReason}".`;
|
1674
1686
|
if (PANIC_REASONS.includes(statusReason)) {
|
1675
1687
|
errorMessage = `${errorMessage}
|
@@ -1678,10 +1690,13 @@ You can read more about this error at:
|
|
1678
1690
|
|
1679
1691
|
${PANIC_DOC_URL}#variant.${statusReason}`;
|
1680
1692
|
}
|
1681
|
-
return
|
1693
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
1694
|
+
...metadata,
|
1695
|
+
reason: statusReason
|
1696
|
+
});
|
1682
1697
|
};
|
1683
1698
|
var stringify = (obj) => JSON.stringify(obj, null, 2);
|
1684
|
-
var assembleRevertError = (receipts, logs) => {
|
1699
|
+
var assembleRevertError = (receipts, logs, metadata) => {
|
1685
1700
|
let errorMessage = "The transaction reverted with an unknown reason.";
|
1686
1701
|
const revertReceipt = receipts.find(({ type }) => type === ReceiptType3.Revert);
|
1687
1702
|
let reason = "";
|
@@ -1714,25 +1729,36 @@ var assembleRevertError = (receipts, logs) => {
|
|
1714
1729
|
errorMessage = `The transaction reverted because it's missing an "OutputChange".`;
|
1715
1730
|
break;
|
1716
1731
|
default:
|
1717
|
-
|
1718
|
-
|
1732
|
+
throw new FuelError7(
|
1733
|
+
ErrorCode7.UNKNOWN,
|
1734
|
+
`The transaction reverted with an unknown reason: ${revertReceipt.val}`,
|
1735
|
+
{
|
1736
|
+
...metadata,
|
1737
|
+
reason: "unknown"
|
1738
|
+
}
|
1739
|
+
);
|
1719
1740
|
}
|
1720
1741
|
}
|
1721
|
-
return
|
1742
|
+
return new FuelError7(ErrorCode7.SCRIPT_REVERTED, errorMessage, {
|
1743
|
+
...metadata,
|
1744
|
+
reason
|
1745
|
+
});
|
1722
1746
|
};
|
1723
1747
|
var extractTxError = (params) => {
|
1724
1748
|
const { receipts, statusReason, logs } = params;
|
1725
1749
|
const isPanic = receipts.some(({ type }) => type === ReceiptType3.Panic);
|
1726
1750
|
const isRevert = receipts.some(({ type }) => type === ReceiptType3.Revert);
|
1727
|
-
const { errorMessage, reason } = isPanic ? assemblePanicError(statusReason) : assembleRevertError(receipts, logs);
|
1728
1751
|
const metadata = {
|
1729
1752
|
logs,
|
1730
1753
|
receipts,
|
1731
1754
|
panic: isPanic,
|
1732
1755
|
revert: isRevert,
|
1733
|
-
reason
|
1756
|
+
reason: ""
|
1734
1757
|
};
|
1735
|
-
|
1758
|
+
if (isPanic) {
|
1759
|
+
return assemblePanicError(statusReason, metadata);
|
1760
|
+
}
|
1761
|
+
return assembleRevertError(receipts, logs, metadata);
|
1736
1762
|
};
|
1737
1763
|
|
1738
1764
|
// src/providers/transaction-request/errors.ts
|
@@ -3610,6 +3636,7 @@ var TransactionResponse = class {
|
|
3610
3636
|
};
|
3611
3637
|
|
3612
3638
|
// src/providers/utils/auto-retry-fetch.ts
|
3639
|
+
import { sleep } from "@fuel-ts/utils";
|
3613
3640
|
function getWaitDelay(options, retryAttemptNum) {
|
3614
3641
|
const duration = options.baseDelay ?? 150;
|
3615
3642
|
switch (options.backoff) {
|
@@ -4036,7 +4063,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4036
4063
|
* @param sendTransactionParams - The provider call parameters (optional).
|
4037
4064
|
* @returns A promise that resolves to the call result object.
|
4038
4065
|
*/
|
4039
|
-
async
|
4066
|
+
async dryRun(transactionRequestLike, { utxoValidation, estimateTxDependencies = true } = {}) {
|
4040
4067
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
4041
4068
|
if (estimateTxDependencies) {
|
4042
4069
|
return this.estimateTxDependencies(transactionRequest);
|
@@ -4575,6 +4602,21 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4575
4602
|
0
|
4576
4603
|
)?.[0];
|
4577
4604
|
}
|
4605
|
+
/**
|
4606
|
+
* Retrieves transactions based on the provided pagination arguments.
|
4607
|
+
* @param paginationArgs - The pagination arguments for retrieving transactions.
|
4608
|
+
* @returns A promise that resolves to an object containing the retrieved transactions and pagination information.
|
4609
|
+
*/
|
4610
|
+
async getTransactions(paginationArgs) {
|
4611
|
+
const {
|
4612
|
+
transactions: { edges, pageInfo }
|
4613
|
+
} = await this.operations.getTransactions(paginationArgs);
|
4614
|
+
const coder = new TransactionCoder5();
|
4615
|
+
const transactions = edges.map(
|
4616
|
+
({ node: { rawPayload } }) => coder.decode(arrayify11(rawPayload), 0)[0]
|
4617
|
+
);
|
4618
|
+
return { transactions, pageInfo };
|
4619
|
+
}
|
4578
4620
|
/**
|
4579
4621
|
* Get deployed contract with the given ID.
|
4580
4622
|
*
|
@@ -4892,8 +4934,8 @@ var CHAIN_IDS = {
|
|
4892
4934
|
foundry: 31337
|
4893
4935
|
},
|
4894
4936
|
fuel: {
|
4895
|
-
|
4896
|
-
|
4937
|
+
devnet: 0,
|
4938
|
+
testnet: 0
|
4897
4939
|
}
|
4898
4940
|
};
|
4899
4941
|
|
@@ -4941,15 +4983,15 @@ var rawAssets = [
|
|
4941
4983
|
},
|
4942
4984
|
{
|
4943
4985
|
type: "fuel",
|
4944
|
-
chainId: CHAIN_IDS.fuel.
|
4986
|
+
chainId: CHAIN_IDS.fuel.devnet,
|
4945
4987
|
decimals: 9,
|
4946
|
-
assetId: "
|
4988
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4947
4989
|
},
|
4948
4990
|
{
|
4949
4991
|
type: "fuel",
|
4950
|
-
chainId: CHAIN_IDS.fuel.
|
4992
|
+
chainId: CHAIN_IDS.fuel.testnet,
|
4951
4993
|
decimals: 9,
|
4952
|
-
assetId: "
|
4994
|
+
assetId: "0xf8f8b6283d7fa5b672b530cbb84fcccb4ff8dc40f8176ef4544ddb1f1952ad07"
|
4953
4995
|
}
|
4954
4996
|
]
|
4955
4997
|
}
|
@@ -5463,6 +5505,21 @@ var Account = class extends AbstractAccount {
|
|
5463
5505
|
}
|
5464
5506
|
return this.provider.simulate(transactionRequest, { estimateTxDependencies: false });
|
5465
5507
|
}
|
5508
|
+
/**
|
5509
|
+
* Generates an array of fake resources based on the provided coins.
|
5510
|
+
*
|
5511
|
+
* @param coins - An array of `FakeResources` objects representing the coins.
|
5512
|
+
* @returns An array of `Resource` objects with generated properties.
|
5513
|
+
*/
|
5514
|
+
generateFakeResources(coins) {
|
5515
|
+
return coins.map((coin) => ({
|
5516
|
+
id: hexlify13(randomBytes2(UTXO_ID_LEN3)),
|
5517
|
+
owner: this.address,
|
5518
|
+
blockCreated: bn19(1),
|
5519
|
+
txCreatedIdx: bn19(1),
|
5520
|
+
...coin
|
5521
|
+
}));
|
5522
|
+
}
|
5466
5523
|
/** @hidden * */
|
5467
5524
|
validateTransferAmount(amount) {
|
5468
5525
|
if (bn19(amount).lte(0)) {
|
@@ -5517,10 +5574,10 @@ var Account = class extends AbstractAccount {
|
|
5517
5574
|
|
5518
5575
|
// src/signer/signer.ts
|
5519
5576
|
import { Address as Address4 } from "@fuel-ts/address";
|
5520
|
-
import { randomBytes as
|
5577
|
+
import { randomBytes as randomBytes3 } from "@fuel-ts/crypto";
|
5521
5578
|
import { hash } from "@fuel-ts/hasher";
|
5522
5579
|
import { toBytes } from "@fuel-ts/math";
|
5523
|
-
import { hexlify as
|
5580
|
+
import { hexlify as hexlify14, concat as concat3, arrayify as arrayify15 } from "@fuel-ts/utils";
|
5524
5581
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
5525
5582
|
var Signer = class {
|
5526
5583
|
address;
|
@@ -5540,9 +5597,9 @@ var Signer = class {
|
|
5540
5597
|
}
|
5541
5598
|
}
|
5542
5599
|
const privateKeyBytes = toBytes(privateKey, 32);
|
5543
|
-
this.privateKey =
|
5544
|
-
this.publicKey =
|
5545
|
-
this.compressedPublicKey =
|
5600
|
+
this.privateKey = hexlify14(privateKeyBytes);
|
5601
|
+
this.publicKey = hexlify14(secp256k1.getPublicKey(privateKeyBytes, false).slice(1));
|
5602
|
+
this.compressedPublicKey = hexlify14(secp256k1.getPublicKey(privateKeyBytes, true));
|
5546
5603
|
this.address = Address4.fromPublicKey(this.publicKey);
|
5547
5604
|
}
|
5548
5605
|
/**
|
@@ -5560,7 +5617,7 @@ var Signer = class {
|
|
5560
5617
|
const r = toBytes(`0x${signature.r.toString(16)}`, 32);
|
5561
5618
|
const s = toBytes(`0x${signature.s.toString(16)}`, 32);
|
5562
5619
|
s[0] |= (signature.recovery || 0) << 7;
|
5563
|
-
return
|
5620
|
+
return hexlify14(concat3([r, s]));
|
5564
5621
|
}
|
5565
5622
|
/**
|
5566
5623
|
* Add point on the current elliptic curve
|
@@ -5587,11 +5644,11 @@ var Signer = class {
|
|
5587
5644
|
const s = signedMessageBytes.slice(32, 64);
|
5588
5645
|
const recoveryParam = (s[0] & 128) >> 7;
|
5589
5646
|
s[0] &= 127;
|
5590
|
-
const sig = new secp256k1.Signature(BigInt(
|
5647
|
+
const sig = new secp256k1.Signature(BigInt(hexlify14(r)), BigInt(hexlify14(s))).addRecoveryBit(
|
5591
5648
|
recoveryParam
|
5592
5649
|
);
|
5593
5650
|
const publicKey = sig.recoverPublicKey(arrayify15(data)).toRawBytes(false).slice(1);
|
5594
|
-
return
|
5651
|
+
return hexlify14(publicKey);
|
5595
5652
|
}
|
5596
5653
|
/**
|
5597
5654
|
* Recover the address from a signature performed with [`sign`](#sign).
|
@@ -5610,7 +5667,7 @@ var Signer = class {
|
|
5610
5667
|
* @returns random 32-byte hashed
|
5611
5668
|
*/
|
5612
5669
|
static generatePrivateKey(entropy) {
|
5613
|
-
return entropy ? hash(concat3([
|
5670
|
+
return entropy ? hash(concat3([randomBytes3(32), arrayify15(entropy)])) : randomBytes3(32);
|
5614
5671
|
}
|
5615
5672
|
/**
|
5616
5673
|
* Extended publicKey from a compact publicKey
|
@@ -5620,7 +5677,7 @@ var Signer = class {
|
|
5620
5677
|
*/
|
5621
5678
|
static extendPublicKey(publicKey) {
|
5622
5679
|
const point = secp256k1.ProjectivePoint.fromHex(arrayify15(publicKey));
|
5623
|
-
return
|
5680
|
+
return hexlify14(point.toRawBytes(false).slice(1));
|
5624
5681
|
}
|
5625
5682
|
};
|
5626
5683
|
|
@@ -5629,14 +5686,14 @@ import { Address as Address5 } from "@fuel-ts/address";
|
|
5629
5686
|
import {
|
5630
5687
|
bufferFromString,
|
5631
5688
|
keccak256,
|
5632
|
-
randomBytes as
|
5689
|
+
randomBytes as randomBytes4,
|
5633
5690
|
scrypt,
|
5634
5691
|
stringFromBuffer,
|
5635
5692
|
decryptJsonWalletData,
|
5636
5693
|
encryptJsonWalletData
|
5637
5694
|
} from "@fuel-ts/crypto";
|
5638
5695
|
import { ErrorCode as ErrorCode16, FuelError as FuelError16 } from "@fuel-ts/errors";
|
5639
|
-
import { hexlify as
|
5696
|
+
import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
5640
5697
|
import { v4 as uuidv4 } from "uuid";
|
5641
5698
|
var DEFAULT_KDF_PARAMS_LOG_N = 13;
|
5642
5699
|
var DEFAULT_KDF_PARAMS_R = 8;
|
@@ -5652,7 +5709,7 @@ var removeHexPrefix = (hexString) => {
|
|
5652
5709
|
async function encryptKeystoreWallet(privateKey, address, password) {
|
5653
5710
|
const privateKeyBuffer = bufferFromString(removeHexPrefix(privateKey), "hex");
|
5654
5711
|
const ownerAddress = Address5.fromAddressOrString(address);
|
5655
|
-
const salt =
|
5712
|
+
const salt = randomBytes4(DEFAULT_KEY_SIZE);
|
5656
5713
|
const key = scrypt({
|
5657
5714
|
password: bufferFromString(password),
|
5658
5715
|
salt,
|
@@ -5661,7 +5718,7 @@ async function encryptKeystoreWallet(privateKey, address, password) {
|
|
5661
5718
|
r: DEFAULT_KDF_PARAMS_R,
|
5662
5719
|
p: DEFAULT_KDF_PARAMS_P
|
5663
5720
|
});
|
5664
|
-
const iv =
|
5721
|
+
const iv = randomBytes4(DEFAULT_IV_SIZE);
|
5665
5722
|
const ciphertext = await encryptJsonWalletData(privateKeyBuffer, key, iv);
|
5666
5723
|
const data = Uint8Array.from([...key.subarray(16, 32), ...ciphertext]);
|
5667
5724
|
const macHashUint8Array = keccak256(data);
|
@@ -5719,7 +5776,7 @@ async function decryptKeystoreWallet(jsonWallet, password) {
|
|
5719
5776
|
);
|
5720
5777
|
}
|
5721
5778
|
const buffer = await decryptJsonWalletData(ciphertextBuffer, key, ivBuffer);
|
5722
|
-
const privateKey =
|
5779
|
+
const privateKey = hexlify15(buffer);
|
5723
5780
|
return privateKey;
|
5724
5781
|
}
|
5725
5782
|
|
@@ -5764,7 +5821,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5764
5821
|
*/
|
5765
5822
|
async signMessage(message) {
|
5766
5823
|
const signedMessage = await this.signer().sign(hashMessage(message));
|
5767
|
-
return
|
5824
|
+
return hexlify16(signedMessage);
|
5768
5825
|
}
|
5769
5826
|
/**
|
5770
5827
|
* Signs a transaction with the wallet's private key.
|
@@ -5777,7 +5834,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5777
5834
|
const chainId = this.provider.getChainId();
|
5778
5835
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
5779
5836
|
const signature = await this.signer().sign(hashedTransaction);
|
5780
|
-
return
|
5837
|
+
return hexlify16(signature);
|
5781
5838
|
}
|
5782
5839
|
/**
|
5783
5840
|
* Populates a transaction with the witnesses signature.
|
@@ -5810,7 +5867,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5810
5867
|
);
|
5811
5868
|
}
|
5812
5869
|
/**
|
5813
|
-
* Populates the witness signature for a transaction and sends a call to the network using `provider.
|
5870
|
+
* Populates the witness signature for a transaction and sends a call to the network using `provider.dryRun`.
|
5814
5871
|
*
|
5815
5872
|
* @param transactionRequestLike - The transaction request to simulate.
|
5816
5873
|
* @returns A promise that resolves to the CallResult object.
|
@@ -5820,7 +5877,7 @@ var BaseWalletUnlocked = class extends Account {
|
|
5820
5877
|
if (estimateTxDependencies) {
|
5821
5878
|
await this.provider.estimateTxDependencies(transactionRequest);
|
5822
5879
|
}
|
5823
|
-
return this.provider.
|
5880
|
+
return this.provider.dryRun(
|
5824
5881
|
await this.populateTransactionWitnessesSignature(transactionRequest),
|
5825
5882
|
{
|
5826
5883
|
utxoValidation: true,
|
@@ -5848,13 +5905,13 @@ import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
|
5848
5905
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5849
5906
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5850
5907
|
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5851
|
-
import { arrayify as arrayify18, hexlify as
|
5908
|
+
import { arrayify as arrayify18, hexlify as hexlify18, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
5852
5909
|
|
5853
5910
|
// src/mnemonic/mnemonic.ts
|
5854
|
-
import { randomBytes as
|
5911
|
+
import { randomBytes as randomBytes5, pbkdf2, computeHmac } from "@fuel-ts/crypto";
|
5855
5912
|
import { ErrorCode as ErrorCode18, FuelError as FuelError18 } from "@fuel-ts/errors";
|
5856
5913
|
import { sha256 as sha2563 } from "@fuel-ts/hasher";
|
5857
|
-
import { arrayify as arrayify17, hexlify as
|
5914
|
+
import { arrayify as arrayify17, hexlify as hexlify17, concat as concat4, dataSlice, encodeBase58, toUtf8Bytes } from "@fuel-ts/utils";
|
5858
5915
|
|
5859
5916
|
// src/wordlists/words/english.ts
|
5860
5917
|
var english = [
|
@@ -8048,7 +8105,7 @@ var Mnemonic = class {
|
|
8048
8105
|
static mnemonicToEntropy(phrase, wordlist = english) {
|
8049
8106
|
const words = getWords(phrase);
|
8050
8107
|
assertMnemonic(words);
|
8051
|
-
return
|
8108
|
+
return hexlify17(mnemonicWordsToEntropy(words, wordlist));
|
8052
8109
|
}
|
8053
8110
|
/**
|
8054
8111
|
* @param entropy - Entropy source to the mnemonic phrase.
|
@@ -8173,7 +8230,7 @@ var Mnemonic = class {
|
|
8173
8230
|
* @returns A randomly generated mnemonic
|
8174
8231
|
*/
|
8175
8232
|
static generate(size = 32, extraEntropy = "") {
|
8176
|
-
const entropy = extraEntropy ? sha2563(concat4([
|
8233
|
+
const entropy = extraEntropy ? sha2563(concat4([randomBytes5(size), arrayify17(extraEntropy)])) : randomBytes5(size);
|
8177
8234
|
return Mnemonic.entropyToMnemonic(entropy);
|
8178
8235
|
}
|
8179
8236
|
};
|
@@ -8181,10 +8238,10 @@ var mnemonic_default = Mnemonic;
|
|
8181
8238
|
|
8182
8239
|
// src/hdwallet/hdwallet.ts
|
8183
8240
|
var HARDENED_INDEX = 2147483648;
|
8184
|
-
var MainnetPRV2 =
|
8185
|
-
var MainnetPUB =
|
8186
|
-
var TestnetPRV2 =
|
8187
|
-
var TestnetPUB =
|
8241
|
+
var MainnetPRV2 = hexlify18("0x0488ade4");
|
8242
|
+
var MainnetPUB = hexlify18("0x0488b21e");
|
8243
|
+
var TestnetPRV2 = hexlify18("0x04358394");
|
8244
|
+
var TestnetPUB = hexlify18("0x043587cf");
|
8188
8245
|
function base58check(data) {
|
8189
8246
|
return encodeBase582(concat5([data, dataSlice2(sha2564(sha2564(data)), 0, 4)]));
|
8190
8247
|
}
|
@@ -8195,11 +8252,11 @@ function getExtendedKeyPrefix(isPublic = false, testnet = false) {
|
|
8195
8252
|
return testnet ? TestnetPRV2 : MainnetPRV2;
|
8196
8253
|
}
|
8197
8254
|
function isPublicExtendedKey(extendedKey) {
|
8198
|
-
return [MainnetPUB, TestnetPUB].includes(
|
8255
|
+
return [MainnetPUB, TestnetPUB].includes(hexlify18(extendedKey.slice(0, 4)));
|
8199
8256
|
}
|
8200
8257
|
function isValidExtendedKey(extendedKey) {
|
8201
8258
|
return [MainnetPRV2, TestnetPRV2, MainnetPUB, TestnetPUB].includes(
|
8202
|
-
|
8259
|
+
hexlify18(extendedKey.slice(0, 4))
|
8203
8260
|
);
|
8204
8261
|
}
|
8205
8262
|
function parsePath(path2, depth = 0) {
|
@@ -8217,8 +8274,8 @@ function parsePath(path2, depth = 0) {
|
|
8217
8274
|
var HDWallet = class {
|
8218
8275
|
depth = 0;
|
8219
8276
|
index = 0;
|
8220
|
-
fingerprint =
|
8221
|
-
parentFingerprint =
|
8277
|
+
fingerprint = hexlify18("0x00000000");
|
8278
|
+
parentFingerprint = hexlify18("0x00000000");
|
8222
8279
|
privateKey;
|
8223
8280
|
publicKey;
|
8224
8281
|
chainCode;
|
@@ -8230,8 +8287,8 @@ var HDWallet = class {
|
|
8230
8287
|
constructor(config) {
|
8231
8288
|
if (config.privateKey) {
|
8232
8289
|
const signer = new Signer(config.privateKey);
|
8233
|
-
this.publicKey =
|
8234
|
-
this.privateKey =
|
8290
|
+
this.publicKey = hexlify18(signer.compressedPublicKey);
|
8291
|
+
this.privateKey = hexlify18(config.privateKey);
|
8235
8292
|
} else {
|
8236
8293
|
if (!config.publicKey) {
|
8237
8294
|
throw new FuelError19(
|
@@ -8239,7 +8296,7 @@ var HDWallet = class {
|
|
8239
8296
|
"Both public and private Key cannot be missing. At least one should be provided."
|
8240
8297
|
);
|
8241
8298
|
}
|
8242
|
-
this.publicKey =
|
8299
|
+
this.publicKey = hexlify18(config.publicKey);
|
8243
8300
|
}
|
8244
8301
|
this.parentFingerprint = config.parentFingerprint || this.parentFingerprint;
|
8245
8302
|
this.fingerprint = dataSlice2(ripemd160(sha2564(this.publicKey)), 0, 4);
|
@@ -8288,7 +8345,7 @@ var HDWallet = class {
|
|
8288
8345
|
parentFingerprint: this.fingerprint
|
8289
8346
|
});
|
8290
8347
|
}
|
8291
|
-
const signer = new Signer(
|
8348
|
+
const signer = new Signer(hexlify18(IL));
|
8292
8349
|
const Ki = signer.addPoint(publicKey);
|
8293
8350
|
return new HDWallet({
|
8294
8351
|
publicKey: Ki,
|
@@ -8323,7 +8380,7 @@ var HDWallet = class {
|
|
8323
8380
|
);
|
8324
8381
|
}
|
8325
8382
|
const prefix = getExtendedKeyPrefix(this.privateKey == null || isPublic, testnet);
|
8326
|
-
const depth =
|
8383
|
+
const depth = hexlify18(Uint8Array.from([this.depth]));
|
8327
8384
|
const parentFingerprint = this.parentFingerprint;
|
8328
8385
|
const index = toHex(this.index, 4);
|
8329
8386
|
const chainCode = this.chainCode;
|
@@ -8345,7 +8402,7 @@ var HDWallet = class {
|
|
8345
8402
|
});
|
8346
8403
|
}
|
8347
8404
|
static fromExtendedKey(extendedKey) {
|
8348
|
-
const decoded =
|
8405
|
+
const decoded = hexlify18(toBytes2(decodeBase58(extendedKey)));
|
8349
8406
|
const bytes = arrayify18(decoded);
|
8350
8407
|
const validChecksum = base58check(bytes.slice(0, 78)) === extendedKey;
|
8351
8408
|
if (bytes.length !== 82 || !isValidExtendedKey(bytes)) {
|
@@ -8355,9 +8412,9 @@ var HDWallet = class {
|
|
8355
8412
|
throw new FuelError19(ErrorCode19.HD_WALLET_ERROR, "Provided key has an invalid checksum.");
|
8356
8413
|
}
|
8357
8414
|
const depth = bytes[4];
|
8358
|
-
const parentFingerprint =
|
8359
|
-
const index = parseInt(
|
8360
|
-
const chainCode =
|
8415
|
+
const parentFingerprint = hexlify18(bytes.slice(5, 9));
|
8416
|
+
const index = parseInt(hexlify18(bytes.slice(9, 13)).substring(2), 16);
|
8417
|
+
const chainCode = hexlify18(bytes.slice(13, 45));
|
8361
8418
|
const key = bytes.slice(45, 78);
|
8362
8419
|
if (depth === 0 && parentFingerprint !== "0x00000000" || depth === 0 && index !== 0) {
|
8363
8420
|
throw new FuelError19(
|
@@ -8544,11 +8601,11 @@ __publicField(Wallet, "fromExtendedKey", WalletUnlocked.fromExtendedKey);
|
|
8544
8601
|
__publicField(Wallet, "fromEncryptedJson", WalletUnlocked.fromEncryptedJson);
|
8545
8602
|
|
8546
8603
|
// src/test-utils/seedTestWallet.ts
|
8547
|
-
import { randomBytes as
|
8604
|
+
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8548
8605
|
var seedTestWallet = async (wallet, quantities, utxosAmount = 1) => {
|
8549
8606
|
const accountsToBeFunded = Array.isArray(wallet) ? wallet : [wallet];
|
8550
8607
|
const [{ provider }] = accountsToBeFunded;
|
8551
|
-
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET ||
|
8608
|
+
const genesisWallet = new WalletUnlocked(process.env.GENESIS_SECRET || randomBytes6(32), provider);
|
8552
8609
|
const request = new ScriptTransactionRequest();
|
8553
8610
|
quantities.map(coinQuantityfy).forEach(
|
8554
8611
|
({ amount, assetId }) => accountsToBeFunded.forEach(({ address }) => {
|
@@ -8575,9 +8632,9 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8575
8632
|
|
8576
8633
|
// src/test-utils/launchNode.ts
|
8577
8634
|
import { BYTES_32 as BYTES_322 } from "@fuel-ts/abi-coder";
|
8578
|
-
import { randomBytes as
|
8579
|
-
import {
|
8580
|
-
import {
|
8635
|
+
import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
|
8636
|
+
import { FuelError as FuelError20 } from "@fuel-ts/errors";
|
8637
|
+
import { defaultConsensusKey, hexlify as hexlify19, defaultSnapshotConfigs } from "@fuel-ts/utils";
|
8581
8638
|
import { randomUUID } from "crypto";
|
8582
8639
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from "fs";
|
8583
8640
|
import os from "os";
|
@@ -8608,22 +8665,55 @@ var killNode = (params) => {
|
|
8608
8665
|
state.isDead = true;
|
8609
8666
|
killFn(Number(child.pid));
|
8610
8667
|
}
|
8611
|
-
child.stdout.removeAllListeners();
|
8612
8668
|
child.stderr.removeAllListeners();
|
8613
8669
|
if (existsSync(configPath)) {
|
8614
8670
|
rmSync(configPath, { recursive: true });
|
8615
8671
|
}
|
8616
8672
|
}
|
8617
8673
|
};
|
8674
|
+
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8675
|
+
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8676
|
+
...coin,
|
8677
|
+
amount: "18446744073709551615"
|
8678
|
+
}));
|
8679
|
+
const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8680
|
+
...message,
|
8681
|
+
amount: "18446744073709551615"
|
8682
|
+
}));
|
8683
|
+
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);
|
8684
|
+
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);
|
8685
|
+
if (!process.env.GENESIS_SECRET) {
|
8686
|
+
const pk = Signer.generatePrivateKey();
|
8687
|
+
const signer = new Signer(pk);
|
8688
|
+
process.env.GENESIS_SECRET = hexlify19(pk);
|
8689
|
+
coins.push({
|
8690
|
+
tx_id: hexlify19(randomBytes7(BYTES_322)),
|
8691
|
+
owner: signer.address.toHexString(),
|
8692
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8693
|
+
amount: "18446744073709551615",
|
8694
|
+
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8695
|
+
output_index: 0,
|
8696
|
+
tx_pointer_block_height: 0,
|
8697
|
+
tx_pointer_tx_idx: 0
|
8698
|
+
});
|
8699
|
+
}
|
8700
|
+
const json = JSON.stringify({
|
8701
|
+
...stateConfig,
|
8702
|
+
coins,
|
8703
|
+
messages
|
8704
|
+
});
|
8705
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8706
|
+
return json.replace(regexMakeNumber, "$1$2");
|
8707
|
+
}
|
8618
8708
|
var launchNode = async ({
|
8619
8709
|
ip,
|
8620
8710
|
port,
|
8621
8711
|
args = [],
|
8622
|
-
fuelCorePath = process.env.FUEL_CORE_PATH
|
8712
|
+
fuelCorePath = process.env.FUEL_CORE_PATH || void 0,
|
8623
8713
|
loggingEnabled = true,
|
8624
|
-
|
8625
|
-
|
8626
|
-
}) => (
|
8714
|
+
basePath,
|
8715
|
+
snapshotConfig = defaultSnapshotConfigs
|
8716
|
+
} = {}) => (
|
8627
8717
|
// eslint-disable-next-line no-async-promise-executor
|
8628
8718
|
new Promise(async (resolve, reject) => {
|
8629
8719
|
const remainingArgs = extractRemainingArgs(args, [
|
@@ -8640,7 +8730,7 @@ var launchNode = async ({
|
|
8640
8730
|
const poaInstant = poaInstantFlagValue === "true" || poaInstantFlagValue === void 0;
|
8641
8731
|
const nativeExecutorVersion = getFlagValueFromArgs(args, "--native-executor-version") || "0";
|
8642
8732
|
const graphQLStartSubstring = "Binding GraphQL provider to";
|
8643
|
-
const command = fuelCorePath
|
8733
|
+
const command = fuelCorePath || "fuel-core";
|
8644
8734
|
const ipToUse = ip || "0.0.0.0";
|
8645
8735
|
const portToUse = port || (await getPortPromise({
|
8646
8736
|
port: 4e3,
|
@@ -8651,64 +8741,32 @@ var launchNode = async ({
|
|
8651
8741
|
let snapshotDirToUse;
|
8652
8742
|
const prefix = basePath || os.tmpdir();
|
8653
8743
|
const suffix = basePath ? "" : randomUUID();
|
8654
|
-
const
|
8744
|
+
const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8655
8745
|
if (snapshotDir) {
|
8656
8746
|
snapshotDirToUse = snapshotDir;
|
8657
8747
|
} else {
|
8658
|
-
if (!existsSync(
|
8659
|
-
mkdirSync(
|
8660
|
-
}
|
8661
|
-
let { stateConfigJson } = defaultSnapshotConfigs;
|
8662
|
-
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
8663
|
-
stateConfigJson = {
|
8664
|
-
...stateConfigJson,
|
8665
|
-
coins: [
|
8666
|
-
...stateConfigJson.coins.map((coin) => ({
|
8667
|
-
...coin,
|
8668
|
-
amount: "18446744073709551615"
|
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
|
-
});
|
8748
|
+
if (!existsSync(tempDir)) {
|
8749
|
+
mkdirSync(tempDir, { recursive: true });
|
8691
8750
|
}
|
8692
|
-
|
8693
|
-
const
|
8694
|
-
|
8695
|
-
const
|
8696
|
-
const
|
8697
|
-
|
8698
|
-
|
8699
|
-
writeFileSync(
|
8700
|
-
writeFileSync(
|
8701
|
-
|
8702
|
-
|
8703
|
-
|
8704
|
-
}
|
8751
|
+
const { metadata } = snapshotConfig;
|
8752
|
+
const metadataPath = path.join(tempDir, "metadata.json");
|
8753
|
+
const chainConfigPath = path.join(tempDir, metadata.chain_config);
|
8754
|
+
const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
|
8755
|
+
const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
|
8756
|
+
writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
8757
|
+
writeFileSync(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
8758
|
+
writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
|
8759
|
+
writeFileSync(stateTransitionPath, JSON.stringify(""));
|
8760
|
+
snapshotDirToUse = tempDir;
|
8761
|
+
}
|
8762
|
+
const { spawn } = await import("child_process");
|
8705
8763
|
const child = spawn(
|
8706
8764
|
command,
|
8707
8765
|
[
|
8708
8766
|
"run",
|
8709
8767
|
["--ip", ipToUse],
|
8710
8768
|
["--port", portToUse],
|
8711
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8769
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8712
8770
|
["--min-gas-price", "1"],
|
8713
8771
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8714
8772
|
["--native-executor-version", nativeExecutorVersion],
|
@@ -8719,35 +8777,38 @@ var launchNode = async ({
|
|
8719
8777
|
"--debug",
|
8720
8778
|
...remainingArgs
|
8721
8779
|
].flat(),
|
8722
|
-
{
|
8723
|
-
stdio: "pipe"
|
8724
|
-
}
|
8780
|
+
{ stdio: "pipe" }
|
8725
8781
|
);
|
8726
8782
|
if (loggingEnabled) {
|
8727
|
-
child.stderr.
|
8728
|
-
|
8729
|
-
|
8730
|
-
child.stdout.pipe(process.stdout);
|
8783
|
+
child.stderr.on("data", (chunk) => {
|
8784
|
+
console.log(chunk.toString());
|
8785
|
+
});
|
8731
8786
|
}
|
8732
8787
|
const cleanupConfig = {
|
8733
8788
|
child,
|
8734
|
-
configPath:
|
8789
|
+
configPath: tempDir,
|
8735
8790
|
killFn: treeKill,
|
8736
8791
|
state: {
|
8737
8792
|
isDead: false
|
8738
8793
|
}
|
8739
8794
|
};
|
8740
8795
|
child.stderr.on("data", (chunk) => {
|
8741
|
-
|
8796
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
8797
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8798
|
+
const rows = text.split("\n");
|
8799
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8800
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8742
8801
|
resolve({
|
8743
8802
|
cleanup: () => killNode(cleanupConfig),
|
8744
|
-
ip:
|
8745
|
-
port:
|
8803
|
+
ip: realIp,
|
8804
|
+
port: realPort,
|
8805
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8746
8806
|
snapshotDir: snapshotDirToUse
|
8747
8807
|
});
|
8748
8808
|
}
|
8749
|
-
if (/error/i.test(
|
8750
|
-
|
8809
|
+
if (/error/i.test(text)) {
|
8810
|
+
console.log(text);
|
8811
|
+
reject(new FuelError20(FuelError20.CODES.NODE_LAUNCH_FAILED, text));
|
8751
8812
|
}
|
8752
8813
|
});
|
8753
8814
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8780,11 +8841,258 @@ var launchNodeAndGetWallets = async ({
|
|
8780
8841
|
};
|
8781
8842
|
return { wallets, stop: cleanup, provider };
|
8782
8843
|
};
|
8844
|
+
|
8845
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8846
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
|
8847
|
+
import { mergeDeepRight } from "ramda";
|
8848
|
+
|
8849
|
+
// src/test-utils/asset-id.ts
|
8850
|
+
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
8851
|
+
import { hexlify as hexlify20 } from "@fuel-ts/utils";
|
8852
|
+
var _AssetId = class {
|
8853
|
+
constructor(value) {
|
8854
|
+
this.value = value;
|
8855
|
+
}
|
8856
|
+
static random(count = 1) {
|
8857
|
+
const assetIds = [];
|
8858
|
+
for (let i = 0; i < count; i++) {
|
8859
|
+
assetIds.push(new _AssetId(hexlify20(randomBytes8(32))));
|
8860
|
+
}
|
8861
|
+
return assetIds;
|
8862
|
+
}
|
8863
|
+
};
|
8864
|
+
var AssetId = _AssetId;
|
8865
|
+
__publicField(AssetId, "A", new _AssetId(
|
8866
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8867
|
+
));
|
8868
|
+
__publicField(AssetId, "B", new _AssetId(
|
8869
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8870
|
+
));
|
8871
|
+
|
8872
|
+
// src/test-utils/wallet-config.ts
|
8873
|
+
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
8874
|
+
import { FuelError as FuelError21 } from "@fuel-ts/errors";
|
8875
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify21 } from "@fuel-ts/utils";
|
8876
|
+
var WalletsConfig = class {
|
8877
|
+
initialState;
|
8878
|
+
options;
|
8879
|
+
wallets;
|
8880
|
+
generateWallets = () => {
|
8881
|
+
const generatedWallets = [];
|
8882
|
+
for (let index = 1; index <= this.options.count; index++) {
|
8883
|
+
generatedWallets.push(new WalletUnlocked(randomBytes9(32)));
|
8884
|
+
}
|
8885
|
+
return generatedWallets;
|
8886
|
+
};
|
8887
|
+
constructor(baseAssetId, config) {
|
8888
|
+
WalletsConfig.validate(config);
|
8889
|
+
this.options = config;
|
8890
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8891
|
+
this.wallets = this.generateWallets();
|
8892
|
+
this.initialState = {
|
8893
|
+
messages: WalletsConfig.createMessages(this.wallets, messages),
|
8894
|
+
coins: WalletsConfig.createCoins(
|
8895
|
+
this.wallets,
|
8896
|
+
baseAssetId,
|
8897
|
+
assets2,
|
8898
|
+
coinsPerAsset,
|
8899
|
+
amountPerCoin
|
8900
|
+
)
|
8901
|
+
};
|
8902
|
+
}
|
8903
|
+
apply(snapshotConfig) {
|
8904
|
+
return {
|
8905
|
+
...snapshotConfig,
|
8906
|
+
stateConfig: {
|
8907
|
+
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
|
8908
|
+
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8909
|
+
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8910
|
+
}
|
8911
|
+
};
|
8912
|
+
}
|
8913
|
+
/**
|
8914
|
+
* Create messages for the wallets in the format that the chain expects.
|
8915
|
+
*/
|
8916
|
+
static createMessages(wallets, messages) {
|
8917
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8918
|
+
}
|
8919
|
+
/**
|
8920
|
+
* Create coins for the wallets in the format that the chain expects.
|
8921
|
+
*/
|
8922
|
+
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8923
|
+
const coins = [];
|
8924
|
+
let assetIds = [baseAssetId];
|
8925
|
+
if (Array.isArray(assets2)) {
|
8926
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8927
|
+
} else {
|
8928
|
+
assetIds = assetIds.concat(AssetId.random(assets2 - 1).map((a) => a.value));
|
8929
|
+
}
|
8930
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8931
|
+
assetIds.forEach((assetId) => {
|
8932
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
8933
|
+
coins.push({
|
8934
|
+
amount: amountPerCoin,
|
8935
|
+
asset_id: assetId,
|
8936
|
+
owner: walletAddress,
|
8937
|
+
tx_pointer_block_height: 0,
|
8938
|
+
tx_pointer_tx_idx: 0,
|
8939
|
+
output_index: 0,
|
8940
|
+
tx_id: hexlify21(randomBytes9(32))
|
8941
|
+
});
|
8942
|
+
}
|
8943
|
+
});
|
8944
|
+
});
|
8945
|
+
return coins;
|
8946
|
+
}
|
8947
|
+
static validate({
|
8948
|
+
count: wallets,
|
8949
|
+
assets: assets2,
|
8950
|
+
coinsPerAsset,
|
8951
|
+
amountPerCoin
|
8952
|
+
}) {
|
8953
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8954
|
+
throw new FuelError21(
|
8955
|
+
FuelError21.CODES.INVALID_INPUT_PARAMETERS,
|
8956
|
+
"Number of wallets must be greater than zero."
|
8957
|
+
);
|
8958
|
+
}
|
8959
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8960
|
+
throw new FuelError21(
|
8961
|
+
FuelError21.CODES.INVALID_INPUT_PARAMETERS,
|
8962
|
+
"Number of assets per wallet must be greater than zero."
|
8963
|
+
);
|
8964
|
+
}
|
8965
|
+
if (coinsPerAsset <= 0) {
|
8966
|
+
throw new FuelError21(
|
8967
|
+
FuelError21.CODES.INVALID_INPUT_PARAMETERS,
|
8968
|
+
"Number of coins per asset must be greater than zero."
|
8969
|
+
);
|
8970
|
+
}
|
8971
|
+
if (amountPerCoin <= 0) {
|
8972
|
+
throw new FuelError21(
|
8973
|
+
FuelError21.CODES.INVALID_INPUT_PARAMETERS,
|
8974
|
+
"Amount per coin must be greater than zero."
|
8975
|
+
);
|
8976
|
+
}
|
8977
|
+
}
|
8978
|
+
};
|
8979
|
+
|
8980
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8981
|
+
var defaultWalletConfigOptions = {
|
8982
|
+
count: 2,
|
8983
|
+
assets: [AssetId.A, AssetId.B],
|
8984
|
+
coinsPerAsset: 1,
|
8985
|
+
amountPerCoin: 1e10,
|
8986
|
+
messages: []
|
8987
|
+
};
|
8988
|
+
async function setupTestProviderAndWallets({
|
8989
|
+
walletsConfig: walletsConfigOptions = {},
|
8990
|
+
providerOptions,
|
8991
|
+
nodeOptions = {},
|
8992
|
+
launchNodeServerPort = process.env.LAUNCH_NODE_SERVER_PORT || void 0
|
8993
|
+
} = {}) {
|
8994
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8995
|
+
const walletsConfig = new WalletsConfig(
|
8996
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
|
8997
|
+
{
|
8998
|
+
...defaultWalletConfigOptions,
|
8999
|
+
...walletsConfigOptions
|
9000
|
+
}
|
9001
|
+
);
|
9002
|
+
const launchNodeOptions = {
|
9003
|
+
loggingEnabled: false,
|
9004
|
+
...nodeOptions,
|
9005
|
+
snapshotConfig: mergeDeepRight(
|
9006
|
+
defaultSnapshotConfigs3,
|
9007
|
+
walletsConfig.apply(nodeOptions?.snapshotConfig)
|
9008
|
+
),
|
9009
|
+
port: "0"
|
9010
|
+
};
|
9011
|
+
let cleanup;
|
9012
|
+
let url;
|
9013
|
+
if (launchNodeServerPort) {
|
9014
|
+
const serverUrl = `http://localhost:${launchNodeServerPort}`;
|
9015
|
+
url = await (await fetch(serverUrl, { method: "POST", body: JSON.stringify(launchNodeOptions) })).text();
|
9016
|
+
cleanup = () => {
|
9017
|
+
fetch(`${serverUrl}/cleanup/${url}`);
|
9018
|
+
};
|
9019
|
+
} else {
|
9020
|
+
const settings = await launchNode(launchNodeOptions);
|
9021
|
+
url = settings.url;
|
9022
|
+
cleanup = settings.cleanup;
|
9023
|
+
}
|
9024
|
+
let provider;
|
9025
|
+
try {
|
9026
|
+
provider = await Provider.create(url, providerOptions);
|
9027
|
+
} catch (err) {
|
9028
|
+
cleanup();
|
9029
|
+
throw err;
|
9030
|
+
}
|
9031
|
+
const wallets = walletsConfig.wallets;
|
9032
|
+
wallets.forEach((wallet) => {
|
9033
|
+
wallet.connect(provider);
|
9034
|
+
});
|
9035
|
+
return {
|
9036
|
+
provider,
|
9037
|
+
wallets,
|
9038
|
+
cleanup,
|
9039
|
+
[Symbol.dispose]: cleanup
|
9040
|
+
};
|
9041
|
+
}
|
9042
|
+
|
9043
|
+
// src/test-utils/test-message.ts
|
9044
|
+
import { Address as Address6 } from "@fuel-ts/address";
|
9045
|
+
import { randomBytes as randomBytes10 } from "@fuel-ts/crypto";
|
9046
|
+
import { bn as bn21 } from "@fuel-ts/math";
|
9047
|
+
import { hexlify as hexlify22 } from "@fuel-ts/utils";
|
9048
|
+
var TestMessage = class {
|
9049
|
+
sender;
|
9050
|
+
recipient;
|
9051
|
+
nonce;
|
9052
|
+
amount;
|
9053
|
+
data;
|
9054
|
+
da_height;
|
9055
|
+
/**
|
9056
|
+
* A helper class to create messages for testing purposes.
|
9057
|
+
*
|
9058
|
+
* Used in tandem with `WalletsConfig`.
|
9059
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
9060
|
+
*/
|
9061
|
+
constructor({
|
9062
|
+
sender = Address6.fromRandom(),
|
9063
|
+
recipient = Address6.fromRandom(),
|
9064
|
+
nonce = hexlify22(randomBytes10(32)),
|
9065
|
+
amount = 1e6,
|
9066
|
+
data = "02",
|
9067
|
+
da_height = 0
|
9068
|
+
} = {}) {
|
9069
|
+
this.sender = sender;
|
9070
|
+
this.recipient = recipient;
|
9071
|
+
this.nonce = nonce;
|
9072
|
+
this.amount = amount;
|
9073
|
+
this.data = data;
|
9074
|
+
this.da_height = da_height;
|
9075
|
+
}
|
9076
|
+
toChainMessage(recipient) {
|
9077
|
+
return {
|
9078
|
+
sender: this.sender.toB256(),
|
9079
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
9080
|
+
nonce: this.nonce,
|
9081
|
+
amount: bn21(this.amount).toNumber(),
|
9082
|
+
data: this.data,
|
9083
|
+
da_height: this.da_height
|
9084
|
+
};
|
9085
|
+
}
|
9086
|
+
};
|
8783
9087
|
export {
|
9088
|
+
AssetId,
|
9089
|
+
TestMessage,
|
9090
|
+
WalletsConfig,
|
8784
9091
|
generateTestWallet,
|
8785
9092
|
killNode,
|
8786
9093
|
launchNode,
|
8787
9094
|
launchNodeAndGetWallets,
|
8788
|
-
seedTestWallet
|
9095
|
+
seedTestWallet,
|
9096
|
+
setupTestProviderAndWallets
|
8789
9097
|
};
|
8790
9098
|
//# sourceMappingURL=test-utils.mjs.map
|