Skip to content

Commit

Permalink
Merge pull request #8 from cgewecke/draft-tests
Browse files Browse the repository at this point in the history
Draft test suite
  • Loading branch information
area authored Dec 15, 2016
2 parents f0c5f08 + 10254a4 commit fe42d14
Show file tree
Hide file tree
Showing 43 changed files with 1,298 additions and 50 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha --timeout 10000"
},
"author": "",
"license": "ISC",
Expand Down
39 changes: 39 additions & 0 deletions test/function.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var solc = require('solc');
var getInstrumentedVersion = require('./../instrumentSolidity.js');
var util = require('./util/util.js');

/**
* NB: passing '1' to solc as an option activates the optimiser
* NB: solc will throw if there is a compilation error, causing the test to fail
* and passing the error to mocha.
*/
describe('function declarations', function(){

it('should compile after instrumenting an ordinary function declaration', function(){
var contract = util.getCode('function/function.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting an abstract function declaration', function(){
var contract = util.getCode('function/abstract.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting a function declaration with an empty body', function(){
var contract = util.getCode('function/empty-body.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting lots of declarations in row', function(){
var contract = util.getCode('function/multiple.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})
})
44 changes: 44 additions & 0 deletions test/if.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var solc = require('solc');
var getInstrumentedVersion = require('./../instrumentSolidity.js');
var util = require('./util/util.js')

/**
* NB: passing '1' to solc as an option activates the optimiser
*/
describe('if, else, and else if statements', function(){

it('should compile after instrumenting else statements with brackets',function(){
var contract = util.getCode('if/else-with-brackets.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting else statements without brackets',function(){
var contract = util.getCode('if/else-without-brackets.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting if statements with no brackets',function(){
var contract = util.getCode('if/if-no-brackets.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting if statements with brackets',function(){
var contract = util.getCode('if/if-with-brackets.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting nested if statements with missing else statements',function(){
var contract = util.getCode('if/nested-if-missing-else.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})
})
49 changes: 0 additions & 49 deletions test/ifStatements.js

This file was deleted.

20 changes: 20 additions & 0 deletions test/return.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var solc = require('solc');
var getInstrumentedVersion = require('./../instrumentSolidity.js');
var util = require('./util/util.js');

describe('return statements', function(){

it('should compile after instrumenting function that returns true',function(){
var contract = util.getCode('return/return.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})

it('should compile after instrumenting function that returns without specifying val (null)',function(){
var contract = util.getCode('return/return-null.sol');
var info = getInstrumentedVersion(contract, "test.sol", true);
var output = solc.compile(info.contract, 1);
util.report(output.errors);
})
})
5 changes: 5 additions & 0 deletions test/sources/function/abstract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity ^0.4.3;

contract Test {
function abstractFn(uint x);
}
5 changes: 5 additions & 0 deletions test/sources/function/empty-body.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma solidity ^0.4.3;

contract Test {
function emptyBody(uint x){}
}
7 changes: 7 additions & 0 deletions test/sources/function/function.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(bytes32 x) {
x;
}
}
15 changes: 15 additions & 0 deletions test/sources/function/multiple.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.4.3;

contract Test {
function f1(bytes32 x) {
x = 1;
}

function f2(uint x){ x = 2; }

address a;

function f3(uint y){
y = 1;
}
}
11 changes: 11 additions & 0 deletions test/sources/if/else-with-brackets.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
if (x == 1) {
throw;
} else {
x = 5;
}
}
}
10 changes: 10 additions & 0 deletions test/sources/if/else-without-brackets.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
if (x == 1) {
throw;
} else
x = 5;
}
}
7 changes: 7 additions & 0 deletions test/sources/if/if-no-brackets.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
if (x == 1) throw;
}
}
7 changes: 7 additions & 0 deletions test/sources/if/if-with-brackets.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
if (x == 1) { throw; }
}
}
11 changes: 11 additions & 0 deletions test/sources/if/nested-if-missing-else.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x,uint y, uint z) {
if (x==y){
} else if (x==2){
if (y==z){
}
}
}
}
7 changes: 7 additions & 0 deletions test/sources/return/return-null.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) returns (bool) {
return;
}
}
7 changes: 7 additions & 0 deletions test/sources/return/return.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) returns (bool) {
return true;
}
}
22 changes: 22 additions & 0 deletions test/sources/statements/fn-argument-multiline.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity ^0.4.3;

contract Test {

function multiline(
uint a,
uint b,
uint c,
bytes32 d)
{
var x = a;
}

function Test(){
multiline(
1,
2,
3,
sha3('hello')
);
}
}
11 changes: 11 additions & 0 deletions test/sources/statements/fn-argument.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.3;

contract Test {
function a(bytes32 x) {
x;
}

function b (){
a(sha3(0));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
if (x == 1)
throw;
}
}
8 changes: 8 additions & 0 deletions test/sources/statements/multiple.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
sha3(x);
sha3(0);
}
}
7 changes: 7 additions & 0 deletions test/sources/statements/single.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pragma solidity ^0.4.3;

contract Test {
function a(uint x) {
sha3(x);
}
}
Loading

0 comments on commit fe42d14

Please sign in to comment.