Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ganache for tests instead of Infura HTTP API #51

Merged
merged 2 commits into from
Dec 8, 2023
Merged
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: 0 additions & 2 deletions .github/workflows/build-lint-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ on:
jobs:
build-lint-test:
name: Build, Lint, and Test
env:
INFURA_PROJECT_ID: ${{ secrets.INFURA_PROJECT_ID }}
runs-on: ubuntu-20.04
strategy:
matrix:
Expand Down
1 change: 0 additions & 1 deletion .infurarc.template

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-node": "^11.1.0",
"ganache": "7.3.1",
"prettier": "2.2.1",
"rc": "^1.2.8",
"tape": "^5.1.1",
"typescript": "^4.1.3"
"typescript": "^4.8.4"
},
"directories": {
"test": "test"
Expand Down
21 changes: 2 additions & 19 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
const test = require('tape');
const Eth = require('ethjs');

const { INFURA_PROJECT_ID } = require('rc')('infura', {
// eslint-disable-next-line node/no-process-env
INFURA_PROJECT_ID: process.env.INFURA_PROJECT_ID,
});
const Ganache = require('ganache');

const { MethodRegistry } = require('../dist');

const provider = new Eth.HttpProvider(`https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`);
const { provider } = Ganache.server();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're just testing the parse method in these tests; we're not testing the lookup method, which actually makes us of the provider. So, could we just use a fake provider object here? That way we don't even need Ganache.

Copy link
Contributor Author

@legobeat legobeat Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but perhaps in a follow-up? Given that this is currently blocking doing any other changes in this repo.

Copy link

@NicholasEllul NicholasEllul Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@legobeat While I do love the idea of eliminating the need to make HTTP requests in tests, Ganache is going to be at its EOL on December 20th, and is no longer recommended in new projects.

Are we able to make this additional change here?

const registry = new MethodRegistry({ provider });

test('connecting to main net contract', function (t) {
t.plan(1);

registry.lookup('0xa9059cbb')
.then((result) => {
t.equal(result, 'transfer(address,uint256)', 'finds correct value');
})
.catch((reason) => {
t.fail(reason.message);
});
});

test('parse signature', function (t) {
const sig = 'transfer(address,uint256)';
const parsed = registry.parse(sig);
Expand Down
Loading
Loading