@fuel-ts/account 0.0.0-rc-1356-20240514125020 → 0.0.0-rc-2238-20240514153703
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.map +1 -1
- package/dist/index.global.js +432 -1164
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +234 -254
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -145
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +0 -1
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +0 -1
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +0 -2
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +0 -1
- package/dist/providers/transaction-request/transaction-request.d.ts.map +1 -1
- package/dist/providers/transaction-summary/call.d.ts +1 -1
- package/dist/providers/transaction-summary/call.d.ts.map +1 -1
- package/dist/providers/utils/auto-retry-fetch.d.ts.map +1 -1
- package/dist/providers/utils/index.d.ts +1 -0
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/providers/utils/sleep.d.ts +3 -0
- package/dist/providers/utils/sleep.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +0 -4
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +1 -8
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils.global.js +428 -1475
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +272 -523
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +166 -413
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +15 -16
- package/dist/test-utils/asset-id.d.ts +0 -8
- package/dist/test-utils/asset-id.d.ts.map +0 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +0 -33
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +0 -1
- package/dist/test-utils/test-message.d.ts +0 -28
- package/dist/test-utils/test-message.d.ts.map +0 -1
- package/dist/test-utils/wallet-config.d.ts +0 -49
- package/dist/test-utils/wallet-config.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -26,7 +26,7 @@ import { hexlify as hexlify15 } from "@fuel-ts/utils";
|
|
26
26
|
import { Address as Address3 } from "@fuel-ts/address";
|
27
27
|
import { ErrorCode as ErrorCode15, FuelError as FuelError15 } from "@fuel-ts/errors";
|
28
28
|
import { AbstractAccount } from "@fuel-ts/interfaces";
|
29
|
-
import { bn as
|
29
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
30
30
|
import { arrayify as arrayify14, isDefined as isDefined2 } from "@fuel-ts/utils";
|
31
31
|
import { clone as clone4 } from "ramda";
|
32
32
|
|
@@ -68,7 +68,7 @@ var addAmountToCoinQuantities = (params) => {
|
|
68
68
|
// src/providers/provider.ts
|
69
69
|
import { Address as Address2 } from "@fuel-ts/address";
|
70
70
|
import { ErrorCode as ErrorCode13, FuelError as FuelError13 } from "@fuel-ts/errors";
|
71
|
-
import { BN, bn as
|
71
|
+
import { BN, bn as bn17 } from "@fuel-ts/math";
|
72
72
|
import {
|
73
73
|
InputType as InputType7,
|
74
74
|
TransactionType as TransactionType8,
|
@@ -1645,6 +1645,15 @@ function normalizeJSON(root) {
|
|
1645
1645
|
return normalize(clone(root));
|
1646
1646
|
}
|
1647
1647
|
|
1648
|
+
// src/providers/utils/sleep.ts
|
1649
|
+
function sleep(time) {
|
1650
|
+
return new Promise((resolve) => {
|
1651
|
+
setTimeout(() => {
|
1652
|
+
resolve(true);
|
1653
|
+
}, time);
|
1654
|
+
});
|
1655
|
+
}
|
1656
|
+
|
1648
1657
|
// src/providers/utils/extract-tx-error.ts
|
1649
1658
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1650
1659
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -2273,15 +2282,6 @@ var BaseTransactionRequest = class {
|
|
2273
2282
|
}
|
2274
2283
|
});
|
2275
2284
|
}
|
2276
|
-
shiftPredicateData() {
|
2277
|
-
this.inputs.forEach((input) => {
|
2278
|
-
if ("predicateData" in input && "padPredicateData" in input && typeof input.padPredicateData === "function") {
|
2279
|
-
input.predicateData = input.padPredicateData(
|
2280
|
-
BaseTransactionRequest.getPolicyMeta(this).policies.length
|
2281
|
-
);
|
2282
|
-
}
|
2283
|
-
});
|
2284
|
-
}
|
2285
2285
|
};
|
2286
2286
|
|
2287
2287
|
// src/providers/transaction-request/create-transaction-request.ts
|
@@ -2704,12 +2704,12 @@ var transactionRequestify = (obj) => {
|
|
2704
2704
|
|
2705
2705
|
// src/providers/transaction-response/transaction-response.ts
|
2706
2706
|
import { ErrorCode as ErrorCode12, FuelError as FuelError12 } from "@fuel-ts/errors";
|
2707
|
-
import { bn as
|
2707
|
+
import { bn as bn16 } from "@fuel-ts/math";
|
2708
2708
|
import { TransactionCoder as TransactionCoder4 } from "@fuel-ts/transactions";
|
2709
2709
|
import { arrayify as arrayify10 } from "@fuel-ts/utils";
|
2710
2710
|
|
2711
2711
|
// src/providers/transaction-summary/assemble-transaction-summary.ts
|
2712
|
-
import { bn as
|
2712
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
2713
2713
|
import { PolicyType as PolicyType3 } from "@fuel-ts/transactions";
|
2714
2714
|
import { DateTime, hexlify as hexlify11 } from "@fuel-ts/utils";
|
2715
2715
|
|
@@ -2786,43 +2786,32 @@ var calculateTXFeeForSummary = (params) => {
|
|
2786
2786
|
// src/providers/transaction-summary/operations.ts
|
2787
2787
|
import { ZeroBytes32 as ZeroBytes328 } from "@fuel-ts/address/configs";
|
2788
2788
|
import { ErrorCode as ErrorCode10, FuelError as FuelError10 } from "@fuel-ts/errors";
|
2789
|
-
import { bn as
|
2789
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2790
2790
|
import { ReceiptType as ReceiptType4, TransactionType as TransactionType7 } from "@fuel-ts/transactions";
|
2791
2791
|
|
2792
2792
|
// src/providers/transaction-summary/call.ts
|
2793
|
-
import { Interface as Interface2
|
2794
|
-
|
2795
|
-
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2793
|
+
import { Interface as Interface2 } from "@fuel-ts/abi-coder";
|
2794
|
+
var getFunctionCall = ({ abi, receipt }) => {
|
2796
2795
|
const abiInterface = new Interface2(abi);
|
2797
2796
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2798
2797
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2799
2798
|
const inputs = functionFragment.jsonFn.inputs;
|
2800
|
-
|
2801
|
-
if (functionFragment.isInputDataPointer) {
|
2802
|
-
if (rawPayload) {
|
2803
|
-
const argsOffset = bn13(receipt.param2).sub(calculateVmTxMemory({ maxInputs: maxInputs.toNumber() })).toNumber();
|
2804
|
-
encodedArgs = `0x${rawPayload.slice(2).slice(argsOffset * 2)}`;
|
2805
|
-
}
|
2806
|
-
} else {
|
2807
|
-
encodedArgs = receipt.param2.toHex();
|
2808
|
-
}
|
2799
|
+
const encodedArgs = receipt.param2.toHex();
|
2809
2800
|
let argumentsProvided;
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2815
|
-
|
2816
|
-
|
2817
|
-
|
2818
|
-
|
2819
|
-
|
2820
|
-
|
2821
|
-
|
2822
|
-
|
2823
|
-
|
2824
|
-
}, {});
|
2825
|
-
}
|
2801
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
2802
|
+
if (data) {
|
2803
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
2804
|
+
const value = data[index];
|
2805
|
+
const name = input.name;
|
2806
|
+
if (name) {
|
2807
|
+
return {
|
2808
|
+
...prev,
|
2809
|
+
// reparse to remove bn
|
2810
|
+
[name]: JSON.parse(JSON.stringify(value))
|
2811
|
+
};
|
2812
|
+
}
|
2813
|
+
return prev;
|
2814
|
+
}, {});
|
2826
2815
|
}
|
2827
2816
|
const call = {
|
2828
2817
|
functionSignature: functionFragment.signature,
|
@@ -2962,7 +2951,7 @@ var mergeAssets = (op1, op2) => {
|
|
2962
2951
|
if (!matchingAsset) {
|
2963
2952
|
return asset1;
|
2964
2953
|
}
|
2965
|
-
const mergedAmount =
|
2954
|
+
const mergedAmount = bn13(asset1.amount).add(matchingAsset.amount);
|
2966
2955
|
return { ...asset1, amount: mergedAmount };
|
2967
2956
|
});
|
2968
2957
|
return mergedAssets.concat(filteredAssets);
|
@@ -3285,7 +3274,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3285
3274
|
|
3286
3275
|
// src/providers/transaction-summary/status.ts
|
3287
3276
|
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3288
|
-
import { bn as
|
3277
|
+
import { bn as bn14 } from "@fuel-ts/math";
|
3289
3278
|
var getTransactionStatusName = (gqlStatus) => {
|
3290
3279
|
switch (gqlStatus) {
|
3291
3280
|
case "FailureStatus":
|
@@ -3319,15 +3308,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3319
3308
|
time = gqlTransactionStatus.time;
|
3320
3309
|
blockId = gqlTransactionStatus.block.id;
|
3321
3310
|
isStatusSuccess = true;
|
3322
|
-
totalFee =
|
3323
|
-
totalGas =
|
3311
|
+
totalFee = bn14(gqlTransactionStatus.totalFee);
|
3312
|
+
totalGas = bn14(gqlTransactionStatus.totalGas);
|
3324
3313
|
break;
|
3325
3314
|
case "FailureStatus":
|
3326
3315
|
time = gqlTransactionStatus.time;
|
3327
3316
|
blockId = gqlTransactionStatus.block.id;
|
3328
3317
|
isStatusFailure = true;
|
3329
|
-
totalFee =
|
3330
|
-
totalGas =
|
3318
|
+
totalFee = bn14(gqlTransactionStatus.totalFee);
|
3319
|
+
totalGas = bn14(gqlTransactionStatus.totalGas);
|
3331
3320
|
break;
|
3332
3321
|
case "SubmittedStatus":
|
3333
3322
|
time = gqlTransactionStatus.time;
|
@@ -3377,7 +3366,7 @@ function assembleTransactionSummary(params) {
|
|
3377
3366
|
maxInputs
|
3378
3367
|
});
|
3379
3368
|
const typeName = getTransactionTypeName(transaction.type);
|
3380
|
-
const tip =
|
3369
|
+
const tip = bn15(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3381
3370
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
3382
3371
|
const fee = calculateTXFeeForSummary({
|
3383
3372
|
totalFee,
|
@@ -3448,7 +3437,7 @@ var TransactionResponse = class {
|
|
3448
3437
|
/** Current provider */
|
3449
3438
|
provider;
|
3450
3439
|
/** Gas used on the transaction */
|
3451
|
-
gasUsed =
|
3440
|
+
gasUsed = bn16(0);
|
3452
3441
|
/** The graphql Transaction with receipts object. */
|
3453
3442
|
gqlTransaction;
|
3454
3443
|
abis;
|
@@ -3616,7 +3605,6 @@ var TransactionResponse = class {
|
|
3616
3605
|
};
|
3617
3606
|
|
3618
3607
|
// src/providers/utils/auto-retry-fetch.ts
|
3619
|
-
import { sleep } from "@fuel-ts/utils";
|
3620
3608
|
function getWaitDelay(options, retryAttemptNum) {
|
3621
3609
|
const duration = options.baseDelay ?? 150;
|
3622
3610
|
switch (options.backoff) {
|
@@ -3683,47 +3671,47 @@ var processGqlChain = (chain) => {
|
|
3683
3671
|
} = consensusParameters;
|
3684
3672
|
return {
|
3685
3673
|
name,
|
3686
|
-
baseChainHeight:
|
3674
|
+
baseChainHeight: bn17(daHeight),
|
3687
3675
|
consensusParameters: {
|
3688
3676
|
version,
|
3689
|
-
chainId:
|
3677
|
+
chainId: bn17(chainId),
|
3690
3678
|
baseAssetId,
|
3691
3679
|
feeParameters: {
|
3692
3680
|
version: feeParams.version,
|
3693
|
-
gasPerByte:
|
3694
|
-
gasPriceFactor:
|
3681
|
+
gasPerByte: bn17(feeParams.gasPerByte),
|
3682
|
+
gasPriceFactor: bn17(feeParams.gasPriceFactor)
|
3695
3683
|
},
|
3696
3684
|
contractParameters: {
|
3697
3685
|
version: contractParams.version,
|
3698
|
-
contractMaxSize:
|
3699
|
-
maxStorageSlots:
|
3686
|
+
contractMaxSize: bn17(contractParams.contractMaxSize),
|
3687
|
+
maxStorageSlots: bn17(contractParams.maxStorageSlots)
|
3700
3688
|
},
|
3701
3689
|
txParameters: {
|
3702
3690
|
version: txParams.version,
|
3703
|
-
maxInputs:
|
3704
|
-
maxOutputs:
|
3705
|
-
maxWitnesses:
|
3706
|
-
maxGasPerTx:
|
3707
|
-
maxSize:
|
3708
|
-
maxBytecodeSubsections:
|
3691
|
+
maxInputs: bn17(txParams.maxInputs),
|
3692
|
+
maxOutputs: bn17(txParams.maxOutputs),
|
3693
|
+
maxWitnesses: bn17(txParams.maxWitnesses),
|
3694
|
+
maxGasPerTx: bn17(txParams.maxGasPerTx),
|
3695
|
+
maxSize: bn17(txParams.maxSize),
|
3696
|
+
maxBytecodeSubsections: bn17(txParams.maxBytecodeSubsections)
|
3709
3697
|
},
|
3710
3698
|
predicateParameters: {
|
3711
3699
|
version: predicateParams.version,
|
3712
|
-
maxPredicateLength:
|
3713
|
-
maxPredicateDataLength:
|
3714
|
-
maxGasPerPredicate:
|
3715
|
-
maxMessageDataLength:
|
3700
|
+
maxPredicateLength: bn17(predicateParams.maxPredicateLength),
|
3701
|
+
maxPredicateDataLength: bn17(predicateParams.maxPredicateDataLength),
|
3702
|
+
maxGasPerPredicate: bn17(predicateParams.maxGasPerPredicate),
|
3703
|
+
maxMessageDataLength: bn17(predicateParams.maxMessageDataLength)
|
3716
3704
|
},
|
3717
3705
|
scriptParameters: {
|
3718
3706
|
version: scriptParams.version,
|
3719
|
-
maxScriptLength:
|
3720
|
-
maxScriptDataLength:
|
3707
|
+
maxScriptLength: bn17(scriptParams.maxScriptLength),
|
3708
|
+
maxScriptDataLength: bn17(scriptParams.maxScriptDataLength)
|
3721
3709
|
},
|
3722
3710
|
gasCosts
|
3723
3711
|
},
|
3724
3712
|
latestBlock: {
|
3725
3713
|
id: latestBlock.id,
|
3726
|
-
height:
|
3714
|
+
height: bn17(latestBlock.height),
|
3727
3715
|
time: latestBlock.header.time,
|
3728
3716
|
transactions: latestBlock.transactions.map((i) => ({
|
3729
3717
|
id: i.id
|
@@ -3919,7 +3907,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3919
3907
|
*/
|
3920
3908
|
async getBlockNumber() {
|
3921
3909
|
const { chain } = await this.operations.getChain();
|
3922
|
-
return
|
3910
|
+
return bn17(chain.latestBlock.height, 10);
|
3923
3911
|
}
|
3924
3912
|
/**
|
3925
3913
|
* Returns the chain information.
|
@@ -3929,8 +3917,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3929
3917
|
async fetchNode() {
|
3930
3918
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3931
3919
|
const processedNodeInfo = {
|
3932
|
-
maxDepth:
|
3933
|
-
maxTx:
|
3920
|
+
maxDepth: bn17(nodeInfo.maxDepth),
|
3921
|
+
maxTx: bn17(nodeInfo.maxTx),
|
3934
3922
|
nodeVersion: nodeInfo.nodeVersion,
|
3935
3923
|
utxoValidation: nodeInfo.utxoValidation,
|
3936
3924
|
vmBacktrace: nodeInfo.vmBacktrace
|
@@ -4062,7 +4050,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4062
4050
|
} = response;
|
4063
4051
|
if (inputs) {
|
4064
4052
|
inputs.forEach((input, index) => {
|
4065
|
-
if ("predicateGasUsed" in input &&
|
4053
|
+
if ("predicateGasUsed" in input && bn17(input.predicateGasUsed).gt(0)) {
|
4066
4054
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4067
4055
|
}
|
4068
4056
|
});
|
@@ -4220,12 +4208,12 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4220
4208
|
gasPrice = await this.estimateGasPrice(10);
|
4221
4209
|
}
|
4222
4210
|
const minFee = calculateGasFee({
|
4223
|
-
gasPrice:
|
4211
|
+
gasPrice: bn17(gasPrice),
|
4224
4212
|
gas: minGas,
|
4225
4213
|
priceFactor: gasPriceFactor,
|
4226
4214
|
tip: transactionRequest.tip
|
4227
4215
|
}).add(1);
|
4228
|
-
let gasLimit =
|
4216
|
+
let gasLimit = bn17(0);
|
4229
4217
|
if (transactionRequest.type === TransactionType8.Script) {
|
4230
4218
|
gasLimit = transactionRequest.gasLimit;
|
4231
4219
|
if (transactionRequest.gasLimit.eq(0)) {
|
@@ -4238,7 +4226,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4238
4226
|
}
|
4239
4227
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4240
4228
|
const maxFee = calculateGasFee({
|
4241
|
-
gasPrice:
|
4229
|
+
gasPrice: bn17(gasPrice),
|
4242
4230
|
gas: maxGas,
|
4243
4231
|
priceFactor: gasPriceFactor,
|
4244
4232
|
tip: transactionRequest.tip
|
@@ -4303,7 +4291,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4303
4291
|
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4304
4292
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4305
4293
|
if (isScriptTransaction) {
|
4306
|
-
txRequestClone.gasLimit =
|
4294
|
+
txRequestClone.gasLimit = bn17(0);
|
4307
4295
|
}
|
4308
4296
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4309
4297
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4324,7 +4312,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4324
4312
|
let dryRunStatus;
|
4325
4313
|
let missingContractIds = [];
|
4326
4314
|
let outputVariables = 0;
|
4327
|
-
let gasUsed =
|
4315
|
+
let gasUsed = bn17(0);
|
4328
4316
|
txRequestClone.maxFee = maxFee;
|
4329
4317
|
if (isScriptTransaction) {
|
4330
4318
|
txRequestClone.gasLimit = gasLimit;
|
@@ -4389,10 +4377,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4389
4377
|
return coins.map((coin) => ({
|
4390
4378
|
id: coin.utxoId,
|
4391
4379
|
assetId: coin.assetId,
|
4392
|
-
amount:
|
4380
|
+
amount: bn17(coin.amount),
|
4393
4381
|
owner: Address2.fromAddressOrString(coin.owner),
|
4394
|
-
blockCreated:
|
4395
|
-
txCreatedIdx:
|
4382
|
+
blockCreated: bn17(coin.blockCreated),
|
4383
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4396
4384
|
}));
|
4397
4385
|
}
|
4398
4386
|
/**
|
@@ -4429,9 +4417,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4429
4417
|
switch (coin.type) {
|
4430
4418
|
case "MessageCoin":
|
4431
4419
|
return {
|
4432
|
-
amount:
|
4420
|
+
amount: bn17(coin.amount),
|
4433
4421
|
assetId: coin.assetId,
|
4434
|
-
daHeight:
|
4422
|
+
daHeight: bn17(coin.daHeight),
|
4435
4423
|
sender: Address2.fromAddressOrString(coin.sender),
|
4436
4424
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4437
4425
|
nonce: coin.nonce
|
@@ -4439,11 +4427,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4439
4427
|
case "Coin":
|
4440
4428
|
return {
|
4441
4429
|
id: coin.utxoId,
|
4442
|
-
amount:
|
4430
|
+
amount: bn17(coin.amount),
|
4443
4431
|
assetId: coin.assetId,
|
4444
4432
|
owner: Address2.fromAddressOrString(coin.owner),
|
4445
|
-
blockCreated:
|
4446
|
-
txCreatedIdx:
|
4433
|
+
blockCreated: bn17(coin.blockCreated),
|
4434
|
+
txCreatedIdx: bn17(coin.txCreatedIdx)
|
4447
4435
|
};
|
4448
4436
|
default:
|
4449
4437
|
return null;
|
@@ -4460,13 +4448,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4460
4448
|
async getBlock(idOrHeight) {
|
4461
4449
|
let variables;
|
4462
4450
|
if (typeof idOrHeight === "number") {
|
4463
|
-
variables = { height:
|
4451
|
+
variables = { height: bn17(idOrHeight).toString(10) };
|
4464
4452
|
} else if (idOrHeight === "latest") {
|
4465
4453
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4466
4454
|
} else if (idOrHeight.length === 66) {
|
4467
4455
|
variables = { blockId: idOrHeight };
|
4468
4456
|
} else {
|
4469
|
-
variables = { blockId:
|
4457
|
+
variables = { blockId: bn17(idOrHeight).toString(10) };
|
4470
4458
|
}
|
4471
4459
|
const { block } = await this.operations.getBlock(variables);
|
4472
4460
|
if (!block) {
|
@@ -4474,7 +4462,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4474
4462
|
}
|
4475
4463
|
return {
|
4476
4464
|
id: block.id,
|
4477
|
-
height:
|
4465
|
+
height: bn17(block.height),
|
4478
4466
|
time: block.header.time,
|
4479
4467
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4480
4468
|
};
|
@@ -4489,7 +4477,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4489
4477
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4490
4478
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4491
4479
|
id: block.id,
|
4492
|
-
height:
|
4480
|
+
height: bn17(block.height),
|
4493
4481
|
time: block.header.time,
|
4494
4482
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4495
4483
|
}));
|
@@ -4504,7 +4492,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4504
4492
|
async getBlockWithTransactions(idOrHeight) {
|
4505
4493
|
let variables;
|
4506
4494
|
if (typeof idOrHeight === "number") {
|
4507
|
-
variables = { blockHeight:
|
4495
|
+
variables = { blockHeight: bn17(idOrHeight).toString(10) };
|
4508
4496
|
} else if (idOrHeight === "latest") {
|
4509
4497
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4510
4498
|
} else {
|
@@ -4516,7 +4504,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4516
4504
|
}
|
4517
4505
|
return {
|
4518
4506
|
id: block.id,
|
4519
|
-
height:
|
4507
|
+
height: bn17(block.height, 10),
|
4520
4508
|
time: block.header.time,
|
4521
4509
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4522
4510
|
transactions: block.transactions.map(
|
@@ -4565,7 +4553,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4565
4553
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4566
4554
|
asset: hexlify12(assetId)
|
4567
4555
|
});
|
4568
|
-
return
|
4556
|
+
return bn17(contractBalance.amount, 10);
|
4569
4557
|
}
|
4570
4558
|
/**
|
4571
4559
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4579,7 +4567,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4579
4567
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4580
4568
|
assetId: hexlify12(assetId)
|
4581
4569
|
});
|
4582
|
-
return
|
4570
|
+
return bn17(balance.amount, 10);
|
4583
4571
|
}
|
4584
4572
|
/**
|
4585
4573
|
* Returns balances for the given owner.
|
@@ -4597,7 +4585,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4597
4585
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4598
4586
|
return balances.map((balance) => ({
|
4599
4587
|
assetId: balance.assetId,
|
4600
|
-
amount:
|
4588
|
+
amount: bn17(balance.amount)
|
4601
4589
|
}));
|
4602
4590
|
}
|
4603
4591
|
/**
|
@@ -4619,15 +4607,15 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4619
4607
|
sender: message.sender,
|
4620
4608
|
recipient: message.recipient,
|
4621
4609
|
nonce: message.nonce,
|
4622
|
-
amount:
|
4610
|
+
amount: bn17(message.amount),
|
4623
4611
|
data: message.data
|
4624
4612
|
}),
|
4625
4613
|
sender: Address2.fromAddressOrString(message.sender),
|
4626
4614
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4627
4615
|
nonce: message.nonce,
|
4628
|
-
amount:
|
4616
|
+
amount: bn17(message.amount),
|
4629
4617
|
data: InputMessageCoder.decodeData(message.data),
|
4630
|
-
daHeight:
|
4618
|
+
daHeight: bn17(message.daHeight)
|
4631
4619
|
}));
|
4632
4620
|
}
|
4633
4621
|
/**
|
@@ -4680,19 +4668,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4680
4668
|
} = result.messageProof;
|
4681
4669
|
return {
|
4682
4670
|
messageProof: {
|
4683
|
-
proofIndex:
|
4671
|
+
proofIndex: bn17(messageProof.proofIndex),
|
4684
4672
|
proofSet: messageProof.proofSet
|
4685
4673
|
},
|
4686
4674
|
blockProof: {
|
4687
|
-
proofIndex:
|
4675
|
+
proofIndex: bn17(blockProof.proofIndex),
|
4688
4676
|
proofSet: blockProof.proofSet
|
4689
4677
|
},
|
4690
4678
|
messageBlockHeader: {
|
4691
4679
|
id: messageBlockHeader.id,
|
4692
|
-
daHeight:
|
4680
|
+
daHeight: bn17(messageBlockHeader.daHeight),
|
4693
4681
|
transactionsCount: Number(messageBlockHeader.transactionsCount),
|
4694
4682
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4695
|
-
height:
|
4683
|
+
height: bn17(messageBlockHeader.height),
|
4696
4684
|
prevRoot: messageBlockHeader.prevRoot,
|
4697
4685
|
time: messageBlockHeader.time,
|
4698
4686
|
applicationHash: messageBlockHeader.applicationHash,
|
@@ -4704,10 +4692,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4704
4692
|
},
|
4705
4693
|
commitBlockHeader: {
|
4706
4694
|
id: commitBlockHeader.id,
|
4707
|
-
daHeight:
|
4695
|
+
daHeight: bn17(commitBlockHeader.daHeight),
|
4708
4696
|
transactionsCount: Number(commitBlockHeader.transactionsCount),
|
4709
4697
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4710
|
-
height:
|
4698
|
+
height: bn17(commitBlockHeader.height),
|
4711
4699
|
prevRoot: commitBlockHeader.prevRoot,
|
4712
4700
|
time: commitBlockHeader.time,
|
4713
4701
|
applicationHash: commitBlockHeader.applicationHash,
|
@@ -4720,19 +4708,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4720
4708
|
sender: Address2.fromAddressOrString(sender),
|
4721
4709
|
recipient: Address2.fromAddressOrString(recipient),
|
4722
4710
|
nonce,
|
4723
|
-
amount:
|
4711
|
+
amount: bn17(amount),
|
4724
4712
|
data
|
4725
4713
|
};
|
4726
4714
|
}
|
4727
4715
|
async getLatestGasPrice() {
|
4728
4716
|
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4729
|
-
return
|
4717
|
+
return bn17(latestGasPrice.gasPrice);
|
4730
4718
|
}
|
4731
4719
|
async estimateGasPrice(blockHorizon) {
|
4732
4720
|
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4733
4721
|
blockHorizon: String(blockHorizon)
|
4734
4722
|
});
|
4735
|
-
return
|
4723
|
+
return bn17(estimateGasPrice.gasPrice);
|
4736
4724
|
}
|
4737
4725
|
/**
|
4738
4726
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
@@ -4753,10 +4741,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4753
4741
|
*/
|
4754
4742
|
async produceBlocks(amount, startTime) {
|
4755
4743
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4756
|
-
blocksToProduce:
|
4744
|
+
blocksToProduce: bn17(amount).toString(10),
|
4757
4745
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4758
4746
|
});
|
4759
|
-
return
|
4747
|
+
return bn17(latestBlockHeight);
|
4760
4748
|
}
|
4761
4749
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4762
4750
|
async getTransactionResponse(transactionId) {
|
@@ -4802,7 +4790,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4802
4790
|
|
4803
4791
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4804
4792
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4805
|
-
import { bn as
|
4793
|
+
import { bn as bn18 } from "@fuel-ts/math";
|
4806
4794
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4807
4795
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4808
4796
|
|
@@ -5080,9 +5068,9 @@ var Account = class extends AbstractAccount {
|
|
5080
5068
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
|
5081
5069
|
const fee = request.maxFee;
|
5082
5070
|
const baseAssetId = this.provider.getBaseAssetId();
|
5083
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount ||
|
5071
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn19(0);
|
5084
5072
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5085
|
-
amount:
|
5073
|
+
amount: bn19(fee),
|
5086
5074
|
assetId: baseAssetId,
|
5087
5075
|
coinQuantities: requiredQuantities
|
5088
5076
|
});
|
@@ -5090,7 +5078,7 @@ var Account = class extends AbstractAccount {
|
|
5090
5078
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5091
5079
|
quantitiesDict[assetId] = {
|
5092
5080
|
required: amount,
|
5093
|
-
owned:
|
5081
|
+
owned: bn19(0)
|
5094
5082
|
};
|
5095
5083
|
});
|
5096
5084
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -5117,7 +5105,6 @@ var Account = class extends AbstractAccount {
|
|
5117
5105
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
5118
5106
|
);
|
5119
5107
|
request.addResources(resources);
|
5120
|
-
request.shiftPredicateData();
|
5121
5108
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5122
5109
|
const requestToReestimate2 = clone4(request);
|
5123
5110
|
if (addedSignatures) {
|
@@ -5149,7 +5136,6 @@ var Account = class extends AbstractAccount {
|
|
5149
5136
|
}
|
5150
5137
|
fundingAttempts += 1;
|
5151
5138
|
}
|
5152
|
-
request.shiftPredicateData();
|
5153
5139
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5154
5140
|
const requestToReestimate = clone4(request);
|
5155
5141
|
if (addedSignatures) {
|
@@ -5200,7 +5186,7 @@ var Account = class extends AbstractAccount {
|
|
5200
5186
|
* @returns A promise that resolves to the transaction response.
|
5201
5187
|
*/
|
5202
5188
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5203
|
-
if (
|
5189
|
+
if (bn19(amount).lte(0)) {
|
5204
5190
|
throw new FuelError15(
|
5205
5191
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5206
5192
|
"Transfer amount must be a positive number."
|
@@ -5220,7 +5206,7 @@ var Account = class extends AbstractAccount {
|
|
5220
5206
|
* @returns A promise that resolves to the transaction response.
|
5221
5207
|
*/
|
5222
5208
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5223
|
-
if (
|
5209
|
+
if (bn19(amount).lte(0)) {
|
5224
5210
|
throw new FuelError15(
|
5225
5211
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5226
5212
|
"Transfer amount must be a positive number."
|
@@ -5230,7 +5216,7 @@ var Account = class extends AbstractAccount {
|
|
5230
5216
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5231
5217
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5232
5218
|
hexlifiedContractId: contractAddress.toB256(),
|
5233
|
-
amountToTransfer:
|
5219
|
+
amountToTransfer: bn19(amount),
|
5234
5220
|
assetId: assetIdToTransfer
|
5235
5221
|
});
|
5236
5222
|
let request = new ScriptTransactionRequest({
|
@@ -5241,7 +5227,7 @@ var Account = class extends AbstractAccount {
|
|
5241
5227
|
request.addContractInputAndOutput(contractAddress);
|
5242
5228
|
const txCost = await this.provider.getTransactionCost(request, {
|
5243
5229
|
resourcesOwner: this,
|
5244
|
-
quantitiesToContract: [{ amount:
|
5230
|
+
quantitiesToContract: [{ amount: bn19(amount), assetId: String(assetIdToTransfer) }]
|
5245
5231
|
});
|
5246
5232
|
request = this.validateGasLimitAndMaxFee({
|
5247
5233
|
transactionRequest: request,
|
@@ -5266,7 +5252,7 @@ var Account = class extends AbstractAccount {
|
|
5266
5252
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5267
5253
|
);
|
5268
5254
|
const amountDataArray = arrayify14(
|
5269
|
-
"0x".concat(
|
5255
|
+
"0x".concat(bn19(amount).toHex().substring(2).padStart(16, "0"))
|
5270
5256
|
);
|
5271
5257
|
const script = new Uint8Array([
|
5272
5258
|
...arrayify14(withdrawScript.bytes),
|
@@ -5276,7 +5262,7 @@ var Account = class extends AbstractAccount {
|
|
5276
5262
|
const params = { script, ...txParams };
|
5277
5263
|
const baseAssetId = this.provider.getBaseAssetId();
|
5278
5264
|
let request = new ScriptTransactionRequest(params);
|
5279
|
-
const quantitiesToContract = [{ amount:
|
5265
|
+
const quantitiesToContract = [{ amount: bn19(amount), assetId: baseAssetId }];
|
5280
5266
|
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5281
5267
|
request = this.validateGasLimitAndMaxFee({
|
5282
5268
|
transactionRequest: request,
|
@@ -5693,7 +5679,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5693
5679
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
5694
5680
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5695
5681
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5696
|
-
import { bn as
|
5682
|
+
import { bn as bn20, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5697
5683
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
5698
5684
|
|
5699
5685
|
// src/mnemonic/mnemonic.ts
|
@@ -8157,7 +8143,7 @@ var HDWallet = class {
|
|
8157
8143
|
const IR = bytes.slice(32);
|
8158
8144
|
if (privateKey) {
|
8159
8145
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8160
|
-
const ki =
|
8146
|
+
const ki = bn20(IL).add(privateKey).mod(N).toBytes(32);
|
8161
8147
|
return new HDWallet({
|
8162
8148
|
privateKey: ki,
|
8163
8149
|
chainCode: IR,
|
@@ -8454,7 +8440,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8454
8440
|
// src/test-utils/launchNode.ts
|
8455
8441
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8456
8442
|
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8457
|
-
import { defaultConsensusKey, hexlify as hexlify18
|
8443
|
+
import { defaultSnapshotConfigs, defaultConsensusKey, hexlify as hexlify18 } from "@fuel-ts/utils";
|
8458
8444
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8459
8445
|
import { spawn } from "child_process";
|
8460
8446
|
import { randomUUID } from "crypto";
|
@@ -8494,40 +8480,6 @@ var killNode = (params) => {
|
|
8494
8480
|
}
|
8495
8481
|
}
|
8496
8482
|
};
|
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
|
-
}
|
8531
8483
|
var launchNode = async ({
|
8532
8484
|
ip,
|
8533
8485
|
port,
|
@@ -8535,8 +8487,7 @@ var launchNode = async ({
|
|
8535
8487
|
useSystemFuelCore = false,
|
8536
8488
|
loggingEnabled = true,
|
8537
8489
|
debugEnabled = false,
|
8538
|
-
basePath
|
8539
|
-
snapshotConfig = defaultSnapshotConfigs
|
8490
|
+
basePath
|
8540
8491
|
}) => (
|
8541
8492
|
// eslint-disable-next-line no-async-promise-executor
|
8542
8493
|
new Promise(async (resolve, reject) => {
|
@@ -8565,23 +8516,56 @@ var launchNode = async ({
|
|
8565
8516
|
let snapshotDirToUse;
|
8566
8517
|
const prefix = basePath || os.tmpdir();
|
8567
8518
|
const suffix = basePath ? "" : randomUUID();
|
8568
|
-
const
|
8519
|
+
const tempDirPath = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8569
8520
|
if (snapshotDir) {
|
8570
8521
|
snapshotDirToUse = snapshotDir;
|
8571
8522
|
} else {
|
8572
|
-
if (!existsSync(
|
8573
|
-
mkdirSync(
|
8523
|
+
if (!existsSync(tempDirPath)) {
|
8524
|
+
mkdirSync(tempDirPath, { recursive: true });
|
8525
|
+
}
|
8526
|
+
let { stateConfigJson } = defaultSnapshotConfigs;
|
8527
|
+
const { chainConfigJson, metadataJson } = defaultSnapshotConfigs;
|
8528
|
+
stateConfigJson = {
|
8529
|
+
...stateConfigJson,
|
8530
|
+
coins: [
|
8531
|
+
...stateConfigJson.coins.map((coin) => ({
|
8532
|
+
...coin,
|
8533
|
+
amount: "18446744073709551615"
|
8534
|
+
}))
|
8535
|
+
],
|
8536
|
+
messages: stateConfigJson.messages.map((message) => ({
|
8537
|
+
...message,
|
8538
|
+
amount: "18446744073709551615"
|
8539
|
+
}))
|
8540
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8541
|
+
};
|
8542
|
+
if (!process.env.GENESIS_SECRET) {
|
8543
|
+
const pk = Signer.generatePrivateKey();
|
8544
|
+
const signer = new Signer(pk);
|
8545
|
+
process.env.GENESIS_SECRET = hexlify18(pk);
|
8546
|
+
stateConfigJson.coins.push({
|
8547
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8548
|
+
owner: signer.address.toHexString(),
|
8549
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8550
|
+
amount: "18446744073709551615",
|
8551
|
+
asset_id: chainConfigJson.consensus_parameters.V1.base_asset_id,
|
8552
|
+
output_index: 0,
|
8553
|
+
tx_pointer_block_height: 0,
|
8554
|
+
tx_pointer_tx_idx: 0
|
8555
|
+
});
|
8574
8556
|
}
|
8575
|
-
|
8576
|
-
const
|
8577
|
-
|
8578
|
-
const
|
8579
|
-
const
|
8580
|
-
|
8581
|
-
|
8582
|
-
writeFileSync(
|
8583
|
-
writeFileSync(
|
8584
|
-
|
8557
|
+
let fixedStateConfigJSON = JSON.stringify(stateConfigJson);
|
8558
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8559
|
+
fixedStateConfigJSON = fixedStateConfigJSON.replace(regexMakeNumber, "$1$2");
|
8560
|
+
const chainConfigWritePath = path.join(tempDirPath, "chainConfig.json");
|
8561
|
+
const stateConfigWritePath = path.join(tempDirPath, "stateConfig.json");
|
8562
|
+
const metadataWritePath = path.join(tempDirPath, "metadata.json");
|
8563
|
+
const stateTransitionWritePath = path.join(tempDirPath, "state_transition_bytecode.wasm");
|
8564
|
+
writeFileSync(chainConfigWritePath, JSON.stringify(chainConfigJson), "utf8");
|
8565
|
+
writeFileSync(stateConfigWritePath, fixedStateConfigJSON, "utf8");
|
8566
|
+
writeFileSync(metadataWritePath, JSON.stringify(metadataJson), "utf8");
|
8567
|
+
writeFileSync(stateTransitionWritePath, JSON.stringify(""));
|
8568
|
+
snapshotDirToUse = tempDirPath;
|
8585
8569
|
}
|
8586
8570
|
const child = spawn(
|
8587
8571
|
command,
|
@@ -8589,7 +8573,7 @@ var launchNode = async ({
|
|
8589
8573
|
"run",
|
8590
8574
|
["--ip", ipToUse],
|
8591
8575
|
["--port", portToUse],
|
8592
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8576
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDirPath],
|
8593
8577
|
["--min-gas-price", "1"],
|
8594
8578
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8595
8579
|
["--consensus-key", consensusKey],
|
@@ -8611,28 +8595,23 @@ var launchNode = async ({
|
|
8611
8595
|
}
|
8612
8596
|
const cleanupConfig = {
|
8613
8597
|
child,
|
8614
|
-
configPath:
|
8598
|
+
configPath: tempDirPath,
|
8615
8599
|
killFn: treeKill,
|
8616
8600
|
state: {
|
8617
8601
|
isDead: false
|
8618
8602
|
}
|
8619
8603
|
};
|
8620
8604
|
child.stderr.on("data", (chunk) => {
|
8621
|
-
|
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(":");
|
8605
|
+
if (chunk.indexOf(graphQLStartSubstring) !== -1) {
|
8626
8606
|
resolve({
|
8627
8607
|
cleanup: () => killNode(cleanupConfig),
|
8628
|
-
ip:
|
8629
|
-
port:
|
8630
|
-
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8608
|
+
ip: ipToUse,
|
8609
|
+
port: portToUse,
|
8631
8610
|
snapshotDir: snapshotDirToUse
|
8632
8611
|
});
|
8633
8612
|
}
|
8634
|
-
if (/error/i.test(
|
8635
|
-
reject(
|
8613
|
+
if (/error/i.test(chunk)) {
|
8614
|
+
reject(chunk.toString());
|
8636
8615
|
}
|
8637
8616
|
});
|
8638
8617
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8665,237 +8644,11 @@ var launchNodeAndGetWallets = async ({
|
|
8665
8644
|
};
|
8666
8645
|
return { wallets, stop: cleanup, provider };
|
8667
8646
|
};
|
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
|
-
};
|
8890
8647
|
export {
|
8891
|
-
AssetId,
|
8892
|
-
TestMessage,
|
8893
|
-
WalletConfig,
|
8894
8648
|
generateTestWallet,
|
8895
8649
|
killNode,
|
8896
8650
|
launchNode,
|
8897
8651
|
launchNodeAndGetWallets,
|
8898
|
-
seedTestWallet
|
8899
|
-
setupTestProviderAndWallets
|
8652
|
+
seedTestWallet
|
8900
8653
|
};
|
8901
8654
|
//# sourceMappingURL=test-utils.mjs.map
|