mirror of https://github.com/status-im/web3.js.git
first integration tests
This commit is contained in:
parent
a4cf661f24
commit
89b1ca6f43
|
@ -1117,7 +1117,7 @@ var shh = require('./web3/shh');
|
|||
var watches = require('./web3/watches');
|
||||
var filter = require('./web3/filter');
|
||||
var utils = require('./utils/utils');
|
||||
var formatters = require('./solidity/formatters');
|
||||
var formatters = require('./web3/formatters');
|
||||
var RequestManager = require('./web3/requestmanager');
|
||||
var c = require('./utils/config');
|
||||
var Method = require('./web3/method');
|
||||
|
@ -1128,7 +1128,7 @@ var web3Methods = function () {
|
|||
name: 'sha3',
|
||||
call: 'web3_sha3',
|
||||
params: 1,
|
||||
inputFormatter: utils.toHex
|
||||
inputFormatter: function (args) { return [utils.toHex(args[0])]; }
|
||||
});
|
||||
|
||||
return [sha3];
|
||||
|
@ -1362,7 +1362,7 @@ setupMethods(shhWatch, watches.shh());
|
|||
module.exports = web3;
|
||||
|
||||
|
||||
},{"./solidity/formatters":2,"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/db":10,"./web3/eth":12,"./web3/filter":14,"./web3/method":18,"./web3/net":19,"./web3/requestmanager":21,"./web3/shh":22,"./web3/watches":24}],9:[function(require,module,exports){
|
||||
},{"./utils/config":5,"./utils/utils":6,"./version.json":7,"./web3/db":10,"./web3/eth":12,"./web3/filter":14,"./web3/formatters":15,"./web3/method":18,"./web3/net":19,"./web3/requestmanager":21,"./web3/shh":22,"./web3/watches":24}],9:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of ethereum.js.
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -32,7 +32,7 @@ var shh = require('./web3/shh');
|
|||
var watches = require('./web3/watches');
|
||||
var filter = require('./web3/filter');
|
||||
var utils = require('./utils/utils');
|
||||
var formatters = require('./solidity/formatters');
|
||||
var formatters = require('./web3/formatters');
|
||||
var RequestManager = require('./web3/requestmanager');
|
||||
var c = require('./utils/config');
|
||||
var Method = require('./web3/method');
|
||||
|
@ -43,7 +43,7 @@ var web3Methods = function () {
|
|||
name: 'sha3',
|
||||
call: 'web3_sha3',
|
||||
params: 1,
|
||||
inputFormatter: utils.toHex
|
||||
inputFormatter: function (args) { return [utils.toHex(args[0])]; }
|
||||
});
|
||||
|
||||
return [sha3];
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var web3 = require('../index');
|
||||
var FakeHttpProvider = require('./FakeHttpProvider');
|
||||
|
||||
describe('eth', function () {
|
||||
describe('getBalance', function () {
|
||||
it('should get balance synchronously', function () {
|
||||
|
||||
// given
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
var address = '0x12d';
|
||||
var blockNumber = '0x1';
|
||||
var expected = '0x31981';
|
||||
provider.injectResult(expected);
|
||||
var validation = function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_getBalance');
|
||||
assert.deepEqual(payload.params, [address, blockNumber]);
|
||||
};
|
||||
provider.injectValidation(validation);
|
||||
|
||||
// when
|
||||
var result = web3.eth.getBalance(address, blockNumber);
|
||||
|
||||
// then
|
||||
assert.equal(expected, result);
|
||||
});
|
||||
|
||||
it('should get balance asynchronously', function (done) {
|
||||
|
||||
// given
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
var address = '0x12d';
|
||||
var blockNumber = '0x1';
|
||||
var expected = '0x31981';
|
||||
provider.injectResult(expected);
|
||||
var validation = function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'eth_getBalance');
|
||||
assert.deepEqual(payload.params, [address, blockNumber]);
|
||||
};
|
||||
provider.injectValidation(validation);
|
||||
var callback = function (err, result) {
|
||||
assert.equal(expected, result);
|
||||
done();
|
||||
};
|
||||
|
||||
// when
|
||||
web3.eth.getBalance(address, blockNumber, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,13 +1,16 @@
|
|||
var web3 = require('../index');
|
||||
var assert = require('assert');
|
||||
|
||||
var methodExists = function (object, method) {
|
||||
it('should have method ' + method + ' implemented', function() {
|
||||
web3.setProvider(null);
|
||||
assert.equal('function', typeof object[method], 'method ' + method + ' is not implemented');
|
||||
});
|
||||
};
|
||||
|
||||
var propertyExists = function (object, property) {
|
||||
it('should have property ' + property + ' implemented', function() {
|
||||
web3.setProvider(null);
|
||||
assert.notEqual('undefined', typeof object[property], 'property ' + property + ' is not implemented');
|
||||
});
|
||||
};
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
var chai = require('chai');
|
||||
var assert = chai.assert;
|
||||
var web3 = require('../index');
|
||||
var FakeHttpProvider = require('./FakeHttpProvider');
|
||||
|
||||
describe('web3', function () {
|
||||
describe('sha3', function () {
|
||||
it('should get simple sha3 payload synchronously', function () {
|
||||
|
||||
// given
|
||||
var provider = new FakeHttpProvider();
|
||||
web3.setProvider(provider);
|
||||
var input = '0x12d';
|
||||
var expected = '0x31981';
|
||||
provider.injectResult(expected);
|
||||
var validation = function (payload) {
|
||||
assert.equal(payload.jsonrpc, '2.0');
|
||||
assert.equal(payload.method, 'web3_sha3');
|
||||
assert.deepEqual(payload.params, [input]);
|
||||
};
|
||||
provider.injectValidation(validation);
|
||||
|
||||
// when
|
||||
var result = web3.sha3(input);
|
||||
|
||||
// then
|
||||
assert.equal(expected, result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue