diff --git a/.circleci/config.yml b/.circleci/config.yml index ec8f13f..aa51b5b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,8 +8,8 @@ step_install_nvm: &step_install_nvm set +e export NVM_DIR="/opt/circleci/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - nvm install v8.15.0 - nvm alias default v8.15.0 + nvm install v10.15.3 + nvm alias default v10.15.3 echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV jobs: diff --git a/dist/truffle.plugin.js b/dist/truffle.plugin.js index 8eed257..7c862cf 100644 --- a/dist/truffle.plugin.js +++ b/dist/truffle.plugin.js @@ -35,6 +35,7 @@ const Web3 = require('web3'); const util = require('util'); const globby = require('globby'); const globalModules = require('global-modules'); +const TruffleProvider = require('@truffle/provider'); async function plugin(truffleConfig){ let app; @@ -71,18 +72,25 @@ async function plugin(truffleConfig){ death(app.cleanUp); // This doesn't work... // Launch in-process provider - const provider = await app.provider(truffle.ganache); - const web3 = new Web3(provider); + //const provider = await app.provider(truffle.ganache); + //const web3 = new Web3(provider); + await app.provider(truffle.ganache); + const web3 = new Web3('http://localhost:8777'); + console.log('post web3 in plugin'); const accounts = await web3.eth.getAccounts(); const nodeInfo = await web3.eth.getNodeInfo(); const ganacheVersion = nodeInfo.split('/')[1]; + console.log('post initial web3 calls') app.ui.report('truffle-version', [truffle.version]); app.ui.report('ganache-version', [ganacheVersion]); app.ui.report('coverage-version',[pkg.version]); // Bail early if user ran: --version - if (truffleConfig.version) return; + if (truffleConfig.version){ + await app.cleanUp(); + return; + }; // Write instrumented sources to temp folder app.instrument(); @@ -108,12 +116,17 @@ async function plugin(truffleConfig){ // are not manually set try { truffleConfig.network_id = "*"; - truffleConfig.provider = provider; - } catch (err){} + truffleConfig.port = 8777; + truffleConfig.host = "127.0.0.1"; + truffleConfig.provider = TruffleProvider.create(truffleConfig); + } catch (err){ + console.log('errored on initial setting of truffleConfig.provider...') + } truffleConfig.networks[networkName] = { network_id: "*", - provider: provider, + provider: TruffleProvider.create(truffleConfig), + port: 8777, gas: app.gasLimit, gasPrice: app.gasPrice, from: accounts[0] diff --git a/lib/app.js b/lib/app.js index 80b7047..8dc8f1a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -4,7 +4,7 @@ const path = require('path'); const istanbul = require('istanbul'); const util = require('util'); const assert = require('assert'); -const memdown = require('memdown'); +const pify = require('pify'); const Instrumenter = require('./instrumenter'); const Coverage = require('./coverage'); @@ -34,7 +34,9 @@ class App { this.originalContractsDir = config.originalContractsDir this.client = config.client; + this.server = null; this.providerOptions = config.providerOptions || {}; + this.defaultPort = 8777; this.skippedFolders = []; this.skipFiles = config.skipFiles || []; @@ -124,14 +126,13 @@ class App { this.providerOptions.gasLimit = this.gasLimitString; this.providerOptions.allowUnlimitedContractSize = true; - this.providerOptions.db = memdown(); - this.providerOptions.asyncRequestProcessing = true; // Try to launch provider and attach to vm step of // either plugin's ganache or a provider passed via options try { this.provider = await this.attachToVM(); } catch(err){ + console.log('err --> ' + err); retry = true; this.ui.report('vm-fail', []) } @@ -190,8 +191,8 @@ class App { shell.rm('-Rf', this.artifactsDir); if (this.provider && this.provider.close){ - this.log('Shutting down ganache-core') - return new Promise(res => self.provider.close(res)) + this.log('Shutting down ganache-core.server') + await pify(self.server.close)(); } } // ------------------------------------------ Utils ---------------------------------------------- @@ -201,7 +202,9 @@ class App { // ======== async attachToVM(){ const self = this; - const provider = this.client.provider(this.providerOptions); + const port = this.providerOptions.port || this.defaultPort; + this.server = this.client.server(this.providerOptions); + const provider = this.server.provider; this.assertHasBlockchain(provider); @@ -221,6 +224,7 @@ class App { return vm; } + await pify(this.server.listen)(port); return provider; } diff --git a/package.json b/package.json index eb3e674..18696f4 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "author": "", "license": "ISC", "dependencies": { + "@truffle/provider": "^0.1.17", "chalk": "^2.4.2", "death": "^1.1.0", "ganache-core-sc": "2.7.0-sc.0", @@ -30,6 +31,7 @@ "memdown": "^5.0.0", "node-dir": "^0.1.17", "node-emoji": "^1.10.0", + "pify": "^4.0.1", "req-cwd": "^1.0.1", "shelljs": "^0.8.3", "solidity-parser-antlr": "^0.4.7", diff --git a/yarn.lock b/yarn.lock index a47f645..5a34444 100644 --- a/yarn.lock +++ b/yarn.lock @@ -166,6 +166,30 @@ dependencies: defer-to-connect "^1.0.1" +"@truffle/error@^0.0.7": + version "0.0.7" + resolved "https://registry.yarnpkg.com/@truffle/error/-/error-0.0.7.tgz#e9db39885575647ef08bf624b0c13fe46d41a209" + integrity sha512-UIfVKsXSXocKnn5+RNklUXNoGd/JVj7V8KmC48TQzmjU33HQI86PX0JDS7SpHMHasI3w9X//1q7Lu7nZtj3Zzg== + +"@truffle/interface-adapter@^0.2.6": + version "0.2.6" + resolved "https://registry.yarnpkg.com/@truffle/interface-adapter/-/interface-adapter-0.2.6.tgz#41bdf5a1a120e8b76c441fa1a746bdc3c6d3fad2" + integrity sha512-8ByMwqC9hWaHQDlwCEMoIhEewvkZXeeywu46/7yM7BHE1XoSDjiQzWjagg6nLJwmFRwB1ZHYC3RXiDyFJLWd0g== + dependencies: + bn.js "^4.11.8" + ethers "^4.0.32" + lodash "^4.17.13" + web3 "1.2.1" + +"@truffle/provider@^0.1.17": + version "0.1.17" + resolved "https://registry.yarnpkg.com/@truffle/provider/-/provider-0.1.17.tgz#9b72a76a7ce18a054eabb3ebd21a55a33dc7d7b6" + integrity sha512-V8k2jErxotpMt/R6qS7GL0stM1TWsuJYnm6iRcYDGwp0D33pZDLrnmwsuIbtXIfbAuaJ26kQHu2LGCUxuFh0LA== + dependencies: + "@truffle/error" "^0.0.7" + "@truffle/interface-adapter" "^0.2.6" + web3 "1.2.1" + "@types/bn.js@^4.11.2": version "4.11.5" resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.5.tgz#40e36197433f78f807524ec623afcf0169ac81dc"