ADD browser-tests

state-channel
pubkey 7 years ago
parent 5585135151
commit 5c1d109abd
  1. 7
      .travis.yml
  2. 0
      config/.eslintignore
  3. 57
      config/karma.conf.js
  4. 12
      package.json
  5. 62
      test/performance.test.js

@ -3,8 +3,13 @@ os:
- linux
node_js:
- "9.4.0"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
script:
- npm install --depth 0 --silent
- npm run lint
- npm run build
- npm test
- npm run test:node
- travis_retry npm run test:browser

@ -0,0 +1,57 @@
const configuration = {
basePath: '',
frameworks: [
'mocha',
'browserify'
],
files: [
'../test/unit.test.js',
'../test/performance.test.js'
],
port: 9876,
colors: true,
autoWatch: false,
// Karma plugins loaded
plugins: [
'karma-mocha',
'karma-browserify',
'karma-chrome-launcher'
],
// Source files that you wanna generate coverage for.
// Do not include tests or libraries (these files will be instrumented by Istanbul)
preprocessors: {
'../test/*.test.js': ['browserify']
},
client: {
mocha: {
bail: true,
timeout: 6000
}
},
browsers: ['ChromeNoSandbox'],
browserDisconnectTimeout: 6000,
processKillTimeout: 6000,
customLaunchers: {
ChromeNoSandbox: {
base: 'Chrome',
flags: ['--no-sandbox']
}
},
singleRun: true
};
if (process.env.TRAVIS) {
/**
* overwrite reporters-default
* So no big list will be shown at log
*/
configuration.reporters = [];
}
module.exports = function(config) {
config.set(configuration);
};

@ -19,8 +19,10 @@
"module": "./dist/es/index.js",
"types": "./typings/index.d.ts",
"scripts": {
"test": "npm run build && mocha ./test/index.test.js -b --timeout 6000 --exit",
"lint": "eslint src test scripts && solhint \"contracts/**/*.sol\"",
"test": "npm run test:node && npm run test:browser",
"test:node": "npm run build && mocha ./test/index.test.js -b --timeout 6000 --exit",
"test:browser": "npm run build && karma start ./config/karma.conf.js --single-run",
"lint": "eslint --ignore-path ./config/.eslintignore src test config scripts && solhint \"contracts/**/*.sol\"",
"clear": "rimraf -rf ./dist",
"build:sol": "mkdir -p ./gen && node ./scripts/compile-contract.node.js",
"build:es6": "rimraf -rf dist/es && cross-env NODE_ENV=es6 babel src --out-dir dist/es",
@ -66,6 +68,12 @@
"eslint": "4.18.1",
"ganache-cli": "6.0.3",
"js-sha3": "0.7.0",
"karma": "2.0.0",
"karma-babel-preprocessor": "7.0.0",
"karma-browserify": "5.2.0",
"karma-chrome-launcher": "2.2.0",
"karma-coverage": "1.1.1",
"karma-mocha": "1.3.0",
"mocha": "5.0.1",
"node": "9.5.0",
"rimraf": "2.6.2",

@ -10,19 +10,35 @@ const benchmark = {
decryptWithPrivateKey: {}
};
const nowTime = () => {
try {
return process.hrtime();
} catch (err) {
return performance.now();
}
};
const elapsedTime = before => {
try {
return convertHrtime(process.hrtime(before)).milliseconds;
} catch (err) {
return performance.now() - before;
}
};
describe('performance.test.js', () => {
describe('.sign()', () => {
it('sameKey', async () => {
// prepare
const identity = EthCrypto.createIdentity();
const runs = 300;
const runs = 200;
const hashes = new Array(runs)
.fill(0)
.map(() => AsyncTestUtil.randomString(12))
.map(s => EthCrypto.hash.keccak256(s).replace(/^.{2}/g, ''));
// run
const startTime = process.hrtime();
const startTime = nowTime();
for (let i = 0; i < runs; i++) {
const hash = hashes.pop();
EthCrypto.sign(
@ -31,8 +47,8 @@ describe('performance.test.js', () => {
);
}
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.sign.sameKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.sign.sameKey = elapsed;
});
it('otherKey', async () => {
// prepare
@ -46,7 +62,7 @@ describe('performance.test.js', () => {
.map(() => EthCrypto.createIdentity().privateKey);
// run
const startTime = process.hrtime();
const startTime = nowTime();
for (let i = 0; i < runs; i++) {
const hash = hashes.pop();
const key = keys.pop();
@ -56,15 +72,15 @@ describe('performance.test.js', () => {
);
}
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.sign.otherKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.sign.otherKey = elapsed;
});
});
describe('.recoverPublicKey()', () => {
it('run', async () => {
// prepare
const identity = EthCrypto.createIdentity();
const runs = 300;
const runs = 200;
const hashes = new Array(runs)
.fill(0)
.map(() => AsyncTestUtil.randomString(12))
@ -76,7 +92,7 @@ describe('performance.test.js', () => {
));
// run
const startTime = process.hrtime();
const startTime = nowTime();
for (let i = 0; i < runs; i++) {
const sig = signatures.pop();
const hash = hashes.pop();
@ -86,8 +102,8 @@ describe('performance.test.js', () => {
);
}
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.recoverPublicKey.sameKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.recoverPublicKey.sameKey = elapsed;
});
});
describe('.encryptWithPublicKey()', () => {
@ -95,14 +111,14 @@ describe('performance.test.js', () => {
// prepare
const identity = EthCrypto.createIdentity();
const runs = 1000;
const runs = 200;
const hashes = new Array(runs)
.fill(0)
.map(() => AsyncTestUtil.randomString(12))
.map(s => EthCrypto.hash.keccak256(s));
// run
const startTime = process.hrtime();
const startTime = nowTime();
await Promise.all(
new Array(runs)
@ -116,12 +132,12 @@ describe('performance.test.js', () => {
})
);
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.encryptWithPublicKey.sameKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.encryptWithPublicKey.sameKey = elapsed;
});
it('otherKey', async () => {
// prepare
const runs = 1000;
const runs = 200;
const hashes = new Array(runs)
.fill(0)
.map(() => AsyncTestUtil.randomString(12))
@ -131,7 +147,7 @@ describe('performance.test.js', () => {
.map(() => EthCrypto.createIdentity().publicKey);
// run
const startTime = process.hrtime();
const startTime = nowTime();
await Promise.all(
new Array(runs)
.fill(0)
@ -145,8 +161,8 @@ describe('performance.test.js', () => {
})
);
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.encryptWithPublicKey.otherKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.encryptWithPublicKey.otherKey = elapsed;
});
});
describe('.decryptWithPrivateKey()', () => {
@ -154,7 +170,7 @@ describe('performance.test.js', () => {
// prepare
const identity = EthCrypto.createIdentity();
const runs = 1000;
const runs = 200;
const hashes = await Promise.all(
new Array(runs)
.fill(0)
@ -167,7 +183,7 @@ describe('performance.test.js', () => {
);
// run
const startTime = process.hrtime();
const startTime = nowTime();
await Promise.all(
new Array(runs)
.fill(0)
@ -181,8 +197,8 @@ describe('performance.test.js', () => {
})
);
const elapsed = convertHrtime(process.hrtime(startTime));
benchmark.decryptWithPrivateKey.sameKey = elapsed.milliseconds;
const elapsed = elapsedTime(startTime);
benchmark.decryptWithPrivateKey.sameKey = elapsed;
});
});
describe('show', () => {

Loading…
Cancel
Save