Skip to content

Commit f671b72

Browse files
authored
Merge pull request #335 from sc-forks/test/else-if
Add tests for instrumenting multiple unbracketed else ifs
2 parents 22c85f8 + aa77b3d commit f671b72

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,4 @@ $ yarn
164164
+ [@bingen](https://github.com/bingen)
165165
+ [@pinkiebell](https://github.com/pinkiebell)
166166
+ [@obernardovieira](https://github.com/obernardovieira)
167+
+ [@angus-hamill](https://github.com/angus-hamill)

test/assembly.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ describe('generic expressions', () => {
1717
const contract = util.getCode('assembly/spaces-in-function.sol');
1818
const info = getInstrumentedVersion(contract, filePath);
1919
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
20-
console.log(info)
2120
util.report(output.errors);
2221
});
2322

test/if.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-env node, mocha */
22

3+
const solc = require('solc');
34
const path = require('path');
45
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js');
56
const util = require('./util/util.js');
@@ -11,6 +12,13 @@ describe('if, else, and else if statements', () => {
1112
const filePath = path.resolve('./test.sol');
1213
const pathPrefix = './';
1314

15+
it('should compile after instrumenting multiple if-elses', () => {
16+
const contract = util.getCode('if/else-if-unbracketed-multi.sol');
17+
const info = getInstrumentedVersion(contract, filePath);
18+
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
19+
util.report(output.errors);
20+
});
21+
1422
it('should cover an if statement with a bracketed consequent', done => {
1523
const contract = util.getCode('if/if-with-brackets.sol');
1624
const info = getInstrumentedVersion(contract, filePath);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
pragma solidity >=0.4.22 <0.6.0;
2+
3+
contract Test {
4+
mapping (address => uint) balances;
5+
6+
event Transfer(address indexed _from, address indexed _to, uint256 _value);
7+
8+
constructor() public {
9+
balances[tx.origin] = 10000;
10+
}
11+
12+
function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
13+
if (balances[msg.sender] < amount)
14+
return false;
15+
else if (amount == 1)
16+
return false;
17+
else if (amount == 2 || amount == 3 || amount == 4)
18+
return false;
19+
else if (amount == 5)
20+
return false;
21+
else if (amount == 1)
22+
return false;
23+
else if (amount == 2 || amount == 3 || amount == 4)
24+
return false;
25+
else if (amount == 5)
26+
return false;
27+
else if (amount == 1)
28+
return false;
29+
else if (amount == 2 || amount == 3 || amount == 4)
30+
return false;
31+
else if (amount == 5)
32+
return false;
33+
else if (amount == 1)
34+
return false;
35+
else if (amount == 2 || amount == 3 || amount == 4)
36+
return false;
37+
else if (amount == 5)
38+
return false;
39+
else if (amount == 1)
40+
return false;
41+
else if (amount == 2 || amount == 3 || amount == 4)
42+
return false;
43+
else if (amount == 5)
44+
return false;
45+
46+
balances[msg.sender] -= amount;
47+
balances[receiver] += amount;
48+
emit Transfer(msg.sender, receiver, amount);
49+
50+
if(balances[receiver] >= amount)
51+
sufficient = true;
52+
}
53+
54+
function getBalance(address addr) public view returns(uint) {
55+
return balances[addr];
56+
}
57+
}
58+

0 commit comments

Comments
 (0)