Skip to content

Commit be25c4f

Browse files
committedMar 2, 2019
Add tests for #316 #317
1 parent ffdb986 commit be25c4f

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed
 

‎test/assembly.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* eslint-env node, mocha */
2+
3+
const solc = require('solc');
4+
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js');
5+
const util = require('./util/util.js');
6+
const path = require('path');
7+
8+
/**
9+
* NB: passing '1' to solc as an option activates the optimiser
10+
* NB: solc will throw if there is a compilation error, causing the test to fail
11+
* and passing the error to mocha.
12+
*/
13+
describe('generic expressions', () => {
14+
const filePath = path.resolve('./test.sol');
15+
16+
it('should compile after instrumenting an assembly function with spaces in parameters', () => {
17+
const contract = util.getCode('assembly/spaces-in-function.sol');
18+
const info = getInstrumentedVersion(contract, filePath);
19+
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
20+
console.log(info)
21+
util.report(output.errors);
22+
});
23+
24+
});

‎test/function.js

+7
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ describe('function declarations', () => {
5959
util.report(output.errors);
6060
});
6161

62+
it('should compile after instrumenting a function with calldata keyword', () => {
63+
const contract = util.getCode('function/calldata.sol');
64+
const info = getInstrumentedVersion(contract, 'test.sol');
65+
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
66+
util.report(output.errors);
67+
});
68+
6269
it('should compile after instrumenting a constructor-->method-->value chain', () => {
6370
const contract = util.getCode('function/chainable-value.sol');
6471
const info = getInstrumentedVersion(contract, 'test.sol');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pragma solidity ^0.5.0;
2+
3+
contract Test {
4+
function a() public {
5+
assembly {
6+
function power(base, exponent) -> result {
7+
switch exponent
8+
case 0 { result := 1 }
9+
case 1 { result := base }
10+
default {
11+
result := power(mul(base, base), div(exponent, 2))
12+
switch mod(exponent, 2)
13+
case 1 { result := mul(base, result) }
14+
}
15+
}
16+
}
17+
}
18+
}

‎test/sources/function/calldata.sol

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma solidity ^0.5.0;
2+
3+
contract Test {
4+
function a(string calldata x) external {
5+
x;
6+
}
7+
}

0 commit comments

Comments
 (0)