Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add websocket / misc tests (#3190) #3299

Merged
merged 9 commits into from
Jan 15, 2020
6 changes: 3 additions & 3 deletions packages/web3-providers-ws/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ WebsocketProvider.prototype._onClose = function (event) {

if (this.requestQueue.size > 0) {
this.requestQueue.forEach(function (request, key) {
request.callback(errors.ConnectionClosedError(event));
request.callback(errors.ConnectionNotOpenError());
_this.requestQueue.delete(key);
});
}
Expand Down Expand Up @@ -251,7 +251,6 @@ WebsocketProvider.prototype._parseResponse = function (data) {

try {
result = JSON.parse(data);

} catch (e) {

_this.lastChunk = data;
Expand All @@ -265,6 +264,7 @@ WebsocketProvider.prototype._parseResponse = function (data) {
return;
}


_this.emit(_this.ERROR, errors.ConnectionTimeout(_this._customTimeout));

if (_this.requestQueue.size > 0) {
Expand Down Expand Up @@ -344,7 +344,7 @@ WebsocketProvider.prototype.send = function (payload, callback) {
WebsocketProvider.prototype.reset = function () {
this.responseQueue.clear();
this.requestQueue.clear();

this.removeAllListeners();

this._removeSocketListeners();
Expand Down
2 changes: 1 addition & 1 deletion scripts/e2e.npm.publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi
# To model publication correctly, this script needs to run
# without web3's dev deps being installed. It installs
# what it needs here.
npm install -g verdaccio@4.3.4
npm install -g verdaccio@4.4.2
npm install -g npm-auth-to-token@1.0.0
npm install -g lerna@3.18.3

Expand Down
25 changes: 25 additions & 0 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,31 @@ describe('typical usage', function () {
assert.deepEqual(eth.currentProvider, provider2);
});

it('should update contract instance provider when calling setProvider on itself', function () {
var provider1 = new FakeIpcProvider();
var provider2 = new FakeHttpProvider();

var eth = new Eth(provider1);
var contract = new eth.Contract(abi, address);
assert.deepEqual(contract.currentProvider, provider1);

contract.setProvider(provider2);
assert.deepEqual(contract.currentProvider, provider2);
});

it('errors when invoked without the "new" operator', function () {
try {
var provider = new FakeHttpProvider();
var eth = new Eth(provider);

eth.Contract(abi, address);

assert.fail();
} catch(err) {
assert(err.message.includes('the "new" keyword'));
}
});

it('should deploy a contract, sign transaction, and return contract instance', function (done) {
var provider = new FakeIpcProvider();
var eth = new Eth(provider);
Expand Down
Loading