diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..d2bd7a6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Build +on: + push: + branches: + - master + tags: + - '*' + pull_request: + types: [opened, reopened, synchronize] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [10.x, 12.x, 13.x] + + steps: + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - uses: actions/checkout@v1 + - run: npm install + - run: npm run lint + - run: npm run coverage + - run: npm run test:browser + + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.nycrc b/.nycrc deleted file mode 100644 index af39578..0000000 --- a/.nycrc +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "@ethereumjs/config-nyc", - "include": [ - "dist/**/*.js" - ], - "extension": [ - ".js" - ], - "source-map": false -} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f637413..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -language: node_js -node_js: - - "8" - - "9" - - "10" - - "12" -env: - - CXX=g++-4.8 -services: - - xvfb -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 -env: - global: - - DISPLAY=:99.0 - matrix: - - CXX=g++-4.8 TEST_SUITE=test:node -matrix: - fast_finish: true - include: - - os: linux - node_js: "8" - env: CXX=g++-4.8 TEST_SUITE=coveralls - - os: linux - node_js: "8" - env: CXX=g++-4.8 TEST_SUITE=lint - - os: linux - node_js: "8" - env: CXX=g++-4.8 TEST_SUITE=test:browser -script: npm run build && npm run $TEST_SUITE diff --git a/README.md b/README.md index ac6e0f3..f4b8a51 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,15 @@ # SYNOPSIS [![NPM Package](https://img.shields.io/npm/v/merkle-patricia-tree)](https://www.npmjs.org/package/merkle-patricia-tree) -[![Build Status](https://img.shields.io/travis/ethereumjs/merkle-patricia-tree/master)](https://travis-ci.org/ethereumjs/merkle-patricia-tree) +[![Actions Status](https://github.com/ethereumjs/ethereumjs-util/workflows/Build/badge.svg)](https://github.com/ethereumjs/merkle-patricia-tree/actions) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/merkle-patricia-tree.svg)](https://coveralls.io/r/ethereumjs/merkle-patricia-tree) [![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg)](https://gitter.im/ethereum/ethereumjs-lib) [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) -This is an implementation of the modified merkle patricia tree as specified in the [Ethereum's yellow paper](http://gavwood.com/Paper.pdf). +This is an implementation of the modified merkle patricia tree as specified in the [Ethereum's Yellow Paper](http://gavwood.com/Paper.pdf): -> The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification is to provide a single 32-byte value that identifies a given set of key-value pairs. -> \- Ethereum's yellow paper +> The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification is to provide a single 32-byte value that identifies a given set of key-value pairs. The only backing store supported is LevelDB through the `levelup` module. @@ -30,8 +29,8 @@ const Trie = require('merkle-patricia-tree').BaseTrie, db = level('./testdb'), trie = new Trie(db) -trie.put(Buffer.from('test'), Buffer.from('one'), function() { - trie.get(Buffer.from('test'), function(err, value) { +trie.put(Buffer.from('test'), Buffer.from('one'), function () { + trie.get(Buffer.from('test'), function (err, value) { if (value) console.log(value.toString()) }) }) @@ -40,9 +39,9 @@ trie.put(Buffer.from('test'), Buffer.from('one'), function() { ## Merkle Proofs ```javascript -Trie.prove(trie, Buffer.from('test'), function(err, prove) { +Trie.prove(trie, Buffer.from('test'), function (err, prove) { if (err) return cb(err) - Trie.verifyProof(trie.root, Buffer.from('test'), prove, function(err, value) { + Trie.verifyProof(trie.root, Buffer.from('test'), prove, function (err, value) { if (err) return cb(err) console.log(value.toString()) cb() @@ -63,10 +62,10 @@ var trie = new Trie(db, stateRoot) trie .createReadStream() - .on('data', function(data) { + .on('data', function (data) { console.log(data) }) - .on('end', function() { + .on('end', function () { console.log('End.') }) ``` @@ -89,7 +88,7 @@ var trie = new Trie(db, stateRoot) var address = 'AN_ETHEREUM_ACCOUNT_ADDRESS' -trie.get(address, function(err, data) { +trie.get(address, function (err, data) { if (err) return cb(err) var acc = new Account(data) @@ -105,11 +104,11 @@ trie.get(address, function(err, data) { console.log('------Storage------') var stream = storageTrie.createReadStream() stream - .on('data', function(data) { + .on('data', function (data) { console.log(`key: ${ethutil.bufferToHex(data.key)}`) console.log(`Value: ${ethutil.bufferToHex(rlp.decode(data.value))}`) }) - .on('end', function() { + .on('end', function () { console.log('Finished reading storage.') }) }) diff --git a/karma.conf.js b/karma.conf.js index 0490154..a46e6cb 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,19 +1,16 @@ module.exports = function(config) { config.set({ - browserNoActivityTimeout: 60000, - frameworks: ['browserify', 'detectBrowsers', 'tap'], + browserDisconnectTimeout: 100000, + browserNoActivityTimeout: 100000, + frameworks: ['browserify', 'tap'], + plugins: ['karma-browserify', 'karma-tap', 'karma-chrome-launcher', 'karma-firefox-launcher'], files: ['./test/*.js'], preprocessors: { './dist/**/*.js': ['browserify'], - './test/**/*.js': ['browserify'] + './test/**/*.js': ['browserify'], }, + colors: true, + browsers: ['FirefoxHeadless', 'ChromeHeadless'], singleRun: true, - detectBrowsers: { - enabled: true, - usePhantomJS: false, - postDetection: function(availableBrowsers) { - return ['Firefox'] - }, - } }) } diff --git a/package.json b/package.json index f537b2c..89f4a42 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "scripts": { "build": "ethereumjs-config-build", "prepublishOnly": "npm run test && npm run build", - "coverage": "nyc npm run test:node && nyc report --reporter=text-lcov > .nyc_output/lcov.info", - "coveralls": "npm run coverage && coveralls < .nyc_output/lcov.info", + "coverage": "nyc --reporter=lcov npm run test:node", "docs:build": "npx typedoc", "tslint": "ethereumjs-config-tslint", "tslint:fix": "ethereumjs-config-tslint-fix", @@ -21,9 +20,9 @@ "format:fix": "ethereumjs-config-format-fix", "formatTest": "node ./scripts/formatTest", "tsc": "ethereumjs-config-tsc", - "test": "npm run build && npm run test:node && npm run test:browser", + "test": "npm run test:node && npm run test:browser", "test:browser": "npm run build && karma start karma.conf.js", - "test:node": "npm run build && tape ./test/*.js" + "test:node": "npm run build && tape test/*.js | tap-prettify -" }, "husky": { "hooks": { @@ -64,17 +63,17 @@ "@ethereumjs/config-tslint": "^1.1.1", "@types/bn.js": "^4.11.5", "@types/levelup": "^3.1.1", - "browserify": "^13.0.0", - "coveralls": "^3.0.5", - "husky": "^2.1.0", - "karma": "^1.7.1", - "karma-browserify": "^5.0.0", - "karma-detect-browsers": "^2.0.2", - "karma-firefox-launcher": "^1.0.1", - "karma-tap": "^1.0.3", - "nyc": "^14.1.1", - "prettier": "^1.18.2", - "tape": "^4.10.1", + "browserify": "^16.5.0", + "husky": "^4.2.3", + "karma": "^4.4.1", + "karma-browserify": "^7.0.0", + "karma-chrome-launcher": "^3.1.0", + "karma-firefox-launcher": "^1.3.0", + "karma-tap": "^4.2.0", + "nyc": "^15.0.0", + "prettier": "^2.0.2", + "tap-prettify": "^0.0.2", + "tape": "^4.13.0", "tslint": "^5.18.0", "typedoc": "next", "typedoc-plugin-markdown": "^2.2.16", diff --git a/src/baseTrie.ts b/src/baseTrie.ts index 4661fe9..abaab5e 100644 --- a/src/baseTrie.ts +++ b/src/baseTrie.ts @@ -47,7 +47,7 @@ export class Trie { } static fromProof(proofNodes: Buffer[], cb: Function, proofTrie?: Trie) { - let opStack = proofNodes.map(nodeValue => { + let opStack = proofNodes.map((nodeValue) => { return { type: 'put', key: ethUtil.keccak(nodeValue), @@ -68,14 +68,14 @@ export class Trie { } static prove(trie: Trie, key: Buffer, cb: Function) { - trie.findPath(key, function( + trie.findPath(key, function ( err: Error, node: TrieNode, remaining: number[], stack: TrieNode[], ) { if (err) return cb(err) - let p = stack.map(stackElem => { + let p = stack.map((stackElem) => { return stackElem.serialize() }) cb(null, p) @@ -473,7 +473,7 @@ export class Trie { _walkTrie(root: Buffer, onNode: Function, onDone: Function) { const self = this root = root || this.root - onDone = onDone || function() {} + onDone = onDone || function () {} let aborted = false let returnValues: any = [] @@ -507,17 +507,17 @@ export class Trie { let stopped = false const walkController = { - stop: function() { + stop: function () { stopped = true cb() }, // end all traversal and return values to the onDone cb - return: function(...args: any) { + return: function (...args: any) { aborted = true returnValues = args cb() }, - next: function() { + next: function () { if (aborted || stopped) { return cb() } @@ -530,7 +530,7 @@ export class Trie { if (node instanceof ExtensionNode) { children = [[node.key, node.value]] } else if (node instanceof BranchNode) { - children = node.getChildren().map(b => [[b[0]], b[1]]) + children = node.getChildren().map((b) => [[b[0]], b[1]]) } async.forEachOf( children, @@ -552,7 +552,7 @@ export class Trie { cb, ) }, - only: function(childIndex: number) { + only: function (childIndex: number) { if (!(node instanceof BranchNode)) { return cb(new Error('Expected branch node')) } diff --git a/src/checkpointTrie.ts b/src/checkpointTrie.ts index 4a5b71f..c4a3f67 100644 --- a/src/checkpointTrie.ts +++ b/src/checkpointTrie.ts @@ -137,9 +137,7 @@ export class CheckpointTrie extends BaseTrie { this.db = this._mainDB if (commitState) { - this._createScratchReadStream(scratch) - .pipe(WriteStream(this.db._leveldb)) - .on('close', cb) + this._createScratchReadStream(scratch).pipe(WriteStream(this.db._leveldb)).on('close', cb) } else { async.nextTick(cb) } diff --git a/src/util/async.ts b/src/util/async.ts index 2a4cc58..3a7ddc4 100644 --- a/src/util/async.ts +++ b/src/util/async.ts @@ -9,10 +9,10 @@ export function callTogether(...funcs: Function[]) { const index = length if (!length) { - return function() {} + return function () {} } - return function(this: any, ...args: any) { + return function (this: any, ...args: any) { length = index while (length--) { @@ -33,9 +33,9 @@ export function asyncFirstSeries(array: any[], iterator: Function, cb: Function) var didComplete = false async.eachSeries( array, - function(item: any, next: Function) { + function (item: any, next: Function) { if (didComplete) return next - iterator(item, function(err: Error, result: any) { + iterator(item, function (err: Error, result: any) { if (result) { didComplete = true process.nextTick(cb.bind(null, null, result)) @@ -43,7 +43,7 @@ export function asyncFirstSeries(array: any[], iterator: Function, cb: Function) next(err) }) }, - function() { + function () { if (!didComplete) { cb() }