@@ -4,17 +4,13 @@ require("ts-node/register/transpile-only");
44Object . defineProperty ( Error , "prepareStackTrace" , { writable : false } ) ;
55
66const HDWalletProvider = require ( "@truffle/hdwallet-provider" ) ;
7- const mnemonic = "talisman" ;
87const fs = require ( "fs" ) ;
8+ const path = require ( "path" ) ;
99
10- // INFURA Setup - see validate/README.validate.md for more info
11- let infuraKey = "none" ;
12- try {
13- infuraKey = fs . readFileSync ( "./validate/apikey.infura" , "utf8" ) ;
14- } catch ( err ) {
15- console . log (
16- "No Infura access token detected. Unit tests will still work. See ./validate/README.validate.md for more details."
17- ) ;
10+ // Read config file if it exists
11+ let config = { MNEMONIC : "" , INFURA_KEY : "" } ;
12+ if ( fs . existsSync ( path . join ( __dirname , "config.js" ) ) ) {
13+ config = require ( "./config.js" ) ;
1814}
1915
2016module . exports = {
@@ -40,25 +36,35 @@ module.exports = {
4036 port : 8545 ,
4137 network_id : "*" , // Match any network id
4238 } ,
43- // INFURA Setup
44- infura_mainnet : {
45- provider ( ) {
46- return new HDWalletProvider (
47- mnemonic ,
48- "https://mainnet.infura.io/v3/" + infuraKey
49- ) ;
50- } ,
39+ mainnet : {
40+ provider : infuraProvider ( "mainnet" ) ,
5141 network_id : 1 ,
5242 } ,
43+ ropsten : {
44+ provider : infuraProvider ( "ropsten" ) ,
45+ network_id : 3 ,
46+ } ,
5347 } ,
5448 mocha : {
5549 timeout : 10000 , // prevents tests from failing when pc is under heavy load
56- /*
57- * To disable the spreadsheet verification tool ensure that
58- * the reporter is set to 'Spec' by commenting/uncommenting the lines below.
59- */
6050 reporter : "Spec" ,
61- // reporter: './verification/verification_reporter.js',
6251 } ,
6352 plugins : [ "solidity-coverage" ] ,
6453} ;
54+
55+ function infuraProvider ( network ) {
56+ return ( ) => {
57+ if ( ! config . MNEMONIC ) {
58+ console . error ( "A valid MNEMONIC must be provided in config.js" ) ;
59+ process . exit ( 1 ) ;
60+ }
61+ if ( ! config . INFURA_KEY ) {
62+ console . error ( "A valid INFURA_KEY must be provided in config.js" ) ;
63+ process . exit ( 1 ) ;
64+ }
65+ return new HDWalletProvider (
66+ config . MNEMONIC ,
67+ `https://${ network } .infura.io/v3/${ config . INFURA_KEY } `
68+ ) ;
69+ } ;
70+ }
0 commit comments