Merge pull request #335 from sc-forks/test/else-if

Add tests for instrumenting multiple unbracketed else ifs
update/parser
cgewecke 5 years ago committed by GitHub
commit f671b72628
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      README.md
  2. 1
      test/assembly.js
  3. 8
      test/if.js
  4. 58
      test/sources/if/else-if-unbracketed-multi.sol

@ -164,3 +164,4 @@ $ yarn
+ [@bingen](https://github.com/bingen)
+ [@pinkiebell](https://github.com/pinkiebell)
+ [@obernardovieira](https://github.com/obernardovieira)
+ [@angus-hamill](https://github.com/angus-hamill)

@ -17,7 +17,6 @@ describe('generic expressions', () => {
const contract = util.getCode('assembly/spaces-in-function.sol');
const info = getInstrumentedVersion(contract, filePath);
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
console.log(info)
util.report(output.errors);
});

@ -1,5 +1,6 @@
/* eslint-env node, mocha */
const solc = require('solc');
const path = require('path');
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js');
const util = require('./util/util.js');
@ -11,6 +12,13 @@ describe('if, else, and else if statements', () => {
const filePath = path.resolve('./test.sol');
const pathPrefix = './';
it('should compile after instrumenting multiple if-elses', () => {
const contract = util.getCode('if/else-if-unbracketed-multi.sol');
const info = getInstrumentedVersion(contract, filePath);
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
util.report(output.errors);
});
it('should cover an if statement with a bracketed consequent', done => {
const contract = util.getCode('if/if-with-brackets.sol');
const info = getInstrumentedVersion(contract, filePath);

@ -0,0 +1,58 @@
pragma solidity >=0.4.22 <0.6.0;
contract Test {
mapping (address => uint) balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor() public {
balances[tx.origin] = 10000;
}
function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
if (balances[msg.sender] < amount)
return false;
else if (amount == 1)
return false;
else if (amount == 2 || amount == 3 || amount == 4)
return false;
else if (amount == 5)
return false;
else if (amount == 1)
return false;
else if (amount == 2 || amount == 3 || amount == 4)
return false;
else if (amount == 5)
return false;
else if (amount == 1)
return false;
else if (amount == 2 || amount == 3 || amount == 4)
return false;
else if (amount == 5)
return false;
else if (amount == 1)
return false;
else if (amount == 2 || amount == 3 || amount == 4)
return false;
else if (amount == 5)
return false;
else if (amount == 1)
return false;
else if (amount == 2 || amount == 3 || amount == 4)
return false;
else if (amount == 5)
return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
if(balances[receiver] >= amount)
sufficient = true;
}
function getBalance(address addr) public view returns(uint) {
return balances[addr];
}
}
Loading…
Cancel
Save