Updated test suite utils.

This commit is contained in:
Richard Moore 2018-07-23 03:02:39 -04:00
parent 3a5ec9b4ca
commit 62987ac3a8
No known key found for this signature in database
GPG Key ID: 525F70A6FCABC295
13 changed files with 100 additions and 56 deletions

@ -2,6 +2,7 @@
module.exports = {
account: require('./test-account'),
build: require('./test-build'),
contractInterface: require('./test-contract-interface'),
contract: require('./test-contract'),
hdnode: require('./test-hdnode'),

@ -2,14 +2,8 @@
var assert = require('assert');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
describe('Private key generation', function() {
var tests = utils.loadTests('accounts');

50
tests/test-build.js Normal file

@ -0,0 +1,50 @@
var assert = require('assert');
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
describe("Package Version", function() {
var url = "http://registry.npmjs.org/ethers"
it("is not already published", function() {
return ethers.utils.fetchJson(url).then(function(data) {
console.log(data);
assert.ok(Object.keys(data.versions).indexOf(ethers.version) === -1);
});
});
});
/*
describe("Test package path resolution:", function() {
var Tests = {
"..": [
"Wallet"
],
"../contracts": [
],
"../contracts/contract": [
],
"../contracts/interface": [
],
"../providers": [
],
"../providers/InfuraProvider": [
],
"../providers/JsonRpcProvider": [
],
"../providers/FallbackProvider": [
],
"../providers/IpcProvider": [
],
"../providers/Provider": [
],
"../wallet": [
],
};
for (var key in Tests) {
it(key, function() {
var test = require(key);
});
}
});
*/

@ -2,14 +2,9 @@
var assert = require('assert');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
function equals(actual, expected) {

@ -2,12 +2,8 @@
var assert = require('assert');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
var provider = new ethers.providers.InfuraProvider('rinkeby');

@ -2,14 +2,8 @@
var assert = require('assert');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
describe('Test HD Node Derivation', function(test) {

@ -3,12 +3,8 @@
var assert = require('assert');
var web3 = require('web3');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
var providers = ethers.providers;
var bigNumberify = ethers.utils.bigNumberify;

@ -2,14 +2,8 @@
var assert = require('assert');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
function equals(a, b) {
if (Array.isArray(a)) {

@ -1,14 +1,9 @@
'use strict';
var assert = require('assert');
var utils = require('./utils');
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
describe('Test JSON Wallets', function() {
var Wallet = ethers.Wallet;

@ -3,13 +3,8 @@
var assert = require('assert');
var utils = require('./utils');
var ethers = utils.getEthers(__filename);
if (global.ethers) {
console.log('Using global ethers; ' + __filename);
var ethers = global.ethers;
} else {
var ethers = require('..');
}
function checkWordlist(filename, wordlist) {
var words = utils.loadText(filename).split('\n');

@ -0,0 +1,11 @@
var assert = require('assert');
function getEthers(filename) {
var ethers = global.ethers
if (!ethers) { return undefined; }
console.log('Using global ethers; ' + filename);
assert.equal(ethers.platform, 'browser', 'platform: ' + ethers.platform + ' != "brwoser"');
return ethers;
}
module.exports = getEthers;

10
tests/utils-ethers.js Normal file

@ -0,0 +1,10 @@
var assert = require('assert');
function getEthers(filename) {
let ethers = require('../index');
console.log('Loaded local ethers: ' + filename);
assert.equal(ethers.platform, 'node', 'platform: ' + ethers.platform + ' != "node"');
return ethers;
}
module.exports = getEthers;

@ -5,11 +5,22 @@ var fs = require('fs');
var path = require('path');
var zlib = require('zlib');
var getEthers = require('./utils-ethers');
var bigNumber = require('../utils/bignumber');
var convert = require('../utils/bytes');
var keccak256 = require('../utils/keccak256').keccak256;
var utf8 = require('../utils/utf8');
var readFileSync = fs.readFileSync;
if (!readFileSync) {
var data = require('./dist/tests.json');
readFileSync = function(filename) {
return new Buffer(data[filename], 'base64');
}
}
/*
function random(lowerRandomInterval, upperOpenInterval) {
return lowerRandomInterval + parseInt((upperOpenInterval - lowerRandomInterval) * Math.random());
@ -95,21 +106,23 @@ function saveTests(tag, data) {
function loadTests(tag) {
var filename = path.resolve(__dirname, 'tests', tag + '.json.gz');
return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)));
return JSON.parse(zlib.gunzipSync(readFileSync(filename)));
}
function loadJson(filename) {
var filename = path.resolve(__dirname, 'tests', filename);
return JSON.parse(fs.readFileSync(filename).toString());
return JSON.parse(readFileSync(filename).toString());
}
function loadText(filename) {
var filename = path.resolve(__dirname, filename);
return fs.readFileSync(filename).toString();
return readFileSync(filename).toString();
}
module.exports = {
getEthers: getEthers,
randomBytes: randomBytes,
randomHexString: randomHexString,
randomNumber:randomNumber,