Remove migrations and skipped/stale tests from test suite (#840)

pull/845/head
cgewecke 10 months ago committed by GitHub
parent 3f767d765e
commit 1c257b0c74
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      test/integration/generic/contracts/.marker
  2. 25
      test/integration/generic/contracts/Migrations.sol
  3. 4
      test/integration/generic/migrations/1_initial.js
  4. 5
      test/integration/projects/libraries/migrations/1_initial_migration.js
  5. 8
      test/integration/projects/libraries/migrations/2_contracta.js
  6. 8
      test/integration/projects/solc-6/.solcover.js
  7. 24
      test/integration/projects/solc-6/contracts/B_Wallet.sol
  8. 66
      test/integration/projects/solc-6/contracts/ContractA.sol
  9. 19
      test/integration/projects/solc-6/contracts/ContractB.sol
  10. 9
      test/integration/projects/solc-6/hardhat.config.js
  11. 26
      test/integration/projects/solc-6/test/b_wallet.js
  12. 27
      test/integration/projects/solc-6/test/test.js
  13. 6
      test/integration/projects/solc-7/.solcover.js
  14. 52
      test/integration/projects/solc-7/contracts/Contract_solc7.sol
  15. 19
      test/integration/projects/solc-7/contracts/Functions_solc7.sol
  16. 9
      test/integration/projects/solc-7/hardhat.config.js
  17. 23
      test/integration/projects/solc-7/test/test_solc7.js
  18. 5
      test/integration/projects/test-files/migrations/1_initial_migration.js
  19. 5
      test/integration/projects/test-files/migrations/2_contracta.js
  20. 5
      test/integration/projects/test-files/migrations/3_contractb.js
  21. 5
      test/integration/projects/test-files/migrations/4_contractc.js
  22. 26
      test/units/hardhat/errors.js
  23. 11
      test/units/hardhat/flags.js
  24. 56
      test/units/hardhat/standard.js
  25. 40
      test/util/integration.js

@ -0,0 +1 @@
// because circle won't copy the folder w/out contents

@ -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);
}
}

@ -1,4 +0,0 @@
const Migrations = artifacts.require('./Migrations.sol');
module.exports = async function(deployer) {
await deployer.deploy(Migrations);
};

@ -1,5 +0,0 @@
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};

@ -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);
};

@ -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'],
}

@ -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;
}
}

@ -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++;
}
}

@ -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;
}
}

@ -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,
};

@ -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],
});
});
});

@ -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();
})
});

@ -1,6 +0,0 @@
module.exports = {
silent: process.env.SILENT ? true : false,
skipFiles: ['skipped-folder'],
istanbulReporter: ['json-summary', 'text'],
configureYulOptimizer: true
}

@ -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);
}
}

@ -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;
}

@ -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,
};

@ -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();
})
});

@ -1,5 +0,0 @@
const Migrations = artifacts.require("Migrations");
module.exports = function(deployer) {
deployer.deploy(Migrations);
};

@ -1,5 +0,0 @@
const ContractA = artifacts.require("ContractA");
module.exports = function(deployer) {
deployer.deploy(ContractA);
};

@ -1,5 +0,0 @@
const ContractB = artifacts.require("ContractB");
module.exports = function(deployer) {
deployer.deploy(ContractB);
};

@ -1,5 +0,0 @@
const ContractC = artifacts.require("ContractC");
module.exports = function(deployer) {
deployer.deploy(ContractC);
};

@ -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);

@ -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": [

@ -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);

@ -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}`);

Loading…
Cancel
Save