add more tests
This commit is contained in:
parent
cd92d44098
commit
14f1c5c903
|
@ -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
|
@ -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
|
@ -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);
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue