Try using ganache.server

perf/memdown
cgewecke 5 years ago
parent 01fe67e8d1
commit 042cf5f29a
  1. 4
      .circleci/config.yml
  2. 25
      dist/truffle.plugin.js
  3. 16
      lib/app.js
  4. 2
      package.json
  5. 24
      yarn.lock

@ -8,8 +8,8 @@ step_install_nvm: &step_install_nvm
set +e set +e
export NVM_DIR="/opt/circleci/.nvm" export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install v8.15.0 nvm install v10.15.3
nvm alias default v8.15.0 nvm alias default v10.15.3
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
jobs: jobs:

@ -35,6 +35,7 @@ const Web3 = require('web3');
const util = require('util'); const util = require('util');
const globby = require('globby'); const globby = require('globby');
const globalModules = require('global-modules'); const globalModules = require('global-modules');
const TruffleProvider = require('@truffle/provider');
async function plugin(truffleConfig){ async function plugin(truffleConfig){
let app; let app;
@ -71,18 +72,25 @@ async function plugin(truffleConfig){
death(app.cleanUp); // This doesn't work... death(app.cleanUp); // This doesn't work...
// Launch in-process provider // Launch in-process provider
const provider = await app.provider(truffle.ganache); //const provider = await app.provider(truffle.ganache);
const web3 = new Web3(provider); //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 accounts = await web3.eth.getAccounts();
const nodeInfo = await web3.eth.getNodeInfo(); const nodeInfo = await web3.eth.getNodeInfo();
const ganacheVersion = nodeInfo.split('/')[1]; const ganacheVersion = nodeInfo.split('/')[1];
console.log('post initial web3 calls')
app.ui.report('truffle-version', [truffle.version]); app.ui.report('truffle-version', [truffle.version]);
app.ui.report('ganache-version', [ganacheVersion]); app.ui.report('ganache-version', [ganacheVersion]);
app.ui.report('coverage-version',[pkg.version]); app.ui.report('coverage-version',[pkg.version]);
// Bail early if user ran: --version // Bail early if user ran: --version
if (truffleConfig.version) return; if (truffleConfig.version){
await app.cleanUp();
return;
};
// Write instrumented sources to temp folder // Write instrumented sources to temp folder
app.instrument(); app.instrument();
@ -108,12 +116,17 @@ async function plugin(truffleConfig){
// are not manually set // are not manually set
try { try {
truffleConfig.network_id = "*"; truffleConfig.network_id = "*";
truffleConfig.provider = provider; truffleConfig.port = 8777;
} catch (err){} 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] = { truffleConfig.networks[networkName] = {
network_id: "*", network_id: "*",
provider: provider, provider: TruffleProvider.create(truffleConfig),
port: 8777,
gas: app.gasLimit, gas: app.gasLimit,
gasPrice: app.gasPrice, gasPrice: app.gasPrice,
from: accounts[0] from: accounts[0]

@ -4,7 +4,7 @@ const path = require('path');
const istanbul = require('istanbul'); const istanbul = require('istanbul');
const util = require('util'); const util = require('util');
const assert = require('assert'); const assert = require('assert');
const memdown = require('memdown'); const pify = require('pify');
const Instrumenter = require('./instrumenter'); const Instrumenter = require('./instrumenter');
const Coverage = require('./coverage'); const Coverage = require('./coverage');
@ -34,7 +34,9 @@ class App {
this.originalContractsDir = config.originalContractsDir this.originalContractsDir = config.originalContractsDir
this.client = config.client; this.client = config.client;
this.server = null;
this.providerOptions = config.providerOptions || {}; this.providerOptions = config.providerOptions || {};
this.defaultPort = 8777;
this.skippedFolders = []; this.skippedFolders = [];
this.skipFiles = config.skipFiles || []; this.skipFiles = config.skipFiles || [];
@ -124,14 +126,13 @@ class App {
this.providerOptions.gasLimit = this.gasLimitString; this.providerOptions.gasLimit = this.gasLimitString;
this.providerOptions.allowUnlimitedContractSize = true; this.providerOptions.allowUnlimitedContractSize = true;
this.providerOptions.db = memdown();
this.providerOptions.asyncRequestProcessing = true;
// Try to launch provider and attach to vm step of // Try to launch provider and attach to vm step of
// either plugin's ganache or a provider passed via options // either plugin's ganache or a provider passed via options
try { try {
this.provider = await this.attachToVM(); this.provider = await this.attachToVM();
} catch(err){ } catch(err){
console.log('err --> ' + err);
retry = true; retry = true;
this.ui.report('vm-fail', []) this.ui.report('vm-fail', [])
} }
@ -190,8 +191,8 @@ class App {
shell.rm('-Rf', this.artifactsDir); shell.rm('-Rf', this.artifactsDir);
if (this.provider && this.provider.close){ if (this.provider && this.provider.close){
this.log('Shutting down ganache-core') this.log('Shutting down ganache-core.server')
return new Promise(res => self.provider.close(res)) await pify(self.server.close)();
} }
} }
// ------------------------------------------ Utils ---------------------------------------------- // ------------------------------------------ Utils ----------------------------------------------
@ -201,7 +202,9 @@ class App {
// ======== // ========
async attachToVM(){ async attachToVM(){
const self = this; 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); this.assertHasBlockchain(provider);
@ -221,6 +224,7 @@ class App {
return vm; return vm;
} }
await pify(this.server.listen)(port);
return provider; return provider;
} }

@ -21,6 +21,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@truffle/provider": "^0.1.17",
"chalk": "^2.4.2", "chalk": "^2.4.2",
"death": "^1.1.0", "death": "^1.1.0",
"ganache-core-sc": "2.7.0-sc.0", "ganache-core-sc": "2.7.0-sc.0",
@ -30,6 +31,7 @@
"memdown": "^5.0.0", "memdown": "^5.0.0",
"node-dir": "^0.1.17", "node-dir": "^0.1.17",
"node-emoji": "^1.10.0", "node-emoji": "^1.10.0",
"pify": "^4.0.1",
"req-cwd": "^1.0.1", "req-cwd": "^1.0.1",
"shelljs": "^0.8.3", "shelljs": "^0.8.3",
"solidity-parser-antlr": "^0.4.7", "solidity-parser-antlr": "^0.4.7",

@ -166,6 +166,30 @@
dependencies: dependencies:
defer-to-connect "^1.0.1" 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": "@types/bn.js@^4.11.2":
version "4.11.5" version "4.11.5"
resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.5.tgz#40e36197433f78f807524ec623afcf0169ac81dc" resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.5.tgz#40e36197433f78f807524ec623afcf0169ac81dc"

Loading…
Cancel
Save