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

Commit

Permalink
Merge branch 'develop' into feat/logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsmale90 authored Jun 21, 2023
2 parents 7671bea + ac5deea commit 084b583
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 58 deletions.
35 changes: 26 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,40 @@

If installation fails due to a `node-gyp` issue you may need to perform some additional system configuration.

### on Linux (Ubuntu-based)

- Make sure `npm` commands are not run as `root`.
- Determine if you have Python 2.7 installed
- example: `which python2.7`
- If you do not have Python 2.7 installed, you need to install it
- example: `sudo apt update && sudo apt install python2.7`
- Run `npm config set python python2.7`
note: Ganache uses [node-gyp v7.1.2](https://github.com/nodejs/node-gyp/tree/v7.1.2) as part of its build system, which requires Python v2.7, v3.5, v3.6, v3.7, or v3.8 to be installed on the system.

### on Windows

- Install [https://www.npmjs.com/package/windows-build-tools](Windows-Build-Tools)
- `npm install --global windows-build-tools`

### on Linux (Ubuntu-based)

- Make sure `npm` commands are not run as `root`.
- If you get an error that `make` isn't installed you might need to also install the `build-essential` package
- example `sudo apt update && sudo apt install build-essential`
- Determine whether you have a compatible version of Python installed:
- example: `python --version` (and `python3 --version` if `python3` is installed)
- If you do not have a compatible version installed: (v2.7, v3.5, v3.6, v3.7, or v3.8), you will need to install it:
- example: `sudo apt update && sudo apt install python2.7`
- You may need to configure the python dependency (see [node-gyp for details on different ways to do this](https://github.com/nodejs/node-gyp/tree/v7.1.2#configuring-python-dependency)):
- example: `npm config set python <path-to-python-executable>`

### on macOS

- I have no idea.
- Attempt to install Xcode command line tools (the console will tell you if they're already installed)
- example: `xcode-select --install`
- Determine whether you have a compatible version of Python installed:
- example: `python --version` (and `python3 --version` if `python3` is installed)
- If you do not have a compatible version installed: (v2.7, v3.5, v3.6, v3.7, or v3.8), you will need to install it: (we recommend [pyenv](https://github.com/pyenv/pyenv) to manage your python installation)
1. [Install `pyenv`](https://github.com/pyenv/pyenv#homebrew-in-macos)
2. [Setup your shell environment for `pyenv`](https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv)
3. Install Python: `pyenv install 2.7`
4. You may need to configure the python dependency (see [node-gyp for details on different ways to do this](https://github.com/nodejs/node-gyp/tree/v7.1.2#configuring-python-dependency)):
- example: `npm config set python <path-to-python-executable>`
- If the above steps don't fix the `node-gyp` issue and you've recently updated your OS, you may need to re-install Xcode command line tools:
1. Remove the existing, broken installation: `rm -rf /Library/Developer/CommandLineTools`
2. Install them again: `xcode-select --install`

## Clean install

Expand Down
2 changes: 1 addition & 1 deletion src/chains/ethereum/ethereum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"scripts": {
"docs.build": "npx shx rm -rf ./lib/docs ./lib/api.json && npm run docs.typedoc",
"docs.typedoc": "typedoc --options ./typedoc.json --readme ./README.md --out ../../../../docs/typedoc --json ../../../../docs/typedoc/api.json src/api.ts",
"docs.preview": "ws --open --port 3010 --directory ../../../../docs",
"docs.preview": "ws --open --hostname localhost --port 3010 --directory ../../../../docs",
"tsc": "tsc --build",
"test": "nyc --reporter lcov npm run mocha",
"mocha": "cross-env TS_NODE_FILES=true mocha --timeout 5000 -s 0 --exit --check-leaks --throw-deprecation --trace-warnings --require ts-node/register 'tests/**/*.test.ts'",
Expand Down
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)
);
});

});
});
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 environment variable was provided. When process.env.CI is "true", an INFURA_KEY must be provided.`
);
} else {
this.skip();
}
}
});
}

export default skipIfNoInfuraKey;
10 changes: 9 additions & 1 deletion src/packages/cli/src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,17 @@ export default function (
}
)
.version(false);
},
function () {
// this handler executes when `ganache instances` is called without a subcommand
const command = chalk`{hex("${TruffleColors.porsche}") ganache instances}`;
console.log(`Missing subcommand for ${command}.`);
console.log();
yargs.showHelp();
yargs.exit(1, new Error("No subcommand provided"));
}
)
.showHelpOnFail(false, "Specify -? or --help for available options")
.showHelpOnFail(false)
.alias("help", "?")
.wrap(wrapWidth)
.version(version);
Expand Down
5 changes: 3 additions & 2 deletions src/packages/cli/src/initialize/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ export default function (provider: EthereumProvider, cliSettings: CliSettings) {
}

logs.push("");
logs.push("Chain Id");
logs.push("Chain");
logs.push("==================");
logs.push(color(liveOptions.chain.chainId.toString()));
logs.push(`Hardfork: ${color(liveOptions.chain.hardfork)}`);
logs.push(`Id: ${color(liveOptions.chain.chainId.toString())}`);

logs.push("");
logs.push("RPC Listening on " + cliSettings.host + ":" + cliSettings.port);
Expand Down
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 () {
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();
}

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

0 comments on commit 084b583

Please sign in to comment.