Skip to content

Commit

Permalink
Merge pull request #18 from alesanro/npm-folders
Browse files Browse the repository at this point in the history
Allow to search through parent node_modules folders
  • Loading branch information
Aniket-Engg committed Jun 29, 2019
2 parents 3ba0705 + 01ef38b commit bb63a1c
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 30 deletions.
80 changes: 77 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Expand Up @@ -32,9 +32,11 @@
"coveralls": "^3.0.3",
"eslint": "^5.16.0",
"mocha": "^6.1.4",
"nyc": "^14.1.0"
"nyc": "^14.1.0",
"@0xcert/ethereum-erc721": "2.0.0"
},
"dependencies": {
"axios": "^0.19.0"
"axios": "^0.19.0",
"get-installed-path": "~4.0.8"
}
}
6 changes: 6 additions & 0 deletions test/contracts/ImportFromParentNodeModules.sol
@@ -0,0 +1,6 @@
pragma solidity 0.5.6;

import "@0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";

contract ImportFromParentNodeModules is Ownable {
}
68 changes: 68 additions & 0 deletions test/contracts/straightened/ImportFromParentNodeModules.sol
@@ -0,0 +1,68 @@
pragma solidity 0.5.6;

/**
* @dev The contract has an owner address, and provides basic authorization control whitch
* simplifies the implementation of user permissions. This contract is based on the source code at:
* https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/ownership/Ownable.sol
*/
contract Ownable
{

/**
* @dev Error constants.
*/
string public constant NOT_OWNER = "018001";
string public constant ZERO_ADDRESS = "018002";

/**
* @dev Current owner address.
*/
address public owner;

/**
* @dev An event which is triggered when the owner is changed.
* @param previousOwner The address of the previous owner.
* @param newOwner The address of the new owner.
*/
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);

/**
* @dev The constructor sets the original `owner` of the contract to the sender account.
*/
constructor()
public
{
owner = msg.sender;
}

/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner()
{
require(msg.sender == owner, NOT_OWNER);
_;
}

/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(
address _newOwner
)
public
onlyOwner
{
require(_newOwner != address(0), ZERO_ADDRESS);
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}

}

contract ImportFromParentNodeModules is Ownable {
}
2 changes: 1 addition & 1 deletion test/package.json
Expand Up @@ -12,6 +12,6 @@
"author": "Aniket-Engg",
"license": "MIT",
"dependencies": {
"openzeppelin-solidity": "^2.2.0"
"openzeppelin-solidity": "2.2.0"
}
}
14 changes: 10 additions & 4 deletions test/straighten.js
@@ -1,7 +1,7 @@
'use strict';

const Straightener = require('../'),
expect = require('chai').expect,
expect = require('chai').expect,
fs = require('fs');

describe('sol-straightener', () => {
Expand All @@ -13,9 +13,9 @@ describe('sol-straightener', () => {
});

it('Fails for contract with non existing file import', async () => {
try{
try {
await Straightener.straighten(__dirname + '/contracts/SampleWithImportNotExisting.sol');
}catch(error){
} catch (error) {
expect(error.message).to.include('no such file or directory');
}
});
Expand All @@ -35,7 +35,13 @@ describe('sol-straightener', () => {
it('Contract with imports from node_modules', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/ImportFromNodeModules.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/ImportFromNodeModules.sol');
// expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});

it('Contract with imports from parent node_modules', async () => {
const strtnFile = await Straightener.straighten(__dirname + '/contracts/ImportFromParentNodeModules.sol');
const strtnContent = fs.readFileSync(__dirname + '/contracts/straightened/ImportFromParentNodeModules.sol');
expect(Buffer.from(strtnFile)).to.deep.equal(strtnContent);
});

it('Contract with multiple imports from Github', async () => {
Expand Down

0 comments on commit bb63a1c

Please sign in to comment.