@argonprotocol/testing 1.4.3-dev.1f0d7a33 → 1.4.3-dev.25eec055

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/index.cjs CHANGED
@@ -32,16 +32,19 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  SKIP_E2E: () => SKIP_E2E,
34
34
  TestBitcoinCli: () => TestBitcoinCli,
35
+ TestEthereum: () => TestEthereum,
35
36
  TestMainchain: () => TestMainchain,
36
37
  TestNotary: () => TestNotary,
37
38
  TestOracle: () => TestOracle,
38
39
  activateNotary: () => activateNotary,
39
40
  addTeardown: () => addTeardown,
41
+ argonTokenArtifact: () => argonTokenArtifact,
40
42
  cleanHostForDocker: () => cleanHostForDocker,
41
43
  closeOnTeardown: () => closeOnTeardown,
42
44
  disconnectOnTeardown: () => disconnectOnTeardown,
43
45
  getDockerPortMapping: () => getDockerPortMapping,
44
46
  getProxy: () => getProxy,
47
+ mintingGatewayArtifact: () => mintingGatewayArtifact,
45
48
  projectRoot: () => projectRoot,
46
49
  runOnTeardown: () => runOnTeardown,
47
50
  runTestScript: () => runTestScript,
@@ -51,13 +54,19 @@ __export(index_exports, {
51
54
  teardown: () => teardown
52
55
  });
53
56
  module.exports = __toCommonJS(index_exports);
57
+
58
+ // node_modules/tsup/assets/cjs_shims.js
59
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
60
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
61
+
62
+ // src/index.ts
54
63
  var import_mainchain4 = require("@argonprotocol/mainchain");
55
64
  var process4 = __toESM(require("process"), 1);
56
65
  var import_http_proxy = __toESM(require("http-proxy"), 1);
57
66
  var child_process4 = __toESM(require("child_process"), 1);
58
- var http = __toESM(require("http"), 1);
67
+ var http2 = __toESM(require("http"), 1);
59
68
  var url = __toESM(require("url"), 1);
60
- var Path6 = __toESM(require("path"), 1);
69
+ var Path7 = __toESM(require("path"), 1);
61
70
 
62
71
  // src/TestNotary.ts
63
72
  var import_nanoid = require("nanoid");
@@ -246,7 +255,6 @@ var Path2 = __toESM(require("path"), 1);
246
255
  var readline2 = __toESM(require("readline"), 1);
247
256
  var import_detect_port = require("detect-port");
248
257
  var import_nanoid2 = require("nanoid");
249
- var import_bitcoin_core = __toESM(require("bitcoin-core"), 1);
250
258
  var lockfile = __toESM(require("proper-lockfile"), 1);
251
259
  var import_mainchain2 = require("@argonprotocol/mainchain");
252
260
  var nanoid2 = (0, import_nanoid2.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 4);
@@ -282,11 +290,7 @@ var TestMainchain = class {
282
290
  addTeardown(this);
283
291
  }
284
292
  getBitcoinClient() {
285
- return new import_bitcoin_core.default({
286
- username: "bitcoin",
287
- password: "bitcoin",
288
- host: `http://localhost:${this.bitcoinPort}`
289
- });
293
+ return new BitcoinRpcClient(`http://localhost:${this.bitcoinPort}`, "bitcoin", "bitcoin");
290
294
  }
291
295
  /**
292
296
  * Launch and return the localhost url. NOTE: this url will not work cross-docker. You need to use the containerAddress property
@@ -376,9 +380,20 @@ var TestMainchain = class {
376
380
  return this.address;
377
381
  }
378
382
  async client() {
379
- const client = await (0, import_mainchain2.getClient)(this.address);
380
- disconnectOnTeardown(client);
381
- return client;
383
+ let lastError;
384
+ for (let attempt = 0; attempt < 20; attempt += 1) {
385
+ try {
386
+ const client = await (0, import_mainchain2.getClient)(this.address);
387
+ disconnectOnTeardown(client);
388
+ return client;
389
+ } catch (error) {
390
+ lastError = error;
391
+ await new Promise((resolve3) => setTimeout(resolve3, 250));
392
+ }
393
+ }
394
+ throw new Error(`Unable to connect to mainchain client at ${this.address}`, {
395
+ cause: lastError instanceof Error ? lastError : void 0
396
+ });
382
397
  }
383
398
  async bootAddress() {
384
399
  const client = await this.client();
@@ -469,6 +484,51 @@ var TestMainchain = class {
469
484
  return cleanHostForDocker(`http://bitcoin:bitcoin@localhost:${rpcPort}`);
470
485
  }
471
486
  };
487
+ var BitcoinRpcClient = class {
488
+ #rpcUrl;
489
+ #authorization;
490
+ constructor(rpcUrl, username, password) {
491
+ this.#rpcUrl = rpcUrl;
492
+ this.#authorization = `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
493
+ }
494
+ async command(method, ...params) {
495
+ const response = await fetch(this.#rpcUrl, {
496
+ method: "POST",
497
+ headers: {
498
+ authorization: this.#authorization,
499
+ "content-type": "application/json"
500
+ },
501
+ body: JSON.stringify({
502
+ jsonrpc: "1.0",
503
+ id: `${method}-${Date.now()}`,
504
+ method,
505
+ params
506
+ })
507
+ });
508
+ const body = await response.text();
509
+ let payload;
510
+ if (body) {
511
+ try {
512
+ payload = JSON.parse(body);
513
+ } catch {
514
+ payload = void 0;
515
+ }
516
+ }
517
+ if (payload?.error) {
518
+ const httpStatus = response.ok ? "" : ` with HTTP ${response.status}`;
519
+ throw new Error(
520
+ `Bitcoin RPC ${method} failed${httpStatus} (${payload.error.code}): ${payload.error.message}`
521
+ );
522
+ }
523
+ if (!response.ok) {
524
+ throw new Error(`Bitcoin RPC ${method} failed with HTTP ${response.status}`);
525
+ }
526
+ if (!payload) {
527
+ throw new Error(`Bitcoin RPC ${method} returned an invalid JSON response`);
528
+ }
529
+ return payload.result;
530
+ }
531
+ };
472
532
 
473
533
  // src/TestBitcoinCli.ts
474
534
  var child_process2 = __toESM(require("child_process"), 1);
@@ -546,11 +606,474 @@ var TestOracle = class _TestOracle {
546
606
  }
547
607
  };
548
608
 
609
+ // src/TestEthereum.ts
610
+ var fs4 = __toESM(require("fs/promises"), 1);
611
+ var os = __toESM(require("os"), 1);
612
+ var Path5 = __toESM(require("path"), 1);
613
+ var import_node_child_process2 = require("child_process");
614
+ var import_detect_port2 = require("detect-port");
615
+
616
+ // src/ethereumContracts.ts
617
+ var import_node_fs = require("fs");
618
+ function loadArtifact(fileName) {
619
+ return JSON.parse(
620
+ (0, import_node_fs.readFileSync)(new URL(`./ethereum-contracts/${fileName}`, importMetaUrl), "utf8")
621
+ );
622
+ }
623
+ var argonTokenArtifact = loadArtifact("ArgonToken.json");
624
+ var argonotTokenArtifact = loadArtifact("ArgonotToken.json");
625
+ var mintingGatewayArtifact = loadArtifact("MintingGateway.json");
626
+ var proxyAdminArtifact = loadArtifact("ProxyAdmin.json");
627
+ var transparentUpgradeableProxyArtifact = loadArtifact("TransparentUpgradeableProxy.json");
628
+
629
+ // src/TestEthereum.ts
630
+ var import_accounts = require("viem/accounts");
631
+ var import_viem = require("viem");
632
+ var DEFAULT_KURTOSIS_BIN = "kurtosis";
633
+ var DEFAULT_ETHEREUM_PACKAGE = "github.com/ethpandaops/ethereum-package";
634
+ var DEFAULT_EL_PORT_START = 32e3;
635
+ var DEFAULT_CL_PORT_START = 33e3;
636
+ var PORT_RANGE_SIZE = 32;
637
+ var ENCLAVE_NAME_PREFIX = "argon-eth-";
638
+ var PROBE_INTERVAL_MS = 1e3;
639
+ var PROBE_TIMEOUT_MS = 6e4;
640
+ var LIGHT_CLIENT_READY_TIMEOUT_MS = 5 * 6e4;
641
+ var KURTOSIS_RUN_TIMEOUT_MS = 20 * 6e4;
642
+ var DEFAULT_SEED_ARGON_AMOUNT_BASE_UNITS = 1000000000n;
643
+ var DEFAULT_INITIAL_MICROGONS_PER_ARGONOT = 1000000n;
644
+ var ERC1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
645
+ var TestEthereum = class {
646
+ enclaveName;
647
+ kurtosisBin;
648
+ packageRef;
649
+ executionRpcUrl;
650
+ beaconApiUrl;
651
+ chainId;
652
+ #argsDir;
653
+ constructor(enclaveName = `${ENCLAVE_NAME_PREFIX}${Math.random().toString(36).slice(2, 8)}`, kurtosisBin = DEFAULT_KURTOSIS_BIN, packageRef = DEFAULT_ETHEREUM_PACKAGE) {
654
+ this.enclaveName = enclaveName;
655
+ this.kurtosisBin = kurtosisBin;
656
+ this.packageRef = packageRef;
657
+ addTeardown(this);
658
+ }
659
+ static isInstalled(kurtosisBin = DEFAULT_KURTOSIS_BIN) {
660
+ return (0, import_node_child_process2.spawnSync)(kurtosisBin, ["version"], { stdio: "ignore" }).status === 0;
661
+ }
662
+ async launch(options) {
663
+ const {
664
+ consensusClient = "lighthouse",
665
+ preset = "mainnet",
666
+ secondsPerSlot,
667
+ waitForFinalization = true,
668
+ prefundedAccounts
669
+ } = options ?? {};
670
+ const elPublicPortStart = await findFreePortRange(DEFAULT_EL_PORT_START, PORT_RANGE_SIZE);
671
+ const clPublicPortStart = await findFreePortRange(DEFAULT_CL_PORT_START, PORT_RANGE_SIZE);
672
+ this.#argsDir = await fs4.mkdtemp(Path5.join(os.tmpdir(), "argon-ethereum-devnet-"));
673
+ const argsFile = Path5.join(this.#argsDir, "network-params.yaml");
674
+ await fs4.writeFile(
675
+ argsFile,
676
+ renderEthereumArgs(
677
+ elPublicPortStart,
678
+ clPublicPortStart,
679
+ consensusClient,
680
+ preset,
681
+ secondsPerSlot,
682
+ waitForFinalization,
683
+ prefundedAccounts
684
+ )
685
+ );
686
+ await runCommand(
687
+ this.kurtosisBin,
688
+ ["run", "--enclave", this.enclaveName, this.packageRef, "--args-file", argsFile],
689
+ KURTOSIS_RUN_TIMEOUT_MS
690
+ );
691
+ const executionRpc = await waitForProbe(
692
+ () => findExecutionRpcUrl(elPublicPortStart, PORT_RANGE_SIZE),
693
+ PROBE_TIMEOUT_MS
694
+ );
695
+ const beaconApi = await waitForProbe(
696
+ () => findBeaconApiUrl(clPublicPortStart, PORT_RANGE_SIZE),
697
+ PROBE_TIMEOUT_MS
698
+ );
699
+ this.executionRpcUrl = executionRpc.url;
700
+ this.beaconApiUrl = beaconApi.url;
701
+ this.chainId = executionRpc.chainId;
702
+ await waitForProbe(
703
+ () => this.getBeacon("/eth/v1/beacon/genesis"),
704
+ LIGHT_CLIENT_READY_TIMEOUT_MS
705
+ );
706
+ return {
707
+ executionRpcUrl: this.executionRpcUrl,
708
+ beaconApiUrl: this.beaconApiUrl,
709
+ chainId: this.chainId
710
+ };
711
+ }
712
+ async callExecution(method, params = []) {
713
+ const executionRpcUrl = this.executionRpcUrl;
714
+ if (!executionRpcUrl) {
715
+ throw new Error("Execution RPC URL is not available before launch");
716
+ }
717
+ const response = await fetch(executionRpcUrl, {
718
+ method: "POST",
719
+ headers: { "content-type": "application/json" },
720
+ body: JSON.stringify({
721
+ id: 1,
722
+ jsonrpc: "2.0",
723
+ method,
724
+ params
725
+ }),
726
+ signal: AbortSignal.timeout(1e4)
727
+ });
728
+ if (!response.ok) {
729
+ throw new Error(`Execution RPC request failed for ${method}: ${response.status}`);
730
+ }
731
+ const body = await response.json();
732
+ if (body.error) {
733
+ throw new Error(
734
+ `Execution RPC ${method} failed (${body.error.code ?? "unknown"}): ${body.error.message ?? "unknown error"}`
735
+ );
736
+ }
737
+ return body.result;
738
+ }
739
+ async getBeacon(path) {
740
+ const beaconApiUrl = this.beaconApiUrl;
741
+ if (!beaconApiUrl) {
742
+ throw new Error("Beacon API URL is not available before launch");
743
+ }
744
+ const response = await fetch(new URL(path, `${beaconApiUrl}/`), {
745
+ signal: AbortSignal.timeout(1e4)
746
+ });
747
+ if (!response.ok) {
748
+ throw new Error(`Beacon API request failed for ${path}: ${response.status}`);
749
+ }
750
+ return await response.json();
751
+ }
752
+ async deployMintingGatewayFixture(options) {
753
+ const { executionRpcUrl, chainId } = this;
754
+ if (!executionRpcUrl || !chainId) {
755
+ throw new Error("Ethereum devnet must be launched before deploying MintingGateway fixtures");
756
+ }
757
+ const account = (0, import_accounts.privateKeyToAccount)(options.deployerPrivateKey);
758
+ const adminSafe = options.adminSafe ?? account.address;
759
+ const guardianSafe = options.guardianSafe ?? adminSafe;
760
+ const chain = createExecutionChain(chainId, executionRpcUrl);
761
+ const publicClient = (0, import_viem.createPublicClient)({
762
+ chain,
763
+ transport: (0, import_viem.http)(executionRpcUrl)
764
+ });
765
+ const walletClient = (0, import_viem.createWalletClient)({
766
+ account,
767
+ chain,
768
+ transport: (0, import_viem.http)(executionRpcUrl)
769
+ });
770
+ const bootstrapCouncil = {
771
+ signers: [adminSafe],
772
+ weights: [1n]
773
+ };
774
+ const bootstrapCouncilHash = (0, import_viem.keccak256)(
775
+ (0, import_viem.encodeAbiParameters)(
776
+ [{ type: "address[]" }, { type: "uint256[]" }],
777
+ [bootstrapCouncil.signers, bootstrapCouncil.weights]
778
+ )
779
+ );
780
+ const bootstrapImplementationAddress = await deployContract(walletClient, publicClient, {
781
+ abi: mintingGatewayArtifact.abi,
782
+ bytecode: mintingGatewayArtifact.bytecode,
783
+ args: [import_viem.zeroAddress, import_viem.zeroAddress]
784
+ });
785
+ const initializeData = (0, import_viem.encodeFunctionData)({
786
+ abi: mintingGatewayArtifact.abi,
787
+ functionName: "initialize",
788
+ args: [
789
+ adminSafe,
790
+ guardianSafe,
791
+ bootstrapCouncilHash,
792
+ BigInt(bootstrapCouncil.signers.length),
793
+ 1n,
794
+ DEFAULT_INITIAL_MICROGONS_PER_ARGONOT
795
+ ]
796
+ });
797
+ const gatewayAddress = await deployContract(walletClient, publicClient, {
798
+ abi: transparentUpgradeableProxyArtifact.abi,
799
+ bytecode: transparentUpgradeableProxyArtifact.bytecode,
800
+ args: [bootstrapImplementationAddress, adminSafe, initializeData]
801
+ });
802
+ const proxyAdminAddress = getAddressFromStorage(
803
+ await publicClient.getStorageAt({
804
+ address: gatewayAddress,
805
+ slot: ERC1967_ADMIN_SLOT
806
+ })
807
+ );
808
+ const argonTokenAddress = await deployContract(walletClient, publicClient, {
809
+ abi: argonTokenArtifact.abi,
810
+ bytecode: argonTokenArtifact.bytecode,
811
+ args: [gatewayAddress]
812
+ });
813
+ const argonotTokenAddress = await deployContract(walletClient, publicClient, {
814
+ abi: argonotTokenArtifact.abi,
815
+ bytecode: argonotTokenArtifact.bytecode,
816
+ args: [gatewayAddress]
817
+ });
818
+ const finalImplementationAddress = await deployContract(walletClient, publicClient, {
819
+ abi: mintingGatewayArtifact.abi,
820
+ bytecode: mintingGatewayArtifact.bytecode,
821
+ args: [argonTokenAddress, argonotTokenAddress]
822
+ });
823
+ const upgradeHash = await walletClient.sendTransaction({
824
+ to: proxyAdminAddress,
825
+ data: (0, import_viem.encodeFunctionData)({
826
+ abi: proxyAdminArtifact.abi,
827
+ functionName: "upgradeAndCall",
828
+ args: [gatewayAddress, finalImplementationAddress, "0x"]
829
+ })
830
+ });
831
+ const upgradeReceipt = await waitForExecutionReceipt(publicClient, upgradeHash);
832
+ if (upgradeReceipt.status !== "success") {
833
+ throw new Error("MintingGateway proxy upgrade failed");
834
+ }
835
+ if (options.seedArgonRecipient) {
836
+ const mintHash = await walletClient.sendTransaction({
837
+ to: gatewayAddress,
838
+ data: (0, import_viem.encodeFunctionData)({
839
+ abi: mintingGatewayArtifact.abi,
840
+ functionName: "migrate",
841
+ args: [
842
+ {
843
+ recipients: [options.seedArgonRecipient],
844
+ amounts: [options.seedArgonAmountBaseUnits ?? DEFAULT_SEED_ARGON_AMOUNT_BASE_UNITS]
845
+ },
846
+ {
847
+ recipients: [],
848
+ amounts: []
849
+ }
850
+ ]
851
+ })
852
+ });
853
+ const mintReceipt = await waitForExecutionReceipt(publicClient, mintHash);
854
+ if (mintReceipt.status !== "success") {
855
+ throw new Error("MintingGateway migrate failed");
856
+ }
857
+ }
858
+ return {
859
+ argonTokenAddress,
860
+ argonotTokenAddress,
861
+ gatewayAddress
862
+ };
863
+ }
864
+ async teardown() {
865
+ if (this.#argsDir) {
866
+ await fs4.rm(this.#argsDir, { recursive: true, force: true });
867
+ this.#argsDir = void 0;
868
+ }
869
+ await runCommand(this.kurtosisBin, ["enclave", "rm", "-f", this.enclaveName], 6e4, true);
870
+ }
871
+ };
872
+ async function deployContract(walletClient, publicClient, request) {
873
+ const hash = await walletClient.deployContract({
874
+ ...request,
875
+ account: walletClient.account,
876
+ chain: walletClient.chain
877
+ });
878
+ const receipt = await waitForExecutionReceipt(publicClient, hash);
879
+ if (receipt.status !== "success" || !receipt.contractAddress) {
880
+ throw new Error(`Contract deployment failed for ${request.bytecode.slice(0, 10)}`);
881
+ }
882
+ return receipt.contractAddress;
883
+ }
884
+ function getAddressFromStorage(value) {
885
+ if (!value || value === "0x") {
886
+ throw new Error("Missing proxy admin address in ERC1967 admin slot");
887
+ }
888
+ return (0, import_viem.getAddress)(`0x${value.slice(-40)}`);
889
+ }
890
+ function renderEthereumArgs(elPublicPortStart, clPublicPortStart, consensusClient, preset, secondsPerSlot, waitForFinalization, prefundedAccounts) {
891
+ const lines = [
892
+ "participants:",
893
+ " - el_type: geth",
894
+ ` cl_type: ${consensusClient}`,
895
+ "network_params:",
896
+ " network: kurtosis",
897
+ ` preset: ${preset}`,
898
+ ...secondsPerSlot ? [` seconds_per_slot: ${secondsPerSlot}`] : [],
899
+ ...prefundedAccounts && Object.keys(prefundedAccounts).length > 0 ? [` prefunded_accounts: '${JSON.stringify(prefundedAccounts)}'`] : [],
900
+ "additional_services: []",
901
+ `wait_for_finalization: ${waitForFinalization ? "true" : "false"}`,
902
+ "global_log_level: warn",
903
+ "port_publisher:",
904
+ " el:",
905
+ " enabled: true",
906
+ ` public_port_start: ${elPublicPortStart}`,
907
+ " cl:",
908
+ " enabled: true",
909
+ ` public_port_start: ${clPublicPortStart}`
910
+ ];
911
+ lines.push("");
912
+ return lines.join("\n");
913
+ }
914
+ async function findExecutionRpcUrl(portStart, rangeSize) {
915
+ for (let port2 = portStart; port2 < portStart + rangeSize; port2 += 1) {
916
+ const url2 = `http://127.0.0.1:${port2}`;
917
+ const response = await fetchJsonRpc(url2, "eth_chainId");
918
+ if (typeof response === "string") {
919
+ return { url: url2, chainId: response };
920
+ }
921
+ }
922
+ throw new Error(
923
+ `Unable to find an execution RPC endpoint in ${portStart}-${portStart + rangeSize - 1}`
924
+ );
925
+ }
926
+ async function findBeaconApiUrl(portStart, rangeSize) {
927
+ for (let port2 = portStart; port2 < portStart + rangeSize; port2 += 1) {
928
+ const url2 = `http://127.0.0.1:${port2}`;
929
+ try {
930
+ const response = await fetch(new URL("/eth/v1/node/version", `${url2}/`), {
931
+ signal: AbortSignal.timeout(2e3)
932
+ });
933
+ if (!response.ok) {
934
+ continue;
935
+ }
936
+ const body = await response.json();
937
+ if (body.data?.version) {
938
+ return { url: url2 };
939
+ }
940
+ } catch {
941
+ }
942
+ }
943
+ throw new Error(
944
+ `Unable to find a Beacon API endpoint in ${portStart}-${portStart + rangeSize - 1}`
945
+ );
946
+ }
947
+ async function fetchJsonRpc(url2, method) {
948
+ try {
949
+ const response = await fetch(url2, {
950
+ method: "POST",
951
+ headers: { "content-type": "application/json" },
952
+ body: JSON.stringify({
953
+ id: 1,
954
+ jsonrpc: "2.0",
955
+ method,
956
+ params: []
957
+ }),
958
+ signal: AbortSignal.timeout(2e3)
959
+ });
960
+ if (!response.ok) {
961
+ return null;
962
+ }
963
+ const body = await response.json();
964
+ return body.result ?? null;
965
+ } catch {
966
+ return null;
967
+ }
968
+ }
969
+ function createExecutionChain(chainId, executionRpcUrl) {
970
+ return (0, import_viem.defineChain)({
971
+ id: Number.parseInt(chainId, 16),
972
+ name: "argon-test-ethereum",
973
+ nativeCurrency: {
974
+ name: "Ether",
975
+ symbol: "ETH",
976
+ decimals: 18
977
+ },
978
+ rpcUrls: {
979
+ default: {
980
+ http: [executionRpcUrl]
981
+ }
982
+ }
983
+ });
984
+ }
985
+ async function findFreePortRange(start, size) {
986
+ for (let candidate = start; candidate < start + 1e3; candidate += size) {
987
+ const ports = Array.from({ length: size }, (_, index) => candidate + index);
988
+ const results = await Promise.all(ports.map((port2) => (0, import_detect_port2.detectPort)(port2)));
989
+ if (results.every((resolvedPort, index) => resolvedPort === ports[index])) {
990
+ return candidate;
991
+ }
992
+ }
993
+ throw new Error(`Unable to find a free port range starting near ${start}`);
994
+ }
995
+ async function waitForProbe(probe, timeoutMs) {
996
+ const start = Date.now();
997
+ let lastError;
998
+ while (Date.now() - start < timeoutMs) {
999
+ try {
1000
+ return await probe();
1001
+ } catch (error) {
1002
+ lastError = error;
1003
+ await delay(PROBE_INTERVAL_MS);
1004
+ }
1005
+ }
1006
+ throw lastError instanceof Error ? lastError : new Error("Timed out waiting for probe");
1007
+ }
1008
+ async function waitForExecutionReceipt(publicClient, hash) {
1009
+ const start = Date.now();
1010
+ let lastError;
1011
+ while (Date.now() - start < 12e4) {
1012
+ try {
1013
+ const receipt = await publicClient.getTransactionReceipt({ hash });
1014
+ if (receipt) {
1015
+ return receipt;
1016
+ }
1017
+ } catch (error) {
1018
+ const errorText = error instanceof Error ? [
1019
+ error.message,
1020
+ "details" in error && typeof error.details === "string" ? error.details : void 0
1021
+ ].filter(Boolean).join(" ") : String(error);
1022
+ if (!errorText.includes("indexing is in progress") && !errorText.includes("Transaction receipt with hash") && !errorText.includes("could not be found")) {
1023
+ throw error;
1024
+ }
1025
+ lastError = error instanceof Error ? error : new Error(errorText);
1026
+ }
1027
+ await delay(500);
1028
+ }
1029
+ throw lastError ?? new Error(`Timed out waiting for execution receipt ${hash}`);
1030
+ }
1031
+ async function runCommand(command, args, timeoutMs, allowFailure = false) {
1032
+ await new Promise((resolve3, reject) => {
1033
+ const child = (0, import_node_child_process2.spawn)(command, args, {
1034
+ stdio: ["ignore", "pipe", "pipe"]
1035
+ });
1036
+ let stdout = "";
1037
+ let stderr = "";
1038
+ const timeout = setTimeout(() => {
1039
+ child.kill("SIGTERM");
1040
+ reject(new Error(`Command timed out: ${command} ${args.join(" ")}`));
1041
+ }, timeoutMs);
1042
+ child.stdout?.setEncoding("utf8");
1043
+ child.stderr?.setEncoding("utf8");
1044
+ child.stdout?.on("data", (chunk) => {
1045
+ stdout += chunk;
1046
+ });
1047
+ child.stderr?.on("data", (chunk) => {
1048
+ stderr += chunk;
1049
+ });
1050
+ child.on("error", (error) => {
1051
+ clearTimeout(timeout);
1052
+ reject(error);
1053
+ });
1054
+ child.on("exit", (code) => {
1055
+ clearTimeout(timeout);
1056
+ if (code === 0 || allowFailure) {
1057
+ resolve3();
1058
+ return;
1059
+ }
1060
+ reject(
1061
+ new Error(
1062
+ [`Command failed: ${command} ${args.join(" ")}`, stdout.trim(), stderr.trim()].filter(Boolean).join("\n")
1063
+ )
1064
+ );
1065
+ });
1066
+ });
1067
+ }
1068
+ async function delay(ms) {
1069
+ await new Promise((resolve3) => setTimeout(resolve3, ms));
1070
+ }
1071
+
549
1072
  // src/TestNetwork.ts
550
1073
  var docker = __toESM(require("docker-compose"), 1);
551
- var Path5 = __toESM(require("path"), 1);
1074
+ var Path6 = __toESM(require("path"), 1);
552
1075
  async function startNetwork(testName, options) {
553
- const config = Path5.join(__dirname, `dev.docker-compose.yml`);
1076
+ const config = Path6.join(__dirname, `dev.docker-compose.yml`);
554
1077
  const env4 = {
555
1078
  VERSION: "dev",
556
1079
  ARGON_CHAIN: "dev-docker",
@@ -595,7 +1118,7 @@ async function getProxy() {
595
1118
  autoRewrite: true
596
1119
  });
597
1120
  proxy.on("error", () => null);
598
- proxyServer = http.createServer(function(req, res) {
1121
+ proxyServer = http2.createServer(function(req, res) {
599
1122
  const queryData = url.parse(req.url, true).query;
600
1123
  if (!queryData.target) {
601
1124
  res.writeHead(500, { "Content-Type": "text/plain" });
@@ -645,12 +1168,12 @@ function stringifyExt(obj) {
645
1168
  }
646
1169
  function projectRoot() {
647
1170
  if (process4.env.ARGON_PROJECT_ROOT) {
648
- return Path6.join(process4.env.ARGON_PROJECT_ROOT);
1171
+ return Path7.join(process4.env.ARGON_PROJECT_ROOT);
649
1172
  }
650
- return Path6.join(__dirname, `../../..`);
1173
+ return Path7.join(__dirname, `../../..`);
651
1174
  }
652
1175
  async function runTestScript(relativePath) {
653
- const scriptPath = Path6.resolve(projectRoot(), relativePath);
1176
+ const scriptPath = Path7.resolve(projectRoot(), relativePath);
654
1177
  return child_process4.execSync(scriptPath, { encoding: "utf8" }).trim();
655
1178
  }
656
1179
  async function getDockerPortMapping(containerName, port2) {
@@ -701,16 +1224,19 @@ async function activateNotary(sudo2, client, notary) {
701
1224
  0 && (module.exports = {
702
1225
  SKIP_E2E,
703
1226
  TestBitcoinCli,
1227
+ TestEthereum,
704
1228
  TestMainchain,
705
1229
  TestNotary,
706
1230
  TestOracle,
707
1231
  activateNotary,
708
1232
  addTeardown,
1233
+ argonTokenArtifact,
709
1234
  cleanHostForDocker,
710
1235
  closeOnTeardown,
711
1236
  disconnectOnTeardown,
712
1237
  getDockerPortMapping,
713
1238
  getProxy,
1239
+ mintingGatewayArtifact,
714
1240
  projectRoot,
715
1241
  runOnTeardown,
716
1242
  runTestScript,