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

Commit 1281876

Browse files
test: ensure tests that are skipped in development are run in CI (#4353)
Co-authored-by: David Murdoch <187813+davidmurdoch@users.noreply.github.com>
1 parent c6db3c3 commit 1281876

6 files changed

Lines changed: 74 additions & 45 deletions

File tree

src/chains/ethereum/ethereum/tests/forking/account.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from "assert";
22
import getProvider from "../helpers/getProvider";
33
import { EthereumProvider } from "../../src/provider";
44
import request from "superagent";
5+
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
56

67
describe("forking", function () {
78
this.timeout(10000);
@@ -12,10 +13,10 @@ describe("forking", function () {
1213
const blockNumberHex = `0x${blockNumber.toString(16)}`;
1314
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
1415
let provider: EthereumProvider;
15-
before(async function () {
16-
if (!process.env.INFURA_KEY) {
17-
this.skip();
18-
}
16+
17+
skipIfNoInfuraKey();
18+
19+
before(async () => {
1920
provider = await getProvider({
2021
fork: {
2122
url: URL,

src/chains/ethereum/ethereum/tests/forking/block.test.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from "assert";
22
import getProvider from "../helpers/getProvider";
3+
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
34
import { EthereumProvider } from "../../src/provider";
45
import request from "superagent";
56

@@ -11,10 +12,10 @@ describe("forking", function () {
1112
const blockNumHex = `0x${blockNumber.toString(16)}`;
1213
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
1314
let provider: EthereumProvider;
14-
before(async function () {
15-
if (!process.env.INFURA_KEY) {
16-
this.skip();
17-
}
15+
16+
skipIfNoInfuraKey();
17+
18+
before(async () => {
1819
provider = await getProvider({
1920
fork: {
2021
url: URL,
@@ -52,7 +53,10 @@ describe("forking", function () {
5253
"earliest",
5354
true
5455
]);
55-
assert.deepStrictEqual(parseInt(block.number), parseInt(remoteBlock.number));
56+
assert.deepStrictEqual(
57+
parseInt(block.number),
58+
parseInt(remoteBlock.number)
59+
);
5660
assert.deepStrictEqual(block.hash, remoteBlock.hash);
5761
});
5862

@@ -86,10 +90,18 @@ describe("forking", function () {
8690
});
8791

8892
it("should get transaction count by hash from the original chain", async () => {
89-
const block = await provider.send("eth_getBlockByNumber", ["0xB443", true]);
90-
const blockTransactionCountByHash = await provider.send("eth_getBlockTransactionCountByHash", [block.hash]);
91-
assert.deepStrictEqual(block.transactions.length, parseInt(blockTransactionCountByHash));
93+
const block = await provider.send("eth_getBlockByNumber", [
94+
"0xB443",
95+
true
96+
]);
97+
const blockTransactionCountByHash = await provider.send(
98+
"eth_getBlockTransactionCountByHash",
99+
[block.hash]
100+
);
101+
assert.deepStrictEqual(
102+
block.transactions.length,
103+
parseInt(blockTransactionCountByHash)
104+
);
92105
});
93-
94106
});
95107
});

src/chains/ethereum/ethereum/tests/forking/forking.test.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { KNOWN_NETWORKS } from "@ganache/ethereum-options";
22
import getProvider from "../helpers/getProvider";
3+
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
34
import http from "http";
45
import ganache from "../../../../../packages/core";
56
import assert from "assert";
@@ -1047,9 +1048,7 @@ describe("forking", () => {
10471048
let remoteProvider: EthereumProvider;
10481049
let remoteAccounts: string[];
10491050

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

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

1174-
before("skip if we don't have the INFURA_KEY", function () {
1175-
if (!process.env.INFURA_KEY) this.skip();
1176-
});
1173+
skipIfNoInfuraKey();
11771174

11781175
before("configure provider", async () => {
11791176
provider = await getProvider({
@@ -1247,11 +1244,8 @@ describe("forking", function () {
12471244
}
12481245
};
12491246
let localProvider: EthereumProvider;
1250-
before("check conditions", function () {
1251-
if (!process.env.INFURA_KEY) {
1252-
this.skip();
1253-
}
1254-
});
1247+
1248+
skipIfNoInfuraKey();
12551249

12561250
KNOWN_NETWORKS.forEach(network => {
12571251
describe(network, () => {
@@ -1383,12 +1377,12 @@ describe("forking", function () {
13831377
validatorIndex: "0x3a995"
13841378
}
13851379
];
1386-
before("skip if we don't have the INFURA_KEY", function () {
1387-
// this test uses the `network: "goerli"` option, which requires an
1388-
// infura key; when run our tests it must be provided as an environment
1389-
// variable.
1390-
if (!process.env.INFURA_KEY) this.skip();
1391-
});
1380+
1381+
// this test uses the `network: "goerli"` option, which requires an
1382+
// infura key; when run our tests it must be provided as an environment
1383+
// variable.
1384+
skipIfNoInfuraKey();
1385+
13921386
describe("shanghai", () => {
13931387
let provider: EthereumProvider;
13941388
const blockNumber = 8765432;

src/chains/ethereum/ethereum/tests/forking/transaction.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from "assert";
22
import getProvider from "../helpers/getProvider";
3+
import skipIfNoInfuraKey from "../helpers/skipIfNoInfuraKey";
34
import { EthereumProvider } from "../../src/provider";
45
import request from "superagent";
56

@@ -10,10 +11,10 @@ describe("forking", () => {
1011
const blockNumber = 0xcb6169;
1112
const URL = "https://mainnet.infura.io/v3/" + process.env.INFURA_KEY;
1213
let provider: EthereumProvider;
13-
before(async function () {
14-
if (!process.env.INFURA_KEY) {
15-
this.skip();
16-
}
14+
15+
skipIfNoInfuraKey();
16+
17+
before(async () => {
1718
provider = await getProvider({
1819
fork: {
1920
url: URL,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function skipIfNoInfuraKey() {
2+
before("skip if no INFURA_KEY (unless in CI)", function () {
3+
// If there is no INFURA_KEY provided, the test should be skipped. Unless running
4+
// in CI, where there should _always_ be a key provided.
5+
if (!process.env.INFURA_KEY) {
6+
if (process.env.CI === "true") {
7+
throw new Error(
8+
`No INFURA_KEY environment variable was provided. When process.env.CI is "true", an INFURA_KEY must be provided.`
9+
);
10+
} else {
11+
this.skip();
12+
}
13+
}
14+
});
15+
}
16+
17+
export default skipIfNoInfuraKey;

src/packages/core/tests/server.test.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ describe("server", () => {
116116
return deferred;
117117
}
118118

119-
// skip this test unless in GitHub Actions, as this test iterates over
120-
// all available network interfaces and network interfaces on user
121-
// machines are unpredictible and may behave in ways that we don't care
122-
// about.
123-
(process.env.GITHUB_ACTION ? describe : describe.skip)("listen", function () {
119+
describe("listen", function () {
124120
function isIPv6(
125121
info: NetworkInterfaceInfo
126122
): info is NetworkInterfaceInfoIPv6 {
@@ -132,7 +128,7 @@ describe("server", () => {
132128
function getHost(info: NetworkInterfaceInfo, interfaceName: string) {
133129
// a link-local ipv6 address starts with fe80:: and _must_ include a "zone_id"
134130
if (isIPv6(info) && info.address.startsWith("fe80::")) {
135-
if (process.platform == "win32") {
131+
if (IS_WINDOWS) {
136132
// on windows the zone_id is the scopeid
137133
return `${info.address}%${info.scopeid}`;
138134
} else {
@@ -159,7 +155,13 @@ describe("server", () => {
159155
return validInterfaces;
160156
}
161157

162-
it("listens on all interfaces by default", async () => {
158+
it("listens on all interfaces by default", async function () {
159+
// This test iterates over all available network interfaces. This can be problematic on user
160+
// machines (which may be configured in unsupported ways), so we skip it in this case.
161+
if (process.env.CI !== "true") {
162+
this.skip();
163+
}
164+
163165
await setup();
164166
try {
165167
const interfaces = getNetworkInterfaces();
@@ -190,10 +192,12 @@ describe("server", () => {
190192
});
191193

192194
it("listens on given interface only", async function () {
193-
// skip this test unless in CI, as this test iterates over all available network interfaces
194-
// and network interfaces on user machines are unpredictible and may behave in ways that
195-
// we don't care about.
196-
if (process.env.CI) this.skip();
195+
// This test iterates over all available network interfaces. This can be problematic on user
196+
// machines (which may be configured in unsupported ways), and also in macOS (which exposes
197+
// unsupported interfaces). In these cases, we skip this test.
198+
if (process.env.CI !== "true" || process.platform === "darwin") {
199+
this.skip();
200+
}
197201

198202
const interfaces = networkInterfaces();
199203
assert(Object.keys(interfaces).length > 0);

0 commit comments

Comments
 (0)