Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions dist/buidler.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ function plugin() {
// ==============
// Server launch
// ==============
const network = buidlerUtils.setupNetwork(
env,
api,
args,
ui
);

const address = await api.ganache(ganache);
const network = buidlerUtils.setupNetwork(env, api, ui);

const client = api.client || ganache;
const address = await api.ganache(client);
const web3 = new Web3(address);
const accounts = await web3.eth.getAccounts();
const nodeInfo = await web3.eth.getNodeInfo();
Expand All @@ -68,9 +64,8 @@ function plugin() {
pkg.version
]);

// Network Info
ui.report('network', [
api.defaultNetworkName,
env.network.name,
api.port
]);

Expand Down
20 changes: 12 additions & 8 deletions dist/plugin-assets/buidler.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { createProvider } = require("@nomiclabs/buidler/internal/core/providers/c
* @param {BuidlerConfig} config
* @return {BuidlerConfig} updated config
*/
function normalizeConfig(config, args){
function normalizeConfig(config, args={}){
config.workingDir = config.paths.root;
config.contractsDir = config.paths.sources;
config.testDir = config.paths.tests;
Expand All @@ -27,11 +27,15 @@ function normalizeConfig(config, args){
return config;
}

function setupNetwork(env, api, taskArgs, ui){
function setupNetwork(env, api, ui){
let networkConfig = {};

if (taskArgs.network){
networkConfig = env.config.networks[taskArgs.network];
let networkName = (env.buidlerArguments.network !== 'buidlerevm')
? env.buidlerArguments.network
: api.defaultNetworkName;

if (networkName !== api.defaultNetworkName){
networkConfig = env.config.networks[networkName];

const configPort = networkConfig.url.split(':')[2];

Expand All @@ -48,13 +52,13 @@ function setupNetwork(env, api, taskArgs, ui){
networkConfig.gas = api.gasLimit;
networkConfig.gasPrice = api.gasPrice;

const provider = createProvider(api.defaultNetworkName, networkConfig);
const provider = createProvider(networkName, networkConfig);

env.config.networks[api.defaultNetworkName] = networkConfig;
env.config.defaultNetwork = api.defaultNetworkName;
env.config.networks[networkName] = networkConfig;
env.config.defaultNetwork = networkName;

env.network = {
name: api.defaultNetworkName,
name: networkName,
config: networkConfig,
provider: provider,
}
Expand Down
3 changes: 2 additions & 1 deletion dist/truffle.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ async function plugin(config){
truffleUtils.setNetwork(config, api);

// Server launch
const address = await api.ganache(truffle.ganache);
const client = api.client || truffle.ganache;
const address = await api.ganache(client);

const web3 = new Web3(address);
const accounts = await web3.eth.getAccounts();
Expand Down
9 changes: 4 additions & 5 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ class API {
this.onIstanbulComplete = config.onIstanbulComplete || this.defaultHook;

this.server = null;
this.provider = null;
this.defaultPort = 8555;
this.defaultNetworkName = 'soliditycoverage';
this.client = config.client;
this.defaultNetworkName = 'soliditycoverage';
this.port = config.port || this.defaultPort;
this.host = config.host || "127.0.0.1";
this.providerOptions = config.providerOptions || {};
Expand Down Expand Up @@ -224,9 +223,9 @@ class API {
async attachToVM(client){
const self = this;

// Prefer client from options
if(!this.client) this.client = client;
this.server = this.client.server(this.providerOptions);
// Fallback to client from options
if(!client) client = this.client;
this.server = client.server(this.providerOptions);

this.assertHasBlockchain(this.server.provider);
await this.vmIsResolved(this.server.provider);
Expand Down
32 changes: 31 additions & 1 deletion scripts/run-buidler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,47 @@ fi

echo "PR_PATH >>>>> $PR_PATH"

echo ""
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Simple buidler/buidler-trufflev5 "
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo ""

# Install buidler e2e test
git clone https://github.com/sc-forks/buidler-e2e.git
cd buidler-e2e
npm install

# Install and run solidity-coverage @ PR
npm install --save-dev $PR_PATH
cat package.json

npx buidler coverage

# Test that coverage/ was generated
if [ ! -d "coverage" ]; then
echo "ERROR: no coverage folder was created for buidler-trufflev5."
exit 1
fi

echo ""
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Simple buidler/buidler-ethers "
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo ""
cd ..
git clone https://github.com/sc-forks/example-buidler-ethers.git
cd example-buidler-ethers
npm install

# Install and run solidity-coverage @ PR
npm install --save-dev $PR_PATH
cat package.json

npx buidler coverage

# Test that coverage/ was generated
if [ ! -d "coverage" ]; then
echo "ERROR: no coverage folder was created."
echo "ERROR: no coverage folder was created for buidler-ethers."
exit 1
fi
1 change: 1 addition & 0 deletions scripts/run-moloch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ npm install
npm uninstall --save-dev solidity-coverage

# Install and run solidity-coverage @ PR
# Should run on network 'localhost'
npm install --save-dev $PR_PATH
npm run coverage

Expand Down
13 changes: 8 additions & 5 deletions test/units/buidler/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ describe('Buidler Plugin: command line options', function() {
});

it('--network (declared port mismatches)', async function(){
const taskArgs = {
network: 'development' // 8545
}

solcoverConfig.port = 8222;

mock.install('Simple', 'simple.js', solcoverConfig);
mock.buidlerSetupEnv(this);

await this.env.run("coverage", taskArgs);
this.env.buidlerArguments.network = "development";

await this.env.run("coverage");

assert(
mock.loggerOutput.val.includes("The 'port' values"),
Expand All @@ -74,6 +72,11 @@ describe('Buidler Plugin: command line options', function() {
`Should have used default coverage port 8545: ${mock.loggerOutput.val}`
);

assert(
mock.loggerOutput.val.includes("development"),
`Should have used specified network name: ${mock.loggerOutput.val}`
);

const expected = [{
file: mock.pathToContract(buidlerConfig, 'Simple.sol'),
pct: 100
Expand Down
19 changes: 19 additions & 0 deletions test/units/buidler/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,25 @@ describe('Buidler Plugin: standard use cases', function() {
);
});

it('default network ("buidlerevm")', async function(){
mock.install('Simple', 'simple.js', solcoverConfig);
mock.buidlerSetupEnv(this);

this.env.buidlerArguments.network = "buidlerevm"

await this.env.run("coverage");

assert(
mock.loggerOutput.val.includes("8555"),
`Should have used default coverage port 8555: ${mock.loggerOutput.val}`
);

assert(
mock.loggerOutput.val.includes("soliditycoverage"),
`Should have used specified network name: ${mock.loggerOutput.val}`
);
});

it('with relative path solidity imports', async function() {
mock.installFullProject('import-paths');
mock.buidlerSetupEnv(this);
Expand Down