diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..852cb38 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,43 @@ +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, 14.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 test + + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + + test-browser: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v1 + with: + node-version: 12.x + + - uses: actions/checkout@v1 + + - run: npm install + - run: npm run test:browser + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 62cc53f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,28 +0,0 @@ -language: node_js -node_js: - - "8" - - "10" -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 -branches: - # We need to whitelist the branches which we want to have "push" automation. - # Pull request automation is not constrained to this set of branches. - only: - - master -env: - matrix: - - CXX=g++-4.8 TEST_SUITE=test -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 -script: npm run $TEST_SUITE diff --git a/README.md b/README.md index 18455db..a7ebcbc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ethereumjs-wallet [![NPM Package](https://img.shields.io/npm/v/ethereumjs-wallet.svg?style=flat-square)](https://www.npmjs.org/package/ethereumjs-wallet) -[![Build Status](https://travis-ci.org/ethereumjs/ethereumjs-wallet.svg?branch=master)](https://travis-ci.org/ethereumjs/ethereumjs-wallet) +[![Actions Status](https://github.com/ethereumjs/ethereumjs-wallet/workflows/Build/badge.svg)](https://github.com/ethereumjs/ethereumjs-wallet/actions) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/ethereumjs-wallet.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/ethereumjs-wallet) [![Gitter](https://img.shields.io/gitter/room/ethereum/ethereumjs-lib.svg?style=flat-square)](https://gitter.im/ethereum/ethereumjs-lib) or #ethereumjs on freenode diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..d11df0c --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,27 @@ +module.exports = function(config) { + config.set({ + frameworks: ['mocha', 'karma-typescript'], + files: ['src/**/*.ts', 'test/**/*.ts'], + preprocessors: { + '**/*.ts': ['karma-typescript'], + }, + plugins: ['karma-mocha', 'karma-typescript', 'karma-chrome-launcher', 'karma-firefox-launcher'], + karmaTypescriptConfig: { + bundlerOptions: { + entrypoints: /\.spec\.ts$/, + acornOptions: { + ecmaVersion: 8, + }, + transforms: [require('karma-typescript-es6-transform')()], + }, + }, + colors: true, + reporters: ['progress', 'karma-typescript'], + browsers: ['FirefoxHeadless', 'ChromeHeadless'], + singleRun: true, + concurrency: Infinity, + // Extend timeouts for long tests + browserDisconnectTimeout: 1000000, + browserNoActivityTimeout: 1000000, + }) +} diff --git a/package.json b/package.json index 4d36ad5..55287be 100644 --- a/package.json +++ b/package.json @@ -12,13 +12,12 @@ "prepublishOnly": "npm run format && npm run tslint && npm run test", "docs:build": "typedoc --out docs --mode file --readme none --theme markdown --mdEngine github --excludeNotExported src", "coverage": "ethereumjs-config-coverage", - "coveralls": "ethereumjs-config-coveralls", "format": "ethereumjs-config-format", "format:fix": "ethereumjs-config-format-fix", "lint": "ethereumjs-config-lint", "lint:fix": "ethereumjs-config-lint-fix", - "pretest": "npm run build", - "test": "nyc mocha ./test/**/*.ts", + "test": "npm run build && nyc --reporter=lcov mocha ./test/**/*.ts", + "test:browser": "karma start karma.conf.js", "tsc": "ethereumjs-config-tsc", "tslint": "ethereumjs-config-tslint", "tslint:fix": "ethereumjs-config-tslint-fix" @@ -62,19 +61,24 @@ "@types/lodash.zip": "^4.2.6", "@types/mocha": "^5.2.7", "@types/node": "^12.0.10", - "coveralls": "^3.0.0", "ethers": "^4.0.33", "husky": "^2.1.0", + "karma": "^5.0.2", + "karma-chrome-launcher": "^2.0.0", + "karma-firefox-launcher": "^1.0.0", + "karma-mocha": "^2.0.0", + "karma-typescript": "^4.1.1", + "karma-typescript-es6-transform": "^5.0.2", "lodash.zip": "^4.2.0", - "mocha": "^5.2.0", - "nyc": "^14.1.1", + "mocha": "^7.1.2", + "nyc": "^15.0.1", "prettier": "^1.15.3", "source-map-support": "^0.5.12", - "ts-node": "^8.3.0", + "ts-node": "^8.9.1", "tslint": "^5.12.0", - "typescript": "^3.2.2", - "typestrict": "^1.0.2", "typedoc": "^0.14.2", - "typedoc-plugin-markdown": "^1.2.0" + "typedoc-plugin-markdown": "^1.2.0", + "typescript": "^3.8.3", + "typestrict": "^1.0.2" } } diff --git a/test/hdkey.ts b/test/hdkey.spec.ts similarity index 100% rename from test/hdkey.ts rename to test/hdkey.spec.ts diff --git a/test/index.ts b/test/index.spec.ts similarity index 98% rename from test/index.ts rename to test/index.spec.ts index 3c8c724..abd1b85 100644 --- a/test/index.ts +++ b/test/index.spec.ts @@ -24,6 +24,10 @@ const fixturePublicKeyBuffer = Buffer.from(fixturePublicKey, 'hex') const fixtureWallet = Wallet.fromPrivateKey(fixturePrivateKeyBuffer) const fixtureEthersWallet = new ethersWallet(fixtureWallet.getPrivateKeyString()) +const isRunningInKarma = () => { + return typeof (global as any).window !== 'undefined' && (global as any).window.__karma__ +} + describe('.getPrivateKey()', function() { it('should work', function() { assert.strictEqual(fixtureWallet.getPrivateKey().toString('hex'), fixturePrivateKey) @@ -212,7 +216,7 @@ describe('.toV3()', function() { const makePermutations = (...objs: Array): Array => { const permus = [] const keys = Array.from( - objs.reduce((acc: Set, curr: object) => { + objs.reduce((acc: any, curr: object) => { Object.keys(curr).forEach(key => { acc.add(key) }) @@ -246,7 +250,13 @@ describe('.toV3()', function() { return obj } - const permutations = makePermutations(strKdfOptions, buffKdfOptions) + let permutations = makePermutations(strKdfOptions, buffKdfOptions) + + if (isRunningInKarma()) { + // These tests take a long time in the browser due to + // the amount of permutations so we will shorten them. + permutations = permutations.slice(1) + } it('should work with PBKDF2', async function() { this.timeout(0) // never @@ -669,6 +679,7 @@ describe('.fromV3()', function() { it('should fail with invalid password', function() { const w = '{"crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}' + this.timeout(0) // never assert.throws(function() { Wallet.fromV3(w, 'wrongtestpassword') }, /^Error: Key derivation failed - possibly wrong passphrase$/) @@ -676,12 +687,14 @@ describe('.fromV3()', function() { it('should work with (broken) mixed-case input files', function() { const w = '{"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}' + this.timeout(0) // never const wallet = Wallet.fromV3(w, 'testpassword', true) assert.strictEqual(wallet.getAddressString(), '0x008aeeda4d805471df9b2a5b0f38a0c3bcba786b') }) it("shouldn't work with (broken) mixed-case input files in strict mode", function() { const w = '{"Crypto":{"cipher":"aes-128-ctr","cipherparams":{"iv":"6087dab2f9fdbbfaddc31a909735c1e6"},"ciphertext":"5318b4d5bcd28de64ee5559e671353e16f075ecae9f99c7a79a38af5f869aa46","kdf":"pbkdf2","kdfparams":{"c":262144,"dklen":32,"prf":"hmac-sha256","salt":"ae3cd4e7013836a3df6bd7241b12db061dbe2c6785853cce422d148a624ce0bd"},"mac":"517ead924a9d0dc3124507e3393d175ce3ff7c1e96529c6c555ce9e51205e9b2"},"id":"3198bc9c-6672-5ab3-d995-4942343ae5b6","version":3}' + this.timeout(0) // never assert.throws(function() { Wallet.fromV3(w, 'testpassword') }) // FIXME: check for assert message(s) @@ -760,6 +773,7 @@ describe('.fromKryptoKit()', function() { 'qhah1VeT0RgTvff1UKrUrxtFViiQuki16dd353d59888c25', 'testtest', ) + this.timeout(0) // never assert.strictEqual(wallet.getAddressString(), '0x3c753e27834db67329d1ec1fab67970ec1e27112') }) })