Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

Add basic client/cli test #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ jobs:
- uses: actions/checkout@v2
- run: npm install
- run: npm run test:browser
test-cli:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v1
with:
node-version: 12.x
- uses: actions/checkout@v2
- run: npm install
- run: npm run test:cli
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Coverage Status][coverage-badge]][coverage-link]
[![Discord][discord-badge]][discord-link]

This is the work repository for the EthereumJS client project targeting both Node.js and the browser as a platform.
This is the work repository for the EthereumJS client project targeting both Node.js and the browser.

See [Technical Guidelines](#technical-guidelines) to dive directly into development info.

Expand All @@ -31,8 +31,7 @@ For the `ethereumjs` CLI command to work run:
npm link
```

Note: for development purposes you can invoke the client by build with `npm run build:node` and
then run `node ./dist/bin/cli.js`.
Note: for development purposes you can invoke the client with `npm run client:start`

**Running the Client**

Expand All @@ -44,7 +43,7 @@ You can run the current state of the client with:
ethereumjs --network=mainnet [--loglevel=debug]
```

For development you might want to connect to `rinkeby` as the network with the currently
For development you might want to connect to `rinkeby` as the network with the currently
most reliable connection:

```shell
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "dist/lib/index.d.ts",
"browser": "dist/bundle.js",
"bin": {
"ethereumjs": "bin/cli.js"
"ethereumjs": "dist/bin/cli.js"
},
"files": [
"bin",
Expand All @@ -17,15 +17,16 @@
"build:node": "tsc -p ./tsconfig.prod.json",
"build:browser": "tsc -p ./tsconfig.browser.json && npm run bundle && rm -rf dist.browser",
"bundle": "webpack",
"client:start": "tsc -p tsconfig.prod.json && node dist/bin/cli.js",
"client:start": "ts-node bin/cli.ts",
ryanio marked this conversation as resolved.
Show resolved Hide resolved
"coverage": "nyc npm run test && nyc report --reporter=lcov",
"docs:build": "typedoc --tsconfig tsconfig.prod.json",
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"tape": "tape -r ts-node/register",
"test": "npm run test:unit && npm run test:integration",
"test:unit": "npm run tape -- 'test/!(integration)/**/*.spec.ts'",
"test:unit": "npm run tape -- 'test/!(integration|cli)/**/*.spec.ts'",
"test:integration": "npm run tape -- 'test/integration/**/*.spec.ts'",
"test:cli": "npm run build:node && npm run tape -- 'test/cli/*.spec.ts'",
"test:browser": "karma start karma.conf.js"
},
"husky": {
Expand Down
49 changes: 49 additions & 0 deletions test/cli/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { spawn } from 'child_process'
import tape from 'tape'

tape('[CLI]', (t) => {
t.test('should begin downloading blocks', { timeout: 260000 }, (t) => {
const file = require.resolve('../../dist/bin/cli.js')
const child = spawn(process.execPath, [file])

const timeout = setTimeout(() => {
child.kill('SIGINT')
t.fail('timed out before finishing')
t.end()
}, 240000)

const end = () => {
clearTimeout(timeout)
child.kill('SIGINT')
t.end()
}

child.stdout.on('data', (data) => {
const message = data.toString()
if (message.toLowerCase().includes('error')) {
t.fail(message)
end()
}
if (message.includes('Imported blocks')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI If data chunk size exceeds 16Kb (default value for readableHighWaterMark), then it will be split into several chunks to fit 16Kb size limit. So it's possible to meet the situation, when some part of 'Imported block' is in the first chunk and other is in another. It could be highly possible if script writes big bunch of data in one libuv event loop cycle, not sure if Client will ever do it. But if it will, then there will be false negative tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good to know, thanks, I was wondering about how it may be chunked. Any suggestions on a better or more reliable way to parse the incoming data?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think native IPC could be used here, it will simplify things dramatically. I've added #177 with a support of IPC logger. So we can just merge this PR (cause it works) and then apply that PR. Or if #177 wouldn't be applied to add IPC logger into current code.

t.pass('successfully imported blocks')
end()
}
// log for easier debugging
// eslint-disable-next-line no-console
console.log(message)
})

child.stderr.on('data', (data) => {
const message = data.toString()
t.fail(`stderr: ${message}`)
end()
})

child.on('close', (code) => {
if (code !== 0) {
t.fail(`child process exited with code ${code}`)
end()
}
})
})
})