Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanio committed Jul 7, 2020
1 parent dba9201 commit eb8dac7
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/1_givenProvider-ethereumProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,69 @@ describe('Web3.providers.givenProvider', function () {
assert.deepEqual(Bzz.givenProvider, global.ethereum.bzz);
});
});

describe('should use request() if available, otherwise falling back to sendAsync() and send()', function () {

after(function(){
global.ethereum = undefined
})

it('should use request()', function () {
global.ethereum = {
request: () => { throw new Error('used request') },
sendAsync: () => { throw new Error('used sendAsync') },
send: () => { throw new Error('used send') }
};

const Web3 = require('../packages/web3');
const web3 = new Web3(Web3.givenProvider)
try {
web3.eth.getBlockNumber()
} catch (error) {
assert.equal(error.message, 'used request')
}
});

it('should use sendAsync()', function () {
global.ethereum = {
sendAsync: () => { throw new Error('used sendAsync') },
send: () => { throw new Error('used send') }
};

const Web3 = require('../packages/web3');
const web3 = new Web3(Web3.givenProvider)
try {
web3.eth.getBlockNumber()
} catch (error) {
assert.equal(error.message, 'used sendAsync')
}
});

it('should use send()', function () {
global.ethereum = {
send: () => { throw new Error('used send') }
};

const Web3 = require('../packages/web3');
const web3 = new Web3(Web3.givenProvider)
try {
web3.eth.getBlockNumber()
} catch (error) {
assert.equal(error.message, 'used send')
}
});

it('should error without any request or send method', function () {
global.ethereum = {};

const Web3 = require('../packages/web3');
const web3 = new Web3(Web3.givenProvider)
try {
web3.eth.getBlockNumber()
} catch (error) {
assert.equal(error.message, 'Provider does not have a request or send method to use.')
}
});
});
});

0 comments on commit eb8dac7

Please sign in to comment.