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

test: ensure tests that are skipped in development are run in CI #4353

Merged
merged 4 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 5 additions & 4 deletions src/chains/ethereum/ethereum/tests/forking/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from "assert";
import getProvider from "../helpers/getProvider";
import { EthereumProvider } from "../../src/provider";
import request from "superagent";
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";

describe("forking", function () {
this.timeout(10000);
Expand All @@ -12,10 +13,10 @@ describe("forking", function () {
const blockNumberHex = `0x${blockNumber.toString(16)}`;
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
let provider: EthereumProvider;
before(async function () {
if (!process.env.INFURA_KEY) {
this.skip();
}

skipIfNoInfuraKey();

before(async () => {
provider = await getProvider({
fork: {
url: URL,
Expand Down
30 changes: 21 additions & 9 deletions src/chains/ethereum/ethereum/tests/forking/block.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from "assert";
import getProvider from "../helpers/getProvider";
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
import { EthereumProvider } from "../../src/provider";
import request from "superagent";

Expand All @@ -11,10 +12,10 @@ describe("forking", function () {
const blockNumHex = `0x${blockNumber.toString(16)}`;
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
let provider: EthereumProvider;
before(async function () {
if (!process.env.INFURA_KEY) {
this.skip();
}

skipIfNoInfuraKey();

before(async () => {
provider = await getProvider({
fork: {
url: URL,
Expand Down Expand Up @@ -52,7 +53,10 @@ describe("forking", function () {
"earliest",
true
]);
assert.deepStrictEqual(parseInt(block.number), parseInt(remoteBlock.number));
assert.deepStrictEqual(
parseInt(block.number),
parseInt(remoteBlock.number)
);
assert.deepStrictEqual(block.hash, remoteBlock.hash);
});

Expand Down Expand Up @@ -86,10 +90,18 @@ describe("forking", function () {
});

it("should get transaction count by hash from the original chain", async () => {
const block = await provider.send("eth_getBlockByNumber", ["0xB443", true]);
const blockTransactionCountByHash = await provider.send("eth_getBlockTransactionCountByHash", [block.hash]);
assert.deepStrictEqual(block.transactions.length, parseInt(blockTransactionCountByHash));
const block = await provider.send("eth_getBlockByNumber", [
"0xB443",
true
]);
const blockTransactionCountByHash = await provider.send(
"eth_getBlockTransactionCountByHash",
[block.hash]
);
assert.deepStrictEqual(
block.transactions.length,
parseInt(blockTransactionCountByHash)
);
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved
});

});
});
28 changes: 11 additions & 17 deletions src/chains/ethereum/ethereum/tests/forking/forking.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { KNOWN_NETWORKS } from "@ganache/ethereum-options";
import getProvider from "../helpers/getProvider";
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
import http from "http";
import ganache from "../../../../../packages/core";
import assert from "assert";
Expand Down Expand Up @@ -1047,9 +1048,7 @@ describe("forking", () => {
let remoteProvider: EthereumProvider;
let remoteAccounts: string[];

before("skip if we don't have the INFURA_KEY", function () {
if (!process.env.INFURA_KEY) this.skip();
});
skipIfNoInfuraKey();

before("configure mainnet", async function () {
// we fork from mainnet, but configure our fork such that it looks like
Expand Down Expand Up @@ -1171,9 +1170,7 @@ describe("forking", () => {
let provider: EthereumProvider;
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;

before("skip if we don't have the INFURA_KEY", function () {
if (!process.env.INFURA_KEY) this.skip();
});
skipIfNoInfuraKey();

before("configure provider", async () => {
provider = await getProvider({
Expand Down Expand Up @@ -1247,11 +1244,8 @@ describe("forking", function () {
}
};
let localProvider: EthereumProvider;
before("check conditions", function () {
if (!process.env.INFURA_KEY) {
this.skip();
}
});

skipIfNoInfuraKey();

KNOWN_NETWORKS.forEach(network => {
describe(network, () => {
Expand Down Expand Up @@ -1383,12 +1377,12 @@ describe("forking", function () {
validatorIndex: "0x3a995"
}
];
before("skip if we don't have the INFURA_KEY", function () {
// this test uses the `network: "goerli"` option, which requires an
// infura key; when run our tests it must be provided as an environment
// variable.
if (!process.env.INFURA_KEY) this.skip();
});

// this test uses the `network: "goerli"` option, which requires an
// infura key; when run our tests it must be provided as an environment
// variable.
skipIfNoInfuraKey();

describe("shanghai", () => {
let provider: EthereumProvider;
const blockNumber = 8765432;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from "assert";
import getProvider from "../helpers/getProvider";
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
import { EthereumProvider } from "../../src/provider";
import request from "superagent";

Expand All @@ -10,10 +11,10 @@ describe("forking", () => {
const blockNumber = 0xcb6169;
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
let provider: EthereumProvider;
before(async function () {
if (!process.env.INFURA_KEY) {
this.skip();
}

skipIfNoInfuraKey();

before(async () => {
provider = await getProvider({
fork: {
url: URL,
Expand Down
17 changes: 17 additions & 0 deletions src/chains/ethereum/ethereum/tests/helpers/skipIfNoInfuraKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function skipIfNoInfuraKey() {
before("skip if no INFURA_KEY (unless in CI)", function () {
// If there is no INFURA_KEY provided, the test should be skipped. Unless running
// in CI, where there should _always_ be a key provided.
if (!process.env.INFURA_KEY) {
if (process.env.CI === "true") {
throw new Error(
"No INFURA_KEY was provided. When CI is true, an INFURA_KEY must be provided."
jeffsmale90 marked this conversation as resolved.
Show resolved Hide resolved
);
} else {
this.skip();
}
}
});
}

export default skipIfNoInfuraKey;
26 changes: 15 additions & 11 deletions src/packages/core/tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ describe("server", () => {
return deferred;
}

// skip this test unless in GitHub Actions, as this test iterates over
// all available network interfaces and network interfaces on user
// machines are unpredictible and may behave in ways that we don't care
// about.
(process.env.GITHUB_ACTION ? describe : describe.skip)("listen", function () {
describe("listen", function () {
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved
function isIPv6(
info: NetworkInterfaceInfo
): info is NetworkInterfaceInfoIPv6 {
Expand All @@ -132,7 +128,7 @@ describe("server", () => {
function getHost(info: NetworkInterfaceInfo, interfaceName: string) {
// a link-local ipv6 address starts with fe80:: and _must_ include a "zone_id"
if (isIPv6(info) && info.address.startsWith("fe80::")) {
if (process.platform == "win32") {
if (IS_WINDOWS) {
// on windows the zone_id is the scopeid
return `${info.address}%${info.scopeid}`;
} else {
Expand All @@ -159,7 +155,13 @@ describe("server", () => {
return validInterfaces;
}

it("listens on all interfaces by default", async () => {
it("listens on all interfaces by default", async function () {
// This test iterates over all available network interfaces. This can be problematic on user
// machines (which may be configured in unsupported ways), so we skip it in this case.
if (process.env.CI !== "true") {
this.skip();
}

await setup();
try {
const interfaces = getNetworkInterfaces();
Expand Down Expand Up @@ -190,10 +192,12 @@ describe("server", () => {
});

it("listens on given interface only", async function () {
// skip this test unless in CI, as this test iterates over all available network interfaces
// and network interfaces on user machines are unpredictible and may behave in ways that
// we don't care about.
if (process.env.CI) this.skip();
// This test iterates over all available network interfaces. This can be problematic on user
// machines (which may be configured in unsupported ways), and also in macOS (which exposes
// unsupported interfaces). In these cases, we skip this test.
if (process.env.CI !== "true" || process.platform === "darwin") {
this.skip();
}
davidmurdoch marked this conversation as resolved.
Show resolved Hide resolved

const interfaces = networkInterfaces();
assert(Object.keys(interfaces).length > 0);
Expand Down