Skip to content

Commit 10e79d6

Browse files
committed
uncommented few more tests
1 parent 190f981 commit 10e79d6

20 files changed

+105
-240
lines changed

lib/web3/allevents.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var utils = require('../utils/utils');
2727
var Filter = require('./filter');
2828
var watches = require('./methods/watches');
2929

30-
var AllSolidityEvents = function (json, address) {
30+
var AllSolidityEvents = function (web3, json, address) {
31+
this._web3 = web3;
3132
this._json = json;
3233
this._address = address;
3334
};
@@ -61,7 +62,7 @@ AllSolidityEvents.prototype.decode = function (data) {
6162
return data;
6263
}
6364

64-
var event = new SolidityEvent(match, this._address);
65+
var event = new SolidityEvent(this._web3, match, this._address);
6566
return event.decode(data);
6667
};
6768

@@ -75,7 +76,7 @@ AllSolidityEvents.prototype.execute = function (options, callback) {
7576

7677
var o = this.encode(options);
7778
var formatter = this.decode.bind(this);
78-
return new Filter(o, watches.eth(), formatter, callback);
79+
return new Filter(this._web3, o, watches.eth(), formatter, callback);
7980
};
8081

8182
AllSolidityEvents.prototype.attachToContract = function (contract) {

lib/web3/contract.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var addFunctionsToContract = function (contract, abi) {
5656
abi.filter(function (json) {
5757
return json.type === 'function';
5858
}).map(function (json) {
59-
return new SolidityFunction(json, contract.address);
59+
return new SolidityFunction(contract._web3, json, contract.address);
6060
}).forEach(function (f) {
6161
f.attachToContract(contract);
6262
});
@@ -74,11 +74,11 @@ var addEventsToContract = function (contract, abi) {
7474
return json.type === 'event';
7575
});
7676

77-
var All = new AllEvents(events, contract.address);
77+
var All = new AllEvents(contract._web3, events, contract.address);
7878
All.attachToContract(contract);
7979

8080
events.map(function (json) {
81-
return new SolidityEvent(json, contract.address);
81+
return new SolidityEvent(contract._web3, json, contract.address);
8282
}).forEach(function (e) {
8383
e.attachToContract(contract);
8484
});
@@ -98,7 +98,7 @@ var checkForContractAddress = function(contract, callback){
9898
callbackFired = false;
9999

100100
// wait for receipt
101-
var filter = web3.eth.filter('latest', function(e){
101+
var filter = contract._web3.eth.filter('latest', function(e){
102102
if (!e && !callbackFired) {
103103
count++;
104104

@@ -116,7 +116,7 @@ var checkForContractAddress = function(contract, callback){
116116

117117
} else {
118118

119-
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
119+
contract._web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
120120
if(receipt && !callbackFired) {
121121

122122
web3.eth.getCode(receipt.contractAddress, function(e, code){
@@ -185,7 +185,7 @@ var ContractFactory = function (web3, abi) {
185185
* @returns {Contract} returns contract instance
186186
*/
187187
ContractFactory.prototype.new = function () {
188-
var contract = new Contract(this.abi);
188+
var contract = new Contract(this.web3, this.abi);
189189

190190
// parse arguments
191191
var options = {}; // required!
@@ -240,7 +240,7 @@ ContractFactory.prototype.new = function () {
240240
* otherwise calls callback function (err, contract)
241241
*/
242242
ContractFactory.prototype.at = function (address, callback) {
243-
var contract = new Contract(this.abi, address);
243+
var contract = new Contract(this.web3, this.abi, address);
244244

245245
if (callback) {
246246
callback(null, contract);
@@ -255,7 +255,8 @@ ContractFactory.prototype.at = function (address, callback) {
255255
* @param {Array} abi
256256
* @param {Address} contract address
257257
*/
258-
var Contract = function (abi, address) {
258+
var Contract = function (web3, abi, address) {
259+
this._web3 = web3;
259260
this._transactionHash = null;
260261
this.address = address;
261262

lib/web3/event.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ var watches = require('./methods/watches');
3030
/**
3131
* This prototype should be used to create event filters
3232
*/
33-
var SolidityEvent = function (json, address) {
33+
var SolidityEvent = function (web3, json, address) {
34+
this._web3 = web3;
3435
this._params = json.inputs;
3536
this._name = utils.transformToFullName(json);
3637
this._address = address;
@@ -185,7 +186,7 @@ SolidityEvent.prototype.execute = function (indexed, options, callback) {
185186

186187
var o = this.encode(indexed, options);
187188
var formatter = this.decode.bind(this);
188-
return new Filter(o, watches.eth(), formatter, callback);
189+
return new Filter(this._web3, o, watches.eth(), formatter, callback);
189190
};
190191

191192
/**

lib/web3/function.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
* @date 2015
2121
*/
2222

23-
var web3 = require('../web3');
2423
var coder = require('../solidity/coder');
2524
var utils = require('../utils/utils');
2625
var formatters = require('./formatters');
@@ -29,7 +28,8 @@ var sha3 = require('../utils/sha3');
2928
/**
3029
* This prototype should be used to call/sendTransaction to solidity functions
3130
*/
32-
var SolidityFunction = function (json, address) {
31+
var SolidityFunction = function (web3, json, address) {
32+
this._web3 = web3;
3333
this._inputTypes = json.inputs.map(function (i) {
3434
return i.type;
3535
});
@@ -109,12 +109,12 @@ SolidityFunction.prototype.call = function () {
109109

110110

111111
if (!callback) {
112-
var output = web3.eth.call(payload, defaultBlock);
112+
var output = this._web3.eth.call(payload, defaultBlock);
113113
return this.unpackOutput(output);
114114
}
115115

116116
var self = this;
117-
web3.eth.call(payload, defaultBlock, function (error, output) {
117+
this._web3.eth.call(payload, defaultBlock, function (error, output) {
118118
callback(error, self.unpackOutput(output));
119119
});
120120
};
@@ -131,10 +131,10 @@ SolidityFunction.prototype.sendTransaction = function () {
131131
var payload = this.toPayload(args);
132132

133133
if (!callback) {
134-
return web3.eth.sendTransaction(payload);
134+
return this._web3.eth.sendTransaction(payload);
135135
}
136136

137-
web3.eth.sendTransaction(payload, callback);
137+
this._web3.eth.sendTransaction(payload, callback);
138138
};
139139

140140
/**
@@ -149,10 +149,10 @@ SolidityFunction.prototype.estimateGas = function () {
149149
var payload = this.toPayload(args);
150150

151151
if (!callback) {
152-
return web3.eth.estimateGas(payload);
152+
return this._web3.eth.estimateGas(payload);
153153
}
154154

155-
web3.eth.estimateGas(payload, callback);
155+
this._web3.eth.estimateGas(payload, callback);
156156
};
157157

158158
/**

lib/web3/methods/eth.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var c = require('../../utils/config');
3131
var Contract = require('../contract');
3232
var watches = require('./watches');
3333
var Filter = require('../filter');
34+
var IsSyncing = require('../syncing');
3435

3536
var blockCall = function (args) {
3637
return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
@@ -311,5 +312,9 @@ Eth.prototype.filter = function (fil, callback) {
311312
return new Filter(this.web3, fil, watches.eth(), formatters.outputLogFormatter, callback);
312313
};
313314

315+
Eth.prototype.isSyncing = function (callback) {
316+
return new IsSyncing(this.web3, callback);
317+
};
318+
314319
module.exports = Eth;
315320

lib/web3/methods/eth1.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

lib/web3/methods/shh.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222

2323
var Method = require('../method');
2424
var formatters = require('../formatters');
25+
var Filter = require('../filter');
26+
var watches = require('./watches');
2527

2628
var Shh = function (web3) {
27-
this._requestManager = web3._requestManager;
29+
this.web3 = web3;
2830

2931
var self = this;
3032

3133
methods().forEach(function(method) {
3234
method.attachToObject(self);
3335
method.setRequestManager(web3._requestManager);
3436
});
35-
3637
};
3738

39+
Shh.prototype.filter = function (fil, callback) {
40+
return new Filter(this.web3, fil, watches.shh(), formatters.outputPostFormatter, callback);
41+
};
3842

3943
var methods = function () {
4044

lib/web3/syncing.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@
2020
* @date 2015
2121
*/
2222

23-
var RequestManager = require('./requestmanager');
2423
var Method = require('./method');
2524
var formatters = require('./formatters');
2625
var utils = require('../utils/utils');
2726

28-
29-
3027
/**
3128
Adds the callback and sets up the methods, to iterate over the results.
3229
@@ -47,7 +44,7 @@ var pollSyncing = function(self) {
4744
sync = self.implementation.outputFormatter(sync);
4845

4946
self.callbacks.forEach(function (callback) {
50-
if(lastSyncState !== sync) {
47+
if (lastSyncState !== sync) {
5148

5249
// call the callback with true first so the app can stop anything, before receiving the sync data
5350
if(!lastSyncState && utils.isObject(sync))
@@ -63,14 +60,15 @@ var pollSyncing = function(self) {
6360
});
6461
};
6562

66-
RequestManager.getInstance().startPolling({
63+
self._web3._requestManager.startPolling({
6764
method: self.implementation.call,
6865
params: [],
6966
}, self.pollId, onMessage, self.stopWatching.bind(self));
7067

7168
};
7269

73-
var IsSyncing = function (callback) {
70+
var IsSyncing = function (web3, callback) {
71+
this._web3 = web3;
7472
this.pollId = 'syncPoll_'+ Math.floor(Math.random() * 1000);
7573
this.callbacks = [];
7674
this.implementation = new Method({
@@ -93,7 +91,7 @@ IsSyncing.prototype.addCallback = function (callback) {
9391
};
9492

9593
IsSyncing.prototype.stopWatching = function () {
96-
RequestManager.getInstance().stopPolling(this.pollId);
94+
this._web3._requestManager.stopPolling(this.pollId);
9795
this.callbacks = [];
9896
};
9997

test/contract.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var utils = require('../lib/utils/utils');
88
var BigNumber = require('bignumber.js');
99
var sha3 = require('../lib/utils/sha3');
1010

11-
/*
11+
1212
var desc = [{
1313
"name": "balance(address)",
1414
"type": "function",
@@ -573,4 +573,3 @@ describe('contract', function () {
573573
});
574574
});
575575

576-
*/

test/event.decode.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ var chai = require('chai');
22
var assert = chai.assert;
33
var BigNumber = require('bignumber.js');
44
var SolidityEvent = require('../lib/web3/event');
5+
var Web3 = require('../index');
6+
var web3 = new Web3();
7+
58

69
var name = 'event1';
710
var address = '0x1234567890123456789012345678901234567890';
@@ -169,7 +172,7 @@ describe('lib/web3/event', function () {
169172
describe('decode', function () {
170173
tests.forEach(function (test, index) {
171174
it('test no: ' + index, function () {
172-
var event = new SolidityEvent(test.abi, address);
175+
var event = new SolidityEvent(web3, test.abi, address);
173176

174177
var result = event.decode(test.data);
175178
assert.deepEqual(result, test.expected);

0 commit comments

Comments
 (0)