add more tests

This commit is contained in:
Fabian Vogelsteller 2015-06-24 21:50:27 +02:00
parent cd92d44098
commit 14f1c5c903
10 changed files with 107 additions and 31 deletions

27
dist/web3-light.js vendored
View File

@ -3374,9 +3374,9 @@ var IpcProvider = function (path, net) {
throw errors.InvalidConnection(path);
}
this.connection.on('error', function(e){
throw errors.InvalidConnection(path);
});
// this.connection.on('error', function(e){
// throw errors.InvalidConnection(path);
// });
@ -3385,7 +3385,7 @@ var IpcProvider = function (path, net) {
result = result.toString();
try {
var result = JSON.parse(result);
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
@ -3435,7 +3435,26 @@ IpcProvider.prototype.isConnected = function() {
};
IpcProvider.prototype.send = function (payload) {
if(this.connection.writeSync) {
// try reconnect, when connection is gone
if(!this.connection._handle)
this.connection.connect({path: this.path});
var result = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

27
dist/web3.js vendored
View File

@ -3374,9 +3374,9 @@ var IpcProvider = function (path, net) {
throw errors.InvalidConnection(path);
}
this.connection.on('error', function(e){
throw errors.InvalidConnection(path);
});
// this.connection.on('error', function(e){
// throw errors.InvalidConnection(path);
// });
@ -3385,7 +3385,7 @@ var IpcProvider = function (path, net) {
result = result.toString();
try {
var result = JSON.parse(result);
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
@ -3435,7 +3435,26 @@ IpcProvider.prototype.isConnected = function() {
};
IpcProvider.prototype.send = function (payload) {
if(this.connection.writeSync) {
// try reconnect, when connection is gone
if(!this.connection._handle)
this.connection.connect({path: this.path});
var result = this.connection.writeSync(JSON.stringify(payload));
try {
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);
}
return result;
} else {
throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
}
};
IpcProvider.prototype.sendAsync = function (payload, callback) {

4
dist/web3.js.map vendored

File diff suppressed because one or more lines are too long

10
dist/web3.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -51,7 +51,7 @@ var IpcProvider = function (path, net) {
result = result.toString();
try {
var result = JSON.parse(result);
result = JSON.parse(result);
} catch(e) {
throw errors.InvalidResponse(result);

View File

@ -20,6 +20,12 @@ FakeIpcRequest.prototype.on = function(name, callback) {
}
};
FakeIpcRequest.prototype.writeSync = function (payload) {
assert.equal(typeof payload, 'string');
return payload;
};
FakeIpcRequest.prototype.write = function (payload) {
assert.equal(typeof payload, 'string');

View File

@ -29,5 +29,13 @@ describe('lib/web3/httpprovider', function () {
});
});
});
describe('isConnected', function () {
it('should return a boolean', function () {
var provider = new HttpProvider();
assert.isBoolean(provider.isConnected());
});
});
});

View File

@ -10,14 +10,14 @@ var IpcProvider = SandboxedModule.require('../lib/web3/ipcprovider', {
});
describe('lib/web3/ipcprovider', function () {
// describe('send', function () {
// it('should send basic request', function () {
// var provider = new HttpProvider();
// var result = provider.send({});
describe('send', function () {
it('should send basic request', function () {
var provider = new IpcProvider();
var result = provider.send({});
// assert.equal(typeof result, 'object');
// });
// });
assert.equal(typeof result, 'object');
});
});
describe('sendAsync', function () {
it('should send basic async request', function (done) {
@ -29,5 +29,29 @@ describe('lib/web3/ipcprovider', function () {
});
});
});
describe('isConnected', function () {
it('should return a boolean', function () {
var provider = new IpcProvider();
assert.isBoolean(provider.isConnected());
});
it('should return false', function () {
var provider = new IpcProvider();
provider.connection._handle = null;
assert.isFalse(provider.isConnected());
});
it('should return true, when a net handle is set', function () {
var provider = new IpcProvider();
provider.connection._handle = {fd: true};
assert.isTrue(provider.isConnected());
});
});
});