Fixed default network for providers (#51).

This commit is contained in:
Richard Moore 2017-10-28 17:00:59 -04:00
parent e4c455bdb6
commit 54c19dfb5a
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
3 changed files with 23 additions and 4 deletions

@ -1,6 +1,6 @@
{
"name": "ethers-providers",
"version": "2.1.5",
"version": "2.1.6",
"description": "Service provider for Ethereum wallet library.",
"bugs": {
"url": "http://github.com/ethers-io/ethers.js/issues",

@ -482,6 +482,9 @@ utils.defineProperty(Provider, '_legacyConstructor', function(network, length, a
} else if (typeof(network) === 'string') {
network = networks[network];
if (!network) { throw new Error('unknown network'); }
} else if (network == null) {
network = networks['homestead'];
}
if (typeof(network.chainId) !== 'number') { throw new Error('invalid chainId'); }

@ -83,6 +83,8 @@ var blockchainData = {
},
}
blockchainData['default'] = blockchainData.homestead;
function equals(name, actual, expected) {
if (expected.eq) {
assert.ok(expected.eq(actual), name + ' matches');
@ -100,7 +102,20 @@ function equals(name, actual, expected) {
function testProvider(providerName, networkName) {
describe(('Read-Only ' + providerName + ' (' + networkName + ')'), function() {
var provider = new providers[providerName](networkName);
var provider = null;
if (networkName === 'default') {
if (providerName === 'getDefaultProvider') {
provider = providers.getDefaultProvider();
} else {
provider = new providers[providerName]();
}
} else {
if (providerName === 'getDefaultProvider') {
provider = providers.getDefaultProvider(networkName);
} else {
provider = new providers[providerName](networkName);
}
}
it('fetches block #3', function() {
this.timeout(20000);
@ -148,8 +163,9 @@ function testProvider(providerName, networkName) {
});
}
['homestead', 'ropsten', 'rinkeby', 'kovan'].forEach(function(networkName) {
['InfuraProvider', 'EtherscanProvider'].forEach(function(providerName) {
['default', 'homestead', 'ropsten', 'rinkeby', 'kovan'].forEach(function(networkName) {
['getDefaultProvider', 'InfuraProvider', 'EtherscanProvider'].forEach(function(providerName) {
testProvider(providerName, networkName);
});
});