Skip to content

Commit bdc6f91

Browse files
committed
Update logical-or tests for Hardhat
1 parent 8e8f668 commit bdc6f91

File tree

8 files changed

+42
-37
lines changed

8 files changed

+42
-37
lines changed

test/integration/projects/logical-or/buidler.config.js

-7
This file was deleted.

test/integration/projects/logical-or/contracts/ContractA.sol renamed to test/integration/projects/logical-or/contracts/Contract_OR.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pragma solidity ^0.5.0;
22

33

4-
contract ContractA {
4+
contract Contract_OR {
55

66
function _if(uint i) public pure {
77
if (i == 0 || i > 5){
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require("@nomiclabs/hardhat-truffle5");
2+
require(__dirname + "/../plugins/nomiclabs.plugin");
3+
4+
module.exports = {
5+
solidity: {
6+
version: "0.5.15"
7+
},
8+
logger: process.env.SILENT ? { log: () => {} } : console,
9+
};

test/integration/projects/logical-or/test/test.js renamed to test/integration/projects/logical-or/test/test_or.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
const ContractA = artifacts.require("ContractA");
1+
const Contract_OR = artifacts.require("Contract_OR");
22

3-
contract("contracta", function(accounts) {
3+
contract("contract_or", function(accounts) {
44
let instance;
55

6-
before(async () => instance = await ContractA.new())
6+
before(async () => instance = await Contract_OR.new())
77

88
it('_if', async function(){
99
await instance._if(0);

test/units/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ describe('asserts and requires', () => {
103103
});
104104

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

125125
it('should cover require statements with method arguments & reason string', async function() {
126-
const contract = await util.bootstrapCoverage('assert/Require-fn-reason', provider, collector);
126+
const contract = await util.bootstrapCoverage('assert/Require-fn-reason', api);
127127
coverage.addContract(contract.instrumented, util.filePath);
128128
await contract.instance.a(true);
129129
const mapping = coverage.generate(contract.data, util.pathPrefix);

test/units/hardhat/standard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,15 @@ describe('Hardhat Plugin: standard use cases', function() {
492492
// This works on it's own but there's some kind of weird interaction with
493493
// the solc 6 test which causes subsequent cov measurements to be zero.
494494
// Have tried re-ordering etc...???. Truffle tests this & should be the same anyway...
495-
it.skip('logicalOR', async function(){
495+
it('logicalOR', async function(){
496496
mock.installFullProject('logical-or');
497497
mock.hardhatSetupEnv(this);
498498

499499
await this.env.run("coverage");
500500

501501
const expected = [
502502
{
503-
file: mock.pathToContract(hardhatConfig, 'ContractA.sol'),
503+
file: mock.pathToContract(hardhatConfig, 'Contract_OR.sol'),
504504
pct: 59.09
505505
}
506506
];

test/units/or.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
const assert = require('assert');
22
const util = require('./../util/util.js');
33

4-
const ganache = require('ganache-core-sc');
4+
const client = require('ganache-cli');
55
const Coverage = require('./../../lib/coverage');
6+
const Api = require('./../../lib/api')
67

78
describe('logical OR branches', () => {
89
let coverage;
9-
let provider;
10-
let collector;
10+
let api;
1111

12-
before(async () => ({ provider, collector } = await util.initializeProvider(ganache)));
12+
before(async () => {
13+
api = new Api({silent: true});
14+
await api.ganache(client);
15+
})
1316
beforeEach(() => coverage = new Coverage());
14-
after((done) => provider.close(done));
17+
after(async() => await api.finish());
1518

1619
// if (x == 1 || x == 2) { } else ...
1720
it('should cover an if statement with a simple OR condition (single branch)', async function() {
18-
const contract = await util.bootstrapCoverage('or/if-or', provider, collector);
21+
const contract = await util.bootstrapCoverage('or/if-or', api);
1922
coverage.addContract(contract.instrumented, util.filePath);
2023
await contract.instance.a(1);
2124
const mapping = coverage.generate(contract.data, util.pathPrefix);
@@ -36,7 +39,7 @@ describe('logical OR branches', () => {
3639

3740
// if (x == 1 || x == 2) { } else ...
3841
it('should cover an if statement with a simple OR condition (both branches)', async function() {
39-
const contract = await util.bootstrapCoverage('or/if-or', provider, collector);
42+
const contract = await util.bootstrapCoverage('or/if-or', api);
4043
coverage.addContract(contract.instrumented, util.filePath);
4144
await contract.instance.a(1);
4245
await contract.instance.a(2);
@@ -59,7 +62,7 @@ describe('logical OR branches', () => {
5962

6063
// require(x == 1 || x == 2)
6164
it('should cover a require statement with a simple OR condition (single branch)', async function() {
62-
const contract = await util.bootstrapCoverage('or/require-or', provider, collector);
65+
const contract = await util.bootstrapCoverage('or/require-or', api);
6366
coverage.addContract(contract.instrumented, util.filePath);
6467
await contract.instance.a(1);
6568

@@ -85,7 +88,7 @@ describe('logical OR branches', () => {
8588
// x == 3
8689
// )
8790
it('should cover a require statement with multiline OR condition (two branches)', async function() {
88-
const contract = await util.bootstrapCoverage('or/require-multiline-or', provider, collector);
91+
const contract = await util.bootstrapCoverage('or/require-multiline-or', api);
8992
coverage.addContract(contract.instrumented, util.filePath);
9093
await contract.instance.a(1);
9194
await contract.instance.a(3);
@@ -108,7 +111,7 @@ describe('logical OR branches', () => {
108111

109112
// require(x == 1 || x == 2)
110113
it('should cover a require statement with a simple OR condition (both branches)', async function() {
111-
const contract = await util.bootstrapCoverage('or/require-or', provider, collector);
114+
const contract = await util.bootstrapCoverage('or/require-or', api);
112115
coverage.addContract(contract.instrumented, util.filePath);
113116
await contract.instance.a(1);
114117
await contract.instance.a(2);
@@ -131,7 +134,7 @@ describe('logical OR branches', () => {
131134

132135
// while( (x == 1 || x == 2) && counter < 2 ){
133136
it('should cover a while statement with a simple OR condition (single branch)', async function() {
134-
const contract = await util.bootstrapCoverage('or/while-or', provider, collector);
137+
const contract = await util.bootstrapCoverage('or/while-or', api);
135138
coverage.addContract(contract.instrumented, util.filePath);
136139
await contract.instance.a(1);
137140

@@ -153,7 +156,7 @@ describe('logical OR branches', () => {
153156

154157
// while( (x == 1 || x == 2) && counter < 2 ){
155158
it('should cover a while statement with a simple OR condition (both branches)', async function() {
156-
const contract = await util.bootstrapCoverage('or/while-or', provider, collector);
159+
const contract = await util.bootstrapCoverage('or/while-or', api);
157160
coverage.addContract(contract.instrumented, util.filePath);
158161
await contract.instance.a(1);
159162
await contract.instance.a(2);
@@ -176,7 +179,7 @@ describe('logical OR branches', () => {
176179

177180
// return (x == 1 && true) || (x == 2 && true);
178181
it('should cover a return statement with ANDED OR conditions (single branch)', async function() {
179-
const contract = await util.bootstrapCoverage('or/return-or', provider, collector);
182+
const contract = await util.bootstrapCoverage('or/return-or', api);
180183
coverage.addContract(contract.instrumented, util.filePath);
181184
await contract.instance.a(1);
182185

@@ -198,7 +201,7 @@ describe('logical OR branches', () => {
198201

199202
// return (x == 1 && true) || (x == 2 && true);
200203
it('should cover a return statement with ANDED OR conditions (both branches)', async function() {
201-
const contract = await util.bootstrapCoverage('or/return-or', provider, collector);
204+
const contract = await util.bootstrapCoverage('or/return-or', api);
202205
coverage.addContract(contract.instrumented, util.filePath);
203206
await contract.instance.a(1);
204207
await contract.instance.a(2);
@@ -221,7 +224,7 @@ describe('logical OR branches', () => {
221224

222225
//if (x == 1 && true || x == 2) {
223226
it('should cover an if statement with OR and AND conditions (single branch)', async function() {
224-
const contract = await util.bootstrapCoverage('or/and-or', provider, collector);
227+
const contract = await util.bootstrapCoverage('or/and-or', api);
225228
coverage.addContract(contract.instrumented, util.filePath);
226229
await contract.instance.a(1);
227230

@@ -243,7 +246,7 @@ describe('logical OR branches', () => {
243246

244247
//if (x == 1 && true || x == 2) {
245248
it('should cover an if statement with OR and AND conditions (both branches)', async function() {
246-
const contract = await util.bootstrapCoverage('or/and-or', provider, collector);
249+
const contract = await util.bootstrapCoverage('or/and-or', api);
247250
coverage.addContract(contract.instrumented, util.filePath);
248251
await contract.instance.a(1);
249252
await contract.instance.a(2);
@@ -266,7 +269,7 @@ describe('logical OR branches', () => {
266269

267270
// if ((x == 1) && (x == 2 || true)) {
268271
it('should cover an if statement with bracked ANDED OR conditions (rightmost sub-branch)', async function() {
269-
const contract = await util.bootstrapCoverage('or/and-or-brackets', provider, collector);
272+
const contract = await util.bootstrapCoverage('or/and-or-brackets', api);
270273
coverage.addContract(contract.instrumented, util.filePath);
271274
await contract.instance.a(1);
272275

@@ -288,7 +291,7 @@ describe('logical OR branches', () => {
288291

289292
// if ((x == 1) || (x == 2 || true)) {
290293
it('should cover an if statement with multiple (bracketed) OR conditions (branch 1)', async function() {
291-
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector);
294+
const contract = await util.bootstrapCoverage('or/multi-or', api);
292295
coverage.addContract(contract.instrumented, util.filePath);
293296
await contract.instance.a(1);
294297

@@ -310,7 +313,7 @@ describe('logical OR branches', () => {
310313

311314
// if ((x == 1) || (x == 2 || true)) {
312315
it('should cover an if statement with multiple (bracketed) OR conditions (branch 2)', async function() {
313-
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector);
316+
const contract = await util.bootstrapCoverage('or/multi-or', api);
314317
coverage.addContract(contract.instrumented, util.filePath);
315318
await contract.instance.a(2);
316319

@@ -332,7 +335,7 @@ describe('logical OR branches', () => {
332335

333336
// if ((x == 1) || (x == 2 || true)) {
334337
it('should cover an if statement with multiple (bracketed) OR conditions (branch 3)', async function() {
335-
const contract = await util.bootstrapCoverage('or/multi-or', provider, collector);
338+
const contract = await util.bootstrapCoverage('or/multi-or', api);
336339
coverage.addContract(contract.instrumented, util.filePath);
337340
await contract.instance.a(3);
338341

@@ -353,7 +356,7 @@ describe('logical OR branches', () => {
353356
});
354357

355358
it('should cover the bzx example', async function(){
356-
const contract = await util.bootstrapCoverage('or/bzx-or', provider, collector);
359+
const contract = await util.bootstrapCoverage('or/bzx-or', api);
357360
coverage.addContract(contract.instrumented, util.filePath);
358361
await contract.instance.a(3);
359362

test/units/truffle/standard.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ describe('Truffle Plugin: standard use cases', function() {
505505

506506
const expected = [
507507
{
508-
file: mock.pathToContract(truffleConfig, 'ContractA.sol'),
508+
file: mock.pathToContract(truffleConfig, 'Contract_OR.sol'),
509509
pct: 59.09
510510
}
511511
];

0 commit comments

Comments
 (0)