Update logical-or tests for Hardhat

experimental-options
cgewecke 4 years ago
parent 8e8f6688f8
commit bdc6f91275
  1. 7
      test/integration/projects/logical-or/buidler.config.js
  2. 2
      test/integration/projects/logical-or/contracts/Contract_OR.sol
  3. 9
      test/integration/projects/logical-or/hardhat.config.js
  4. 6
      test/integration/projects/logical-or/test/test_or.js
  5. 4
      test/units/assert.js
  6. 4
      test/units/hardhat/standard.js
  7. 45
      test/units/or.js
  8. 2
      test/units/truffle/standard.js

@ -1,7 +0,0 @@
const { loadPluginFile } = require("@nomiclabs/buidler/plugins-testing");
loadPluginFile(__dirname + "/../plugins/buidler.plugin");
usePlugin("@nomiclabs/buidler-truffle5");
module.exports={
defaultNetwork: "buidlerevm"
};

@ -1,7 +1,7 @@
pragma solidity ^0.5.0; pragma solidity ^0.5.0;
contract ContractA { contract Contract_OR {
function _if(uint i) public pure { function _if(uint i) public pure {
if (i == 0 || i > 5){ if (i == 0 || i > 5){

@ -0,0 +1,9 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports = {
solidity: {
version: "0.5.15"
},
logger: process.env.SILENT ? { log: () => {} } : console,
};

@ -1,9 +1,9 @@
const ContractA = artifacts.require("ContractA"); const Contract_OR = artifacts.require("Contract_OR");
contract("contracta", function(accounts) { contract("contract_or", function(accounts) {
let instance; let instance;
before(async () => instance = await ContractA.new()) before(async () => instance = await Contract_OR.new())
it('_if', async function(){ it('_if', async function(){
await instance._if(0); await instance._if(0);

@ -103,7 +103,7 @@ describe('asserts and requires', () => {
}); });
it('should cover require statements with method arguments', async function() { it('should cover require statements with method arguments', async function() {
const contract = await util.bootstrapCoverage('assert/Require-fn', provider, collector); const contract = await util.bootstrapCoverage('assert/Require-fn', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(true); await contract.instance.a(true);
const mapping = coverage.generate(contract.data, util.pathPrefix); const mapping = coverage.generate(contract.data, util.pathPrefix);
@ -123,7 +123,7 @@ describe('asserts and requires', () => {
}); });
it('should cover require statements with method arguments & reason string', async function() { it('should cover require statements with method arguments & reason string', async function() {
const contract = await util.bootstrapCoverage('assert/Require-fn-reason', provider, collector); const contract = await util.bootstrapCoverage('assert/Require-fn-reason', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(true); await contract.instance.a(true);
const mapping = coverage.generate(contract.data, util.pathPrefix); const mapping = coverage.generate(contract.data, util.pathPrefix);

@ -492,7 +492,7 @@ describe('Hardhat Plugin: standard use cases', function() {
// This works on it's own but there's some kind of weird interaction with // This works on it's own but there's some kind of weird interaction with
// the solc 6 test which causes subsequent cov measurements to be zero. // the solc 6 test which causes subsequent cov measurements to be zero.
// Have tried re-ordering etc...???. Truffle tests this & should be the same anyway... // Have tried re-ordering etc...???. Truffle tests this & should be the same anyway...
it.skip('logicalOR', async function(){ it('logicalOR', async function(){
mock.installFullProject('logical-or'); mock.installFullProject('logical-or');
mock.hardhatSetupEnv(this); mock.hardhatSetupEnv(this);
@ -500,7 +500,7 @@ describe('Hardhat Plugin: standard use cases', function() {
const expected = [ const expected = [
{ {
file: mock.pathToContract(hardhatConfig, 'ContractA.sol'), file: mock.pathToContract(hardhatConfig, 'Contract_OR.sol'),
pct: 59.09 pct: 59.09
} }
]; ];

@ -1,21 +1,24 @@
const assert = require('assert'); const assert = require('assert');
const util = require('./../util/util.js'); const util = require('./../util/util.js');
const ganache = require('ganache-core-sc'); const client = require('ganache-cli');
const Coverage = require('./../../lib/coverage'); const Coverage = require('./../../lib/coverage');
const Api = require('./../../lib/api')
describe('logical OR branches', () => { describe('logical OR branches', () => {
let coverage; let coverage;
let provider; let api;
let collector;
before(async () => ({ provider, collector } = await util.initializeProvider(ganache))); before(async () => {
api = new Api({silent: true});
await api.ganache(client);
})
beforeEach(() => coverage = new Coverage()); beforeEach(() => coverage = new Coverage());
after((done) => provider.close(done)); after(async() => await api.finish());
// if (x == 1 || x == 2) { } else ... // if (x == 1 || x == 2) { } else ...
it('should cover an if statement with a simple OR condition (single branch)', async function() { it('should cover an if statement with a simple OR condition (single branch)', async function() {
const contract = await util.bootstrapCoverage('or/if-or', provider, collector); const contract = await util.bootstrapCoverage('or/if-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
const mapping = coverage.generate(contract.data, util.pathPrefix); const mapping = coverage.generate(contract.data, util.pathPrefix);
@ -36,7 +39,7 @@ describe('logical OR branches', () => {
// if (x == 1 || x == 2) { } else ... // if (x == 1 || x == 2) { } else ...
it('should cover an if statement with a simple OR condition (both branches)', async function() { it('should cover an if statement with a simple OR condition (both branches)', async function() {
const contract = await util.bootstrapCoverage('or/if-or', provider, collector); const contract = await util.bootstrapCoverage('or/if-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(2); await contract.instance.a(2);
@ -59,7 +62,7 @@ describe('logical OR branches', () => {
// require(x == 1 || x == 2) // require(x == 1 || x == 2)
it('should cover a require statement with a simple OR condition (single branch)', async function() { it('should cover a require statement with a simple OR condition (single branch)', async function() {
const contract = await util.bootstrapCoverage('or/require-or', provider, collector); const contract = await util.bootstrapCoverage('or/require-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -85,7 +88,7 @@ describe('logical OR branches', () => {
// x == 3 // x == 3
// ) // )
it('should cover a require statement with multiline OR condition (two branches)', async function() { it('should cover a require statement with multiline OR condition (two branches)', async function() {
const contract = await util.bootstrapCoverage('or/require-multiline-or', provider, collector); const contract = await util.bootstrapCoverage('or/require-multiline-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(3); await contract.instance.a(3);
@ -108,7 +111,7 @@ describe('logical OR branches', () => {
// require(x == 1 || x == 2) // require(x == 1 || x == 2)
it('should cover a require statement with a simple OR condition (both branches)', async function() { it('should cover a require statement with a simple OR condition (both branches)', async function() {
const contract = await util.bootstrapCoverage('or/require-or', provider, collector); const contract = await util.bootstrapCoverage('or/require-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(2); await contract.instance.a(2);
@ -131,7 +134,7 @@ describe('logical OR branches', () => {
// while( (x == 1 || x == 2) && counter < 2 ){ // while( (x == 1 || x == 2) && counter < 2 ){
it('should cover a while statement with a simple OR condition (single branch)', async function() { it('should cover a while statement with a simple OR condition (single branch)', async function() {
const contract = await util.bootstrapCoverage('or/while-or', provider, collector); const contract = await util.bootstrapCoverage('or/while-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -153,7 +156,7 @@ describe('logical OR branches', () => {
// while( (x == 1 || x == 2) && counter < 2 ){ // while( (x == 1 || x == 2) && counter < 2 ){
it('should cover a while statement with a simple OR condition (both branches)', async function() { it('should cover a while statement with a simple OR condition (both branches)', async function() {
const contract = await util.bootstrapCoverage('or/while-or', provider, collector); const contract = await util.bootstrapCoverage('or/while-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(2); await contract.instance.a(2);
@ -176,7 +179,7 @@ describe('logical OR branches', () => {
// return (x == 1 && true) || (x == 2 && true); // return (x == 1 && true) || (x == 2 && true);
it('should cover a return statement with ANDED OR conditions (single branch)', async function() { it('should cover a return statement with ANDED OR conditions (single branch)', async function() {
const contract = await util.bootstrapCoverage('or/return-or', provider, collector); const contract = await util.bootstrapCoverage('or/return-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -198,7 +201,7 @@ describe('logical OR branches', () => {
// return (x == 1 && true) || (x == 2 && true); // return (x == 1 && true) || (x == 2 && true);
it('should cover a return statement with ANDED OR conditions (both branches)', async function() { it('should cover a return statement with ANDED OR conditions (both branches)', async function() {
const contract = await util.bootstrapCoverage('or/return-or', provider, collector); const contract = await util.bootstrapCoverage('or/return-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(2); await contract.instance.a(2);
@ -221,7 +224,7 @@ describe('logical OR branches', () => {
//if (x == 1 && true || x == 2) { //if (x == 1 && true || x == 2) {
it('should cover an if statement with OR and AND conditions (single branch)', async function() { it('should cover an if statement with OR and AND conditions (single branch)', async function() {
const contract = await util.bootstrapCoverage('or/and-or', provider, collector); const contract = await util.bootstrapCoverage('or/and-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -243,7 +246,7 @@ describe('logical OR branches', () => {
//if (x == 1 && true || x == 2) { //if (x == 1 && true || x == 2) {
it('should cover an if statement with OR and AND conditions (both branches)', async function() { it('should cover an if statement with OR and AND conditions (both branches)', async function() {
const contract = await util.bootstrapCoverage('or/and-or', provider, collector); const contract = await util.bootstrapCoverage('or/and-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
await contract.instance.a(2); await contract.instance.a(2);
@ -266,7 +269,7 @@ describe('logical OR branches', () => {
// if ((x == 1) && (x == 2 || true)) { // if ((x == 1) && (x == 2 || true)) {
it('should cover an if statement with bracked ANDED OR conditions (rightmost sub-branch)', async function() { it('should cover an if statement with bracked ANDED OR conditions (rightmost sub-branch)', async function() {
const contract = await util.bootstrapCoverage('or/and-or-brackets', provider, collector); const contract = await util.bootstrapCoverage('or/and-or-brackets', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -288,7 +291,7 @@ describe('logical OR branches', () => {
// if ((x == 1) || (x == 2 || true)) { // if ((x == 1) || (x == 2 || true)) {
it('should cover an if statement with multiple (bracketed) OR conditions (branch 1)', async function() { it('should cover an if statement with multiple (bracketed) OR conditions (branch 1)', async function() {
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector); const contract = await util.bootstrapCoverage('or/multi-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(1); await contract.instance.a(1);
@ -310,7 +313,7 @@ describe('logical OR branches', () => {
// if ((x == 1) || (x == 2 || true)) { // if ((x == 1) || (x == 2 || true)) {
it('should cover an if statement with multiple (bracketed) OR conditions (branch 2)', async function() { it('should cover an if statement with multiple (bracketed) OR conditions (branch 2)', async function() {
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector); const contract = await util.bootstrapCoverage('or/multi-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(2); await contract.instance.a(2);
@ -332,7 +335,7 @@ describe('logical OR branches', () => {
// if ((x == 1) || (x == 2 || true)) { // if ((x == 1) || (x == 2 || true)) {
it('should cover an if statement with multiple (bracketed) OR conditions (branch 3)', async function() { it('should cover an if statement with multiple (bracketed) OR conditions (branch 3)', async function() {
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector); const contract = await util.bootstrapCoverage('or/multi-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(3); await contract.instance.a(3);
@ -353,7 +356,7 @@ describe('logical OR branches', () => {
}); });
it('should cover the bzx example', async function(){ it('should cover the bzx example', async function(){
const contract = await util.bootstrapCoverage('or/bzx-or', provider, collector); const contract = await util.bootstrapCoverage('or/bzx-or', api);
coverage.addContract(contract.instrumented, util.filePath); coverage.addContract(contract.instrumented, util.filePath);
await contract.instance.a(3); await contract.instance.a(3);

@ -505,7 +505,7 @@ describe('Truffle Plugin: standard use cases', function() {
const expected = [ const expected = [
{ {
file: mock.pathToContract(truffleConfig, 'ContractA.sol'), file: mock.pathToContract(truffleConfig, 'Contract_OR.sol'),
pct: 59.09 pct: 59.09
} }
]; ];

Loading…
Cancel
Save