From 6260a6ba87eb71e4d9563c875bb2418f02e454ba Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:01:41 -0500 Subject: [PATCH 01/15] add get port dev dep --- src/chains/ethereum/ethereum/package.json | 1 + src/packages/core/package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/src/chains/ethereum/ethereum/package.json b/src/chains/ethereum/ethereum/package.json index 0bcae0a502..624fc2a25f 100644 --- a/src/chains/ethereum/ethereum/package.json +++ b/src/chains/ethereum/ethereum/package.json @@ -103,6 +103,7 @@ "cross-env": "7.0.3", "fast-check": "3.0.1", "fs-extra": "9.0.1", + "get-port": "6.1.2", "local-web-server": "4.2.1", "memdown": "6.1.1", "mocha": "9.1.3", diff --git a/src/packages/core/package.json b/src/packages/core/package.json index 95c845f295..883440ff4a 100644 --- a/src/packages/core/package.json +++ b/src/packages/core/package.json @@ -61,6 +61,7 @@ "@types/mocha": "9.0.0", "@types/superagent": "4.1.10", "cross-env": "7.0.3", + "get-port": "6.1.2", "mocha": "9.1.3", "nyc": "15.1.0", "superagent": "6.1.0", From b8280523927732b1bf547f41fa806674e1932a2e Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:02:01 -0500 Subject: [PATCH 02/15] package locks for get-port dev dep --- src/chains/ethereum/ethereum/package-lock.json | 6 ++++++ src/packages/core/package-lock.json | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/chains/ethereum/ethereum/package-lock.json b/src/chains/ethereum/ethereum/package-lock.json index 834f0202dc..eedfd3a387 100644 --- a/src/chains/ethereum/ethereum/package-lock.json +++ b/src/chains/ethereum/ethereum/package-lock.json @@ -5080,6 +5080,12 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-port": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", + "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", + "dev": true + }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", diff --git a/src/packages/core/package-lock.json b/src/packages/core/package-lock.json index 783e051aca..6cc08c92a5 100644 --- a/src/packages/core/package-lock.json +++ b/src/packages/core/package-lock.json @@ -1047,6 +1047,12 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-port": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", + "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", + "dev": true + }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", From 1180f3cf11b66db98e10c6faf2bfc9b1b552eacc Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:02:24 -0500 Subject: [PATCH 03/15] make port param in forking helper optional --- src/chains/ethereum/ethereum/tests/forking/helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chains/ethereum/ethereum/tests/forking/helpers.ts b/src/chains/ethereum/ethereum/tests/forking/helpers.ts index 6be1324cfe..80e133d687 100644 --- a/src/chains/ethereum/ethereum/tests/forking/helpers.ts +++ b/src/chains/ethereum/ethereum/tests/forking/helpers.ts @@ -53,7 +53,7 @@ export const updateRemotesAccountNonces = async ( }; export const startLocalChain = async ( - port: number, + port?: number, options?: EthereumProviderOptions["fork"] ) => { const fork: EthereumProviderOptions["fork"] = { ...options }; From fc7fd6be1a33a9d70a22a92810133b9f2ad5b895 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:03:08 -0500 Subject: [PATCH 04/15] get open port in forking tests --- .../ethereum/tests/forking/forking.test.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts index 802f14d876..41805c0b91 100644 --- a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts +++ b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts @@ -17,6 +17,7 @@ import { import compile from "../helpers/compile"; import path from "path"; import { CodedError } from "@ganache/ethereum-utils"; +import getPort from "get-port"; async function deployContract( remoteProvider: EthereumProvider, @@ -53,9 +54,11 @@ async function deployContract( methods }; } -const PORT = 9999; +const getRemotePort = async () => { + return await getPort(); +}; -describe("forking", function () { +describe("forking", async function () { this.timeout(10000); const NETWORK_ID = 1234; @@ -63,6 +66,7 @@ describe("forking", function () { let remoteServer: Server; let remoteProvider: EthereumProvider; let remoteAccounts: string[]; + let remotePort: number; beforeEach("start remote chain", async () => { remoteServer = ganache.server({ @@ -72,7 +76,8 @@ describe("forking", function () { }); remoteProvider = remoteServer.provider as unknown as EthereumProvider; remoteAccounts = Object.keys(remoteProvider.getInitialAccounts()); - await remoteServer.listen(PORT); + remotePort = await getRemotePort(); + await remoteServer.listen(remotePort); }); afterEach(async () => { @@ -111,7 +116,7 @@ describe("forking", function () { totalDifficulty: "0x0", transactions: [] }; - const port = 9988; + const port = await getPort(); let junk: any; let server: http.Server; beforeEach("start mock http server", async () => { @@ -187,7 +192,7 @@ describe("forking", function () { it("throws on invalid provider", async () => { await assert.rejects( () => - startLocalChain(PORT, { + startLocalChain(remotePort, { provider: { request: "not a function" } as any, disableCache: true }), @@ -200,7 +205,7 @@ describe("forking", function () { beforeEach( "start up localProvider fork with remoteProvider", async () => { - const provider = await startLocalChain(PORT, { + const provider = await startLocalChain(remotePort, { provider: remoteProvider as any, disableCache: true }); @@ -272,7 +277,7 @@ describe("forking", function () { return (send as any).apply(remoteProvider, args); }; - const provider = await startLocalChain(PORT, { + const provider = await startLocalChain(remotePort, { provider: remoteProvider as any, disableCache: true }); @@ -340,7 +345,7 @@ describe("forking", function () { describe("initial state", () => { it("should get the Network ID of the forked chain", async () => { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); @@ -363,7 +368,7 @@ describe("forking", function () { ); assert.strictEqual(remoteBlockNumber, 10); const localStartBlockNum = blocks / 2; - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { blockNumber: localStartBlockNum, disableCache: true }); @@ -388,7 +393,7 @@ describe("forking", function () { describe("block number", () => { let localProvider: EthereumProvider; beforeEach("start local chain", async () => { - ({ localProvider } = await startLocalChain(PORT, { + ({ localProvider } = await startLocalChain(remotePort, { disableCache: true })); }); @@ -410,7 +415,7 @@ describe("forking", function () { }); beforeEach("start local chain", async () => { - ({ localProvider } = await startLocalChain(PORT, { + ({ localProvider } = await startLocalChain(remotePort, { disableCache: true })); }); @@ -437,7 +442,7 @@ describe("forking", function () { }); beforeEach("start local chain", async () => { - ({ localProvider, localAccounts } = await startLocalChain(PORT, { + ({ localProvider, localAccounts } = await startLocalChain(remotePort, { disableCache: true })); }); @@ -641,7 +646,7 @@ describe("forking", function () { }); it("should fetch contract code from the remote chain via the local chain", async () => { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); const { blockNumbersWithCode, blockNumbersWithoutCode } = @@ -671,7 +676,7 @@ describe("forking", function () { }); it("should fetch initial contract data from the remote chain via the local chain", async () => { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); const { blockNum, blockNumbersWithCode, blockNumbersWithoutCode } = @@ -720,7 +725,7 @@ describe("forking", function () { }); it("should fetch changed contract data from the remote chain via the local chain", async () => { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); const { blockNum, blockNumbersWithCode, blockNumbersWithoutCode } = @@ -829,7 +834,7 @@ describe("forking", function () { initialValue: number, snapshotValues: number[] ) { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); const subId = await localProvider.send("eth_subscribe", ["newHeads"]); @@ -925,7 +930,7 @@ describe("forking", function () { describe("gas estimation", () => { it("should not affect live state", async () => { - const { localProvider } = await startLocalChain(PORT, { + const { localProvider } = await startLocalChain(remotePort, { disableCache: true }); const blockNum = await getBlockNumber(localProvider); @@ -974,7 +979,7 @@ describe("forking", function () { await remoteProvider.once("message"); await remoteProvider.send("eth_unsubscribe", [subId]); - ({ localProvider } = await startLocalChain(PORT)); + ({ localProvider } = await startLocalChain(remotePort)); }); it("ensure local block's latest matches remote block's latest (with transaction)", async () => { @@ -1223,7 +1228,7 @@ describe("forking", function () { KNOWN_NETWORKS.forEach(network => { describe(network, () => { beforeEach("set up network provider", async () => { - const provider = await startLocalChain(PORT, { + const provider = await startLocalChain(null, { network, disableCache: true }); From 675965b3c7b9e2b1a4971914b913755ce942a0e7 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:03:20 -0500 Subject: [PATCH 05/15] get open port for server tets --- src/packages/core/tests/server.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/packages/core/tests/server.test.ts b/src/packages/core/tests/server.test.ts index 09cab25b13..0b6e31c6c9 100644 --- a/src/packages/core/tests/server.test.ts +++ b/src/packages/core/tests/server.test.ts @@ -26,12 +26,13 @@ import { NetworkInterfaceInfoIPv6, networkInterfaces } from "os"; +import getPort from "get-port"; + const chunkSize = 1024 * 1024; const IS_WINDOWS = process.platform === "win32"; describe("server", () => { - const port = 5234; const networkId = 1234; const jsonRpcJson: any = { jsonrpc: "2.0", @@ -43,6 +44,7 @@ describe("server", () => { log: (_message: string) => {} }; let s: Server; + let port: number; const defaultOptions = { chain: { @@ -52,7 +54,9 @@ describe("server", () => { logger } }; - + before(async () => { + port = await getPort(); + }); async function setup( options: ServerOptions = defaultOptions, host: string | null = null From 8ef38649dcf609c534930020323f458d9eebdfe6 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:03:27 -0500 Subject: [PATCH 06/15] increase concurrency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a19c21c2b1..5f44bf0cc4 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prepublishOnly": "cd scripts && ts-node filter-shrinkwrap.ts \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "postpublish": "git restore \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "start": "lerna exec --loglevel=silent --scope ganache -- npm run start --silent -- ", - "test": "lerna exec --concurrency 1 -- npm run test", + "test": "lerna exec --concurrency 22 -- npm run test", "tsc": "tsc --build src", "tsc.clean": "npx lerna exec -- npx shx rm -rf lib dist typings" }, From 10dab075d060d69c3f5e7499db6cb2cb49a403b6 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:03:48 -0500 Subject: [PATCH 07/15] add get-port dep to filecoin --- src/chains/filecoin/filecoin/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chains/filecoin/filecoin/package.json b/src/chains/filecoin/filecoin/package.json index ba49a560d5..9ca7f40863 100644 --- a/src/chains/filecoin/filecoin/package.json +++ b/src/chains/filecoin/filecoin/package.json @@ -80,6 +80,7 @@ "deep-equal": "2.0.3", "emittery": "0.10.0", "encoding-down": "7.1.0", + "get-port": "6.1.2", "ipfs-http-client": "48.1.3", "levelup": "5.1.1", "lodash.clonedeep": "4.5.0", From 0c50a8540bc3169bc3fe72b5da5d0c95cf9f9633 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 11:04:02 -0500 Subject: [PATCH 08/15] add get-port dev dep to filecoin lockfile --- src/chains/filecoin/filecoin/package-lock.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/chains/filecoin/filecoin/package-lock.json b/src/chains/filecoin/filecoin/package-lock.json index 2787192bea..e5613d9e03 100644 --- a/src/chains/filecoin/filecoin/package-lock.json +++ b/src/chains/filecoin/filecoin/package-lock.json @@ -4010,6 +4010,12 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, + "get-port": { + "version": "6.1.2", + "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", + "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", + "dev": true + }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", From f46e502dddc63730b08b924643a037d7f523ca3e Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 12:40:30 -0500 Subject: [PATCH 09/15] use find-open-port instead of get-port --- src/chains/ethereum/ethereum/package-lock.json | 12 ++++++------ src/chains/ethereum/ethereum/package.json | 2 +- src/chains/filecoin/filecoin/package-lock.json | 12 ++++++------ src/chains/filecoin/filecoin/package.json | 2 +- src/packages/core/package-lock.json | 12 ++++++------ src/packages/core/package.json | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/chains/ethereum/ethereum/package-lock.json b/src/chains/ethereum/ethereum/package-lock.json index eedfd3a387..afd4d45ba6 100644 --- a/src/chains/ethereum/ethereum/package-lock.json +++ b/src/chains/ethereum/ethereum/package-lock.json @@ -4911,6 +4911,12 @@ "pkg-dir": "^4.1.0" } }, + "find-open-port": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/find-open-port/-/find-open-port-2.0.3.tgz", + "integrity": "sha512-lcYIpPHWNksWSSgUxe+gAq8LqG7wCpkhohhTVG0E0c5KT1Lrpb5cY7bJ+fO49Dax1TkAw5paKAoBSTgYwnBKrA==", + "dev": true + }, "find-replace": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-replace/-/find-replace-3.0.0.tgz", @@ -5080,12 +5086,6 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, - "get-port": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", - "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", - "dev": true - }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", diff --git a/src/chains/ethereum/ethereum/package.json b/src/chains/ethereum/ethereum/package.json index 624fc2a25f..7693d79f50 100644 --- a/src/chains/ethereum/ethereum/package.json +++ b/src/chains/ethereum/ethereum/package.json @@ -102,8 +102,8 @@ "cheerio": "1.0.0-rc.3", "cross-env": "7.0.3", "fast-check": "3.0.1", + "find-open-port": "2.0.3", "fs-extra": "9.0.1", - "get-port": "6.1.2", "local-web-server": "4.2.1", "memdown": "6.1.1", "mocha": "9.1.3", diff --git a/src/chains/filecoin/filecoin/package-lock.json b/src/chains/filecoin/filecoin/package-lock.json index e5613d9e03..382f2593ae 100644 --- a/src/chains/filecoin/filecoin/package-lock.json +++ b/src/chains/filecoin/filecoin/package-lock.json @@ -3388,6 +3388,12 @@ "pkg-dir": "^4.1.0" } }, + "find-open-port": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/find-open-port/-/find-open-port-2.0.3.tgz", + "integrity": "sha512-lcYIpPHWNksWSSgUxe+gAq8LqG7wCpkhohhTVG0E0c5KT1Lrpb5cY7bJ+fO49Dax1TkAw5paKAoBSTgYwnBKrA==", + "dev": true + }, "find-up": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", @@ -4010,12 +4016,6 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, - "get-port": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", - "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", - "dev": true - }, "get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", diff --git a/src/chains/filecoin/filecoin/package.json b/src/chains/filecoin/filecoin/package.json index 9ca7f40863..377b1b511b 100644 --- a/src/chains/filecoin/filecoin/package.json +++ b/src/chains/filecoin/filecoin/package.json @@ -80,7 +80,7 @@ "deep-equal": "2.0.3", "emittery": "0.10.0", "encoding-down": "7.1.0", - "get-port": "6.1.2", + "find-open-port": "2.0.3", "ipfs-http-client": "48.1.3", "levelup": "5.1.1", "lodash.clonedeep": "4.5.0", diff --git a/src/packages/core/package-lock.json b/src/packages/core/package-lock.json index 6cc08c92a5..01808b8587 100644 --- a/src/packages/core/package-lock.json +++ b/src/packages/core/package-lock.json @@ -950,6 +950,12 @@ "pkg-dir": "^4.1.0" } }, + "find-open-port": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/find-open-port/-/find-open-port-2.0.3.tgz", + "integrity": "sha512-lcYIpPHWNksWSSgUxe+gAq8LqG7wCpkhohhTVG0E0c5KT1Lrpb5cY7bJ+fO49Dax1TkAw5paKAoBSTgYwnBKrA==", + "dev": true + }, "find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -1047,12 +1053,6 @@ "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", "dev": true }, - "get-port": { - "version": "6.1.2", - "resolved": "https://registry.npmjs.org/get-port/-/get-port-6.1.2.tgz", - "integrity": "sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==", - "dev": true - }, "glob": { "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", diff --git a/src/packages/core/package.json b/src/packages/core/package.json index 883440ff4a..6f841a7a6f 100644 --- a/src/packages/core/package.json +++ b/src/packages/core/package.json @@ -61,7 +61,7 @@ "@types/mocha": "9.0.0", "@types/superagent": "4.1.10", "cross-env": "7.0.3", - "get-port": "6.1.2", + "find-open-port": "2.0.3", "mocha": "9.1.3", "nyc": "15.1.0", "superagent": "6.1.0", From e4533ba25ca9b89768b4b106b064a9682bcaf808 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 12:40:46 -0500 Subject: [PATCH 10/15] update tests to use find-open-port --- src/chains/ethereum/ethereum/tests/forking/forking.test.ts | 6 +++--- src/packages/core/tests/server.test.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts index 41805c0b91..60e12f58af 100644 --- a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts +++ b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts @@ -17,7 +17,7 @@ import { import compile from "../helpers/compile"; import path from "path"; import { CodedError } from "@ganache/ethereum-utils"; -import getPort from "get-port"; +import { findPort } from "find-open-port"; async function deployContract( remoteProvider: EthereumProvider, @@ -55,7 +55,7 @@ async function deployContract( }; } const getRemotePort = async () => { - return await getPort(); + return await findPort(); }; describe("forking", async function () { @@ -116,7 +116,7 @@ describe("forking", async function () { totalDifficulty: "0x0", transactions: [] }; - const port = await getPort(); + const port = await findPort(); let junk: any; let server: http.Server; beforeEach("start mock http server", async () => { diff --git a/src/packages/core/tests/server.test.ts b/src/packages/core/tests/server.test.ts index 0b6e31c6c9..1257da21eb 100644 --- a/src/packages/core/tests/server.test.ts +++ b/src/packages/core/tests/server.test.ts @@ -26,7 +26,7 @@ import { NetworkInterfaceInfoIPv6, networkInterfaces } from "os"; -import getPort from "get-port"; +import { findPort } from "find-open-port"; const chunkSize = 1024 * 1024; @@ -55,7 +55,7 @@ describe("server", () => { } }; before(async () => { - port = await getPort(); + port = await findPort(); }); async function setup( options: ServerOptions = defaultOptions, From f75d764f95de1816aeebd7f2fd0fc50dc36170e7 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 12:40:57 -0500 Subject: [PATCH 11/15] update filecoin tests --- .../filecoin/tests/api/filecoin/subscriptions-ws.test.ts | 6 ++++-- src/chains/filecoin/filecoin/tests/helpers/getServer.ts | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/chains/filecoin/filecoin/tests/api/filecoin/subscriptions-ws.test.ts b/src/chains/filecoin/filecoin/tests/api/filecoin/subscriptions-ws.test.ts index 510bfe82b2..527557108d 100644 --- a/src/chains/filecoin/filecoin/tests/api/filecoin/subscriptions-ws.test.ts +++ b/src/chains/filecoin/filecoin/tests/api/filecoin/subscriptions-ws.test.ts @@ -8,10 +8,12 @@ describe("api", () => { describe("filecoin", () => { let server: Server<"filecoin">; let ws: WebSocket; - const port = 7778; // Use a different port than the default, to test it works + let port: number; before(async () => { - server = await getServer(port); + const serverDetails = await getServer(); + server = serverDetails.server; + port = serverDetails.port; ws = new WebSocket(`ws://localhost:${port}/rpc/v0`); await new Promise((resolve, reject) => { diff --git a/src/chains/filecoin/filecoin/tests/helpers/getServer.ts b/src/chains/filecoin/filecoin/tests/helpers/getServer.ts index 8afcf75a8b..32d487dc1a 100644 --- a/src/chains/filecoin/filecoin/tests/helpers/getServer.ts +++ b/src/chains/filecoin/filecoin/tests/helpers/getServer.ts @@ -1,14 +1,17 @@ import { FilecoinFlavorName } from "../../../../../packages/flavors"; import Server from "../../../../../packages/core/src/server"; +import { findPort } from "find-open-port"; -const getServer = async (port: number) => { +const getServer = async () => { + const port = await findPort(); + const ipfsPort = await findPort(); const server = new Server({ flavor: FilecoinFlavorName, server: { ws: true }, chain: { - ipfsPort: 5002 // Use a different port than the default, to test it works + ipfsPort }, logging: { logger: { @@ -17,7 +20,7 @@ const getServer = async (port: number) => { } }); await server.listen(port); - return server; + return { server, port }; }; export default getServer; From 987d0cd6728e0c6c3fa08d39e596403186f9729e Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 12:41:29 -0500 Subject: [PATCH 12/15] set test concurrency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5f44bf0cc4..13f28a0e73 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prepublishOnly": "cd scripts && ts-node filter-shrinkwrap.ts \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "postpublish": "git restore \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "start": "lerna exec --loglevel=silent --scope ganache -- npm run start --silent -- ", - "test": "lerna exec --concurrency 22 -- npm run test", + "test": "lerna exec --concurrency 21 -- npm run test", "tsc": "tsc --build src", "tsc.clean": "npx lerna exec -- npx shx rm -rf lib dist typings" }, From 41577d9d3f0260e24d05bb2ed45ecbf903cc96f7 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 13:12:28 -0500 Subject: [PATCH 13/15] get new port for each test --- src/chains/ethereum/ethereum/tests/forking/forking.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts index 60e12f58af..24195ce9ec 100644 --- a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts +++ b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts @@ -116,10 +116,11 @@ describe("forking", async function () { totalDifficulty: "0x0", transactions: [] }; - const port = await findPort(); + let port: number; let junk: any; let server: http.Server; beforeEach("start mock http server", async () => { + port = await findPort(); // mock a server so we can send bad requests back at ganache server = http.createServer((req, res) => { let body = ""; From 9c62de59b1602e75f64e58dac96a93a9416349d8 Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Tue, 20 Dec 2022 13:50:38 -0500 Subject: [PATCH 14/15] remove concurrency flag --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13f28a0e73..63c2c562a5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prepublishOnly": "cd scripts && ts-node filter-shrinkwrap.ts \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "postpublish": "git restore \"$(lerna list --parseable --scope ganache)\"/npm-shrinkwrap.json", "start": "lerna exec --loglevel=silent --scope ganache -- npm run start --silent -- ", - "test": "lerna exec --concurrency 21 -- npm run test", + "test": "lerna exec -- npm run test", "tsc": "tsc --build src", "tsc.clean": "npx lerna exec -- npx shx rm -rf lib dist typings" }, From 608f8c6b5366062ae4c645b908a3c33b51e7768c Mon Sep 17 00:00:00 2001 From: MicaiahReid Date: Mon, 9 Jan 2023 10:40:30 -0500 Subject: [PATCH 15/15] cleanup --- src/chains/ethereum/ethereum/tests/forking/forking.test.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts index 24195ce9ec..1461009370 100644 --- a/src/chains/ethereum/ethereum/tests/forking/forking.test.ts +++ b/src/chains/ethereum/ethereum/tests/forking/forking.test.ts @@ -54,9 +54,6 @@ async function deployContract( methods }; } -const getRemotePort = async () => { - return await findPort(); -}; describe("forking", async function () { this.timeout(10000); @@ -76,7 +73,7 @@ describe("forking", async function () { }); remoteProvider = remoteServer.provider as unknown as EthereumProvider; remoteAccounts = Object.keys(remoteProvider.getInitialAccounts()); - remotePort = await getRemotePort(); + remotePort = await findPort(); await remoteServer.listen(remotePort); });