Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

test: allow tests to run concurrently #4068

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- npm run test",
"tsc": "tsc --build src",
"tsc.clean": "npx lerna exec -- npx shx rm -rf lib dist typings"
},
Expand Down
6 changes: 6 additions & 0 deletions src/chains/ethereum/ethereum/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/chains/ethereum/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"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",
"local-web-server": "4.2.1",
"memdown": "6.1.1",
Expand Down
41 changes: 22 additions & 19 deletions src/chains/ethereum/ethereum/tests/forking/forking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import compile from "../helpers/compile";
import path from "path";
import { CodedError } from "@ganache/ethereum-utils";
import { findPort } from "find-open-port";

async function deployContract(
remoteProvider: EthereumProvider,
Expand Down Expand Up @@ -53,16 +54,16 @@ async function deployContract(
methods
};
}
const PORT = 9999;

describe("forking", function () {
describe("forking", async function () {
this.timeout(10000);

const NETWORK_ID = 1234;
const REMOTE_ACCOUNT_COUNT = 15;
let remoteServer: Server;
let remoteProvider: EthereumProvider;
let remoteAccounts: string[];
let remotePort: number;

beforeEach("start remote chain", async () => {
remoteServer = ganache.server({
Expand All @@ -72,7 +73,8 @@ describe("forking", function () {
});
remoteProvider = remoteServer.provider as unknown as EthereumProvider;
remoteAccounts = Object.keys(remoteProvider.getInitialAccounts());
await remoteServer.listen(PORT);
remotePort = await findPort();
await remoteServer.listen(remotePort);
});

afterEach(async () => {
Expand Down Expand Up @@ -111,10 +113,11 @@ describe("forking", function () {
totalDifficulty: "0x0",
transactions: []
};
const port = 9988;
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 = "";
Expand Down Expand Up @@ -187,7 +190,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
}),
Expand All @@ -200,7 +203,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
});
Expand Down Expand Up @@ -272,7 +275,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
});
Expand Down Expand Up @@ -340,7 +343,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
});

Expand All @@ -363,7 +366,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
});
Expand All @@ -388,7 +391,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
}));
});
Expand All @@ -410,7 +413,7 @@ describe("forking", function () {
});

beforeEach("start local chain", async () => {
({ localProvider } = await startLocalChain(PORT, {
({ localProvider } = await startLocalChain(remotePort, {
disableCache: true
}));
});
Expand All @@ -437,7 +440,7 @@ describe("forking", function () {
});

beforeEach("start local chain", async () => {
({ localProvider, localAccounts } = await startLocalChain(PORT, {
({ localProvider, localAccounts } = await startLocalChain(remotePort, {
disableCache: true
}));
});
Expand Down Expand Up @@ -641,7 +644,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 } =
Expand Down Expand Up @@ -671,7 +674,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 } =
Expand Down Expand Up @@ -720,7 +723,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 } =
Expand Down Expand Up @@ -829,7 +832,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"]);
Expand Down Expand Up @@ -925,7 +928,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);
Expand Down Expand Up @@ -974,7 +977,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 () => {
Expand Down Expand Up @@ -1223,7 +1226,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
});
Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/tests/forking/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const updateRemotesAccountNonces = async (
};

export const startLocalChain = async (
port: number,
port?: number,
options?: EthereumProviderOptions["fork"]
) => {
const fork: EthereumProviderOptions["fork"] = { ...options };
Expand Down
6 changes: 6 additions & 0 deletions src/chains/filecoin/filecoin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/chains/filecoin/filecoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"deep-equal": "2.0.3",
"emittery": "0.10.0",
"encoding-down": "7.1.0",
"find-open-port": "2.0.3",
"ipfs-http-client": "48.1.3",
"levelup": "5.1.1",
"lodash.clonedeep": "4.5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>((resolve, reject) => {
Expand Down
9 changes: 6 additions & 3 deletions src/chains/filecoin/filecoin/tests/helpers/getServer.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -17,7 +20,7 @@ const getServer = async (port: number) => {
}
});
await server.listen(port);
return server;
return { server, port };
};

export default getServer;
6 changes: 6 additions & 0 deletions src/packages/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@types/mocha": "9.0.0",
"@types/superagent": "4.1.10",
"cross-env": "7.0.3",
"find-open-port": "2.0.3",
"mocha": "9.1.3",
"nyc": "15.1.0",
"superagent": "6.1.0",
Expand Down
8 changes: 6 additions & 2 deletions src/packages/core/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ import {
NetworkInterfaceInfoIPv6,
networkInterfaces
} from "os";
import { findPort } from "find-open-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",
Expand All @@ -43,6 +44,7 @@ describe("server", () => {
log: (_message: string) => {}
};
let s: Server;
let port: number;

const defaultOptions = {
chain: {
Expand All @@ -52,7 +54,9 @@ describe("server", () => {
logger
}
};

before(async () => {
port = await findPort();
});
async function setup(
options: ServerOptions = defaultOptions,
host: string | null = null
Expand Down