fixed tests

This commit is contained in:
Fabian Vogelsteller 2015-03-06 16:09:21 +01:00
commit b8193914cb
12 changed files with 399 additions and 36 deletions

View File

@ -59,8 +59,6 @@ For another example see `example/index.html`.
* Node.js
* npm
* gulp (build)
* mocha (tests)
```bash
sudo apt-get update
@ -82,6 +80,15 @@ npm run-script build
npm test
```
### Testing (karma)
Karma allows testing within one or several browsers.
```bash
npm run-script karma # default browsers are Chrome and Firefox
npm run-script karma -- --browsers="Chrome,Safari" # custom browsers
```
**Please note this repo is in it's early stage.**
If you'd like to run a Http ethereum node check out

4
dist/ethereum.js vendored
View File

@ -750,6 +750,7 @@ var outputParser = function (event) {
var result = {
event: utils.extractDisplayName(event.name),
number: output.number,
hash: output.hash,
args: {}
};
@ -1929,8 +1930,7 @@ var filterEvents = function (json) {
// DEPRECATED
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)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

96
karma.conf.js Normal file
View File

@ -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: true, 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: {
chromeWithoutSecurity: {
base: 'Chrome',
flags: ['--disable-web-security']
},
IE9: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE8: {
base: 'IE',
'x-ua-compatible': 'IE=EmulateIE8'
}
}
});
};

View File

@ -97,6 +97,7 @@ var outputParser = function (event) {
var result = {
event: utils.extractDisplayName(event.name),
number: output.number,
hash: output.hash,
args: {}
};

View File

@ -133,8 +133,7 @@ var filterEvents = function (json) {
// DEPRECATED
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)

View File

@ -9,6 +9,8 @@
},
"dependencies": {
"bignumber.js": ">=2.0.0",
"envify": "^3.0.0",
"unreachable-branch-transform": "^0.1.0",
"xmlhttprequest": "*"
},
"devDependencies": {
@ -16,7 +18,6 @@
"browserify": ">=6.0",
"coveralls": "^2.11.2",
"del": ">=0.1.1",
"envify": "^3.0.0",
"exorcist": "^0.1.6",
"gulp": ">=3.4.0",
"gulp-jshint": ">=1.5.0",
@ -25,9 +26,13 @@
"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",
"unreachable-branch-transform": "^0.1.0",
"vinyl-source-stream": "^1.0.0"
},
"scripts": {
@ -35,7 +40,8 @@
"watch": "gulp watch",
"lint": "gulp lint",
"test": "mocha",
"test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose"
"test-coveralls": "istanbul cover _mocha -- -R spec && cat coverage/lcov.info | coveralls --verbose",
"karma": "./node_modules/karma/bin/karma start --singleRun=true --browsers=\"Chrome,Firefox\""
},
"repository": {
"type": "git",

View File

@ -22,11 +22,12 @@ describe('contract', function() {
}];
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});
it('should create simple contract with one method from abi with implicit type name', function () {
@ -49,11 +50,12 @@ describe('contract', function() {
}];
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});
it('should create contract with multiple methods', function () {
@ -90,13 +92,14 @@ describe('contract', function() {
}];
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
assert.equal('function', typeof con.test2);
assert.equal('function', typeof con.test2['uint256']);
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
assert.equal('function', typeof myCon.test2);
assert.equal('function', typeof myCon.test2['uint256']);
});
it('should create contract with overloaded methods', function () {
@ -133,12 +136,13 @@ describe('contract', function() {
}];
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
assert.equal('function', typeof con.test['string']);
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
assert.equal('function', typeof myCon.test['string']);
});
it('should create contract with no methods', function () {
@ -161,10 +165,11 @@ describe('contract', function() {
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('undefined', typeof con.test);
assert.equal('undefined', typeof myCon.test);
});
@ -189,11 +194,12 @@ describe('contract', function() {
// when
var con = contract(null, description);
var Con = contract(description);
var myCon = new Con(null);
// then
assert.equal('function', typeof con.test);
assert.equal('function', typeof con.test['uint256']);
assert.equal('function', typeof myCon.test);
assert.equal('function', typeof myCon.test['uint256']);
});

View File

@ -24,14 +24,15 @@ describe('web3', function() {
u.methodExists(web3.eth, 'contract');
u.propertyExists(web3.eth, 'coinbase');
u.propertyExists(web3.eth, 'listening');
u.propertyExists(web3.eth, 'mining');
u.propertyExists(web3.eth, 'gasPrice');
u.propertyExists(web3.eth, 'accounts');
u.propertyExists(web3.eth, 'peerCount');
u.propertyExists(web3.eth, 'defaultBlock');
u.propertyExists(web3.eth, 'blockNumber');
});
});

10
test/net.methods.js Normal file
View File

@ -0,0 +1,10 @@
var assert = require('assert');
var web3 = require('../index.js');
var u = require('./test.utils.js');
describe('web3', function() {
describe('net', function() {
u.propertyExists(web3.net, 'listening');
u.propertyExists(web3.net, 'peerCount');
});
});

237
test/utils.convert.js Normal file
View File

@ -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);
});
});
});