From af5fef01ea51aa24c938293982b2ac963d0025ba Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Thu, 5 Mar 2015 23:17:49 +0100 Subject: [PATCH 1/4] test(karma): Add Karma support - Karma support for Chrome, Firefox, Safari --- karma.conf.js | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 7 ++++ 2 files changed, 103 insertions(+) create mode 100644 karma.conf.js diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..aa26fd2 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,96 @@ +// Karma configuration +// Generated on Thu Feb 19 2015 19:57:47 GMT+0100 (W. Europe Standard Time) + +module.exports = function (config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, logLevel: config.LOG_INFO, + //singleRun: true, logLevel: config.LOG_DEBUG, + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['browserify', 'mocha'], + + + // list of files / patterns to load in the browser + files: [ + 'test/*.js', + + ], + + + // list of files to exclude + exclude: [ + ], + + client: { + mocha: { + //ui: 'tdd' + timeout: 5000 // especially for the post requests + } + }, + browserify: { + bundleDelay: 750, + debug: true + // transform: [], + // //extensions: ['.js'] + }, + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + 'test/*.js': ['browserify'] + }, + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['dots'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + // // Chrome + // // PhantomJS + browsers: ['Chrome', 'Safari', 'Firefox'], + browserNoActivityTimeout: 10000, + browserDisconnectTimeout: 5000, + + customLaunchers: { + chrome_without_security: { + base: 'Chrome', + flags: ['--disable-web-security'] + }, + + IE9: { + base: 'IE', + 'x-ua-compatible': 'IE=EmulateIE9' + }, + IE8: { + base: 'IE', + 'x-ua-compatible': 'IE=EmulateIE8' + } + } + }); +}; diff --git a/package.json b/package.json index 340200d..a404336 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,15 @@ "gulp-uglify": ">=1.0.0", "istanbul": "^0.3.5", "jshint": ">=2.5.0", + "karma": "^0.12.31", + "karma-browserify": "^4.0.0", + "karma-chrome-launcher": "^0.1.7", + "karma-firefox-launcher": "^0.1.4", + "karma-mocha": "^0.1.10", + "karma-safari-launcher": "^0.1.1", "mocha": ">=2.1.0", "mocha-lcov-reporter": "0.0.1", + "phantomjs": "^1.9.16", "unreachable-branch-transform": "^0.1.0", "vinyl-source-stream": "^1.0.0" }, From 1e0d76e687442a9ed8747984165bbc52c7d6886f Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Thu, 5 Mar 2015 23:20:55 +0100 Subject: [PATCH 2/4] Remove phantomjs --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a404336..12355ec 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "karma-safari-launcher": "^0.1.1", "mocha": ">=2.1.0", "mocha-lcov-reporter": "0.0.1", - "phantomjs": "^1.9.16", "unreachable-branch-transform": "^0.1.0", "vinyl-source-stream": "^1.0.0" }, From e46f6f156b53858212f9ab0abf1df96cc171b375 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Fri, 6 Mar 2015 01:03:19 +0100 Subject: [PATCH 3/4] test(utils): Add test for the toEth() function - Several test cases to check the conversion into each unit - Few test cases to check the conversion from strings --- lib/utils.js | 2 +- test/utils.convert.js | 237 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 238 insertions(+), 1 deletion(-) create mode 100644 test/utils.convert.js diff --git a/lib/utils.js b/lib/utils.js index f88e6ab..2ac02ea 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -108,7 +108,7 @@ var filterEvents = function (json) { /// TODO: add tests for it! var toEth = function (str) { /*jshint maxcomplexity:7 */ - var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; + var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str.replace(/,/g,'').replace(/ /g,'')) : str; var unit = 0; var units = c.ETH_UNITS; while (val > 3000 && unit < units.length - 1) diff --git a/test/utils.convert.js b/test/utils.convert.js new file mode 100644 index 0000000..2287574 --- /dev/null +++ b/test/utils.convert.js @@ -0,0 +1,237 @@ +var assert = require('assert'); +var utils = require('../lib/utils.js'); + +describe('utils', function() { + + // given + // NOTE: I made the following tests pass as long as the values are mathematically correct. + // However, in the current state, there are inconsistancy regarding the trailing decimals. + // For instance '10 Mether' but '10.00 Gether' + var data = [{ + test: 10e-9, + res: '0.00 wei' + }, { + test: 10e-6, + res: '0.00 wei' + }, { + test: 10e-3, + res: '0.01 wei' + }, { + test: '-10', + res: '-10 wei' + }, { + test: '0', + res: '0 wei' + }, { + test: 0, + res: '0 wei' + }, { + test: '1200000', + res: '1200 Kwei' + }, { + test: 1e3, + res: '1000 wei' + }, { + test: 10e3, + res: '10 Kwei' + }, { + test: 100e3, + res: '100 Kwei' + }, { + test: 1000e3, + res: '1000 Kwei' + }, { + test: 10e6, + res: '10 Mwei' + }, { + test: 100e6, + res: '100 Mwei' + }, { + test: 1000e6, + res: '1000 Mwei' + }, { + test: 10e9, + res: '10 Gwei' + }, { + test: 100e9, + res: '100 Gwei' + }, { + test: 1000e9, + res: '1000 Gwei' + }, { + test: 10e12, + res: '10 szabo' + }, { + test: 100e12, + res: '100 szabo' + }, { + test: 1000e12, + res: '1000 szabo' + }, { + test: 10e15, + res: '10 finney' + }, { + test: 100e15, + res: '100 finney' + }, { + test: 1000e15, + res: '1000 finney' + }, { + test: 10e18, + res: '10 ether' + }, { + test: 100e18, + res: '100 ether' + }, { + test: 1000e18, + res: '1000 ether' + }, { + test: 10e21, + res: '10 grand' + }, { + test: 100e21, + res: '100.00 grand' + }, { + test: 1000e21, + res: '1000 grand' + }, { + test: 10e24, + res: '10 Mether' + }, { + test: 100e24, + res: '100.00 Mether' + }, { + test: 1000e24, + res: '1000 Mether' + }, { + test: 10e27, + res: '10.00 Gether' + }, { + test: 100e27, + res: '100.00 Gether' + }, { + test: 1000e27, + res: '1000 Gether' + }, { + test: 10e30, + res: '10.00 Tether' + }, { + test: 100e30, + res: '100.00 Tether' + }, { + test: 1000e30, + res: '1,000.00 Tether' + }, { + test: 10e33, + res: '10.00 Pether' + }, { + test: 100e33, + res: '100.00 Pether' + }, { + test: 1000e33, + res: '1000 Pether' + }, { + test: 10e36, + res: '10.00 Eether' + }, { + test: 100e36, + res: '100.00 Eether' + }, { + test: 1000e36, + res: '1,000.00 Eether' + }, { + test: 10e39, + res: '10 Zether' + }, { + test: 100e39, + res: '100.00 Zether' + }, { + test: 1000e39, + res: '1000 Zether' + }, { + test: 10e42, + res: '10 Yether' + }, { + test: 100e42, + res: '100.00 Yether' + }, { + test: 1000e42, + res: '1,000.00 Yether' + }, { + test: 10e45, + res: '10 Nether' + }, { + test: 100e45, + res: '100.00 Nether' + }, { + test: 1000e45, + res: '1000 Nether' + }, { + test: 10e48, + res: '10 Dether' + }, { + test: 100e48, + res: '100.00 Dether' + }, { + test: 1000e48, + res: '1000 Dether' + }, { + test: 10e51, + res: '10 Vether' + }, { + test: 100e51, + res: '100.00 Vether' + }, { + test: 1000e51, + res: '1,000.00 Vether' + }, { + test: 10e54, + res: '10 Uether' + }, { + test: 10e57, + res: '10000 Uether' + }, { + test: 100e57, + res: '100,000.00 Uether' + }, { + test: 1000e57, + res: '1,000,000.00 Uether' + }, { + test: '10', + res: utils.toEth(10) + }, { + test: '100', + res: utils.toEth(100) + }, { + test: '1000', + res: utils.toEth(1000) + }, { + test: '1001', + res: utils.toEth(1001) + }, { + test: '999', + res: utils.toEth(999) + }, { + test: '10000000000000000000000', + res: utils.toEth(10e21) // 10 grand + }, { + test: '10 000', + res: '10 Kwei' + }, { + test: '10,000', + res: '10 Kwei' + }, { + test: '10,000.00', + res: '10 Kwei' + }]; + + data.forEach(function(elem) { + it('should convert ' + elem.test + ' into ' + elem.res, function() { + // when + var res = utils.toEth(elem.test); + + // then + assert.equal(res, elem.res); + }); + }); +}); From 833b8100384542433290bc43f5541a5c38ec93e7 Mon Sep 17 00:00:00 2001 From: Wilfried Kopp Date: Fri, 6 Mar 2015 01:14:01 +0100 Subject: [PATCH 4/4] doc(readme): Information about Karma in the readme test(karma): Fix variable to make linter happy --- README.md | 8 ++++++++ karma.conf.js | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30c20aa..8ef3ba5 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,14 @@ npm run-script build npm test ``` +### Testing (karma) +Karma allows testing within one or several browser. + +```bash +karma start --singleRun=true --browsers="Chrome,Firefox" +``` + + **Please note this repo is in it's early stage.** If you'd like to run a Http ethereum node check out diff --git a/karma.conf.js b/karma.conf.js index aa26fd2..0ed5a15 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -78,7 +78,7 @@ module.exports = function (config) { browserDisconnectTimeout: 5000, customLaunchers: { - chrome_without_security: { + chromeWithoutSecurity: { base: 'Chrome', flags: ['--disable-web-security'] },