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

Commit

Permalink
Add karma test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Apr 30, 2020
1 parent 456f369 commit 1ec76aa
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,16 @@ jobs:
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

27 changes: 27 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -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,
})
}
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"format:fix": "ethereumjs-config-format-fix",
"lint": "ethereumjs-config-lint",
"lint:fix": "ethereumjs-config-lint-fix",
"test": "npm run build && nyc --reporter=lcov mocha ./test/**/*.ts && npm run test:browser",
"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"
Expand Down Expand Up @@ -63,6 +64,12 @@
"@types/node": "^12.0.10",
"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": "^7.1.2",
"nyc": "^15.0.1",
Expand Down
18 changes: 16 additions & 2 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -212,7 +216,7 @@ describe('.toV3()', function() {
const makePermutations = (...objs: Array<object>): Array<object> => {
const permus = []
const keys = Array.from(
objs.reduce((acc: Set<string>, curr: object) => {
objs.reduce((acc: any, curr: object) => {
Object.keys(curr).forEach(key => {
acc.add(key)
})
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -669,19 +679,22 @@ 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$/)
})
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)
Expand Down Expand Up @@ -760,6 +773,7 @@ describe('.fromKryptoKit()', function() {
'qhah1VeT0RgTvff1UKrUrxtFViiQuki16dd353d59888c25',
'testtest',
)
this.timeout(0) // never
assert.strictEqual(wallet.getAddressString(), '0x3c753e27834db67329d1ec1fab67970ec1e27112')
})
})
Expand Down

0 comments on commit 1ec76aa

Please sign in to comment.