Remove more buildler things

experimental-options
cgewecke 3 years ago
parent 1621558758
commit 819bbafadc
  1. 148
      plugins/buidler.plugin.js
  2. 7
      plugins/nomiclabs.plugin.js
  3. 57
      test/util/integration.js

@ -1,148 +0,0 @@
const API = require('./../lib/api');
const utils = require('./resources/plugin.utils');
const buidlerUtils = require('./resources/nomiclabs.utils');
const PluginUI = require('./resources/nomiclabs.ui');
const pkg = require('./../package.json');
const death = require('death');
const path = require('path');
const { task, types } = require("@nomiclabs/buidler/config");
const { ensurePluginLoadedWithUsePlugin } = require("@nomiclabs/buidler/plugins");
const {
TASK_TEST,
TASK_COMPILE,
TASK_COMPILE_GET_COMPILER_INPUT
} = require("@nomiclabs/buidler/builtin-tasks/task-names");
ensurePluginLoadedWithUsePlugin();
function plugin() {
// UI for the task flags...
const ui = new PluginUI();
// Unset useLiteralContent due to solc metadata size restriction
task(TASK_COMPILE_GET_COMPILER_INPUT).setAction(async (_, __, runSuper) => {
const input = await runSuper();
input.settings.metadata.useLiteralContent = false;
return input;
})
task("coverage", "Generates a code coverage report for tests")
.addOptionalParam("testfiles", ui.flags.file, "", types.string)
.addOptionalParam("solcoverjs", ui.flags.solcoverjs, "", types.string)
.addOptionalParam('temp', ui.flags.temp, "", types.string)
.setAction(async function(args, env){
let error;
let ui;
let api;
let config;
try {
death(buidlerUtils.finish.bind(null, config, api)); // Catch interrupt signals
config = buidlerUtils.normalizeConfig(env.config, args);
ui = new PluginUI(config.logger.log);
api = new API(utils.loadSolcoverJS(config));
// ==============
// Server launch
// ==============
const network = buidlerUtils.setupBuidlerNetwork(env, api, ui);
const client = api.client || require('ganache-cli');
const address = await api.ganache(client);
const accountsRequest = await utils.getAccountsGanache(api.server.provider);
const nodeInfoRequest = await utils.getNodeInfoGanache(api.server.provider);
const ganacheVersion = nodeInfoRequest.result.split('/')[1];
// Set default account
network.from = accountsRequest.result[0];
// Version Info
ui.report('versions', [
ganacheVersion,
pkg.version
]);
ui.report('ganache-network', [
env.network.name,
api.port
]);
// Run post-launch server hook;
await api.onServerReady(config);
// ================
// Instrumentation
// ================
const skipFiles = api.skipFiles || [];
let {
targets,
skipped
} = utils.assembleFiles(config, skipFiles);
targets = api.instrument(targets);
utils.reportSkipped(config, skipped);
// ==============
// Compilation
// ==============
config.temp = args.temp;
const {
tempArtifactsDir,
tempContractsDir
} = utils.getTempLocations(config);
utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir)
utils.save(targets, config.paths.sources, tempContractsDir);
utils.save(skipped, config.paths.sources, tempContractsDir);
config.paths.sources = tempContractsDir;
config.paths.artifacts = tempArtifactsDir;
config.paths.cache = buidlerUtils.tempCacheDir(config);
config.solc.optimizer.enabled = false;
await env.run(TASK_COMPILE);
await api.onCompileComplete(config);
// ======
// Tests
// ======
const testfiles = args.testfiles
? buidlerUtils.getTestFilePaths(args.testfiles)
: [];
try {
await env.run(TASK_TEST, {testFiles: testfiles})
} catch (e) {
error = e;
}
await api.onTestsComplete(config);
// ========
// Istanbul
// ========
await api.report();
await api.onIstanbulComplete(config);
} catch(e) {
error = e;
}
await buidlerUtils.finish(config, api);
if (error !== undefined ) throw error;
if (process.exitCode > 0) throw new Error(ui.generate('tests-fail', [process.exitCode]));
})
}
module.exports = plugin;

@ -1,6 +1 @@
if (global && global.__hardhatContext){
require("./hardhat.plugin");
return;
}
module.exports = require('./buidler.plugin')
require("./hardhat.plugin");

@ -13,11 +13,9 @@ const TruffleConfig = require('truffle-config');
const { HARDHAT_NETWORK_NAME } = require("hardhat/plugins")
const { resetHardhatContext } = require("hardhat/plugins-testing")
const { resetBuidlerContext } = require("@nomiclabs/buidler/plugins-testing")
const temp = './sc_temp';
const truffleConfigName = 'truffle-config.js';
const buidlerConfigName = 'buidler.config.js';
const hardhatConfigName = 'hardhat.config.js';
const configPath = `${temp}/.solcover.js`;
const testPath = './test/sources/js/';
@ -35,7 +33,6 @@ function decacheConfigs(){
const paths = [
`${process.cwd()}/${temp}/.solcover.js`,
`${process.cwd()}/${temp}/${truffleConfigName}`,
`${process.cwd()}/${temp}/${buidlerConfigName}`,
`${process.cwd()}/${temp}/${hardhatConfigName}`,
`${process.cwd()}/${temp}/contracts/Simple.sol`,
`${process.cwd()}/${temp}/test/simple.js`,
@ -72,16 +69,6 @@ function getOutput(config){
return JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
}
// Buidler env set up
function buidlerSetupEnv(mocha) {
const mockwd = path.join(process.cwd(), temp);
previousCWD = process.cwd();
process.chdir(mockwd);
mocha.env = require("@nomiclabs/buidler");
mocha.env.config.logger = testLogger
mocha.logger = testLogger
};
// Hardhat env set up
function hardhatSetupEnv(mocha) {
const mockwd = path.join(process.cwd(), temp);
@ -92,12 +79,6 @@ function hardhatSetupEnv(mocha) {
mocha.logger = testLogger
};
// Buidler env tear down
function buidlerTearDownEnv() {
resetBuidlerContext();
process.chdir(previousCWD);
};
// Hardhat env tear down
function hardhatTearDownEnv() {
resetHardhatContext();
@ -178,17 +159,6 @@ function getDefaultNomicLabsConfig(){
return vals;
}
function getDefaultBuidlerConfig() {
const config = getDefaultNomicLabsConfig()
config.defaultNetwork = "buidlerevm";
config.solc = {
version: "0.7.3",
evmVersion: 'petersburg'
}
return config;
}
function getDefaultHardhatConfig() {
const config = getDefaultNomicLabsConfig()
config.defaultNetwork = HARDHAT_NETWORK_NAME;
@ -198,22 +168,6 @@ function getDefaultHardhatConfig() {
return config;
}
function getBuidlerConfigJS(config){
// Hardhat tests will crash if the buidler plugin is loaded from the shared entrypoint
// b/c of some kind of weird cacheing or context reset issue.
const prefix =`
const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing");
loadPluginFile(__dirname + "/../plugins/buidler.plugin");
usePlugin("@nomiclabs/buidler-truffle5");
`
if (config) {
return `${prefix}module.exports = ${JSON.stringify(config, null, ' ')}`;
} else {
return `${prefix}module.exports = ${JSON.stringify(getDefaultBuidlerConfig(), null, ' ')}`;
}
}
function getHardhatConfigJS(config){
const prefix =`
require("@nomiclabs/hardhat-truffle5");
@ -262,7 +216,7 @@ function deployDouble(contractNames){
// Project Installers
// ==========================
/**
* Installs mock truffle/buidler project at ./temp with a single contract
* Installs mock project at ./temp with a single contract
* and test specified by the params.
* @param {String} contract <contractName.sol> located in /test/sources/cli/
* @param {[type]} test <testName.js> located in /test/cli/
@ -293,7 +247,6 @@ function install(
// Configs
fs.writeFileSync(`${temp}/${truffleConfigName}`, getTruffleConfigJS(devPlatformConfig));
fs.writeFileSync(`${temp}/${buidlerConfigName}`, getBuidlerConfigJS(devPlatformConfig));
fs.writeFileSync(`${temp}/${hardhatConfigName}`, getHardhatConfigJS(devPlatformConfig));
if(solcoverConfig) fs.writeFileSync(configPath, solcoverJS);
@ -301,7 +254,7 @@ function install(
};
/**
* Installs mock truffle/buidler project with two contracts (for inheritance, libraries, etc)
* Installs mock project with two contracts (for inheritance, libraries, etc)
*/
function installDouble(contracts, test, config, skipMigration) {
const configjs = getSolcoverJS(config);
@ -328,7 +281,6 @@ function installDouble(contracts, test, config, skipMigration) {
// Configs
fs.writeFileSync(`${temp}/${truffleConfigName}`, getTruffleConfigJS());
fs.writeFileSync(`${temp}/${buidlerConfigName}`, getBuidlerConfigJS());
fs.writeFileSync(`${temp}/${hardhatConfigName}`, getHardhatConfigJS());
fs.writeFileSync(configPath, configjs);
@ -336,7 +288,7 @@ function installDouble(contracts, test, config, skipMigration) {
};
/**
* Installs full truffle/buidler project
* Installs full project
*/
function installFullProject(name, config) {
shell.mkdir(temp);
@ -370,7 +322,6 @@ module.exports = {
testLogger: testLogger,
loggerOutput: loggerOutput,
getDefaultTruffleConfig: getDefaultTruffleConfig,
getDefaultBuidlerConfig: getDefaultBuidlerConfig,
getDefaultHardhatConfig: getDefaultHardhatConfig,
install: install,
installDouble: installDouble,
@ -378,8 +329,6 @@ module.exports = {
clean: clean,
pathToContract: pathToContract,
getOutput: getOutput,
buidlerSetupEnv: buidlerSetupEnv,
buidlerTearDownEnv: buidlerTearDownEnv,
hardhatSetupEnv: hardhatSetupEnv,
hardhatTearDownEnv: hardhatTearDownEnv
}

Loading…
Cancel
Save