|
| 1 | +const ProviderEngine = require('web3-provider-engine'); |
| 2 | +const WebsocketProvider = require('web3-provider-engine/subproviders/websocket.js'); |
| 3 | +const { |
| 4 | + TruffleArtifactAdapter, |
| 5 | + CoverageSubprovider |
| 6 | +} = require('@0x/sol-coverage'); |
| 7 | +const { RevertTraceSubprovider } = require('@0x/sol-trace'); |
| 8 | + |
| 9 | +require('dotenv').config(); |
| 10 | + |
| 11 | +const solcVersion = '0.5.4'; |
| 12 | +const defaultFromAddress = '0x627306090abab3a6e1400e9345bc60c78a8bef57'; |
| 13 | +const isVerbose = true; |
1 | 14 | /** |
2 | | - * Use this file to configure your truffle project. It's seeded with some |
3 | | - * common settings for different networks and features like migrations, |
4 | | - * compilation and testing. Uncomment the ones you need or modify |
5 | | - * them to suit your project as necessary. |
6 | | - * |
7 | | - * More information about configuration can be found at: |
8 | | - * |
9 | | - * truffleframework.com/docs/advanced/configuration |
10 | | - * |
11 | | - * To deploy via Infura you'll need a wallet provider (like truffle-hdwallet-provider) |
12 | | - * to sign your transactions before they're sent to a remote public node. Infura accounts |
13 | | - * are available for free at: infura.io/register. |
14 | | - * |
15 | | - * You'll also need a mnemonic - the twelve word phrase the wallet uses to generate |
16 | | - * public/private key pairs. If you're publishing your code to GitHub make sure you load this |
17 | | - * phrase from a file you've .gitignored so it doesn't accidentally become public. |
| 15 | + * Create's a test provider using 0x tracing and coverage |
18 | 16 | * |
| 17 | + * @param {string} projectRoot - path of project using this config |
| 18 | + * @returns {ProviderEngine} A web3 provider |
| 19 | + * @private |
19 | 20 | */ |
| 21 | +const createTestProvider = projectRoot => { |
| 22 | + const testProvider = new ProviderEngine(); |
| 23 | + const artifactAdapter = new TruffleArtifactAdapter( |
| 24 | + `${projectRoot}`, |
| 25 | + solcVersion |
| 26 | + ); |
| 27 | + const coverageSubProvider = new CoverageSubprovider( |
| 28 | + artifactAdapter, |
| 29 | + defaultFromAddress, |
| 30 | + { |
| 31 | + isVerbose: isVerbose, |
| 32 | + ignoreFilesGlobs: ['**/Migrations.sol'] |
| 33 | + } |
| 34 | + ); |
| 35 | + |
| 36 | + global.coverageSubProvider = coverageSubProvider; |
20 | 37 |
|
21 | | -// const HDWalletProvider = require('truffle-hdwallet-provider'); |
22 | | -// const infuraKey = "fj4jll3k....."; |
23 | | -// |
24 | | -// const fs = require('fs'); |
25 | | -// const mnemonic = fs.readFileSync(".secret").toString().trim(); |
| 38 | + testProvider.addProvider(coverageSubProvider); |
26 | 39 |
|
27 | | -module.exports = { |
28 | | - /** |
29 | | - * Networks define how you connect to your ethereum client and let you set the |
30 | | - * defaults web3 uses to send transactions. If you don't specify one truffle |
31 | | - * will spin up a development blockchain for you on port 9545 when you |
32 | | - * run `develop` or `test`. You can ask a truffle command to use a specific |
33 | | - * network from the command line, e.g |
34 | | - * |
35 | | - * $ truffle test --network <network-name> |
36 | | - */ |
| 40 | + testProvider.addProvider( |
| 41 | + new RevertTraceSubprovider(artifactAdapter, defaultFromAddress, isVerbose) |
| 42 | + ); |
37 | 43 |
|
38 | | - networks: { |
39 | | - // Useful for testing. The `development` name is special - truffle uses it by default |
40 | | - // if it's defined here and no other network is specified at the command line. |
41 | | - // You should run a client (like ganache-cli, geth or parity) in a separate terminal |
42 | | - // tab if you use this network and you must also set the `host`, `port` and `network_id` |
43 | | - // options below to some value. |
44 | | - // |
45 | | - // development: { |
46 | | - // host: "127.0.0.1", // Localhost (default: none) |
47 | | - // port: 8545, // Standard Ethereum port (default: none) |
48 | | - // network_id: "*", // Any network (default: none) |
49 | | - // }, |
50 | | - // Another network with more advanced options... |
51 | | - // advanced: { |
52 | | - // port: 8777, // Custom port |
53 | | - // network_id: 1342, // Custom network |
54 | | - // gas: 8500000, // Gas sent with each transaction (default: ~6700000) |
55 | | - // gasPrice: 20000000000, // 20 gwei (in wei) (default: 100 gwei) |
56 | | - // from: <address>, // Account to send txs from (default: accounts[0]) |
57 | | - // websockets: true // Enable EventEmitter interface for web3 (default: false) |
58 | | - // }, |
59 | | - // Useful for deploying to a public network. |
60 | | - // NB: It's important to wrap the provider as a function. |
61 | | - // ropsten: { |
62 | | - // provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/YOUR-PROJECT-ID`), |
63 | | - // network_id: 3, // Ropsten's id |
64 | | - // gas: 5500000, // Ropsten has a lower block limit than mainnet |
65 | | - // confirmations: 2, // # of confs to wait between deployments. (default: 0) |
66 | | - // timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) |
67 | | - // skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) |
68 | | - // }, |
69 | | - // Useful for private networks |
70 | | - // private: { |
71 | | - // provider: () => new HDWalletProvider(mnemonic, `https://network.io`), |
72 | | - // network_id: 2111, // This network is yours, in the cloud. |
73 | | - // production: true // Treats this network as if it was a public net. (default: false) |
74 | | - // } |
75 | | - }, |
| 44 | + testProvider.send = testProvider.sendAsync.bind(testProvider); |
76 | 45 |
|
77 | | - // Set default mocha options here, use special reporters etc. |
78 | | - mocha: { |
79 | | - // timeout: 100000 |
80 | | - }, |
| 46 | + return testProvider; |
| 47 | +}; |
| 48 | + |
| 49 | +/** |
| 50 | + * A config generation helper function |
| 51 | + * |
| 52 | + * @param {string} projectRoot - path to the project using this config |
| 53 | + * @returns {Object} - Config object for truffle |
| 54 | + */ |
| 55 | +const configHelper = projectRoot => { |
| 56 | + const testProvider = createTestProvider(projectRoot); |
| 57 | + let testProviderStarted = false; |
| 58 | + |
| 59 | + return { |
| 60 | + networks: { |
| 61 | + development: { |
| 62 | + host: '127.0.0.1', |
| 63 | + port: 7545, |
| 64 | + network_id: '*' // Match any network id |
| 65 | + }, |
| 66 | + test: { |
| 67 | + provider: () => { |
| 68 | + if (!testProviderStarted) { |
| 69 | + // Within this function to not start the provider until it's needed |
| 70 | + testProvider.addProvider( |
| 71 | + new WebsocketProvider({ rpcUrl: 'http://localhost:7545' }) |
| 72 | + ); |
81 | 73 |
|
82 | | - // Configure your compilers |
83 | | - compilers: { |
84 | | - solc: { |
85 | | - // version: "0.5.1", // Fetch exact version from solc-bin (default: truffle's version) |
86 | | - // docker: true, // Use "0.5.1" you've installed locally with docker (default: false) |
87 | | - // settings: { // See the solidity docs for advice about optimization and evmVersion |
88 | | - // optimizer: { |
89 | | - // enabled: false, |
90 | | - // runs: 200 |
91 | | - // }, |
92 | | - // evmVersion: "byzantium" |
93 | | - // } |
| 74 | + testProvider.start(err => { |
| 75 | + testProviderStarted = true; |
| 76 | + |
| 77 | + if (err !== undefined) { |
| 78 | + // eslint-disable-next-line no-console |
| 79 | + console.log('Failed to start provider', err); |
| 80 | + process.exit(1); |
| 81 | + } |
| 82 | + }); |
| 83 | + } |
| 84 | + return testProvider; |
| 85 | + }, |
| 86 | + network_id: '*' |
| 87 | + } |
| 88 | + }, |
| 89 | + compilers: { |
| 90 | + solc: { |
| 91 | + version: solcVersion |
| 92 | + } |
94 | 93 | } |
95 | | - } |
| 94 | + }; |
96 | 95 | }; |
| 96 | + |
| 97 | +module.exports = configHelper(__dirname); |
0 commit comments