@fuel-ts/account 0.0.0-rc-2238-20240514123903 → 0.0.0-rc-1356-20240514125020
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 +1140 -408
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +254 -234
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -118
- package/dist/index.mjs.map +1 -1
- package/dist/predicate/predicate.d.ts.map +1 -1
- package/dist/providers/coin.d.ts +1 -0
- package/dist/providers/coin.d.ts.map +1 -1
- package/dist/providers/message.d.ts +1 -0
- package/dist/providers/message.d.ts.map +1 -1
- package/dist/providers/transaction-request/input.d.ts +2 -0
- package/dist/providers/transaction-request/input.d.ts.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +1 -0
- 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 +0 -1
- package/dist/providers/utils/index.d.ts.map +1 -1
- package/dist/test-utils/asset-id.d.ts +8 -0
- package/dist/test-utils/asset-id.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +4 -0
- package/dist/test-utils/index.d.ts.map +1 -1
- package/dist/test-utils/launchNode.d.ts +8 -1
- package/dist/test-utils/launchNode.d.ts.map +1 -1
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts +33 -0
- package/dist/test-utils/setup-test-provider-and-wallets.d.ts.map +1 -0
- package/dist/test-utils/test-message.d.ts +28 -0
- package/dist/test-utils/test-message.d.ts.map +1 -0
- package/dist/test-utils/wallet-config.d.ts +49 -0
- package/dist/test-utils/wallet-config.d.ts.map +1 -0
- package/dist/test-utils.global.js +1465 -418
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +523 -272
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +413 -166
- package/dist/test-utils.mjs.map +1 -1
- package/package.json +16 -15
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
package/dist/test-utils.mjs
CHANGED
@@ -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 bn20 } 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 bn18 } from "@fuel-ts/math";
|
72
72
|
import {
|
73
73
|
InputType as InputType7,
|
74
74
|
TransactionType as TransactionType8,
|
@@ -1645,15 +1645,6 @@ function normalizeJSON(root) {
|
|
1645
1645
|
return normalize(clone(root));
|
1646
1646
|
}
|
1647
1647
|
|
1648
|
-
// src/providers/utils/sleep.ts
|
1649
|
-
function sleep(time) {
|
1650
|
-
return new Promise((resolve) => {
|
1651
|
-
setTimeout(() => {
|
1652
|
-
resolve(true);
|
1653
|
-
}, time);
|
1654
|
-
});
|
1655
|
-
}
|
1656
|
-
|
1657
1648
|
// src/providers/utils/extract-tx-error.ts
|
1658
1649
|
import { ErrorCode as ErrorCode7, FuelError as FuelError7 } from "@fuel-ts/errors";
|
1659
1650
|
import { bn as bn6 } from "@fuel-ts/math";
|
@@ -2282,6 +2273,15 @@ var BaseTransactionRequest = class {
|
|
2282
2273
|
}
|
2283
2274
|
});
|
2284
2275
|
}
|
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 bn17 } 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 bn16 } 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,32 +2786,43 @@ 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 bn14 } 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 } from "@fuel-ts/abi-coder";
|
2794
|
-
|
2793
|
+
import { Interface as Interface2, calculateVmTxMemory } from "@fuel-ts/abi-coder";
|
2794
|
+
import { bn as bn13 } from "@fuel-ts/math";
|
2795
|
+
var getFunctionCall = ({ abi, receipt, rawPayload, maxInputs }) => {
|
2795
2796
|
const abiInterface = new Interface2(abi);
|
2796
2797
|
const callFunctionSelector = receipt.param1.toHex(8);
|
2797
2798
|
const functionFragment = abiInterface.getFunction(callFunctionSelector);
|
2798
2799
|
const inputs = functionFragment.jsonFn.inputs;
|
2799
|
-
|
2800
|
+
let encodedArgs;
|
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
|
+
}
|
2800
2809
|
let argumentsProvided;
|
2801
|
-
|
2802
|
-
|
2803
|
-
|
2804
|
-
|
2805
|
-
|
2806
|
-
|
2807
|
-
|
2808
|
-
|
2809
|
-
|
2810
|
-
|
2811
|
-
|
2812
|
-
|
2813
|
-
|
2814
|
-
|
2810
|
+
if (encodedArgs) {
|
2811
|
+
const data = functionFragment.decodeArguments(encodedArgs);
|
2812
|
+
if (data) {
|
2813
|
+
argumentsProvided = inputs.reduce((prev, input, index) => {
|
2814
|
+
const value = data[index];
|
2815
|
+
const name = input.name;
|
2816
|
+
if (name) {
|
2817
|
+
return {
|
2818
|
+
...prev,
|
2819
|
+
// reparse to remove bn
|
2820
|
+
[name]: JSON.parse(JSON.stringify(value))
|
2821
|
+
};
|
2822
|
+
}
|
2823
|
+
return prev;
|
2824
|
+
}, {});
|
2825
|
+
}
|
2815
2826
|
}
|
2816
2827
|
const call = {
|
2817
2828
|
functionSignature: functionFragment.signature,
|
@@ -2951,7 +2962,7 @@ var mergeAssets = (op1, op2) => {
|
|
2951
2962
|
if (!matchingAsset) {
|
2952
2963
|
return asset1;
|
2953
2964
|
}
|
2954
|
-
const mergedAmount =
|
2965
|
+
const mergedAmount = bn14(asset1.amount).add(matchingAsset.amount);
|
2955
2966
|
return { ...asset1, amount: mergedAmount };
|
2956
2967
|
});
|
2957
2968
|
return mergedAssets.concat(filteredAssets);
|
@@ -3274,7 +3285,7 @@ var extractBurnedAssetsFromReceipts = (receipts) => {
|
|
3274
3285
|
|
3275
3286
|
// src/providers/transaction-summary/status.ts
|
3276
3287
|
import { ErrorCode as ErrorCode11, FuelError as FuelError11 } from "@fuel-ts/errors";
|
3277
|
-
import { bn as
|
3288
|
+
import { bn as bn15 } from "@fuel-ts/math";
|
3278
3289
|
var getTransactionStatusName = (gqlStatus) => {
|
3279
3290
|
switch (gqlStatus) {
|
3280
3291
|
case "FailureStatus":
|
@@ -3308,15 +3319,15 @@ var processGraphqlStatus = (gqlTransactionStatus) => {
|
|
3308
3319
|
time = gqlTransactionStatus.time;
|
3309
3320
|
blockId = gqlTransactionStatus.block.id;
|
3310
3321
|
isStatusSuccess = true;
|
3311
|
-
totalFee =
|
3312
|
-
totalGas =
|
3322
|
+
totalFee = bn15(gqlTransactionStatus.totalFee);
|
3323
|
+
totalGas = bn15(gqlTransactionStatus.totalGas);
|
3313
3324
|
break;
|
3314
3325
|
case "FailureStatus":
|
3315
3326
|
time = gqlTransactionStatus.time;
|
3316
3327
|
blockId = gqlTransactionStatus.block.id;
|
3317
3328
|
isStatusFailure = true;
|
3318
|
-
totalFee =
|
3319
|
-
totalGas =
|
3329
|
+
totalFee = bn15(gqlTransactionStatus.totalFee);
|
3330
|
+
totalGas = bn15(gqlTransactionStatus.totalGas);
|
3320
3331
|
break;
|
3321
3332
|
case "SubmittedStatus":
|
3322
3333
|
time = gqlTransactionStatus.time;
|
@@ -3366,7 +3377,7 @@ function assembleTransactionSummary(params) {
|
|
3366
3377
|
maxInputs
|
3367
3378
|
});
|
3368
3379
|
const typeName = getTransactionTypeName(transaction.type);
|
3369
|
-
const tip =
|
3380
|
+
const tip = bn16(transaction.policies?.find((policy) => policy.type === PolicyType3.Tip)?.data);
|
3370
3381
|
const { isStatusFailure, isStatusPending, isStatusSuccess, blockId, status, time, totalFee } = processGraphqlStatus(gqlTransactionStatus);
|
3371
3382
|
const fee = calculateTXFeeForSummary({
|
3372
3383
|
totalFee,
|
@@ -3437,7 +3448,7 @@ var TransactionResponse = class {
|
|
3437
3448
|
/** Current provider */
|
3438
3449
|
provider;
|
3439
3450
|
/** Gas used on the transaction */
|
3440
|
-
gasUsed =
|
3451
|
+
gasUsed = bn17(0);
|
3441
3452
|
/** The graphql Transaction with receipts object. */
|
3442
3453
|
gqlTransaction;
|
3443
3454
|
abis;
|
@@ -3605,6 +3616,7 @@ var TransactionResponse = class {
|
|
3605
3616
|
};
|
3606
3617
|
|
3607
3618
|
// src/providers/utils/auto-retry-fetch.ts
|
3619
|
+
import { sleep } from "@fuel-ts/utils";
|
3608
3620
|
function getWaitDelay(options, retryAttemptNum) {
|
3609
3621
|
const duration = options.baseDelay ?? 150;
|
3610
3622
|
switch (options.backoff) {
|
@@ -3671,47 +3683,47 @@ var processGqlChain = (chain) => {
|
|
3671
3683
|
} = consensusParameters;
|
3672
3684
|
return {
|
3673
3685
|
name,
|
3674
|
-
baseChainHeight:
|
3686
|
+
baseChainHeight: bn18(daHeight),
|
3675
3687
|
consensusParameters: {
|
3676
3688
|
version,
|
3677
|
-
chainId:
|
3689
|
+
chainId: bn18(chainId),
|
3678
3690
|
baseAssetId,
|
3679
3691
|
feeParameters: {
|
3680
3692
|
version: feeParams.version,
|
3681
|
-
gasPerByte:
|
3682
|
-
gasPriceFactor:
|
3693
|
+
gasPerByte: bn18(feeParams.gasPerByte),
|
3694
|
+
gasPriceFactor: bn18(feeParams.gasPriceFactor)
|
3683
3695
|
},
|
3684
3696
|
contractParameters: {
|
3685
3697
|
version: contractParams.version,
|
3686
|
-
contractMaxSize:
|
3687
|
-
maxStorageSlots:
|
3698
|
+
contractMaxSize: bn18(contractParams.contractMaxSize),
|
3699
|
+
maxStorageSlots: bn18(contractParams.maxStorageSlots)
|
3688
3700
|
},
|
3689
3701
|
txParameters: {
|
3690
3702
|
version: txParams.version,
|
3691
|
-
maxInputs:
|
3692
|
-
maxOutputs:
|
3693
|
-
maxWitnesses:
|
3694
|
-
maxGasPerTx:
|
3695
|
-
maxSize:
|
3696
|
-
maxBytecodeSubsections:
|
3703
|
+
maxInputs: bn18(txParams.maxInputs),
|
3704
|
+
maxOutputs: bn18(txParams.maxOutputs),
|
3705
|
+
maxWitnesses: bn18(txParams.maxWitnesses),
|
3706
|
+
maxGasPerTx: bn18(txParams.maxGasPerTx),
|
3707
|
+
maxSize: bn18(txParams.maxSize),
|
3708
|
+
maxBytecodeSubsections: bn18(txParams.maxBytecodeSubsections)
|
3697
3709
|
},
|
3698
3710
|
predicateParameters: {
|
3699
3711
|
version: predicateParams.version,
|
3700
|
-
maxPredicateLength:
|
3701
|
-
maxPredicateDataLength:
|
3702
|
-
maxGasPerPredicate:
|
3703
|
-
maxMessageDataLength:
|
3712
|
+
maxPredicateLength: bn18(predicateParams.maxPredicateLength),
|
3713
|
+
maxPredicateDataLength: bn18(predicateParams.maxPredicateDataLength),
|
3714
|
+
maxGasPerPredicate: bn18(predicateParams.maxGasPerPredicate),
|
3715
|
+
maxMessageDataLength: bn18(predicateParams.maxMessageDataLength)
|
3704
3716
|
},
|
3705
3717
|
scriptParameters: {
|
3706
3718
|
version: scriptParams.version,
|
3707
|
-
maxScriptLength:
|
3708
|
-
maxScriptDataLength:
|
3719
|
+
maxScriptLength: bn18(scriptParams.maxScriptLength),
|
3720
|
+
maxScriptDataLength: bn18(scriptParams.maxScriptDataLength)
|
3709
3721
|
},
|
3710
3722
|
gasCosts
|
3711
3723
|
},
|
3712
3724
|
latestBlock: {
|
3713
3725
|
id: latestBlock.id,
|
3714
|
-
height:
|
3726
|
+
height: bn18(latestBlock.height),
|
3715
3727
|
time: latestBlock.header.time,
|
3716
3728
|
transactions: latestBlock.transactions.map((i) => ({
|
3717
3729
|
id: i.id
|
@@ -3907,7 +3919,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3907
3919
|
*/
|
3908
3920
|
async getBlockNumber() {
|
3909
3921
|
const { chain } = await this.operations.getChain();
|
3910
|
-
return
|
3922
|
+
return bn18(chain.latestBlock.height, 10);
|
3911
3923
|
}
|
3912
3924
|
/**
|
3913
3925
|
* Returns the chain information.
|
@@ -3917,8 +3929,8 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
3917
3929
|
async fetchNode() {
|
3918
3930
|
const { nodeInfo } = await this.operations.getNodeInfo();
|
3919
3931
|
const processedNodeInfo = {
|
3920
|
-
maxDepth:
|
3921
|
-
maxTx:
|
3932
|
+
maxDepth: bn18(nodeInfo.maxDepth),
|
3933
|
+
maxTx: bn18(nodeInfo.maxTx),
|
3922
3934
|
nodeVersion: nodeInfo.nodeVersion,
|
3923
3935
|
utxoValidation: nodeInfo.utxoValidation,
|
3924
3936
|
vmBacktrace: nodeInfo.vmBacktrace
|
@@ -4050,7 +4062,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4050
4062
|
} = response;
|
4051
4063
|
if (inputs) {
|
4052
4064
|
inputs.forEach((input, index) => {
|
4053
|
-
if ("predicateGasUsed" in input &&
|
4065
|
+
if ("predicateGasUsed" in input && bn18(input.predicateGasUsed).gt(0)) {
|
4054
4066
|
transactionRequest.inputs[index].predicateGasUsed = input.predicateGasUsed;
|
4055
4067
|
}
|
4056
4068
|
});
|
@@ -4208,12 +4220,12 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4208
4220
|
gasPrice = await this.estimateGasPrice(10);
|
4209
4221
|
}
|
4210
4222
|
const minFee = calculateGasFee({
|
4211
|
-
gasPrice:
|
4223
|
+
gasPrice: bn18(gasPrice),
|
4212
4224
|
gas: minGas,
|
4213
4225
|
priceFactor: gasPriceFactor,
|
4214
4226
|
tip: transactionRequest.tip
|
4215
4227
|
}).add(1);
|
4216
|
-
let gasLimit =
|
4228
|
+
let gasLimit = bn18(0);
|
4217
4229
|
if (transactionRequest.type === TransactionType8.Script) {
|
4218
4230
|
gasLimit = transactionRequest.gasLimit;
|
4219
4231
|
if (transactionRequest.gasLimit.eq(0)) {
|
@@ -4226,7 +4238,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4226
4238
|
}
|
4227
4239
|
const maxGas = transactionRequest.calculateMaxGas(chainInfo, minGas);
|
4228
4240
|
const maxFee = calculateGasFee({
|
4229
|
-
gasPrice:
|
4241
|
+
gasPrice: bn18(gasPrice),
|
4230
4242
|
gas: maxGas,
|
4231
4243
|
priceFactor: gasPriceFactor,
|
4232
4244
|
tip: transactionRequest.tip
|
@@ -4291,7 +4303,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4291
4303
|
const allQuantities = mergeQuantities(coinOutputsQuantities, quantitiesToContract);
|
4292
4304
|
txRequestClone.fundWithFakeUtxos(allQuantities, baseAssetId, resourcesOwner?.address);
|
4293
4305
|
if (isScriptTransaction) {
|
4294
|
-
txRequestClone.gasLimit =
|
4306
|
+
txRequestClone.gasLimit = bn18(0);
|
4295
4307
|
}
|
4296
4308
|
if (resourcesOwner && "populateTransactionPredicateData" in resourcesOwner) {
|
4297
4309
|
resourcesOwner.populateTransactionPredicateData(txRequestClone);
|
@@ -4312,7 +4324,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4312
4324
|
let dryRunStatus;
|
4313
4325
|
let missingContractIds = [];
|
4314
4326
|
let outputVariables = 0;
|
4315
|
-
let gasUsed =
|
4327
|
+
let gasUsed = bn18(0);
|
4316
4328
|
txRequestClone.maxFee = maxFee;
|
4317
4329
|
if (isScriptTransaction) {
|
4318
4330
|
txRequestClone.gasLimit = gasLimit;
|
@@ -4377,10 +4389,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4377
4389
|
return coins.map((coin) => ({
|
4378
4390
|
id: coin.utxoId,
|
4379
4391
|
assetId: coin.assetId,
|
4380
|
-
amount:
|
4392
|
+
amount: bn18(coin.amount),
|
4381
4393
|
owner: Address2.fromAddressOrString(coin.owner),
|
4382
|
-
blockCreated:
|
4383
|
-
txCreatedIdx:
|
4394
|
+
blockCreated: bn18(coin.blockCreated),
|
4395
|
+
txCreatedIdx: bn18(coin.txCreatedIdx)
|
4384
4396
|
}));
|
4385
4397
|
}
|
4386
4398
|
/**
|
@@ -4417,9 +4429,9 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4417
4429
|
switch (coin.type) {
|
4418
4430
|
case "MessageCoin":
|
4419
4431
|
return {
|
4420
|
-
amount:
|
4432
|
+
amount: bn18(coin.amount),
|
4421
4433
|
assetId: coin.assetId,
|
4422
|
-
daHeight:
|
4434
|
+
daHeight: bn18(coin.daHeight),
|
4423
4435
|
sender: Address2.fromAddressOrString(coin.sender),
|
4424
4436
|
recipient: Address2.fromAddressOrString(coin.recipient),
|
4425
4437
|
nonce: coin.nonce
|
@@ -4427,11 +4439,11 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4427
4439
|
case "Coin":
|
4428
4440
|
return {
|
4429
4441
|
id: coin.utxoId,
|
4430
|
-
amount:
|
4442
|
+
amount: bn18(coin.amount),
|
4431
4443
|
assetId: coin.assetId,
|
4432
4444
|
owner: Address2.fromAddressOrString(coin.owner),
|
4433
|
-
blockCreated:
|
4434
|
-
txCreatedIdx:
|
4445
|
+
blockCreated: bn18(coin.blockCreated),
|
4446
|
+
txCreatedIdx: bn18(coin.txCreatedIdx)
|
4435
4447
|
};
|
4436
4448
|
default:
|
4437
4449
|
return null;
|
@@ -4448,13 +4460,13 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4448
4460
|
async getBlock(idOrHeight) {
|
4449
4461
|
let variables;
|
4450
4462
|
if (typeof idOrHeight === "number") {
|
4451
|
-
variables = { height:
|
4463
|
+
variables = { height: bn18(idOrHeight).toString(10) };
|
4452
4464
|
} else if (idOrHeight === "latest") {
|
4453
4465
|
variables = { height: (await this.getBlockNumber()).toString(10) };
|
4454
4466
|
} else if (idOrHeight.length === 66) {
|
4455
4467
|
variables = { blockId: idOrHeight };
|
4456
4468
|
} else {
|
4457
|
-
variables = { blockId:
|
4469
|
+
variables = { blockId: bn18(idOrHeight).toString(10) };
|
4458
4470
|
}
|
4459
4471
|
const { block } = await this.operations.getBlock(variables);
|
4460
4472
|
if (!block) {
|
@@ -4462,7 +4474,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4462
4474
|
}
|
4463
4475
|
return {
|
4464
4476
|
id: block.id,
|
4465
|
-
height:
|
4477
|
+
height: bn18(block.height),
|
4466
4478
|
time: block.header.time,
|
4467
4479
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4468
4480
|
};
|
@@ -4477,7 +4489,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4477
4489
|
const { blocks: fetchedData } = await this.operations.getBlocks(params);
|
4478
4490
|
const blocks = fetchedData.edges.map(({ node: block }) => ({
|
4479
4491
|
id: block.id,
|
4480
|
-
height:
|
4492
|
+
height: bn18(block.height),
|
4481
4493
|
time: block.header.time,
|
4482
4494
|
transactionIds: block.transactions.map((tx) => tx.id)
|
4483
4495
|
}));
|
@@ -4492,7 +4504,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4492
4504
|
async getBlockWithTransactions(idOrHeight) {
|
4493
4505
|
let variables;
|
4494
4506
|
if (typeof idOrHeight === "number") {
|
4495
|
-
variables = { blockHeight:
|
4507
|
+
variables = { blockHeight: bn18(idOrHeight).toString(10) };
|
4496
4508
|
} else if (idOrHeight === "latest") {
|
4497
4509
|
variables = { blockHeight: (await this.getBlockNumber()).toString() };
|
4498
4510
|
} else {
|
@@ -4504,7 +4516,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4504
4516
|
}
|
4505
4517
|
return {
|
4506
4518
|
id: block.id,
|
4507
|
-
height:
|
4519
|
+
height: bn18(block.height, 10),
|
4508
4520
|
time: block.header.time,
|
4509
4521
|
transactionIds: block.transactions.map((tx) => tx.id),
|
4510
4522
|
transactions: block.transactions.map(
|
@@ -4553,7 +4565,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4553
4565
|
contract: Address2.fromAddressOrString(contractId).toB256(),
|
4554
4566
|
asset: hexlify12(assetId)
|
4555
4567
|
});
|
4556
|
-
return
|
4568
|
+
return bn18(contractBalance.amount, 10);
|
4557
4569
|
}
|
4558
4570
|
/**
|
4559
4571
|
* Returns the balance for the given owner for the given asset ID.
|
@@ -4567,7 +4579,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4567
4579
|
owner: Address2.fromAddressOrString(owner).toB256(),
|
4568
4580
|
assetId: hexlify12(assetId)
|
4569
4581
|
});
|
4570
|
-
return
|
4582
|
+
return bn18(balance.amount, 10);
|
4571
4583
|
}
|
4572
4584
|
/**
|
4573
4585
|
* Returns balances for the given owner.
|
@@ -4585,7 +4597,7 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4585
4597
|
const balances = result.balances.edges.map((edge) => edge.node);
|
4586
4598
|
return balances.map((balance) => ({
|
4587
4599
|
assetId: balance.assetId,
|
4588
|
-
amount:
|
4600
|
+
amount: bn18(balance.amount)
|
4589
4601
|
}));
|
4590
4602
|
}
|
4591
4603
|
/**
|
@@ -4607,15 +4619,15 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4607
4619
|
sender: message.sender,
|
4608
4620
|
recipient: message.recipient,
|
4609
4621
|
nonce: message.nonce,
|
4610
|
-
amount:
|
4622
|
+
amount: bn18(message.amount),
|
4611
4623
|
data: message.data
|
4612
4624
|
}),
|
4613
4625
|
sender: Address2.fromAddressOrString(message.sender),
|
4614
4626
|
recipient: Address2.fromAddressOrString(message.recipient),
|
4615
4627
|
nonce: message.nonce,
|
4616
|
-
amount:
|
4628
|
+
amount: bn18(message.amount),
|
4617
4629
|
data: InputMessageCoder.decodeData(message.data),
|
4618
|
-
daHeight:
|
4630
|
+
daHeight: bn18(message.daHeight)
|
4619
4631
|
}));
|
4620
4632
|
}
|
4621
4633
|
/**
|
@@ -4668,19 +4680,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4668
4680
|
} = result.messageProof;
|
4669
4681
|
return {
|
4670
4682
|
messageProof: {
|
4671
|
-
proofIndex:
|
4683
|
+
proofIndex: bn18(messageProof.proofIndex),
|
4672
4684
|
proofSet: messageProof.proofSet
|
4673
4685
|
},
|
4674
4686
|
blockProof: {
|
4675
|
-
proofIndex:
|
4687
|
+
proofIndex: bn18(blockProof.proofIndex),
|
4676
4688
|
proofSet: blockProof.proofSet
|
4677
4689
|
},
|
4678
4690
|
messageBlockHeader: {
|
4679
4691
|
id: messageBlockHeader.id,
|
4680
|
-
daHeight:
|
4692
|
+
daHeight: bn18(messageBlockHeader.daHeight),
|
4681
4693
|
transactionsCount: Number(messageBlockHeader.transactionsCount),
|
4682
4694
|
transactionsRoot: messageBlockHeader.transactionsRoot,
|
4683
|
-
height:
|
4695
|
+
height: bn18(messageBlockHeader.height),
|
4684
4696
|
prevRoot: messageBlockHeader.prevRoot,
|
4685
4697
|
time: messageBlockHeader.time,
|
4686
4698
|
applicationHash: messageBlockHeader.applicationHash,
|
@@ -4692,10 +4704,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4692
4704
|
},
|
4693
4705
|
commitBlockHeader: {
|
4694
4706
|
id: commitBlockHeader.id,
|
4695
|
-
daHeight:
|
4707
|
+
daHeight: bn18(commitBlockHeader.daHeight),
|
4696
4708
|
transactionsCount: Number(commitBlockHeader.transactionsCount),
|
4697
4709
|
transactionsRoot: commitBlockHeader.transactionsRoot,
|
4698
|
-
height:
|
4710
|
+
height: bn18(commitBlockHeader.height),
|
4699
4711
|
prevRoot: commitBlockHeader.prevRoot,
|
4700
4712
|
time: commitBlockHeader.time,
|
4701
4713
|
applicationHash: commitBlockHeader.applicationHash,
|
@@ -4708,19 +4720,19 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4708
4720
|
sender: Address2.fromAddressOrString(sender),
|
4709
4721
|
recipient: Address2.fromAddressOrString(recipient),
|
4710
4722
|
nonce,
|
4711
|
-
amount:
|
4723
|
+
amount: bn18(amount),
|
4712
4724
|
data
|
4713
4725
|
};
|
4714
4726
|
}
|
4715
4727
|
async getLatestGasPrice() {
|
4716
4728
|
const { latestGasPrice } = await this.operations.getLatestGasPrice();
|
4717
|
-
return
|
4729
|
+
return bn18(latestGasPrice.gasPrice);
|
4718
4730
|
}
|
4719
4731
|
async estimateGasPrice(blockHorizon) {
|
4720
4732
|
const { estimateGasPrice } = await this.operations.estimateGasPrice({
|
4721
4733
|
blockHorizon: String(blockHorizon)
|
4722
4734
|
});
|
4723
|
-
return
|
4735
|
+
return bn18(estimateGasPrice.gasPrice);
|
4724
4736
|
}
|
4725
4737
|
/**
|
4726
4738
|
* Returns Message Proof for given transaction id and the message id from MessageOut receipt.
|
@@ -4741,10 +4753,10 @@ Supported fuel-core version: ${supportedVersion}.`
|
|
4741
4753
|
*/
|
4742
4754
|
async produceBlocks(amount, startTime) {
|
4743
4755
|
const { produceBlocks: latestBlockHeight } = await this.operations.produceBlocks({
|
4744
|
-
blocksToProduce:
|
4756
|
+
blocksToProduce: bn18(amount).toString(10),
|
4745
4757
|
startTimestamp: startTime ? DateTime2.fromUnixMilliseconds(startTime).toTai64() : void 0
|
4746
4758
|
});
|
4747
|
-
return
|
4759
|
+
return bn18(latestBlockHeight);
|
4748
4760
|
}
|
4749
4761
|
// eslint-disable-next-line @typescript-eslint/require-await
|
4750
4762
|
async getTransactionResponse(transactionId) {
|
@@ -4790,7 +4802,7 @@ __publicField(Provider, "nodeInfoCache", {});
|
|
4790
4802
|
|
4791
4803
|
// src/providers/transaction-summary/get-transaction-summary.ts
|
4792
4804
|
import { ErrorCode as ErrorCode14, FuelError as FuelError14 } from "@fuel-ts/errors";
|
4793
|
-
import { bn as
|
4805
|
+
import { bn as bn19 } from "@fuel-ts/math";
|
4794
4806
|
import { TransactionCoder as TransactionCoder6 } from "@fuel-ts/transactions";
|
4795
4807
|
import { arrayify as arrayify12 } from "@fuel-ts/utils";
|
4796
4808
|
|
@@ -5068,9 +5080,9 @@ var Account = class extends AbstractAccount {
|
|
5068
5080
|
const { addedSignatures, estimatedPredicates, requiredQuantities, updateMaxFee } = params;
|
5069
5081
|
const fee = request.maxFee;
|
5070
5082
|
const baseAssetId = this.provider.getBaseAssetId();
|
5071
|
-
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount ||
|
5083
|
+
const requiredInBaseAsset = requiredQuantities.find((quantity) => quantity.assetId === baseAssetId)?.amount || bn20(0);
|
5072
5084
|
const requiredQuantitiesWithFee = addAmountToCoinQuantities({
|
5073
|
-
amount:
|
5085
|
+
amount: bn20(fee),
|
5074
5086
|
assetId: baseAssetId,
|
5075
5087
|
coinQuantities: requiredQuantities
|
5076
5088
|
});
|
@@ -5078,7 +5090,7 @@ var Account = class extends AbstractAccount {
|
|
5078
5090
|
requiredQuantitiesWithFee.forEach(({ amount, assetId }) => {
|
5079
5091
|
quantitiesDict[assetId] = {
|
5080
5092
|
required: amount,
|
5081
|
-
owned:
|
5093
|
+
owned: bn20(0)
|
5082
5094
|
};
|
5083
5095
|
});
|
5084
5096
|
request.inputs.filter(isRequestInputResource).forEach((input) => {
|
@@ -5105,6 +5117,7 @@ var Account = class extends AbstractAccount {
|
|
5105
5117
|
cacheRequestInputsResourcesFromOwner(request.inputs, this.address)
|
5106
5118
|
);
|
5107
5119
|
request.addResources(resources);
|
5120
|
+
request.shiftPredicateData();
|
5108
5121
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5109
5122
|
const requestToReestimate2 = clone4(request);
|
5110
5123
|
if (addedSignatures) {
|
@@ -5136,6 +5149,7 @@ var Account = class extends AbstractAccount {
|
|
5136
5149
|
}
|
5137
5150
|
fundingAttempts += 1;
|
5138
5151
|
}
|
5152
|
+
request.shiftPredicateData();
|
5139
5153
|
request.updatePredicateGasUsed(estimatedPredicates);
|
5140
5154
|
const requestToReestimate = clone4(request);
|
5141
5155
|
if (addedSignatures) {
|
@@ -5186,7 +5200,7 @@ var Account = class extends AbstractAccount {
|
|
5186
5200
|
* @returns A promise that resolves to the transaction response.
|
5187
5201
|
*/
|
5188
5202
|
async transfer(destination, amount, assetId, txParams = {}) {
|
5189
|
-
if (
|
5203
|
+
if (bn20(amount).lte(0)) {
|
5190
5204
|
throw new FuelError15(
|
5191
5205
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5192
5206
|
"Transfer amount must be a positive number."
|
@@ -5206,7 +5220,7 @@ var Account = class extends AbstractAccount {
|
|
5206
5220
|
* @returns A promise that resolves to the transaction response.
|
5207
5221
|
*/
|
5208
5222
|
async transferToContract(contractId, amount, assetId, txParams = {}) {
|
5209
|
-
if (
|
5223
|
+
if (bn20(amount).lte(0)) {
|
5210
5224
|
throw new FuelError15(
|
5211
5225
|
ErrorCode15.INVALID_TRANSFER_AMOUNT,
|
5212
5226
|
"Transfer amount must be a positive number."
|
@@ -5216,7 +5230,7 @@ var Account = class extends AbstractAccount {
|
|
5216
5230
|
const assetIdToTransfer = assetId ?? this.provider.getBaseAssetId();
|
5217
5231
|
const { script, scriptData } = await assembleTransferToContractScript({
|
5218
5232
|
hexlifiedContractId: contractAddress.toB256(),
|
5219
|
-
amountToTransfer:
|
5233
|
+
amountToTransfer: bn20(amount),
|
5220
5234
|
assetId: assetIdToTransfer
|
5221
5235
|
});
|
5222
5236
|
let request = new ScriptTransactionRequest({
|
@@ -5227,7 +5241,7 @@ var Account = class extends AbstractAccount {
|
|
5227
5241
|
request.addContractInputAndOutput(contractAddress);
|
5228
5242
|
const txCost = await this.provider.getTransactionCost(request, {
|
5229
5243
|
resourcesOwner: this,
|
5230
|
-
quantitiesToContract: [{ amount:
|
5244
|
+
quantitiesToContract: [{ amount: bn20(amount), assetId: String(assetIdToTransfer) }]
|
5231
5245
|
});
|
5232
5246
|
request = this.validateGasLimitAndMaxFee({
|
5233
5247
|
transactionRequest: request,
|
@@ -5252,7 +5266,7 @@ var Account = class extends AbstractAccount {
|
|
5252
5266
|
"0x".concat(recipientAddress.toHexString().substring(2).padStart(64, "0"))
|
5253
5267
|
);
|
5254
5268
|
const amountDataArray = arrayify14(
|
5255
|
-
"0x".concat(
|
5269
|
+
"0x".concat(bn20(amount).toHex().substring(2).padStart(16, "0"))
|
5256
5270
|
);
|
5257
5271
|
const script = new Uint8Array([
|
5258
5272
|
...arrayify14(withdrawScript.bytes),
|
@@ -5262,7 +5276,7 @@ var Account = class extends AbstractAccount {
|
|
5262
5276
|
const params = { script, ...txParams };
|
5263
5277
|
const baseAssetId = this.provider.getBaseAssetId();
|
5264
5278
|
let request = new ScriptTransactionRequest(params);
|
5265
|
-
const quantitiesToContract = [{ amount:
|
5279
|
+
const quantitiesToContract = [{ amount: bn20(amount), assetId: baseAssetId }];
|
5266
5280
|
const txCost = await this.provider.getTransactionCost(request, { quantitiesToContract });
|
5267
5281
|
request = this.validateGasLimitAndMaxFee({
|
5268
5282
|
transactionRequest: request,
|
@@ -5679,7 +5693,7 @@ __publicField(BaseWalletUnlocked, "defaultPath", "m/44'/1179993420'/0'/0/0");
|
|
5679
5693
|
import { computeHmac as computeHmac2, ripemd160 } from "@fuel-ts/crypto";
|
5680
5694
|
import { ErrorCode as ErrorCode19, FuelError as FuelError19 } from "@fuel-ts/errors";
|
5681
5695
|
import { sha256 as sha2564 } from "@fuel-ts/hasher";
|
5682
|
-
import { bn as
|
5696
|
+
import { bn as bn21, toBytes as toBytes2, toHex } from "@fuel-ts/math";
|
5683
5697
|
import { arrayify as arrayify18, hexlify as hexlify17, concat as concat5, dataSlice as dataSlice2, encodeBase58 as encodeBase582, decodeBase58 } from "@fuel-ts/utils";
|
5684
5698
|
|
5685
5699
|
// src/mnemonic/mnemonic.ts
|
@@ -8143,7 +8157,7 @@ var HDWallet = class {
|
|
8143
8157
|
const IR = bytes.slice(32);
|
8144
8158
|
if (privateKey) {
|
8145
8159
|
const N = "0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141";
|
8146
|
-
const ki =
|
8160
|
+
const ki = bn21(IL).add(privateKey).mod(N).toBytes(32);
|
8147
8161
|
return new HDWallet({
|
8148
8162
|
privateKey: ki,
|
8149
8163
|
chainCode: IR,
|
@@ -8440,7 +8454,7 @@ var generateTestWallet = async (provider, quantities) => {
|
|
8440
8454
|
// src/test-utils/launchNode.ts
|
8441
8455
|
import { UTXO_ID_LEN as UTXO_ID_LEN3 } from "@fuel-ts/abi-coder";
|
8442
8456
|
import { randomBytes as randomBytes6 } from "@fuel-ts/crypto";
|
8443
|
-
import {
|
8457
|
+
import { defaultConsensusKey, hexlify as hexlify18, defaultSnapshotConfigs } from "@fuel-ts/utils";
|
8444
8458
|
import { findBinPath } from "@fuel-ts/utils/cli-utils";
|
8445
8459
|
import { spawn } from "child_process";
|
8446
8460
|
import { randomUUID } from "crypto";
|
@@ -8480,6 +8494,40 @@ var killNode = (params) => {
|
|
8480
8494
|
}
|
8481
8495
|
}
|
8482
8496
|
};
|
8497
|
+
function getFinalStateConfigJSON({ stateConfig, chainConfig }) {
|
8498
|
+
const defaultCoins = defaultSnapshotConfigs.stateConfig.coins.map((coin) => ({
|
8499
|
+
...coin,
|
8500
|
+
amount: "18446744073709551615"
|
8501
|
+
}));
|
8502
|
+
const defaultMessages = defaultSnapshotConfigs.stateConfig.messages.map((message) => ({
|
8503
|
+
...message,
|
8504
|
+
amount: "18446744073709551615"
|
8505
|
+
}));
|
8506
|
+
const coins = defaultCoins.concat(stateConfig.coins.map((coin) => ({ ...coin, amount: coin.amount.toString() }))).filter((coin, index, self) => self.findIndex((c) => c.tx_id === coin.tx_id) === index);
|
8507
|
+
const messages = defaultMessages.concat(stateConfig.messages.map((msg) => ({ ...msg, amount: msg.amount.toString() }))).filter((msg, index, self) => self.findIndex((m) => m.nonce === msg.nonce) === index);
|
8508
|
+
if (!process.env.GENESIS_SECRET) {
|
8509
|
+
const pk = Signer.generatePrivateKey();
|
8510
|
+
const signer = new Signer(pk);
|
8511
|
+
process.env.GENESIS_SECRET = hexlify18(pk);
|
8512
|
+
coins.push({
|
8513
|
+
tx_id: hexlify18(randomBytes6(UTXO_ID_LEN3)),
|
8514
|
+
owner: signer.address.toHexString(),
|
8515
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8516
|
+
amount: "18446744073709551615",
|
8517
|
+
asset_id: chainConfig.consensus_parameters.V1.base_asset_id,
|
8518
|
+
output_index: 0,
|
8519
|
+
tx_pointer_block_height: 0,
|
8520
|
+
tx_pointer_tx_idx: 0
|
8521
|
+
});
|
8522
|
+
}
|
8523
|
+
const json = JSON.stringify({
|
8524
|
+
...stateConfig,
|
8525
|
+
coins,
|
8526
|
+
messages
|
8527
|
+
});
|
8528
|
+
const regexMakeNumber = /("amount":)"(\d+)"/gm;
|
8529
|
+
return json.replace(regexMakeNumber, "$1$2");
|
8530
|
+
}
|
8483
8531
|
var launchNode = async ({
|
8484
8532
|
ip,
|
8485
8533
|
port,
|
@@ -8487,7 +8535,8 @@ var launchNode = async ({
|
|
8487
8535
|
useSystemFuelCore = false,
|
8488
8536
|
loggingEnabled = true,
|
8489
8537
|
debugEnabled = false,
|
8490
|
-
basePath
|
8538
|
+
basePath,
|
8539
|
+
snapshotConfig = defaultSnapshotConfigs
|
8491
8540
|
}) => (
|
8492
8541
|
// eslint-disable-next-line no-async-promise-executor
|
8493
8542
|
new Promise(async (resolve, reject) => {
|
@@ -8516,56 +8565,23 @@ var launchNode = async ({
|
|
8516
8565
|
let snapshotDirToUse;
|
8517
8566
|
const prefix = basePath || os.tmpdir();
|
8518
8567
|
const suffix = basePath ? "" : randomUUID();
|
8519
|
-
const
|
8568
|
+
const tempDir = path.join(prefix, ".fuels", suffix, "snapshotDir");
|
8520
8569
|
if (snapshotDir) {
|
8521
8570
|
snapshotDirToUse = snapshotDir;
|
8522
8571
|
} else {
|
8523
|
-
if (!existsSync(
|
8524
|
-
mkdirSync(
|
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
|
-
});
|
8572
|
+
if (!existsSync(tempDir)) {
|
8573
|
+
mkdirSync(tempDir, { recursive: true });
|
8556
8574
|
}
|
8557
|
-
|
8558
|
-
const
|
8559
|
-
|
8560
|
-
const
|
8561
|
-
const
|
8562
|
-
|
8563
|
-
|
8564
|
-
writeFileSync(
|
8565
|
-
writeFileSync(
|
8566
|
-
|
8567
|
-
writeFileSync(stateTransitionWritePath, JSON.stringify(""));
|
8568
|
-
snapshotDirToUse = tempDirPath;
|
8575
|
+
const { metadata } = snapshotConfig;
|
8576
|
+
const metadataPath = path.join(tempDir, "metadata.json");
|
8577
|
+
const chainConfigPath = path.join(tempDir, metadata.chain_config);
|
8578
|
+
const stateConfigPath = path.join(tempDir, metadata.table_encoding.Json.filepath);
|
8579
|
+
const stateTransitionPath = path.join(tempDir, "state_transition_bytecode.wasm");
|
8580
|
+
writeFileSync(chainConfigPath, JSON.stringify(snapshotConfig.chainConfig), "utf8");
|
8581
|
+
writeFileSync(stateConfigPath, getFinalStateConfigJSON(snapshotConfig), "utf8");
|
8582
|
+
writeFileSync(metadataPath, JSON.stringify(metadata), "utf8");
|
8583
|
+
writeFileSync(stateTransitionPath, JSON.stringify(""));
|
8584
|
+
snapshotDirToUse = tempDir;
|
8569
8585
|
}
|
8570
8586
|
const child = spawn(
|
8571
8587
|
command,
|
@@ -8573,7 +8589,7 @@ var launchNode = async ({
|
|
8573
8589
|
"run",
|
8574
8590
|
["--ip", ipToUse],
|
8575
8591
|
["--port", portToUse],
|
8576
|
-
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path",
|
8592
|
+
useInMemoryDb ? ["--db-type", "in-memory"] : ["--db-path", tempDir],
|
8577
8593
|
["--min-gas-price", "1"],
|
8578
8594
|
poaInstant ? ["--poa-instant", "true"] : [],
|
8579
8595
|
["--consensus-key", consensusKey],
|
@@ -8595,23 +8611,28 @@ var launchNode = async ({
|
|
8595
8611
|
}
|
8596
8612
|
const cleanupConfig = {
|
8597
8613
|
child,
|
8598
|
-
configPath:
|
8614
|
+
configPath: tempDir,
|
8599
8615
|
killFn: treeKill,
|
8600
8616
|
state: {
|
8601
8617
|
isDead: false
|
8602
8618
|
}
|
8603
8619
|
};
|
8604
8620
|
child.stderr.on("data", (chunk) => {
|
8605
|
-
|
8621
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
8622
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
8623
|
+
const rows = text.split("\n");
|
8624
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
8625
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
8606
8626
|
resolve({
|
8607
8627
|
cleanup: () => killNode(cleanupConfig),
|
8608
|
-
ip:
|
8609
|
-
port:
|
8628
|
+
ip: realIp,
|
8629
|
+
port: realPort,
|
8630
|
+
url: `http://${realIp}:${realPort}/v1/graphql`,
|
8610
8631
|
snapshotDir: snapshotDirToUse
|
8611
8632
|
});
|
8612
8633
|
}
|
8613
|
-
if (/error/i.test(
|
8614
|
-
reject(
|
8634
|
+
if (/error/i.test(text)) {
|
8635
|
+
reject(text.toString());
|
8615
8636
|
}
|
8616
8637
|
});
|
8617
8638
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -8644,11 +8665,237 @@ var launchNodeAndGetWallets = async ({
|
|
8644
8665
|
};
|
8645
8666
|
return { wallets, stop: cleanup, provider };
|
8646
8667
|
};
|
8668
|
+
|
8669
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8670
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs3 } from "@fuel-ts/utils";
|
8671
|
+
import { mergeDeepRight } from "ramda";
|
8672
|
+
|
8673
|
+
// src/test-utils/asset-id.ts
|
8674
|
+
import { randomBytes as randomBytes7 } from "@fuel-ts/crypto";
|
8675
|
+
import { hexlify as hexlify19 } from "@fuel-ts/utils";
|
8676
|
+
var _AssetId = class {
|
8677
|
+
constructor(value) {
|
8678
|
+
this.value = value;
|
8679
|
+
}
|
8680
|
+
static random() {
|
8681
|
+
return new _AssetId(hexlify19(randomBytes7(32)));
|
8682
|
+
}
|
8683
|
+
};
|
8684
|
+
var AssetId = _AssetId;
|
8685
|
+
__publicField(AssetId, "A", new _AssetId(
|
8686
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
8687
|
+
));
|
8688
|
+
__publicField(AssetId, "B", new _AssetId(
|
8689
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
8690
|
+
));
|
8691
|
+
|
8692
|
+
// src/test-utils/wallet-config.ts
|
8693
|
+
import { randomBytes as randomBytes8 } from "@fuel-ts/crypto";
|
8694
|
+
import { FuelError as FuelError20 } from "@fuel-ts/errors";
|
8695
|
+
import { defaultSnapshotConfigs as defaultSnapshotConfigs2, hexlify as hexlify20 } from "@fuel-ts/utils";
|
8696
|
+
var WalletConfig = class {
|
8697
|
+
initialState;
|
8698
|
+
options;
|
8699
|
+
wallets;
|
8700
|
+
generateWallets = () => {
|
8701
|
+
const generatedWallets = [];
|
8702
|
+
for (let index = 1; index <= this.options.count; index++) {
|
8703
|
+
generatedWallets.push(new WalletUnlocked(randomBytes8(32)));
|
8704
|
+
}
|
8705
|
+
return generatedWallets;
|
8706
|
+
};
|
8707
|
+
constructor(baseAssetId, config) {
|
8708
|
+
const BASE_ASSET_ID = baseAssetId.startsWith("0x") ? baseAssetId : `0x${baseAssetId}`;
|
8709
|
+
WalletConfig.guard(config);
|
8710
|
+
this.options = config;
|
8711
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
8712
|
+
this.wallets = this.generateWallets();
|
8713
|
+
this.initialState = {
|
8714
|
+
messages: WalletConfig.createMessages(this.wallets, messages),
|
8715
|
+
coins: WalletConfig.createCoins(
|
8716
|
+
this.wallets,
|
8717
|
+
BASE_ASSET_ID,
|
8718
|
+
assets2,
|
8719
|
+
coinsPerAsset,
|
8720
|
+
amountPerCoin
|
8721
|
+
)
|
8722
|
+
};
|
8723
|
+
}
|
8724
|
+
apply(snapshotConfig) {
|
8725
|
+
return {
|
8726
|
+
...snapshotConfig,
|
8727
|
+
stateConfig: {
|
8728
|
+
...snapshotConfig?.stateConfig ?? defaultSnapshotConfigs2.stateConfig,
|
8729
|
+
coins: this.initialState.coins.concat(snapshotConfig?.stateConfig?.coins || []),
|
8730
|
+
messages: this.initialState.messages.concat(snapshotConfig?.stateConfig?.messages ?? [])
|
8731
|
+
}
|
8732
|
+
};
|
8733
|
+
}
|
8734
|
+
static createMessages(wallets, messages) {
|
8735
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
8736
|
+
}
|
8737
|
+
static createCoins(wallets, baseAssetId, assets2, coinsPerAsset, amountPerCoin) {
|
8738
|
+
const coins = [];
|
8739
|
+
let assetIds = [baseAssetId];
|
8740
|
+
if (Array.isArray(assets2)) {
|
8741
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
8742
|
+
} else {
|
8743
|
+
for (let index = 0; index < assets2 - 1; index++) {
|
8744
|
+
assetIds.push(AssetId.random().value);
|
8745
|
+
}
|
8746
|
+
}
|
8747
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
8748
|
+
assetIds.forEach((assetId) => {
|
8749
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
8750
|
+
coins.push({
|
8751
|
+
amount: amountPerCoin,
|
8752
|
+
asset_id: assetId,
|
8753
|
+
owner: walletAddress,
|
8754
|
+
tx_pointer_block_height: 0,
|
8755
|
+
tx_pointer_tx_idx: 0,
|
8756
|
+
output_index: 0,
|
8757
|
+
tx_id: hexlify20(randomBytes8(32))
|
8758
|
+
});
|
8759
|
+
}
|
8760
|
+
});
|
8761
|
+
});
|
8762
|
+
return coins;
|
8763
|
+
}
|
8764
|
+
static guard({
|
8765
|
+
count: wallets,
|
8766
|
+
assets: assets2,
|
8767
|
+
coinsPerAsset,
|
8768
|
+
amountPerCoin
|
8769
|
+
}) {
|
8770
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
8771
|
+
throw new FuelError20(
|
8772
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8773
|
+
"Number of wallets must be greater than zero."
|
8774
|
+
);
|
8775
|
+
}
|
8776
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
8777
|
+
throw new FuelError20(
|
8778
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8779
|
+
"Number of assets per wallet must be greater than zero."
|
8780
|
+
);
|
8781
|
+
}
|
8782
|
+
if (coinsPerAsset <= 0) {
|
8783
|
+
throw new FuelError20(
|
8784
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8785
|
+
"Number of coins per asset must be greater than zero."
|
8786
|
+
);
|
8787
|
+
}
|
8788
|
+
if (amountPerCoin <= 0) {
|
8789
|
+
throw new FuelError20(
|
8790
|
+
FuelError20.CODES.INVALID_INPUT_PARAMETERS,
|
8791
|
+
"Amount per coin must be greater than zero."
|
8792
|
+
);
|
8793
|
+
}
|
8794
|
+
}
|
8795
|
+
};
|
8796
|
+
|
8797
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
8798
|
+
var defaultWalletConfigOptions = {
|
8799
|
+
count: 2,
|
8800
|
+
assets: [AssetId.A, AssetId.B],
|
8801
|
+
coinsPerAsset: 1,
|
8802
|
+
amountPerCoin: 1e10,
|
8803
|
+
messages: []
|
8804
|
+
};
|
8805
|
+
async function setupTestProviderAndWallets({
|
8806
|
+
walletConfig: walletConfigOptions = {},
|
8807
|
+
providerOptions,
|
8808
|
+
nodeOptions = {}
|
8809
|
+
} = {}) {
|
8810
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
8811
|
+
const walletConfig = new WalletConfig(
|
8812
|
+
nodeOptions.snapshotConfig?.chainConfig?.consensus_parameters?.V1?.base_asset_id ?? defaultSnapshotConfigs3.chainConfig.consensus_parameters.V1.base_asset_id,
|
8813
|
+
{
|
8814
|
+
...defaultWalletConfigOptions,
|
8815
|
+
...walletConfigOptions
|
8816
|
+
}
|
8817
|
+
);
|
8818
|
+
const { cleanup, url } = await launchNode({
|
8819
|
+
loggingEnabled: false,
|
8820
|
+
...nodeOptions,
|
8821
|
+
snapshotConfig: mergeDeepRight(
|
8822
|
+
defaultSnapshotConfigs3,
|
8823
|
+
walletConfig.apply(nodeOptions?.snapshotConfig)
|
8824
|
+
),
|
8825
|
+
port: "0"
|
8826
|
+
});
|
8827
|
+
let provider;
|
8828
|
+
try {
|
8829
|
+
provider = await Provider.create(url, providerOptions);
|
8830
|
+
} catch (err) {
|
8831
|
+
cleanup();
|
8832
|
+
throw err;
|
8833
|
+
}
|
8834
|
+
const wallets = walletConfig.wallets;
|
8835
|
+
wallets.forEach((wallet) => {
|
8836
|
+
wallet.connect(provider);
|
8837
|
+
});
|
8838
|
+
return {
|
8839
|
+
provider,
|
8840
|
+
wallets,
|
8841
|
+
cleanup,
|
8842
|
+
[Symbol.dispose]: cleanup
|
8843
|
+
};
|
8844
|
+
}
|
8845
|
+
|
8846
|
+
// src/test-utils/test-message.ts
|
8847
|
+
import { Address as Address6 } from "@fuel-ts/address";
|
8848
|
+
import { randomBytes as randomBytes9 } from "@fuel-ts/crypto";
|
8849
|
+
import { bn as bn22 } from "@fuel-ts/math";
|
8850
|
+
import { hexlify as hexlify21 } from "@fuel-ts/utils";
|
8851
|
+
var TestMessage = class {
|
8852
|
+
sender;
|
8853
|
+
recipient;
|
8854
|
+
nonce;
|
8855
|
+
amount;
|
8856
|
+
data;
|
8857
|
+
da_height;
|
8858
|
+
/**
|
8859
|
+
* A helper class to create messages for testing purposes.
|
8860
|
+
*
|
8861
|
+
* Used in tandem with `WalletConfig`.
|
8862
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
8863
|
+
*/
|
8864
|
+
constructor({
|
8865
|
+
sender = Address6.fromRandom(),
|
8866
|
+
recipient = Address6.fromRandom(),
|
8867
|
+
nonce = hexlify21(randomBytes9(32)),
|
8868
|
+
amount = 1e6,
|
8869
|
+
data = "02",
|
8870
|
+
da_height = 0
|
8871
|
+
} = {}) {
|
8872
|
+
this.sender = sender;
|
8873
|
+
this.recipient = recipient;
|
8874
|
+
this.nonce = nonce;
|
8875
|
+
this.amount = amount;
|
8876
|
+
this.data = data;
|
8877
|
+
this.da_height = da_height;
|
8878
|
+
}
|
8879
|
+
toChainMessage(recipient) {
|
8880
|
+
return {
|
8881
|
+
sender: this.sender.toB256(),
|
8882
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
8883
|
+
nonce: this.nonce,
|
8884
|
+
amount: bn22(this.amount).toNumber(),
|
8885
|
+
data: this.data,
|
8886
|
+
da_height: this.da_height
|
8887
|
+
};
|
8888
|
+
}
|
8889
|
+
};
|
8647
8890
|
export {
|
8891
|
+
AssetId,
|
8892
|
+
TestMessage,
|
8893
|
+
WalletConfig,
|
8648
8894
|
generateTestWallet,
|
8649
8895
|
killNode,
|
8650
8896
|
launchNode,
|
8651
8897
|
launchNodeAndGetWallets,
|
8652
|
-
seedTestWallet
|
8898
|
+
seedTestWallet,
|
8899
|
+
setupTestProviderAndWallets
|
8653
8900
|
};
|
8654
8901
|
//# sourceMappingURL=test-utils.mjs.map
|