leapdao
Alex 6 years ago
parent ffdb986ada
commit be25c4f742
  1. 24
      test/assembly.js
  2. 7
      test/function.js
  3. 18
      test/sources/assembly/spaces-in-function.sol
  4. 7
      test/sources/function/calldata.sol

@ -0,0 +1,24 @@
/* eslint-env node, mocha */
const solc = require('solc');
const getInstrumentedVersion = require('./../lib/instrumentSolidity.js');
const util = require('./util/util.js');
const path = require('path');
/**
* 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('generic expressions', () => {
const filePath = path.resolve('./test.sol');
it('should compile after instrumenting an assembly function with spaces in parameters', () => {
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);
});
});

@ -59,6 +59,13 @@ describe('function declarations', () => {
util.report(output.errors);
});
it('should compile after instrumenting a function with calldata keyword', () => {
const contract = util.getCode('function/calldata.sol');
const info = getInstrumentedVersion(contract, 'test.sol');
const output = JSON.parse(solc.compile(util.codeToCompilerInput(info.contract)));
util.report(output.errors);
});
it('should compile after instrumenting a constructor-->method-->value chain', () => {
const contract = util.getCode('function/chainable-value.sol');
const info = getInstrumentedVersion(contract, 'test.sol');

@ -0,0 +1,18 @@
pragma solidity ^0.5.0;
contract Test {
function a() public {
assembly {
function power(base, exponent) -> result {
switch exponent
case 0 { result := 1 }
case 1 { result := base }
default {
result := power(mul(base, base), div(exponent, 2))
switch mod(exponent, 2)
case 1 { result := mul(base, result) }
}
}
}
}
}

@ -0,0 +1,7 @@
pragma solidity ^0.5.0;
contract Test {
function a(string calldata x) external {
x;
}
}
Loading…
Cancel
Save