@argonprotocol/testing 1.4.3-dev.8dfc7f36 → 1.4.3-dev.8e7d7af7
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.
- package/lib/ethereum-contracts/ArgonToken.json +419 -0
- package/lib/ethereum-contracts/ArgonotToken.json +419 -0
- package/lib/ethereum-contracts/MintingGateway.json +538 -0
- package/lib/ethereum-contracts/ProxyAdmin.json +135 -0
- package/lib/ethereum-contracts/TransparentUpgradeableProxy.json +131 -0
- package/lib/index.cjs +520 -17
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +96 -3
- package/lib/index.d.ts +96 -3
- package/lib/index.js +519 -17
- package/lib/index.js.map +1 -1
- package/package.json +5 -6
- /package/lib/{docker-compose.yml → dev.docker-compose.yml} +0 -0
package/lib/index.js
CHANGED
|
@@ -10,9 +10,9 @@ import { Keyring as Keyring3, TxSubmitter as TxSubmitter2 } from "@argonprotocol
|
|
|
10
10
|
import * as process4 from "process";
|
|
11
11
|
import HttpProxy from "http-proxy";
|
|
12
12
|
import * as child_process4 from "child_process";
|
|
13
|
-
import * as
|
|
13
|
+
import * as http2 from "http";
|
|
14
14
|
import * as url from "url";
|
|
15
|
-
import * as
|
|
15
|
+
import * as Path7 from "path";
|
|
16
16
|
|
|
17
17
|
// src/TestNotary.ts
|
|
18
18
|
import { customAlphabet } from "nanoid";
|
|
@@ -201,7 +201,6 @@ import * as Path2 from "path";
|
|
|
201
201
|
import * as readline2 from "readline";
|
|
202
202
|
import { detectPort } from "detect-port";
|
|
203
203
|
import { customAlphabet as customAlphabet2 } from "nanoid";
|
|
204
|
-
import Client from "bitcoin-core";
|
|
205
204
|
import * as lockfile from "proper-lockfile";
|
|
206
205
|
import { getClient } from "@argonprotocol/mainchain";
|
|
207
206
|
var nanoid2 = customAlphabet2("0123456789abcdefghijklmnopqrstuvwxyz", 4);
|
|
@@ -237,11 +236,7 @@ var TestMainchain = class {
|
|
|
237
236
|
addTeardown(this);
|
|
238
237
|
}
|
|
239
238
|
getBitcoinClient() {
|
|
240
|
-
return new
|
|
241
|
-
username: "bitcoin",
|
|
242
|
-
password: "bitcoin",
|
|
243
|
-
host: `http://localhost:${this.bitcoinPort}`
|
|
244
|
-
});
|
|
239
|
+
return new BitcoinRpcClient(`http://localhost:${this.bitcoinPort}`, "bitcoin", "bitcoin");
|
|
245
240
|
}
|
|
246
241
|
/**
|
|
247
242
|
* Launch and return the localhost url. NOTE: this url will not work cross-docker. You need to use the containerAddress property
|
|
@@ -331,9 +326,20 @@ var TestMainchain = class {
|
|
|
331
326
|
return this.address;
|
|
332
327
|
}
|
|
333
328
|
async client() {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
329
|
+
let lastError;
|
|
330
|
+
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
331
|
+
try {
|
|
332
|
+
const client = await getClient(this.address);
|
|
333
|
+
disconnectOnTeardown(client);
|
|
334
|
+
return client;
|
|
335
|
+
} catch (error) {
|
|
336
|
+
lastError = error;
|
|
337
|
+
await new Promise((resolve3) => setTimeout(resolve3, 250));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
throw new Error(`Unable to connect to mainchain client at ${this.address}`, {
|
|
341
|
+
cause: lastError instanceof Error ? lastError : void 0
|
|
342
|
+
});
|
|
337
343
|
}
|
|
338
344
|
async bootAddress() {
|
|
339
345
|
const client = await this.client();
|
|
@@ -424,6 +430,51 @@ var TestMainchain = class {
|
|
|
424
430
|
return cleanHostForDocker(`http://bitcoin:bitcoin@localhost:${rpcPort}`);
|
|
425
431
|
}
|
|
426
432
|
};
|
|
433
|
+
var BitcoinRpcClient = class {
|
|
434
|
+
#rpcUrl;
|
|
435
|
+
#authorization;
|
|
436
|
+
constructor(rpcUrl, username, password) {
|
|
437
|
+
this.#rpcUrl = rpcUrl;
|
|
438
|
+
this.#authorization = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
|
439
|
+
}
|
|
440
|
+
async command(method, ...params) {
|
|
441
|
+
const response = await fetch(this.#rpcUrl, {
|
|
442
|
+
method: "POST",
|
|
443
|
+
headers: {
|
|
444
|
+
authorization: this.#authorization,
|
|
445
|
+
"content-type": "application/json"
|
|
446
|
+
},
|
|
447
|
+
body: JSON.stringify({
|
|
448
|
+
jsonrpc: "1.0",
|
|
449
|
+
id: `${method}-${Date.now()}`,
|
|
450
|
+
method,
|
|
451
|
+
params
|
|
452
|
+
})
|
|
453
|
+
});
|
|
454
|
+
const body = await response.text();
|
|
455
|
+
let payload;
|
|
456
|
+
if (body) {
|
|
457
|
+
try {
|
|
458
|
+
payload = JSON.parse(body);
|
|
459
|
+
} catch {
|
|
460
|
+
payload = void 0;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (payload?.error) {
|
|
464
|
+
const httpStatus = response.ok ? "" : ` with HTTP ${response.status}`;
|
|
465
|
+
throw new Error(
|
|
466
|
+
`Bitcoin RPC ${method} failed${httpStatus} (${payload.error.code}): ${payload.error.message}`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
if (!response.ok) {
|
|
470
|
+
throw new Error(`Bitcoin RPC ${method} failed with HTTP ${response.status}`);
|
|
471
|
+
}
|
|
472
|
+
if (!payload) {
|
|
473
|
+
throw new Error(`Bitcoin RPC ${method} returned an invalid JSON response`);
|
|
474
|
+
}
|
|
475
|
+
return payload.result;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
427
478
|
|
|
428
479
|
// src/TestBitcoinCli.ts
|
|
429
480
|
import * as child_process2 from "child_process";
|
|
@@ -501,11 +552,459 @@ var TestOracle = class _TestOracle {
|
|
|
501
552
|
}
|
|
502
553
|
};
|
|
503
554
|
|
|
555
|
+
// src/TestEthereum.ts
|
|
556
|
+
import * as fs4 from "fs/promises";
|
|
557
|
+
import * as os from "os";
|
|
558
|
+
import * as Path5 from "path";
|
|
559
|
+
import { spawn as spawn4, spawnSync } from "child_process";
|
|
560
|
+
import { detectPort as detectPort2 } from "detect-port";
|
|
561
|
+
|
|
562
|
+
// src/ethereumContracts.ts
|
|
563
|
+
import { readFileSync } from "fs";
|
|
564
|
+
function loadArtifact(fileName) {
|
|
565
|
+
return JSON.parse(
|
|
566
|
+
readFileSync(new URL(`./ethereum-contracts/${fileName}`, import.meta.url), "utf8")
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
var argonTokenArtifact = loadArtifact("ArgonToken.json");
|
|
570
|
+
var argonotTokenArtifact = loadArtifact("ArgonotToken.json");
|
|
571
|
+
var mintingGatewayArtifact = loadArtifact("MintingGateway.json");
|
|
572
|
+
var proxyAdminArtifact = loadArtifact("ProxyAdmin.json");
|
|
573
|
+
var transparentUpgradeableProxyArtifact = loadArtifact("TransparentUpgradeableProxy.json");
|
|
574
|
+
|
|
575
|
+
// src/TestEthereum.ts
|
|
576
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
577
|
+
import {
|
|
578
|
+
createPublicClient,
|
|
579
|
+
createWalletClient,
|
|
580
|
+
defineChain,
|
|
581
|
+
encodeFunctionData,
|
|
582
|
+
getAddress,
|
|
583
|
+
http,
|
|
584
|
+
zeroAddress
|
|
585
|
+
} from "viem";
|
|
586
|
+
var DEFAULT_KURTOSIS_BIN = "kurtosis";
|
|
587
|
+
var DEFAULT_ETHEREUM_PACKAGE = "github.com/ethpandaops/ethereum-package";
|
|
588
|
+
var DEFAULT_EL_PORT_START = 32e3;
|
|
589
|
+
var DEFAULT_CL_PORT_START = 33e3;
|
|
590
|
+
var PORT_RANGE_SIZE = 32;
|
|
591
|
+
var ENCLAVE_NAME_PREFIX = "argon-eth-";
|
|
592
|
+
var PROBE_INTERVAL_MS = 1e3;
|
|
593
|
+
var PROBE_TIMEOUT_MS = 6e4;
|
|
594
|
+
var LIGHT_CLIENT_READY_TIMEOUT_MS = 5 * 6e4;
|
|
595
|
+
var KURTOSIS_RUN_TIMEOUT_MS = 20 * 6e4;
|
|
596
|
+
var DEFAULT_SEED_ARGON_AMOUNT_BASE_UNITS = 1000000000n;
|
|
597
|
+
var ERC1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
|
|
598
|
+
var TestEthereum = class {
|
|
599
|
+
enclaveName;
|
|
600
|
+
kurtosisBin;
|
|
601
|
+
packageRef;
|
|
602
|
+
executionRpcUrl;
|
|
603
|
+
beaconApiUrl;
|
|
604
|
+
chainId;
|
|
605
|
+
#argsDir;
|
|
606
|
+
constructor(enclaveName = `${ENCLAVE_NAME_PREFIX}${Math.random().toString(36).slice(2, 8)}`, kurtosisBin = DEFAULT_KURTOSIS_BIN, packageRef = DEFAULT_ETHEREUM_PACKAGE) {
|
|
607
|
+
this.enclaveName = enclaveName;
|
|
608
|
+
this.kurtosisBin = kurtosisBin;
|
|
609
|
+
this.packageRef = packageRef;
|
|
610
|
+
addTeardown(this);
|
|
611
|
+
}
|
|
612
|
+
static isInstalled(kurtosisBin = DEFAULT_KURTOSIS_BIN) {
|
|
613
|
+
return spawnSync(kurtosisBin, ["version"], { stdio: "ignore" }).status === 0;
|
|
614
|
+
}
|
|
615
|
+
async launch(options) {
|
|
616
|
+
const {
|
|
617
|
+
consensusClient = "lighthouse",
|
|
618
|
+
preset = "mainnet",
|
|
619
|
+
secondsPerSlot,
|
|
620
|
+
waitForFinalization = true,
|
|
621
|
+
prefundedAccounts
|
|
622
|
+
} = options ?? {};
|
|
623
|
+
const elPublicPortStart = await findFreePortRange(DEFAULT_EL_PORT_START, PORT_RANGE_SIZE);
|
|
624
|
+
const clPublicPortStart = await findFreePortRange(DEFAULT_CL_PORT_START, PORT_RANGE_SIZE);
|
|
625
|
+
this.#argsDir = await fs4.mkdtemp(Path5.join(os.tmpdir(), "argon-ethereum-devnet-"));
|
|
626
|
+
const argsFile = Path5.join(this.#argsDir, "network-params.yaml");
|
|
627
|
+
await fs4.writeFile(
|
|
628
|
+
argsFile,
|
|
629
|
+
renderEthereumArgs(
|
|
630
|
+
elPublicPortStart,
|
|
631
|
+
clPublicPortStart,
|
|
632
|
+
consensusClient,
|
|
633
|
+
preset,
|
|
634
|
+
secondsPerSlot,
|
|
635
|
+
waitForFinalization,
|
|
636
|
+
prefundedAccounts
|
|
637
|
+
)
|
|
638
|
+
);
|
|
639
|
+
await runCommand(
|
|
640
|
+
this.kurtosisBin,
|
|
641
|
+
["run", "--enclave", this.enclaveName, this.packageRef, "--args-file", argsFile],
|
|
642
|
+
KURTOSIS_RUN_TIMEOUT_MS
|
|
643
|
+
);
|
|
644
|
+
const executionRpc = await waitForProbe(
|
|
645
|
+
() => findExecutionRpcUrl(elPublicPortStart, PORT_RANGE_SIZE),
|
|
646
|
+
PROBE_TIMEOUT_MS
|
|
647
|
+
);
|
|
648
|
+
const beaconApi = await waitForProbe(
|
|
649
|
+
() => findBeaconApiUrl(clPublicPortStart, PORT_RANGE_SIZE),
|
|
650
|
+
PROBE_TIMEOUT_MS
|
|
651
|
+
);
|
|
652
|
+
this.executionRpcUrl = executionRpc.url;
|
|
653
|
+
this.beaconApiUrl = beaconApi.url;
|
|
654
|
+
this.chainId = executionRpc.chainId;
|
|
655
|
+
await waitForProbe(
|
|
656
|
+
() => this.getBeacon("/eth/v1/beacon/genesis"),
|
|
657
|
+
LIGHT_CLIENT_READY_TIMEOUT_MS
|
|
658
|
+
);
|
|
659
|
+
return {
|
|
660
|
+
executionRpcUrl: this.executionRpcUrl,
|
|
661
|
+
beaconApiUrl: this.beaconApiUrl,
|
|
662
|
+
chainId: this.chainId
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
async callExecution(method, params = []) {
|
|
666
|
+
const executionRpcUrl = this.executionRpcUrl;
|
|
667
|
+
if (!executionRpcUrl) {
|
|
668
|
+
throw new Error("Execution RPC URL is not available before launch");
|
|
669
|
+
}
|
|
670
|
+
const response = await fetch(executionRpcUrl, {
|
|
671
|
+
method: "POST",
|
|
672
|
+
headers: { "content-type": "application/json" },
|
|
673
|
+
body: JSON.stringify({
|
|
674
|
+
id: 1,
|
|
675
|
+
jsonrpc: "2.0",
|
|
676
|
+
method,
|
|
677
|
+
params
|
|
678
|
+
}),
|
|
679
|
+
signal: AbortSignal.timeout(1e4)
|
|
680
|
+
});
|
|
681
|
+
if (!response.ok) {
|
|
682
|
+
throw new Error(`Execution RPC request failed for ${method}: ${response.status}`);
|
|
683
|
+
}
|
|
684
|
+
const body = await response.json();
|
|
685
|
+
if (body.error) {
|
|
686
|
+
throw new Error(
|
|
687
|
+
`Execution RPC ${method} failed (${body.error.code ?? "unknown"}): ${body.error.message ?? "unknown error"}`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
return body.result;
|
|
691
|
+
}
|
|
692
|
+
async getBeacon(path2) {
|
|
693
|
+
const beaconApiUrl = this.beaconApiUrl;
|
|
694
|
+
if (!beaconApiUrl) {
|
|
695
|
+
throw new Error("Beacon API URL is not available before launch");
|
|
696
|
+
}
|
|
697
|
+
const response = await fetch(new URL(path2, `${beaconApiUrl}/`), {
|
|
698
|
+
signal: AbortSignal.timeout(1e4)
|
|
699
|
+
});
|
|
700
|
+
if (!response.ok) {
|
|
701
|
+
throw new Error(`Beacon API request failed for ${path2}: ${response.status}`);
|
|
702
|
+
}
|
|
703
|
+
return await response.json();
|
|
704
|
+
}
|
|
705
|
+
async deployMintingGatewayFixture(options) {
|
|
706
|
+
const { executionRpcUrl, chainId } = this;
|
|
707
|
+
if (!executionRpcUrl || !chainId) {
|
|
708
|
+
throw new Error("Ethereum devnet must be launched before deploying MintingGateway fixtures");
|
|
709
|
+
}
|
|
710
|
+
const account = privateKeyToAccount(options.deployerPrivateKey);
|
|
711
|
+
const adminSafe = options.adminSafe ?? account.address;
|
|
712
|
+
const guardianSafe = options.guardianSafe ?? adminSafe;
|
|
713
|
+
const chain = createExecutionChain(chainId, executionRpcUrl);
|
|
714
|
+
const publicClient = createPublicClient({
|
|
715
|
+
chain,
|
|
716
|
+
transport: http(executionRpcUrl)
|
|
717
|
+
});
|
|
718
|
+
const walletClient = createWalletClient({
|
|
719
|
+
account,
|
|
720
|
+
chain,
|
|
721
|
+
transport: http(executionRpcUrl)
|
|
722
|
+
});
|
|
723
|
+
const bootstrapImplementationAddress = await deployContract(walletClient, publicClient, {
|
|
724
|
+
abi: mintingGatewayArtifact.abi,
|
|
725
|
+
bytecode: mintingGatewayArtifact.bytecode,
|
|
726
|
+
args: [zeroAddress, zeroAddress]
|
|
727
|
+
});
|
|
728
|
+
const initializeData = encodeFunctionData({
|
|
729
|
+
abi: mintingGatewayArtifact.abi,
|
|
730
|
+
functionName: "initialize",
|
|
731
|
+
args: [adminSafe, guardianSafe]
|
|
732
|
+
});
|
|
733
|
+
const gatewayAddress = await deployContract(walletClient, publicClient, {
|
|
734
|
+
abi: transparentUpgradeableProxyArtifact.abi,
|
|
735
|
+
bytecode: transparentUpgradeableProxyArtifact.bytecode,
|
|
736
|
+
args: [bootstrapImplementationAddress, adminSafe, initializeData]
|
|
737
|
+
});
|
|
738
|
+
const proxyAdminAddress = getAddressFromStorage(
|
|
739
|
+
await publicClient.getStorageAt({
|
|
740
|
+
address: gatewayAddress,
|
|
741
|
+
slot: ERC1967_ADMIN_SLOT
|
|
742
|
+
})
|
|
743
|
+
);
|
|
744
|
+
const argonTokenAddress = await deployContract(walletClient, publicClient, {
|
|
745
|
+
abi: argonTokenArtifact.abi,
|
|
746
|
+
bytecode: argonTokenArtifact.bytecode,
|
|
747
|
+
args: [gatewayAddress]
|
|
748
|
+
});
|
|
749
|
+
const argonotTokenAddress = await deployContract(walletClient, publicClient, {
|
|
750
|
+
abi: argonotTokenArtifact.abi,
|
|
751
|
+
bytecode: argonotTokenArtifact.bytecode,
|
|
752
|
+
args: [gatewayAddress]
|
|
753
|
+
});
|
|
754
|
+
const finalImplementationAddress = await deployContract(walletClient, publicClient, {
|
|
755
|
+
abi: mintingGatewayArtifact.abi,
|
|
756
|
+
bytecode: mintingGatewayArtifact.bytecode,
|
|
757
|
+
args: [argonTokenAddress, argonotTokenAddress]
|
|
758
|
+
});
|
|
759
|
+
const upgradeHash = await walletClient.sendTransaction({
|
|
760
|
+
to: proxyAdminAddress,
|
|
761
|
+
data: encodeFunctionData({
|
|
762
|
+
abi: proxyAdminArtifact.abi,
|
|
763
|
+
functionName: "upgradeAndCall",
|
|
764
|
+
args: [gatewayAddress, finalImplementationAddress, "0x"]
|
|
765
|
+
})
|
|
766
|
+
});
|
|
767
|
+
const upgradeReceipt = await waitForExecutionReceipt(publicClient, upgradeHash);
|
|
768
|
+
if (upgradeReceipt.status !== "success") {
|
|
769
|
+
throw new Error("MintingGateway proxy upgrade failed");
|
|
770
|
+
}
|
|
771
|
+
if (options.seedArgonRecipient) {
|
|
772
|
+
const mintHash = await walletClient.sendTransaction({
|
|
773
|
+
to: gatewayAddress,
|
|
774
|
+
data: encodeFunctionData({
|
|
775
|
+
abi: mintingGatewayArtifact.abi,
|
|
776
|
+
functionName: "adminMintBatch",
|
|
777
|
+
args: [
|
|
778
|
+
argonTokenAddress,
|
|
779
|
+
[options.seedArgonRecipient],
|
|
780
|
+
[options.seedArgonAmountBaseUnits ?? DEFAULT_SEED_ARGON_AMOUNT_BASE_UNITS]
|
|
781
|
+
]
|
|
782
|
+
})
|
|
783
|
+
});
|
|
784
|
+
const mintReceipt = await waitForExecutionReceipt(publicClient, mintHash);
|
|
785
|
+
if (mintReceipt.status !== "success") {
|
|
786
|
+
throw new Error("MintingGateway admin mint failed");
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return {
|
|
790
|
+
argonTokenAddress,
|
|
791
|
+
argonotTokenAddress,
|
|
792
|
+
gatewayAddress
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
async teardown() {
|
|
796
|
+
if (this.#argsDir) {
|
|
797
|
+
await fs4.rm(this.#argsDir, { recursive: true, force: true });
|
|
798
|
+
this.#argsDir = void 0;
|
|
799
|
+
}
|
|
800
|
+
await runCommand(this.kurtosisBin, ["enclave", "rm", "-f", this.enclaveName], 6e4, true);
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
async function deployContract(walletClient, publicClient, request) {
|
|
804
|
+
const hash = await walletClient.deployContract({
|
|
805
|
+
...request,
|
|
806
|
+
account: walletClient.account,
|
|
807
|
+
chain: walletClient.chain
|
|
808
|
+
});
|
|
809
|
+
const receipt = await waitForExecutionReceipt(publicClient, hash);
|
|
810
|
+
if (receipt.status !== "success" || !receipt.contractAddress) {
|
|
811
|
+
throw new Error(`Contract deployment failed for ${request.bytecode.slice(0, 10)}`);
|
|
812
|
+
}
|
|
813
|
+
return receipt.contractAddress;
|
|
814
|
+
}
|
|
815
|
+
function getAddressFromStorage(value) {
|
|
816
|
+
if (!value || value === "0x") {
|
|
817
|
+
throw new Error("Missing proxy admin address in ERC1967 admin slot");
|
|
818
|
+
}
|
|
819
|
+
return getAddress(`0x${value.slice(-40)}`);
|
|
820
|
+
}
|
|
821
|
+
function renderEthereumArgs(elPublicPortStart, clPublicPortStart, consensusClient, preset, secondsPerSlot, waitForFinalization, prefundedAccounts) {
|
|
822
|
+
const lines = [
|
|
823
|
+
"participants:",
|
|
824
|
+
" - el_type: geth",
|
|
825
|
+
` cl_type: ${consensusClient}`,
|
|
826
|
+
"network_params:",
|
|
827
|
+
" network: kurtosis",
|
|
828
|
+
` preset: ${preset}`,
|
|
829
|
+
...secondsPerSlot ? [` seconds_per_slot: ${secondsPerSlot}`] : [],
|
|
830
|
+
...prefundedAccounts && Object.keys(prefundedAccounts).length > 0 ? [` prefunded_accounts: '${JSON.stringify(prefundedAccounts)}'`] : [],
|
|
831
|
+
"additional_services: []",
|
|
832
|
+
`wait_for_finalization: ${waitForFinalization ? "true" : "false"}`,
|
|
833
|
+
"global_log_level: warn",
|
|
834
|
+
"port_publisher:",
|
|
835
|
+
" el:",
|
|
836
|
+
" enabled: true",
|
|
837
|
+
` public_port_start: ${elPublicPortStart}`,
|
|
838
|
+
" cl:",
|
|
839
|
+
" enabled: true",
|
|
840
|
+
` public_port_start: ${clPublicPortStart}`
|
|
841
|
+
];
|
|
842
|
+
lines.push("");
|
|
843
|
+
return lines.join("\n");
|
|
844
|
+
}
|
|
845
|
+
async function findExecutionRpcUrl(portStart, rangeSize) {
|
|
846
|
+
for (let port2 = portStart; port2 < portStart + rangeSize; port2 += 1) {
|
|
847
|
+
const url2 = `http://127.0.0.1:${port2}`;
|
|
848
|
+
const response = await fetchJsonRpc(url2, "eth_chainId");
|
|
849
|
+
if (typeof response === "string") {
|
|
850
|
+
return { url: url2, chainId: response };
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
throw new Error(
|
|
854
|
+
`Unable to find an execution RPC endpoint in ${portStart}-${portStart + rangeSize - 1}`
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
async function findBeaconApiUrl(portStart, rangeSize) {
|
|
858
|
+
for (let port2 = portStart; port2 < portStart + rangeSize; port2 += 1) {
|
|
859
|
+
const url2 = `http://127.0.0.1:${port2}`;
|
|
860
|
+
try {
|
|
861
|
+
const response = await fetch(new URL("/eth/v1/node/version", `${url2}/`), {
|
|
862
|
+
signal: AbortSignal.timeout(2e3)
|
|
863
|
+
});
|
|
864
|
+
if (!response.ok) {
|
|
865
|
+
continue;
|
|
866
|
+
}
|
|
867
|
+
const body = await response.json();
|
|
868
|
+
if (body.data?.version) {
|
|
869
|
+
return { url: url2 };
|
|
870
|
+
}
|
|
871
|
+
} catch {
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
throw new Error(
|
|
875
|
+
`Unable to find a Beacon API endpoint in ${portStart}-${portStart + rangeSize - 1}`
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
async function fetchJsonRpc(url2, method) {
|
|
879
|
+
try {
|
|
880
|
+
const response = await fetch(url2, {
|
|
881
|
+
method: "POST",
|
|
882
|
+
headers: { "content-type": "application/json" },
|
|
883
|
+
body: JSON.stringify({
|
|
884
|
+
id: 1,
|
|
885
|
+
jsonrpc: "2.0",
|
|
886
|
+
method,
|
|
887
|
+
params: []
|
|
888
|
+
}),
|
|
889
|
+
signal: AbortSignal.timeout(2e3)
|
|
890
|
+
});
|
|
891
|
+
if (!response.ok) {
|
|
892
|
+
return null;
|
|
893
|
+
}
|
|
894
|
+
const body = await response.json();
|
|
895
|
+
return body.result ?? null;
|
|
896
|
+
} catch {
|
|
897
|
+
return null;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
function createExecutionChain(chainId, executionRpcUrl) {
|
|
901
|
+
return defineChain({
|
|
902
|
+
id: Number.parseInt(chainId, 16),
|
|
903
|
+
name: "argon-test-ethereum",
|
|
904
|
+
nativeCurrency: {
|
|
905
|
+
name: "Ether",
|
|
906
|
+
symbol: "ETH",
|
|
907
|
+
decimals: 18
|
|
908
|
+
},
|
|
909
|
+
rpcUrls: {
|
|
910
|
+
default: {
|
|
911
|
+
http: [executionRpcUrl]
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
async function findFreePortRange(start, size) {
|
|
917
|
+
for (let candidate = start; candidate < start + 1e3; candidate += size) {
|
|
918
|
+
const ports = Array.from({ length: size }, (_, index) => candidate + index);
|
|
919
|
+
const results = await Promise.all(ports.map((port2) => detectPort2(port2)));
|
|
920
|
+
if (results.every((resolvedPort, index) => resolvedPort === ports[index])) {
|
|
921
|
+
return candidate;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
throw new Error(`Unable to find a free port range starting near ${start}`);
|
|
925
|
+
}
|
|
926
|
+
async function waitForProbe(probe, timeoutMs) {
|
|
927
|
+
const start = Date.now();
|
|
928
|
+
let lastError;
|
|
929
|
+
while (Date.now() - start < timeoutMs) {
|
|
930
|
+
try {
|
|
931
|
+
return await probe();
|
|
932
|
+
} catch (error) {
|
|
933
|
+
lastError = error;
|
|
934
|
+
await delay(PROBE_INTERVAL_MS);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
throw lastError instanceof Error ? lastError : new Error("Timed out waiting for probe");
|
|
938
|
+
}
|
|
939
|
+
async function waitForExecutionReceipt(publicClient, hash) {
|
|
940
|
+
const start = Date.now();
|
|
941
|
+
let lastError;
|
|
942
|
+
while (Date.now() - start < 12e4) {
|
|
943
|
+
try {
|
|
944
|
+
const receipt = await publicClient.getTransactionReceipt({ hash });
|
|
945
|
+
if (receipt) {
|
|
946
|
+
return receipt;
|
|
947
|
+
}
|
|
948
|
+
} catch (error) {
|
|
949
|
+
const errorText = error instanceof Error ? [
|
|
950
|
+
error.message,
|
|
951
|
+
"details" in error && typeof error.details === "string" ? error.details : void 0
|
|
952
|
+
].filter(Boolean).join(" ") : String(error);
|
|
953
|
+
if (!errorText.includes("indexing is in progress") && !errorText.includes("Transaction receipt with hash") && !errorText.includes("could not be found")) {
|
|
954
|
+
throw error;
|
|
955
|
+
}
|
|
956
|
+
lastError = error instanceof Error ? error : new Error(errorText);
|
|
957
|
+
}
|
|
958
|
+
await delay(500);
|
|
959
|
+
}
|
|
960
|
+
throw lastError ?? new Error(`Timed out waiting for execution receipt ${hash}`);
|
|
961
|
+
}
|
|
962
|
+
async function runCommand(command, args, timeoutMs, allowFailure = false) {
|
|
963
|
+
await new Promise((resolve3, reject) => {
|
|
964
|
+
const child = spawn4(command, args, {
|
|
965
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
966
|
+
});
|
|
967
|
+
let stdout = "";
|
|
968
|
+
let stderr = "";
|
|
969
|
+
const timeout = setTimeout(() => {
|
|
970
|
+
child.kill("SIGTERM");
|
|
971
|
+
reject(new Error(`Command timed out: ${command} ${args.join(" ")}`));
|
|
972
|
+
}, timeoutMs);
|
|
973
|
+
child.stdout?.setEncoding("utf8");
|
|
974
|
+
child.stderr?.setEncoding("utf8");
|
|
975
|
+
child.stdout?.on("data", (chunk) => {
|
|
976
|
+
stdout += chunk;
|
|
977
|
+
});
|
|
978
|
+
child.stderr?.on("data", (chunk) => {
|
|
979
|
+
stderr += chunk;
|
|
980
|
+
});
|
|
981
|
+
child.on("error", (error) => {
|
|
982
|
+
clearTimeout(timeout);
|
|
983
|
+
reject(error);
|
|
984
|
+
});
|
|
985
|
+
child.on("exit", (code) => {
|
|
986
|
+
clearTimeout(timeout);
|
|
987
|
+
if (code === 0 || allowFailure) {
|
|
988
|
+
resolve3();
|
|
989
|
+
return;
|
|
990
|
+
}
|
|
991
|
+
reject(
|
|
992
|
+
new Error(
|
|
993
|
+
[`Command failed: ${command} ${args.join(" ")}`, stdout.trim(), stderr.trim()].filter(Boolean).join("\n")
|
|
994
|
+
)
|
|
995
|
+
);
|
|
996
|
+
});
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
async function delay(ms) {
|
|
1000
|
+
await new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
1001
|
+
}
|
|
1002
|
+
|
|
504
1003
|
// src/TestNetwork.ts
|
|
505
1004
|
import * as docker from "docker-compose";
|
|
506
|
-
import * as
|
|
1005
|
+
import * as Path6 from "path";
|
|
507
1006
|
async function startNetwork(testName, options) {
|
|
508
|
-
const config =
|
|
1007
|
+
const config = Path6.join(__dirname, `dev.docker-compose.yml`);
|
|
509
1008
|
const env4 = {
|
|
510
1009
|
VERSION: "dev",
|
|
511
1010
|
ARGON_CHAIN: "dev-docker",
|
|
@@ -550,7 +1049,7 @@ async function getProxy() {
|
|
|
550
1049
|
autoRewrite: true
|
|
551
1050
|
});
|
|
552
1051
|
proxy.on("error", () => null);
|
|
553
|
-
proxyServer =
|
|
1052
|
+
proxyServer = http2.createServer(function(req, res) {
|
|
554
1053
|
const queryData = url.parse(req.url, true).query;
|
|
555
1054
|
if (!queryData.target) {
|
|
556
1055
|
res.writeHead(500, { "Content-Type": "text/plain" });
|
|
@@ -600,12 +1099,12 @@ function stringifyExt(obj) {
|
|
|
600
1099
|
}
|
|
601
1100
|
function projectRoot() {
|
|
602
1101
|
if (process4.env.ARGON_PROJECT_ROOT) {
|
|
603
|
-
return
|
|
1102
|
+
return Path7.join(process4.env.ARGON_PROJECT_ROOT);
|
|
604
1103
|
}
|
|
605
|
-
return
|
|
1104
|
+
return Path7.join(__dirname, `../../..`);
|
|
606
1105
|
}
|
|
607
1106
|
async function runTestScript(relativePath) {
|
|
608
|
-
const scriptPath =
|
|
1107
|
+
const scriptPath = Path7.resolve(projectRoot(), relativePath);
|
|
609
1108
|
return child_process4.execSync(scriptPath, { encoding: "utf8" }).trim();
|
|
610
1109
|
}
|
|
611
1110
|
async function getDockerPortMapping(containerName, port2) {
|
|
@@ -655,16 +1154,19 @@ async function activateNotary(sudo2, client, notary) {
|
|
|
655
1154
|
export {
|
|
656
1155
|
SKIP_E2E,
|
|
657
1156
|
TestBitcoinCli,
|
|
1157
|
+
TestEthereum,
|
|
658
1158
|
TestMainchain,
|
|
659
1159
|
TestNotary,
|
|
660
1160
|
TestOracle,
|
|
661
1161
|
activateNotary,
|
|
662
1162
|
addTeardown,
|
|
1163
|
+
argonTokenArtifact,
|
|
663
1164
|
cleanHostForDocker,
|
|
664
1165
|
closeOnTeardown,
|
|
665
1166
|
disconnectOnTeardown,
|
|
666
1167
|
getDockerPortMapping,
|
|
667
1168
|
getProxy,
|
|
1169
|
+
mintingGatewayArtifact,
|
|
668
1170
|
projectRoot,
|
|
669
1171
|
runOnTeardown,
|
|
670
1172
|
runTestScript,
|