@fuel-ts/account 0.0.0-rc-1815-20240322115843 → 0.0.0-rc-1356-20240322130951
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 +0 -7
- package/dist/account.d.ts.map +1 -1
- package/dist/connectors/fuel-connector.d.ts +0 -10
- package/dist/connectors/fuel-connector.d.ts.map +1 -1
- package/dist/index.global.js +12 -70
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +107 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -71
- package/dist/index.mjs.map +1 -1
- package/dist/providers/transaction-request/transaction-request.d.ts +1 -20
- package/dist/providers/transaction-request/transaction-request.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 +9 -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 +328 -70
- package/dist/test-utils.global.js.map +1 -1
- package/dist/test-utils.js +332 -164
- package/dist/test-utils.js.map +1 -1
- package/dist/test-utils.mjs +235 -71
- package/dist/test-utils.mjs.map +1 -1
- package/dist/wallet/base-wallet-unlocked.d.ts.map +1 -1
- package/package.json +17 -16
- package/dist/providers/utils/sleep.d.ts +0 -3
- package/dist/providers/utils/sleep.d.ts.map +0 -1
@@ -32710,6 +32710,13 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
32710
32710
|
};
|
32711
32711
|
var defaultChainConfig = chainConfig_default;
|
32712
32712
|
var defaultConsensusKey = "0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298";
|
32713
|
+
function sleep(time) {
|
32714
|
+
return new Promise((resolve) => {
|
32715
|
+
setTimeout(() => {
|
32716
|
+
resolve(true);
|
32717
|
+
}, time);
|
32718
|
+
});
|
32719
|
+
}
|
32713
32720
|
|
32714
32721
|
// ../crypto/dist/index.mjs
|
32715
32722
|
var import_crypto8 = __toESM(__require("crypto"), 1);
|
@@ -38080,11 +38087,72 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
38080
38087
|
};
|
38081
38088
|
}
|
38082
38089
|
|
38090
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry2.js
|
38091
|
+
function _curry2(fn) {
|
38092
|
+
return function f2(a, b) {
|
38093
|
+
switch (arguments.length) {
|
38094
|
+
case 0:
|
38095
|
+
return f2;
|
38096
|
+
case 1:
|
38097
|
+
return _isPlaceholder(a) ? f2 : _curry1(function(_b) {
|
38098
|
+
return fn(a, _b);
|
38099
|
+
});
|
38100
|
+
default:
|
38101
|
+
return _isPlaceholder(a) && _isPlaceholder(b) ? f2 : _isPlaceholder(a) ? _curry1(function(_a) {
|
38102
|
+
return fn(_a, b);
|
38103
|
+
}) : _isPlaceholder(b) ? _curry1(function(_b) {
|
38104
|
+
return fn(a, _b);
|
38105
|
+
}) : fn(a, b);
|
38106
|
+
}
|
38107
|
+
};
|
38108
|
+
}
|
38109
|
+
|
38110
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_curry3.js
|
38111
|
+
function _curry3(fn) {
|
38112
|
+
return function f3(a, b, c) {
|
38113
|
+
switch (arguments.length) {
|
38114
|
+
case 0:
|
38115
|
+
return f3;
|
38116
|
+
case 1:
|
38117
|
+
return _isPlaceholder(a) ? f3 : _curry2(function(_b, _c) {
|
38118
|
+
return fn(a, _b, _c);
|
38119
|
+
});
|
38120
|
+
case 2:
|
38121
|
+
return _isPlaceholder(a) && _isPlaceholder(b) ? f3 : _isPlaceholder(a) ? _curry2(function(_a, _c) {
|
38122
|
+
return fn(_a, b, _c);
|
38123
|
+
}) : _isPlaceholder(b) ? _curry2(function(_b, _c) {
|
38124
|
+
return fn(a, _b, _c);
|
38125
|
+
}) : _curry1(function(_c) {
|
38126
|
+
return fn(a, b, _c);
|
38127
|
+
});
|
38128
|
+
default:
|
38129
|
+
return _isPlaceholder(a) && _isPlaceholder(b) && _isPlaceholder(c) ? f3 : _isPlaceholder(a) && _isPlaceholder(b) ? _curry2(function(_a, _b) {
|
38130
|
+
return fn(_a, _b, c);
|
38131
|
+
}) : _isPlaceholder(a) && _isPlaceholder(c) ? _curry2(function(_a, _c) {
|
38132
|
+
return fn(_a, b, _c);
|
38133
|
+
}) : _isPlaceholder(b) && _isPlaceholder(c) ? _curry2(function(_b, _c) {
|
38134
|
+
return fn(a, _b, _c);
|
38135
|
+
}) : _isPlaceholder(a) ? _curry1(function(_a) {
|
38136
|
+
return fn(_a, b, c);
|
38137
|
+
}) : _isPlaceholder(b) ? _curry1(function(_b) {
|
38138
|
+
return fn(a, _b, c);
|
38139
|
+
}) : _isPlaceholder(c) ? _curry1(function(_c) {
|
38140
|
+
return fn(a, b, _c);
|
38141
|
+
}) : fn(a, b, c);
|
38142
|
+
}
|
38143
|
+
};
|
38144
|
+
}
|
38145
|
+
|
38083
38146
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isArray.js
|
38084
38147
|
var isArray_default = Array.isArray || function _isArray(val) {
|
38085
38148
|
return val != null && val.length >= 0 && Object.prototype.toString.call(val) === "[object Array]";
|
38086
38149
|
};
|
38087
38150
|
|
38151
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_has.js
|
38152
|
+
function _has(prop, obj) {
|
38153
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
38154
|
+
}
|
38155
|
+
|
38088
38156
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/type.js
|
38089
38157
|
var type = /* @__PURE__ */ _curry1(function type2(val) {
|
38090
38158
|
return val === null ? "Null" : val === void 0 ? "Undefined" : Object.prototype.toString.call(val).slice(8, -1);
|
@@ -38101,6 +38169,11 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
38101
38169
|
return d.getUTCFullYear() + "-" + pad(d.getUTCMonth() + 1) + "-" + pad(d.getUTCDate()) + "T" + pad(d.getUTCHours()) + ":" + pad(d.getUTCMinutes()) + ":" + pad(d.getUTCSeconds()) + "." + (d.getUTCMilliseconds() / 1e3).toFixed(3).slice(2, 5) + "Z";
|
38102
38170
|
};
|
38103
38171
|
|
38172
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isObject.js
|
38173
|
+
function _isObject(x) {
|
38174
|
+
return Object.prototype.toString.call(x) === "[object Object]";
|
38175
|
+
}
|
38176
|
+
|
38104
38177
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/internal/_isInteger.js
|
38105
38178
|
var isInteger_default = Number.isInteger || function _isInteger(n) {
|
38106
38179
|
return n << 0 === n;
|
@@ -38214,6 +38287,46 @@ This unreleased fuel-core build may include features and updates not yet support
|
|
38214
38287
|
});
|
38215
38288
|
var clone_default = clone2;
|
38216
38289
|
|
38290
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeWithKey.js
|
38291
|
+
var mergeWithKey = /* @__PURE__ */ _curry3(function mergeWithKey2(fn, l, r) {
|
38292
|
+
var result = {};
|
38293
|
+
var k;
|
38294
|
+
l = l || {};
|
38295
|
+
r = r || {};
|
38296
|
+
for (k in l) {
|
38297
|
+
if (_has(k, l)) {
|
38298
|
+
result[k] = _has(k, r) ? fn(k, l[k], r[k]) : l[k];
|
38299
|
+
}
|
38300
|
+
}
|
38301
|
+
for (k in r) {
|
38302
|
+
if (_has(k, r) && !_has(k, result)) {
|
38303
|
+
result[k] = r[k];
|
38304
|
+
}
|
38305
|
+
}
|
38306
|
+
return result;
|
38307
|
+
});
|
38308
|
+
var mergeWithKey_default = mergeWithKey;
|
38309
|
+
|
38310
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepWithKey.js
|
38311
|
+
var mergeDeepWithKey = /* @__PURE__ */ _curry3(function mergeDeepWithKey2(fn, lObj, rObj) {
|
38312
|
+
return mergeWithKey_default(function(k, lVal, rVal) {
|
38313
|
+
if (_isObject(lVal) && _isObject(rVal)) {
|
38314
|
+
return mergeDeepWithKey2(fn, lVal, rVal);
|
38315
|
+
} else {
|
38316
|
+
return fn(k, lVal, rVal);
|
38317
|
+
}
|
38318
|
+
}, lObj, rObj);
|
38319
|
+
});
|
38320
|
+
var mergeDeepWithKey_default = mergeDeepWithKey;
|
38321
|
+
|
38322
|
+
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/mergeDeepRight.js
|
38323
|
+
var mergeDeepRight = /* @__PURE__ */ _curry2(function mergeDeepRight2(lObj, rObj) {
|
38324
|
+
return mergeDeepWithKey_default(function(k, lVal, rVal) {
|
38325
|
+
return rVal;
|
38326
|
+
}, lObj, rObj);
|
38327
|
+
});
|
38328
|
+
var mergeDeepRight_default = mergeDeepRight;
|
38329
|
+
|
38217
38330
|
// ../../node_modules/.pnpm/ramda@0.29.0/node_modules/ramda/es/trim.js
|
38218
38331
|
var hasProtoTrim = typeof String.prototype.trim === "function";
|
38219
38332
|
|
@@ -42745,15 +42858,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42745
42858
|
return normalize2(clone_default(root));
|
42746
42859
|
}
|
42747
42860
|
|
42748
|
-
// src/providers/utils/sleep.ts
|
42749
|
-
function sleep(time) {
|
42750
|
-
return new Promise((resolve) => {
|
42751
|
-
setTimeout(() => {
|
42752
|
-
resolve(true);
|
42753
|
-
}, time);
|
42754
|
-
});
|
42755
|
-
}
|
42756
|
-
|
42757
42861
|
// src/providers/transaction-request/errors.ts
|
42758
42862
|
var NoWitnessAtIndexError = class extends Error {
|
42759
42863
|
constructor(index) {
|
@@ -42882,27 +42986,13 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42882
42986
|
this.outputs.push(output3);
|
42883
42987
|
return this.outputs.length - 1;
|
42884
42988
|
}
|
42885
|
-
/**
|
42886
|
-
* @hidden
|
42887
|
-
*
|
42888
|
-
* Pushes a witness to the list and returns the index
|
42889
|
-
*
|
42890
|
-
* @param signature - The signature to add to the witness.
|
42891
|
-
* @returns The index of the created witness.
|
42892
|
-
*/
|
42893
|
-
addWitness(signature) {
|
42894
|
-
this.witnesses.push(signature);
|
42895
|
-
return this.witnesses.length - 1;
|
42896
|
-
}
|
42897
42989
|
/**
|
42898
42990
|
* @hidden
|
42899
42991
|
*
|
42900
42992
|
* Creates an empty witness without any side effects and returns the index
|
42901
|
-
*
|
42902
|
-
* @returns The index of the created witness.
|
42903
42993
|
*/
|
42904
|
-
|
42905
|
-
this.
|
42994
|
+
createWitness() {
|
42995
|
+
this.witnesses.push(concat([ZeroBytes32, ZeroBytes32]));
|
42906
42996
|
return this.witnesses.length - 1;
|
42907
42997
|
}
|
42908
42998
|
/**
|
@@ -42931,21 +43021,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
42931
43021
|
}
|
42932
43022
|
this.witnesses[index] = witness;
|
42933
43023
|
}
|
42934
|
-
/**
|
42935
|
-
* Helper function to add an external signature to the transaction.
|
42936
|
-
*
|
42937
|
-
* @param account - The account/s to sign to the transaction.
|
42938
|
-
* @returns The transaction with the signature witness added.
|
42939
|
-
*/
|
42940
|
-
async addAccountWitnesses(account) {
|
42941
|
-
const accounts = Array.isArray(account) ? account : [account];
|
42942
|
-
await Promise.all(
|
42943
|
-
accounts.map(async (acc) => {
|
42944
|
-
this.addWitness(await acc.signTransaction(this));
|
42945
|
-
})
|
42946
|
-
);
|
42947
|
-
return this;
|
42948
|
-
}
|
42949
43024
|
/**
|
42950
43025
|
* Gets the coin inputs for a transaction.
|
42951
43026
|
*
|
@@ -43011,7 +43086,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
43011
43086
|
} else {
|
43012
43087
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(owner);
|
43013
43088
|
if (typeof witnessIndex !== "number") {
|
43014
|
-
witnessIndex = this.
|
43089
|
+
witnessIndex = this.createWitness();
|
43015
43090
|
}
|
43016
43091
|
}
|
43017
43092
|
const input = {
|
@@ -43045,7 +43120,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
43045
43120
|
} else {
|
43046
43121
|
witnessIndex = this.getCoinInputWitnessIndexByOwner(recipient);
|
43047
43122
|
if (typeof witnessIndex !== "number") {
|
43048
|
-
witnessIndex = this.
|
43123
|
+
witnessIndex = this.createWitness();
|
43049
43124
|
}
|
43050
43125
|
}
|
43051
43126
|
const input = {
|
@@ -45910,21 +45985,6 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
45910
45985
|
}
|
45911
45986
|
return this._connector.signMessage(this.address.toString(), message);
|
45912
45987
|
}
|
45913
|
-
/**
|
45914
|
-
* Signs a transaction with the wallet's private key.
|
45915
|
-
*
|
45916
|
-
* @param transactionRequestLike - The transaction request to sign.
|
45917
|
-
* @returns A promise that resolves to the signature of the transaction.
|
45918
|
-
*/
|
45919
|
-
async signTransaction(transactionRequestLike) {
|
45920
|
-
if (!this._connector) {
|
45921
|
-
throw new FuelError(
|
45922
|
-
ErrorCode.MISSING_CONNECTOR,
|
45923
|
-
"A connector is required to sign transactions."
|
45924
|
-
);
|
45925
|
-
}
|
45926
|
-
return this._connector.signTransaction(this.address.toString(), transactionRequestLike);
|
45927
|
-
}
|
45928
45988
|
/**
|
45929
45989
|
* Sends a transaction to the network.
|
45930
45990
|
*
|
@@ -47536,7 +47596,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
47536
47596
|
*/
|
47537
47597
|
async signTransaction(transactionRequestLike) {
|
47538
47598
|
const transactionRequest = transactionRequestify(transactionRequestLike);
|
47539
|
-
const chainId = this.provider.
|
47599
|
+
const chainId = this.provider.getChain().consensusParameters.chainId.toNumber();
|
47540
47600
|
const hashedTransaction = transactionRequest.getTransactionId(chainId);
|
47541
47601
|
const signature = await this.signer().sign(hashedTransaction);
|
47542
47602
|
return hexlify(signature);
|
@@ -50400,7 +50460,8 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
50400
50460
|
useSystemFuelCore = false,
|
50401
50461
|
loggingEnabled = true,
|
50402
50462
|
debugEnabled = false,
|
50403
|
-
basePath
|
50463
|
+
basePath,
|
50464
|
+
chainConfig = defaultChainConfig
|
50404
50465
|
}) => (
|
50405
50466
|
// eslint-disable-next-line no-async-promise-executor
|
50406
50467
|
new Promise(async (resolve, reject) => {
|
@@ -50437,17 +50498,17 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
50437
50498
|
(0, import_fs2.mkdirSync)(tempDirPath, { recursive: true });
|
50438
50499
|
}
|
50439
50500
|
const tempChainConfigFilePath = import_path8.default.join(tempDirPath, "chainConfig.json");
|
50440
|
-
let
|
50501
|
+
let generatedChainConfig = chainConfig;
|
50441
50502
|
if (!process.env.GENESIS_SECRET) {
|
50442
50503
|
const pk = Signer.generatePrivateKey();
|
50443
50504
|
const signer = new Signer(pk);
|
50444
50505
|
process.env.GENESIS_SECRET = hexlify(pk);
|
50445
|
-
|
50446
|
-
...
|
50506
|
+
generatedChainConfig = {
|
50507
|
+
...generatedChainConfig,
|
50447
50508
|
initial_state: {
|
50448
|
-
...
|
50509
|
+
...generatedChainConfig.initial_state,
|
50449
50510
|
coins: [
|
50450
|
-
...
|
50511
|
+
...generatedChainConfig.initial_state.coins,
|
50451
50512
|
{
|
50452
50513
|
owner: signer.address.toHexString(),
|
50453
50514
|
amount: toHex(1e9),
|
@@ -50457,7 +50518,7 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
50457
50518
|
}
|
50458
50519
|
};
|
50459
50520
|
}
|
50460
|
-
(0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(
|
50521
|
+
(0, import_fs2.writeFileSync)(tempChainConfigFilePath, JSON.stringify(generatedChainConfig), "utf8");
|
50461
50522
|
chainConfigPathToUse = tempChainConfigFilePath;
|
50462
50523
|
}
|
50463
50524
|
const child = (0, import_child_process.spawn)(
|
@@ -50495,16 +50556,21 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
50495
50556
|
}
|
50496
50557
|
};
|
50497
50558
|
child.stderr.on("data", (chunk) => {
|
50498
|
-
|
50559
|
+
const text = typeof chunk === "string" ? chunk : chunk.toString();
|
50560
|
+
if (text.indexOf(graphQLStartSubstring) !== -1) {
|
50561
|
+
const rows = text.split("\n");
|
50562
|
+
const rowWithUrl = rows.find((row) => row.indexOf(graphQLStartSubstring) !== -1);
|
50563
|
+
const [realIp, realPort] = rowWithUrl.split(" ").at(-1).trim().split(":");
|
50499
50564
|
resolve({
|
50500
50565
|
cleanup: () => killNode(cleanupConfig),
|
50501
|
-
ip:
|
50502
|
-
port:
|
50566
|
+
ip: realIp,
|
50567
|
+
port: realPort,
|
50568
|
+
url: `http://${realIp}:${realPort}/graphql`,
|
50503
50569
|
chainConfigPath: chainConfigPathToUse
|
50504
50570
|
});
|
50505
50571
|
}
|
50506
|
-
if (/error/i.test(
|
50507
|
-
reject(
|
50572
|
+
if (/error/i.test(text)) {
|
50573
|
+
reject(text.toString());
|
50508
50574
|
}
|
50509
50575
|
});
|
50510
50576
|
process.on("exit", () => killNode(cleanupConfig));
|
@@ -50536,6 +50602,198 @@ ${MessageCoinFragmentFragmentDoc}`;
|
|
50536
50602
|
};
|
50537
50603
|
return { wallets, stop: cleanup, provider };
|
50538
50604
|
};
|
50605
|
+
|
50606
|
+
// src/test-utils/asset-id.ts
|
50607
|
+
var _AssetId = class {
|
50608
|
+
constructor(value) {
|
50609
|
+
this.value = value;
|
50610
|
+
}
|
50611
|
+
static random() {
|
50612
|
+
return new _AssetId(hexlify(randomBytes22(32)));
|
50613
|
+
}
|
50614
|
+
};
|
50615
|
+
var AssetId = _AssetId;
|
50616
|
+
__publicField(AssetId, "BaseAssetId", new _AssetId(BaseAssetId));
|
50617
|
+
__publicField(AssetId, "A", new _AssetId(
|
50618
|
+
"0x0101010101010101010101010101010101010101010101010101010101010101"
|
50619
|
+
));
|
50620
|
+
__publicField(AssetId, "B", new _AssetId(
|
50621
|
+
"0x0202020202020202020202020202020202020202020202020202020202020202"
|
50622
|
+
));
|
50623
|
+
|
50624
|
+
// src/test-utils/wallet-config.ts
|
50625
|
+
var WalletConfig = class {
|
50626
|
+
initialState;
|
50627
|
+
options;
|
50628
|
+
wallets;
|
50629
|
+
generateWallets = () => {
|
50630
|
+
const generatedWallets = [];
|
50631
|
+
for (let index = 1; index <= this.options.count; index++) {
|
50632
|
+
generatedWallets.push(new WalletUnlocked(randomBytes22(32)));
|
50633
|
+
}
|
50634
|
+
return generatedWallets;
|
50635
|
+
};
|
50636
|
+
constructor(config) {
|
50637
|
+
WalletConfig.guard(config);
|
50638
|
+
this.options = config;
|
50639
|
+
const { assets: assets2, coinsPerAsset, amountPerCoin, messages } = this.options;
|
50640
|
+
this.wallets = this.generateWallets();
|
50641
|
+
this.initialState = {
|
50642
|
+
messages: WalletConfig.createMessages(this.wallets, messages),
|
50643
|
+
coins: WalletConfig.createCoins(this.wallets, assets2, coinsPerAsset, amountPerCoin)
|
50644
|
+
};
|
50645
|
+
}
|
50646
|
+
apply(chainConfig) {
|
50647
|
+
return {
|
50648
|
+
...chainConfig,
|
50649
|
+
initial_state: {
|
50650
|
+
...chainConfig?.initial_state,
|
50651
|
+
coins: this.initialState.coins.concat(chainConfig?.initial_state?.coins || []),
|
50652
|
+
messages: this.initialState.messages.concat(chainConfig?.initial_state?.messages ?? [])
|
50653
|
+
}
|
50654
|
+
};
|
50655
|
+
}
|
50656
|
+
static createMessages(wallets, messages) {
|
50657
|
+
return messages.map((msg) => wallets.map((wallet) => msg.toChainMessage(wallet.address))).flatMap((x) => x);
|
50658
|
+
}
|
50659
|
+
static createCoins(wallets, assets2, coinsPerAsset, amountPerCoin) {
|
50660
|
+
const coins = [];
|
50661
|
+
let assetIds = [AssetId.BaseAssetId.value];
|
50662
|
+
if (Array.isArray(assets2)) {
|
50663
|
+
assetIds = assetIds.concat(assets2.map((a) => a.value));
|
50664
|
+
} else {
|
50665
|
+
for (let index = 0; index < assets2 - 1; index++) {
|
50666
|
+
assetIds.push(AssetId.random().value);
|
50667
|
+
}
|
50668
|
+
}
|
50669
|
+
wallets.map((wallet) => wallet.address.toHexString()).forEach((walletAddress) => {
|
50670
|
+
assetIds.forEach((assetId) => {
|
50671
|
+
for (let index = 0; index < coinsPerAsset; index++) {
|
50672
|
+
coins.push({
|
50673
|
+
amount: toHex(amountPerCoin, 8),
|
50674
|
+
asset_id: assetId,
|
50675
|
+
owner: walletAddress
|
50676
|
+
});
|
50677
|
+
}
|
50678
|
+
});
|
50679
|
+
});
|
50680
|
+
return coins;
|
50681
|
+
}
|
50682
|
+
static guard({
|
50683
|
+
count: wallets,
|
50684
|
+
assets: assets2,
|
50685
|
+
coinsPerAsset,
|
50686
|
+
amountPerCoin
|
50687
|
+
}) {
|
50688
|
+
if (Array.isArray(wallets) && wallets.length === 0 || typeof wallets === "number" && wallets <= 0) {
|
50689
|
+
throw new FuelError(
|
50690
|
+
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
50691
|
+
"Number of wallets must be greater than zero."
|
50692
|
+
);
|
50693
|
+
}
|
50694
|
+
if (Array.isArray(assets2) && assets2.length === 0 || typeof assets2 === "number" && assets2 <= 0) {
|
50695
|
+
throw new FuelError(
|
50696
|
+
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
50697
|
+
"Number of assets per wallet must be greater than zero."
|
50698
|
+
);
|
50699
|
+
}
|
50700
|
+
if (coinsPerAsset <= 0) {
|
50701
|
+
throw new FuelError(
|
50702
|
+
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
50703
|
+
"Number of coins per asset must be greater than zero."
|
50704
|
+
);
|
50705
|
+
}
|
50706
|
+
if (amountPerCoin <= 0) {
|
50707
|
+
throw new FuelError(
|
50708
|
+
FuelError.CODES.INVALID_INPUT_PARAMETERS,
|
50709
|
+
"Amount per coin must be greater than zero."
|
50710
|
+
);
|
50711
|
+
}
|
50712
|
+
}
|
50713
|
+
};
|
50714
|
+
|
50715
|
+
// src/test-utils/setup-test-provider-and-wallets.ts
|
50716
|
+
var defaultWalletConfigOptions = {
|
50717
|
+
count: 2,
|
50718
|
+
assets: [AssetId.A, AssetId.B],
|
50719
|
+
coinsPerAsset: 1,
|
50720
|
+
amountPerCoin: 1e10,
|
50721
|
+
messages: []
|
50722
|
+
};
|
50723
|
+
async function setupTestProviderAndWallets({
|
50724
|
+
walletConfig: walletConfigOptions = {},
|
50725
|
+
providerOptions,
|
50726
|
+
nodeOptions = {}
|
50727
|
+
} = {}) {
|
50728
|
+
Symbol.dispose ??= Symbol("Symbol.dispose");
|
50729
|
+
const walletConfig = new WalletConfig({
|
50730
|
+
...defaultWalletConfigOptions,
|
50731
|
+
...walletConfigOptions
|
50732
|
+
});
|
50733
|
+
const { cleanup, url } = await launchNode({
|
50734
|
+
...nodeOptions,
|
50735
|
+
chainConfig: mergeDeepRight_default(defaultChainConfig, walletConfig.apply(nodeOptions?.chainConfig)),
|
50736
|
+
port: "0"
|
50737
|
+
});
|
50738
|
+
let provider;
|
50739
|
+
try {
|
50740
|
+
provider = await Provider.create(url, providerOptions);
|
50741
|
+
} catch (err) {
|
50742
|
+
cleanup();
|
50743
|
+
throw err;
|
50744
|
+
}
|
50745
|
+
const wallets = walletConfig.wallets;
|
50746
|
+
wallets.forEach((wallet) => {
|
50747
|
+
wallet.connect(provider);
|
50748
|
+
});
|
50749
|
+
return {
|
50750
|
+
provider,
|
50751
|
+
wallets,
|
50752
|
+
cleanup,
|
50753
|
+
[Symbol.dispose]: cleanup
|
50754
|
+
};
|
50755
|
+
}
|
50756
|
+
|
50757
|
+
// src/test-utils/test-message.ts
|
50758
|
+
var TestMessage = class {
|
50759
|
+
sender;
|
50760
|
+
recipient;
|
50761
|
+
nonce;
|
50762
|
+
amount;
|
50763
|
+
data;
|
50764
|
+
da_height;
|
50765
|
+
/**
|
50766
|
+
* A helper class to create messages for testing purposes.
|
50767
|
+
*
|
50768
|
+
* Used in tandem with `WalletConfig`.
|
50769
|
+
* It can also be used standalone and passed into the initial state of a chain via the `.toChainMessage` method.
|
50770
|
+
*/
|
50771
|
+
constructor({
|
50772
|
+
sender = Address.fromRandom(),
|
50773
|
+
recipient = Address.fromRandom(),
|
50774
|
+
nonce = hexlify(randomBytes22(32)),
|
50775
|
+
amount = 1e6,
|
50776
|
+
data = "02",
|
50777
|
+
da_height = "0x00"
|
50778
|
+
} = {}) {
|
50779
|
+
this.sender = sender;
|
50780
|
+
this.recipient = recipient;
|
50781
|
+
this.nonce = nonce;
|
50782
|
+
this.amount = amount;
|
50783
|
+
this.data = data;
|
50784
|
+
this.da_height = da_height;
|
50785
|
+
}
|
50786
|
+
toChainMessage(recipient) {
|
50787
|
+
return {
|
50788
|
+
sender: this.sender.toB256(),
|
50789
|
+
recipient: recipient?.toB256() ?? this.recipient.toB256(),
|
50790
|
+
nonce: this.nonce,
|
50791
|
+
amount: new BN(this.amount).toHex(8),
|
50792
|
+
data: this.data,
|
50793
|
+
da_height: this.da_height
|
50794
|
+
};
|
50795
|
+
}
|
50796
|
+
};
|
50539
50797
|
})();
|
50540
50798
|
/*! Bundled license information:
|
50541
50799
|
|