From 1c257b0c74aa44c3979bf8e681e2bf474165d1f2 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Thu, 1 Feb 2024 21:19:11 -0800 Subject: [PATCH] Remove migrations and skipped/stale tests from test suite (#840) --- test/integration/generic/contracts/.marker | 1 + .../generic/contracts/Migrations.sol | 25 ------- .../generic/migrations/1_initial.js | 4 -- .../migrations/1_initial_migration.js | 5 -- .../libraries/migrations/2_contracta.js | 8 --- test/integration/projects/solc-6/.solcover.js | 8 --- .../projects/solc-6/contracts/B_Wallet.sol | 24 ------- .../projects/solc-6/contracts/ContractA.sol | 66 ------------------- .../projects/solc-6/contracts/ContractB.sol | 19 ------ .../projects/solc-6/hardhat.config.js | 9 --- .../projects/solc-6/test/b_wallet.js | 26 -------- test/integration/projects/solc-6/test/test.js | 27 -------- test/integration/projects/solc-7/.solcover.js | 6 -- .../solc-7/contracts/Contract_solc7.sol | 52 --------------- .../solc-7/contracts/Functions_solc7.sol | 19 ------ .../projects/solc-7/hardhat.config.js | 9 --- .../projects/solc-7/test/test_solc7.js | 23 ------- .../migrations/1_initial_migration.js | 5 -- .../test-files/migrations/2_contracta.js | 5 -- .../test-files/migrations/3_contractb.js | 5 -- .../test-files/migrations/4_contractc.js | 5 -- test/units/hardhat/errors.js | 26 +------- test/units/hardhat/flags.js | 11 +--- test/units/hardhat/standard.js | 56 +--------------- test/util/integration.js | 40 +---------- 25 files changed, 6 insertions(+), 478 deletions(-) create mode 100644 test/integration/generic/contracts/.marker delete mode 100644 test/integration/generic/contracts/Migrations.sol delete mode 100644 test/integration/generic/migrations/1_initial.js delete mode 100644 test/integration/projects/libraries/migrations/1_initial_migration.js delete mode 100644 test/integration/projects/libraries/migrations/2_contracta.js delete mode 100644 test/integration/projects/solc-6/.solcover.js delete mode 100644 test/integration/projects/solc-6/contracts/B_Wallet.sol delete mode 100644 test/integration/projects/solc-6/contracts/ContractA.sol delete mode 100644 test/integration/projects/solc-6/contracts/ContractB.sol delete mode 100644 test/integration/projects/solc-6/hardhat.config.js delete mode 100644 test/integration/projects/solc-6/test/b_wallet.js delete mode 100644 test/integration/projects/solc-6/test/test.js delete mode 100644 test/integration/projects/solc-7/.solcover.js delete mode 100644 test/integration/projects/solc-7/contracts/Contract_solc7.sol delete mode 100644 test/integration/projects/solc-7/contracts/Functions_solc7.sol delete mode 100644 test/integration/projects/solc-7/hardhat.config.js delete mode 100644 test/integration/projects/solc-7/test/test_solc7.js delete mode 100644 test/integration/projects/test-files/migrations/1_initial_migration.js delete mode 100644 test/integration/projects/test-files/migrations/2_contracta.js delete mode 100644 test/integration/projects/test-files/migrations/3_contractb.js delete mode 100644 test/integration/projects/test-files/migrations/4_contractc.js diff --git a/test/integration/generic/contracts/.marker b/test/integration/generic/contracts/.marker new file mode 100644 index 00000000..3cc5d931 --- /dev/null +++ b/test/integration/generic/contracts/.marker @@ -0,0 +1 @@ +// because circle won't copy the folder w/out contents diff --git a/test/integration/generic/contracts/Migrations.sol b/test/integration/generic/contracts/Migrations.sol deleted file mode 100644 index 955d1248..00000000 --- a/test/integration/generic/contracts/Migrations.sol +++ /dev/null @@ -1,25 +0,0 @@ -pragma solidity >=0.4.22 <0.8.0; - - -contract Migrations { - address public owner; - - uint public last_completed_migration; - - modifier restricted() { - if (msg.sender == owner) { _; } - } - - constructor() public { - owner = msg.sender; - } - - function setCompleted(uint completed) public restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) public restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} diff --git a/test/integration/generic/migrations/1_initial.js b/test/integration/generic/migrations/1_initial.js deleted file mode 100644 index cd29782f..00000000 --- a/test/integration/generic/migrations/1_initial.js +++ /dev/null @@ -1,4 +0,0 @@ -const Migrations = artifacts.require('./Migrations.sol'); -module.exports = async function(deployer) { - await deployer.deploy(Migrations); -}; diff --git a/test/integration/projects/libraries/migrations/1_initial_migration.js b/test/integration/projects/libraries/migrations/1_initial_migration.js deleted file mode 100644 index ee2135d2..00000000 --- a/test/integration/projects/libraries/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -const Migrations = artifacts.require("Migrations"); - -module.exports = function(deployer) { - deployer.deploy(Migrations); -}; diff --git a/test/integration/projects/libraries/migrations/2_contracta.js b/test/integration/projects/libraries/migrations/2_contracta.js deleted file mode 100644 index 80eda3a1..00000000 --- a/test/integration/projects/libraries/migrations/2_contracta.js +++ /dev/null @@ -1,8 +0,0 @@ -const UsesPure = artifacts.require("UsesPure"); -const CLibrary = artifacts.require("CLibrary"); - -module.exports = function(deployer) { - deployer.deploy(CLibrary); - deployer.link(CLibrary, UsesPure); - deployer.deploy(UsesPure); -}; \ No newline at end of file diff --git a/test/integration/projects/solc-6/.solcover.js b/test/integration/projects/solc-6/.solcover.js deleted file mode 100644 index c2453041..00000000 --- a/test/integration/projects/solc-6/.solcover.js +++ /dev/null @@ -1,8 +0,0 @@ -// Testing hooks -const fn = (msg, config) => config.logger.log(msg); - -module.exports = { - skipFiles: ['Migrations.sol'], - silent: process.env.SILENT ? true : false, - istanbulReporter: ['json-summary', 'text'], -} diff --git a/test/integration/projects/solc-6/contracts/B_Wallet.sol b/test/integration/projects/solc-6/contracts/B_Wallet.sol deleted file mode 100644 index d47470df..00000000 --- a/test/integration/projects/solc-6/contracts/B_Wallet.sol +++ /dev/null @@ -1,24 +0,0 @@ -pragma solidity ^0.6.0; - -contract B_Wallet { - - event Deposit(address indexed _sender, uint _value, bytes data); - - receive() external payable - { - if (msg.value > 0) - emit Deposit(msg.sender, msg.value, msg.data); - } - - function transferPayment(uint payment, address payable recipient) public { - recipient.transfer(payment); - } - - function sendPayment(uint payment, address payable recipient) public { - require(recipient.send(payment), 'sendPayment failed'); - } - - function getBalance() public view returns(uint){ - return address(this).balance; - } -} diff --git a/test/integration/projects/solc-6/contracts/ContractA.sol b/test/integration/projects/solc-6/contracts/ContractA.sol deleted file mode 100644 index 75bb9195..00000000 --- a/test/integration/projects/solc-6/contracts/ContractA.sol +++ /dev/null @@ -1,66 +0,0 @@ -pragma solidity ^0.6.0; - -import "./ContractB.sol"; - -/** - * New syntaxes in solc 0.6.x - */ -contract ContractA is ContractB { - uint counter; - uint errorCount; - - uint private immutable _a = 100; - uint private immutable override _b = 100; - - modifier overridden() override { - require(true); - _; - } - - constructor() public { - } - - function simpleSet(uint i) - public - override(ContractB) - { - counter = counter + i; - } - - function simpleView(uint i) - view - overridden - external - returns (uint, bool) - { - return (counter + i, true); - } - - function tryCatch() public returns (uint, bool) { - try this.simpleView(5) returns (uint, bool) { - return (2, true); - } catch Error(string memory) { - errorCount++; - return (0, false); - } catch (bytes memory) { - errorCount = errorCount + 1; - return (0, false); - } - } - - function arraySlice(uint _a, uint b_) public pure { - abi.decode(msg.data[4:], (uint, uint)); - } - - function payableFn() public pure { - address x; - //address y = payable(x); // parser-diligence crashing here... - } -} - -// Making sure same-file inheritance works for solc-6... -contract ContractC is ContractA { - function simpleC(uint x) public { - x++; - } -} diff --git a/test/integration/projects/solc-6/contracts/ContractB.sol b/test/integration/projects/solc-6/contracts/ContractB.sol deleted file mode 100644 index a56dbbc6..00000000 --- a/test/integration/projects/solc-6/contracts/ContractB.sol +++ /dev/null @@ -1,19 +0,0 @@ -pragma solidity ^0.6.0; - - -contract ContractB { - uint value; - uint b; - - constructor() public { - } - - modifier overridden() virtual { - require(true); - _; - } - - function simpleSet(uint i) public virtual { - value = 5; - } -} diff --git a/test/integration/projects/solc-6/hardhat.config.js b/test/integration/projects/solc-6/hardhat.config.js deleted file mode 100644 index 448b09d2..00000000 --- a/test/integration/projects/solc-6/hardhat.config.js +++ /dev/null @@ -1,9 +0,0 @@ -require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../plugins/nomiclabs.plugin"); - -module.exports = { - solidity: { - version: "0.6.7" - }, - logger: process.env.SILENT ? { log: () => {} } : console, -}; diff --git a/test/integration/projects/solc-6/test/b_wallet.js b/test/integration/projects/solc-6/test/b_wallet.js deleted file mode 100644 index 0eeb2613..00000000 --- a/test/integration/projects/solc-6/test/b_wallet.js +++ /dev/null @@ -1,26 +0,0 @@ -const Wallet = artifacts.require('B_Wallet'); - -contract('B_Wallet', accounts => { - it('should should allow transfers and sends', async () => { - const walletA = await Wallet.new(); - const walletB = await Wallet.new(); - - await walletA.sendTransaction({ - value: web3.utils.toBN(500), from: accounts[0], - }); - - await walletA.sendPayment(50, walletB.address, { - from: accounts[0], - }); - - await walletA.transferPayment(50, walletB.address, { - from: accounts[0], - }); - - // Also try transferring 0, for branch hit - await walletA.transferPayment(0, walletB.address, { - from: accounts[0], - }); - }); -}); - diff --git a/test/integration/projects/solc-6/test/test.js b/test/integration/projects/solc-6/test/test.js deleted file mode 100644 index 00834d06..00000000 --- a/test/integration/projects/solc-6/test/test.js +++ /dev/null @@ -1,27 +0,0 @@ -const ContractA = artifacts.require("ContractA"); - -contract("contracta", function(accounts) { - let instance; - - before(async () => instance = await ContractA.new()) - - it('simpleSet (overridden method)', async function(){ - await instance.simpleSet(5); - }); - - it('simpleView (overridden modifier)', async function(){ - await instance.simpleView(5); - }); - - it('tryCatch', async function(){ - await instance.tryCatch(); - }); - - it('arraySlice', async function(){ - await instance.arraySlice(5,7); - }); - - it('payableFn', async function(){ - await instance.payableFn(); - }) -}); diff --git a/test/integration/projects/solc-7/.solcover.js b/test/integration/projects/solc-7/.solcover.js deleted file mode 100644 index fc5a56be..00000000 --- a/test/integration/projects/solc-7/.solcover.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - silent: process.env.SILENT ? true : false, - skipFiles: ['skipped-folder'], - istanbulReporter: ['json-summary', 'text'], - configureYulOptimizer: true -} diff --git a/test/integration/projects/solc-7/contracts/Contract_solc7.sol b/test/integration/projects/solc-7/contracts/Contract_solc7.sol deleted file mode 100644 index d93697b4..00000000 --- a/test/integration/projects/solc-7/contracts/Contract_solc7.sol +++ /dev/null @@ -1,52 +0,0 @@ -pragma solidity ^0.7.4; -pragma abicoder v2; - -import { - LENDING_POOL, - CHAINLINK, - _addFive, - _addSeven -} from "./Functions_solc7.sol"; - -function _addTen(uint x) - pure - returns (uint) -{ - return x + 10; -} - -/** - * New syntaxes in solc 0.7.x - */ -contract ContractA { - uint y = 5; - - function addFive() - public - view - returns (uint) - { - return _addFive(y); - } - - function addSeven() - public - view - returns (uint) - { - return _addSeven(y); - } -} - -contract ContractB { - uint y = 5; - - function addTen() - public - view - returns (uint) - { - return _addTen(y); - } - -} diff --git a/test/integration/projects/solc-7/contracts/Functions_solc7.sol b/test/integration/projects/solc-7/contracts/Functions_solc7.sol deleted file mode 100644 index f2f7e39b..00000000 --- a/test/integration/projects/solc-7/contracts/Functions_solc7.sol +++ /dev/null @@ -1,19 +0,0 @@ -pragma solidity ^0.7.4; -pragma experimental ABIEncoderV2; - -address constant LENDING_POOL = 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5; -address constant CHAINLINK = 0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419; - -function _addFive(uint x) - pure - returns (uint) -{ - return x + 5; -} - -function _addSeven(uint x) - pure - returns (uint) -{ - return x + 7; -} diff --git a/test/integration/projects/solc-7/hardhat.config.js b/test/integration/projects/solc-7/hardhat.config.js deleted file mode 100644 index f8f9e1de..00000000 --- a/test/integration/projects/solc-7/hardhat.config.js +++ /dev/null @@ -1,9 +0,0 @@ -require("@nomiclabs/hardhat-truffle5"); -require(__dirname + "/../plugins/nomiclabs.plugin"); - -module.exports = { - solidity: { - version: "0.7.6" - }, - logger: process.env.SILENT ? { log: () => {} } : console, -}; diff --git a/test/integration/projects/solc-7/test/test_solc7.js b/test/integration/projects/solc-7/test/test_solc7.js deleted file mode 100644 index 8de2f486..00000000 --- a/test/integration/projects/solc-7/test/test_solc7.js +++ /dev/null @@ -1,23 +0,0 @@ -const ContractA = artifacts.require("ContractA"); -const ContractB = artifacts.require("ContractB"); - -contract("contracta", function(accounts) { - let a,b; - - before(async () => { - a = await ContractA.new(); - b = await ContractB.new(); - }) - - it('a:addFive', async function(){ - await a.addFive(); - }); - - it('a:addSeven', async function(){ - //await a.addSeven(); - }); - - it('b:addTen', async function(){ - await b.addTen(); - }) -}); diff --git a/test/integration/projects/test-files/migrations/1_initial_migration.js b/test/integration/projects/test-files/migrations/1_initial_migration.js deleted file mode 100644 index ee2135d2..00000000 --- a/test/integration/projects/test-files/migrations/1_initial_migration.js +++ /dev/null @@ -1,5 +0,0 @@ -const Migrations = artifacts.require("Migrations"); - -module.exports = function(deployer) { - deployer.deploy(Migrations); -}; diff --git a/test/integration/projects/test-files/migrations/2_contracta.js b/test/integration/projects/test-files/migrations/2_contracta.js deleted file mode 100644 index ff990ec2..00000000 --- a/test/integration/projects/test-files/migrations/2_contracta.js +++ /dev/null @@ -1,5 +0,0 @@ -const ContractA = artifacts.require("ContractA"); - -module.exports = function(deployer) { - deployer.deploy(ContractA); -}; \ No newline at end of file diff --git a/test/integration/projects/test-files/migrations/3_contractb.js b/test/integration/projects/test-files/migrations/3_contractb.js deleted file mode 100644 index f81775aa..00000000 --- a/test/integration/projects/test-files/migrations/3_contractb.js +++ /dev/null @@ -1,5 +0,0 @@ -const ContractB = artifacts.require("ContractB"); - -module.exports = function(deployer) { - deployer.deploy(ContractB); -}; \ No newline at end of file diff --git a/test/integration/projects/test-files/migrations/4_contractc.js b/test/integration/projects/test-files/migrations/4_contractc.js deleted file mode 100644 index 279761a7..00000000 --- a/test/integration/projects/test-files/migrations/4_contractc.js +++ /dev/null @@ -1,5 +0,0 @@ -const ContractC = artifacts.require("ContractC"); - -module.exports = function(deployer) { - deployer.deploy(ContractC); -}; \ No newline at end of file diff --git a/test/units/hardhat/errors.js b/test/units/hardhat/errors.js index 18907a12..e9fb47dc 100644 --- a/test/units/hardhat/errors.js +++ b/test/units/hardhat/errors.js @@ -20,7 +20,7 @@ describe('Hardhat Plugin: error cases', function() { mock.clean(); mock.loggerOutput.val = ''; - solcoverConfig = { skipFiles: ['Migrations.sol']}; + solcoverConfig = {}; hardhatConfig = mock.getDefaultHardhatConfig(); verify.cleanInitialState(); }) @@ -30,30 +30,6 @@ describe('Hardhat Plugin: error cases', function() { mock.clean(); }); - // We're no longer checking context in HH since 2.0.4 because it just uses - // all the default paths. (HH dev dep currently above that: (>= 2.0.7)) - it.skip('project contains no contract sources folder', async function() { - mock.installFullProject('no-sources'); - mock.hardhatSetupEnv(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(hardhatConfig); - }); - it('.solcover.js has syntax error', async function(){ mock.installFullProject('bad-solcoverjs'); mock.hardhatSetupEnv(this); diff --git a/test/units/hardhat/flags.js b/test/units/hardhat/flags.js index f8765558..10e01ad2 100644 --- a/test/units/hardhat/flags.js +++ b/test/units/hardhat/flags.js @@ -19,7 +19,7 @@ describe('Hardhat Plugin: command line options', function() { mock.loggerOutput.val = ''; solcoverConfig = { - skipFiles: ['Migrations.sol'], + skipFiles: [], silent: process.env.SILENT ? true : false, istanbulReporter: ['json-summary', 'text'] }; @@ -200,15 +200,6 @@ describe('Hardhat Plugin: command line options', function() { it('--abi', async function(){ const expected = [ - { - "contractName": "Migrations", - "humanReadableAbiList": [ - "function last_completed_migration() view returns (uint256)", - "function owner() view returns (address)", - "function setCompleted(uint256) nonpayable", - "function upgrade(address) nonpayable" - ] - }, { "contractName": "Simple", "humanReadableAbiList": [ diff --git a/test/units/hardhat/standard.js b/test/units/hardhat/standard.js index 4d4aa009..2cb13bc6 100644 --- a/test/units/hardhat/standard.js +++ b/test/units/hardhat/standard.js @@ -19,7 +19,7 @@ describe('Hardhat Plugin: standard use cases', function() { mock.loggerOutput.val = ''; solcoverConfig = { - skipFiles: ['Migrations.sol'], + skipFiles: [], istanbulReporter: [ "json-summary", "text"] }; hardhatConfig = mock.getDefaultHardhatConfig(); @@ -72,15 +72,6 @@ describe('Hardhat Plugin: standard use cases', function() { ); }); - // Test fixture is not compatible with HH 2.5.0. Throws mysterious error (though fixture has no libs?) - // HH11: Internal invariant was violated: Libraries should have both name and version, or neither one - it.skip('with relative path solidity imports', async function() { - mock.installFullProject('import-paths'); - mock.hardhatSetupEnv(this); - - await this.env.run("coverage"); - }); - it('uses inheritance', async function() { mock.installDouble( ['Proxy', 'Owned'], @@ -281,51 +272,6 @@ describe('Hardhat Plugin: standard use cases', function() { ); }); - it('solc 0.6.x', async function(){ - mock.installFullProject('solc-6'); - mock.hardhatSetupEnv(this); - - await this.env.run("coverage"); - - const expected = [ - { - file: mock.pathToContract(hardhatConfig, 'ContractA.sol'), - pct: 61.54 - }, - { - file: mock.pathToContract(hardhatConfig, 'ContractB.sol'), - pct: 0, - }, - { - file: mock.pathToContract(hardhatConfig, 'B_Wallet.sol'), - pct: 80, - }, - - ]; - - verify.lineCoverage(expected); - }) - - it('solc 0.7.x', async function(){ - mock.installFullProject('solc-7'); - mock.hardhatSetupEnv(this); - - await this.env.run("coverage"); - - const expected = [ - { - file: mock.pathToContract(hardhatConfig, 'Contract_solc7.sol'), - pct: 75 - }, - { - file: mock.pathToContract(hardhatConfig, 'Functions_solc7.sol'), - pct: 50, - } - ]; - - verify.lineCoverage(expected); - }) - it('solc 0.8.x', async function(){ mock.installFullProject('solc-8'); mock.hardhatSetupEnv(this); diff --git a/test/util/integration.js b/test/util/integration.js index 4f68cf28..68d96800 100644 --- a/test/util/integration.js +++ b/test/util/integration.js @@ -17,7 +17,6 @@ const hardhatConfigName = 'hardhat.config.js'; const configPath = `${temp}/.solcover.js`; const testPath = './test/sources/js/'; const sourcesPath = './test/sources/solidity/contracts/app/'; -const migrationPath = `${temp}/migrations/2_deploy.js`; const templatePath = './test/integration/generic/*'; const projectPath = './test/integration/projects/' @@ -141,29 +140,6 @@ function getSolcoverJS(config){ return `module.exports = ${JSON.stringify(config, null, ' ')}` } - -// ========================== -// Migration Generators -// ========================== -function deploySingle(contractName){ - return ` - const A = artifacts.require("${contractName}"); - module.exports = function(deployer) { deployer.deploy(A) }; - `; -} - -function deployDouble(contractNames){ - return ` - var A = artifacts.require("${contractNames[0]}"); - var B = artifacts.require("${contractNames[1]}"); - module.exports = function(deployer) { - deployer.deploy(A); - deployer.link(A, B); - deployer.deploy(B); - }; - `; -} - // ========================== // Project Installers // ========================== @@ -177,13 +153,10 @@ function install( contract, test, solcoverConfig, - devPlatformConfig, - noMigrations + devPlatformConfig ) { if(solcoverConfig) solcoverJS = getSolcoverJS(solcoverConfig); - const migration = deploySingle(contract); - // Scaffold shell.mkdir(temp); shell.cp('-Rf', templatePath, temp); @@ -191,9 +164,6 @@ function install( // Contract shell.cp(`${sourcesPath}${contract}.sol`, `${temp}/contracts/${contract}.sol`); - // Migration - if (!noMigrations) fs.writeFileSync(migrationPath, migration); - // Test shell.cp(`${testPath}${test}`, `${temp}/test/${test}`); @@ -207,9 +177,8 @@ function install( /** * Installs mock project with two contracts (for inheritance, libraries, etc) */ -function installDouble(contracts, test, config, skipMigration) { +function installDouble(contracts, test, config) { const configjs = getSolcoverJS(config); - const migration = deployDouble(contracts); // Scaffold shell.mkdir(temp); @@ -222,11 +191,6 @@ function installDouble(contracts, test, config, skipMigration) { : shell.cp(`${sourcesPath}${item}.sol`, `${temp}/contracts/${item}.sol`); }); - // Migration - if (!skipMigration){ - fs.writeFileSync(migrationPath, migration) - } - // Test shell.cp(`${testPath}${test}`, `${temp}/test/${test}`);