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
180 changes: 180 additions & 0 deletions test/units/buidler/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
const assert = require('assert');
const fs = require('fs');
const path = require('path')
const pify = require('pify')
const shell = require('shelljs');
const ganache = require('ganache-core-sc');

const verify = require('../../util/verifiers')
const mock = require('../../util/integration');
const plugin = require('../../../dist/buidler.plugin');

// =======
// Errors
// =======

describe('Buidler Plugin: error cases', function() {
let buidlerConfig;
let solcoverConfig;

beforeEach(() => {
mock.clean();

mock.loggerOutput.val = '';
solcoverConfig = { skipFiles: ['Migrations.sol']};
buidlerConfig = mock.getDefaultBuidlerConfig();
verify.cleanInitialState();
})

afterEach(() => {
mock.buidlerTearDownEnv();
mock.clean();
});

it('project contains no contract sources folder', async function() {
mock.installFullProject('no-sources');
mock.buidlerSetupEnv(this);

try {
await this.env.run("coverage");
assert.fail()
} catch(err){
assert(
err.message.includes('Cannot locate expected contract sources folder'),
`Should error when contract sources cannot be found:: ${err.message}`
);

assert(
err.message.includes('sc_temp/contracts'),
`Error message should contain path:: ${err.message}`
);
}

verify.coverageNotGenerated(buidlerConfig);
});

it('.solcover.js has syntax error', async function(){
mock.installFullProject('bad-solcoverjs');
mock.buidlerSetupEnv(this);

try {
await this.env.run("coverage");
assert.fail()
} catch(err){
assert(
err.message.includes('Could not load .solcover.js config file.'),
`Should notify when solcoverjs has syntax error:: ${err.message}`
);
}

verify.coverageNotGenerated(buidlerConfig);
})

it('.solcover.js has incorrectly formatted option', async function(){
solcoverConfig.port = "Antwerpen";

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

try {
await this.env.run("coverage");
assert.fail()
} catch (err) {
assert(
err.message.includes('config option'),
`Should error on incorrect config options: ${err.message}`
);
}
});

it('tries to launch with a port already in use', async function(){
const server = ganache.server();

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

await pify(server.listen)(8555);

try {
await this.env.run("coverage");
assert.fail();
} catch(err){
assert(
err.message.includes('is already in use') &&
err.message.includes('lsof'),
`Should error on port-in-use with advice: ${err.message}`
)
}

await pify(server.close)();
});

it('uses an invalid istanbul reporter', async function() {
solcoverConfig = {
silent: process.env.SILENT ? true : false,
istanbulReporter: ['does-not-exist']
};

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

try {
await this.env.run("coverage");
assert.fail();
} catch(err){
assert(
err.message.includes('does-not-exist') &&
err.message.includes('coverage reports could not be generated'),
`Should error on invalid reporter: ${err.message}`
)
}

});

// Truffle test contains syntax error
it('truffle crashes', async function() {
mock.install('Simple', 'truffle-crash.js', solcoverConfig);
mock.buidlerSetupEnv(this);

try {
await this.env.run("coverage");
assert.fail()
} catch(err){
assert(err.toString().includes('SyntaxError'));
}
});

// Solidity syntax errors
it('compilation failure', async function(){
mock.install('SimpleError', 'simple.js', solcoverConfig);
mock.buidlerSetupEnv(this);

try {
await this.env.run("coverage");
assert.fail()
} catch(err){
assert(err.message.includes('Compilation failed'));
}

verify.coverageNotGenerated(buidlerConfig);
});

it('instrumentation failure', async function(){
mock.install('Unparseable', 'simple.js', solcoverConfig);
mock.buidlerSetupEnv(this);

try {
await this.env.run("coverage");
assert.fail()
} catch(err){
assert(
err.message.includes('Unparseable.sol.'),
`Should throw instrumentation errors with file name: ${err.toString()}`
);

assert(err.stack !== undefined, 'Should have error trace')
}

verify.coverageNotGenerated(buidlerConfig);
});
})
1 change: 0 additions & 1 deletion test/units/truffle/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ describe('Truffle Plugin: error cases', function() {
}
});

// This case *does* throw an error, but it's uncatch-able;
it('tries to launch with a port already in use', async function(){
const server = ganache.server();

Expand Down