Skip to content

Commit

Permalink
Merge pull request #18 from Aniket-Engg/fix/import
Browse files Browse the repository at this point in the history
import supported, fixes #12
  • Loading branch information
Aniket-Engg authored Apr 2, 2019
2 parents b2e3a7c + 10f13d4 commit 7a193da
Show file tree
Hide file tree
Showing 14 changed files with 1,717 additions and 15 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/node_modules
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:

- stage: tests
name: "Unit tests"
script: npm run test && npm run coverage
script:
- cd test && npm install
- cd .. && npm run test && npm run coverage


12 changes: 6 additions & 6 deletions lib/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ const map = require('../lib/mapping.json');
const Web3 = require('web3');
const web3 = new Web3(Web3.givenProvider);
const solReleases = require('./solReleases');
const { getPragma, processFile } = require('./../utils/import');


module.exports.verify = (data) => {

const { key, path, contractAddress, network, contractName, cvalues, optimizationFlag } = data;
return new Promise(function (resolve, reject){
return new Promise(async function (resolve, reject){

if(Object.keys(map.urls).indexOf(network) > -1){
let oFlag = 0;
let compiler;
let name;
let abiEncodedParams;
const contractSource = fs.readFileSync(path, 'UTF-8');
let parsedData = parser.parse(contractSource).body;
const pragma = await getPragma(path);
const contractSource = await processFile(path, true);
let parsedData = parser.parse(pragma + '\n\n' + contractSource).body;
solReleases.getCompilerVersion(parsedData, map)
.then(result => {
compiler = result;
const noOfContracts = parsedData.filter(e => e.type == 'ContractStatement').length;

if( noOfContracts == 1){
name = parsedData[1].name;
parsedData = parsedData[1];
Expand All @@ -39,7 +40,7 @@ module.exports.verify = (data) => {
}

const cParamsArray = parsedData.body.filter(obj => obj.type == 'ConstructorDeclaration');
if(cParamsArray.length > 0 && cParamsArray[0].params.length > 0){
if(cParamsArray.length > 0 && cParamsArray[0].params && cParamsArray[0].params.length > 0){
if(cvalues){
const cparams = [];
cParamsArray[0].params.forEach(param => cparams.push(param.literal.literal));
Expand Down Expand Up @@ -74,7 +75,6 @@ module.exports.verify = (data) => {
form: data,
json: true,
};

rp(options)
.then(function (result) {
resolve(result);
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"commander": "^2.19.0",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"solc": "^0.5.7",
"solparse": "^2.2.5",
"truffle-hdwallet-provider": "0.0.6",
"web3": "1.0.0-beta.37"
Expand Down
10 changes: 10 additions & 0 deletions test/contracts/SampleWithImport.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.5.6;

import "./Sample.sol";

contract SampleWithImport is Sample{

function increment(uint _n) public pure returns (uint) {
return _n++;
}
}
20 changes: 20 additions & 0 deletions test/contracts/SampleWithImport_merged.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.5.6;

contract Sample {
uint public n;

function set(uint _n) public returns (uint) {
n = _n;
}

function get() public view returns (uint) {
return n;
}
}

contract SampleWithImport is Sample{

function increment(uint _n) public pure returns (uint) {
return _n++;
}
}
13 changes: 13 additions & 0 deletions test/contracts/SampleWithNodeModulesImport.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pragma solidity ^0.5.7;

import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Mintable.sol";

contract SampleWithNodeModulesImport is ERC721Full, ERC721Mintable {
constructor() ERC721Full("TEST721", "T721") public {
}

function setTokenURI(uint256 tokenId, string memory uri) public {
_setTokenURI(tokenId, uri);
}
}
Loading

0 comments on commit 7a193da

Please sign in to comment.