Unverified Commit e7d6e863 by Francisco Giordano Committed by GitHub

Make Truffle provider creation lazy (#1526)

* make provider creation lazy

* change getter for function

* remove unused networks from truffle config

* remove unused dotenv package

* remove truffle-hdwallet-provider dependency

* install ethereumjs-util

* replace sha3 with keccak256 for ethereumjs-util v6
parent c0bda4db
# configure your infura api key (not technically required)
INFURA_API_KEY=
# change the mnemonic that your hd wallet is seeded with
MNEMONIC=
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
"chai": "^4.1.2", "chai": "^4.1.2",
"chai-bignumber": "^2.0.2", "chai-bignumber": "^2.0.2",
"coveralls": "^3.0.1", "coveralls": "^3.0.1",
"dotenv": "^4.0.0",
"eslint": "^4.19.1", "eslint": "^4.19.1",
"eslint-config-standard": "^10.2.1", "eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.13.0", "eslint-plugin-import": "^2.13.0",
...@@ -49,12 +48,12 @@ ...@@ -49,12 +48,12 @@
"eslint-plugin-node": "^5.2.1", "eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.8.0", "eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0", "eslint-plugin-standard": "^3.1.0",
"ethereumjs-util": "^6.0.0",
"ethjs-abi": "^0.2.1", "ethjs-abi": "^0.2.1",
"ganache-cli": "6.1.0", "ganache-cli": "6.1.0",
"solidity-coverage": "^0.5.4", "solidity-coverage": "^0.5.4",
"solium": "^1.1.8", "solium": "^1.1.8",
"truffle": "^4.1.13", "truffle": "^4.1.13",
"truffle-hdwallet-provider": "0.0.5",
"web3-utils": "^1.0.0-beta.34" "web3-utils": "^1.0.0-beta.34"
}, },
"dependencies": {} "dependencies": {}
......
const { MerkleTree } = require('../helpers/merkleTree.js'); const { MerkleTree } = require('../helpers/merkleTree.js');
const { sha3, bufferToHex } = require('ethereumjs-util'); const { keccak256, bufferToHex } = require('ethereumjs-util');
const MerkleProofWrapper = artifacts.require('MerkleProofWrapper'); const MerkleProofWrapper = artifacts.require('MerkleProofWrapper');
...@@ -20,7 +20,7 @@ contract('MerkleProof', function () { ...@@ -20,7 +20,7 @@ contract('MerkleProof', function () {
const proof = merkleTree.getHexProof(elements[0]); const proof = merkleTree.getHexProof(elements[0]);
const leaf = bufferToHex(sha3(elements[0])); const leaf = bufferToHex(keccak256(elements[0]));
(await this.merkleProof.verify(proof, root, leaf)).should.equal(true); (await this.merkleProof.verify(proof, root, leaf)).should.equal(true);
}); });
...@@ -31,7 +31,7 @@ contract('MerkleProof', function () { ...@@ -31,7 +31,7 @@ contract('MerkleProof', function () {
const correctRoot = correctMerkleTree.getHexRoot(); const correctRoot = correctMerkleTree.getHexRoot();
const correctLeaf = bufferToHex(sha3(correctElements[0])); const correctLeaf = bufferToHex(keccak256(correctElements[0]));
const badElements = ['d', 'e', 'f']; const badElements = ['d', 'e', 'f'];
const badMerkleTree = new MerkleTree(badElements); const badMerkleTree = new MerkleTree(badElements);
...@@ -50,7 +50,7 @@ contract('MerkleProof', function () { ...@@ -50,7 +50,7 @@ contract('MerkleProof', function () {
const proof = merkleTree.getHexProof(elements[0]); const proof = merkleTree.getHexProof(elements[0]);
const badProof = proof.slice(0, proof.length - 5); const badProof = proof.slice(0, proof.length - 5);
const leaf = bufferToHex(sha3(elements[0])); const leaf = bufferToHex(keccak256(elements[0]));
(await this.merkleProof.verify(badProof, root, leaf)).should.equal(false); (await this.merkleProof.verify(badProof, root, leaf)).should.equal(false);
}); });
......
const { sha3, bufferToHex } = require('ethereumjs-util'); const { keccak256, bufferToHex } = require('ethereumjs-util');
class MerkleTree { class MerkleTree {
constructor (elements) { constructor (elements) {
// Filter empty strings and hash elements // Filter empty strings and hash elements
this.elements = elements.filter(el => el).map(el => sha3(el)); this.elements = elements.filter(el => el).map(el => keccak256(el));
// Deduplicate elements // Deduplicate elements
this.elements = this.bufDedup(this.elements); this.elements = this.bufDedup(this.elements);
...@@ -45,7 +45,7 @@ class MerkleTree { ...@@ -45,7 +45,7 @@ class MerkleTree {
if (!first) { return second; } if (!first) { return second; }
if (!second) { return first; } if (!second) { return first; }
return sha3(this.sortAndConcat(first, second)); return keccak256(this.sortAndConcat(first, second));
} }
getRoot () { getRoot () {
...@@ -97,7 +97,7 @@ class MerkleTree { ...@@ -97,7 +97,7 @@ class MerkleTree {
// Convert element to 32 byte hash if it is not one already // Convert element to 32 byte hash if it is not one already
if (el.length !== 32 || !Buffer.isBuffer(el)) { if (el.length !== 32 || !Buffer.isBuffer(el)) {
hash = sha3(el); hash = keccak256(el);
} else { } else {
hash = el; hash = el;
} }
......
require('dotenv').config();
const HDWalletProvider = require('truffle-hdwallet-provider');
const providerWithMnemonic = (mnemonic, rpcEndpoint) =>
new HDWalletProvider(mnemonic, rpcEndpoint);
const infuraProvider = network => providerWithMnemonic(
process.env.MNEMONIC || '',
`https://${network}.infura.io/${process.env.INFURA_API_KEY}`
);
const ropstenProvider = process.env.SOLIDITY_COVERAGE
? undefined
: infuraProvider('ropsten');
module.exports = { module.exports = {
networks: { networks: {
development: { development: {
...@@ -21,10 +5,6 @@ module.exports = { ...@@ -21,10 +5,6 @@ module.exports = {
port: 8545, port: 8545,
network_id: '*', // eslint-disable-line camelcase network_id: '*', // eslint-disable-line camelcase
}, },
ropsten: {
provider: ropstenProvider,
network_id: 3, // eslint-disable-line camelcase
},
coverage: { coverage: {
host: 'localhost', host: 'localhost',
network_id: '*', // eslint-disable-line camelcase network_id: '*', // eslint-disable-line camelcase
...@@ -32,10 +12,5 @@ module.exports = { ...@@ -32,10 +12,5 @@ module.exports = {
gas: 0xfffffffffff, gas: 0xfffffffffff,
gasPrice: 0x01, gasPrice: 0x01,
}, },
ganache: {
host: 'localhost',
port: 8545,
network_id: '*', // eslint-disable-line camelcase
},
}, },
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment