diff --git a/.npmignore b/.npmignore index b59f7e3..292161c 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,64 @@ -test/ \ No newline at end of file +# Test directory +test/ + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next diff --git a/package.json b/package.json index 3b2bb30..8b7e7da 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sol-verifier", - "version": "1.1.1", + "version": "1.1.2", "description": "Verify Solidity Contracts on Etherscan", "main": "index.js", "scripts": { diff --git a/test/sol-verifier.js b/test/sol-verifier.js index e712f5c..7892ebf 100644 --- a/test/sol-verifier.js +++ b/test/sol-verifier.js @@ -89,6 +89,33 @@ describe('sol-verifier', () => { }); }); + describe('Compiling & Verifying Sample.sol by enabling optimization', () => { + var contractAddress; + var contractName; + var network; + var sampleData; + before('Compile & Deploy Sample.sol', async () => { + try{ + contractName = 'Sample'; + network = 'rinkeby'; + contractAddress = await deployContract(contractName, network, [], true); // Optimization Enabled + await sleep(30000); // To make sure that contractCode is stored + }catch(err){ + throw err; + } + }) + it('Verifies Sample.sol contract successfully by enabling optimization', async () => { + sampleData = { + key: process.env.KEY, + path : __dirname + '/contracts/'+ contractName +'.sol', + contractAddress: contractAddress, + network : network, + optimizationFlag: true // Optimization Enabled + }; + let response = await Verifier.verifyContract(sampleData); + response.status.should.equal('1'); + }); + }); describe('Deploying & Verifying SampleWithConstructor.sol', () => { @@ -105,6 +132,7 @@ describe('sol-verifier', () => { contractAddress = await deployContract(contractName, network, constructParams); await sleep(30000); // To make sure that contractCode is stored }catch(err){ + console.log(err); throw err; } }) @@ -121,7 +149,7 @@ describe('sol-verifier', () => { response.status.should.equal('1'); }); - it('Trying to verify SampleWithConstructor contract with passing constructor values (should fail)', async () => { + it('Trying to verify SampleWithConstructor contract without passing constructor values (should fail)', async () => { sampleData.cvalues = null; try{ await Verifier.verifyContract(sampleData); diff --git a/test/utils/deploy.js b/test/utils/deploy.js index ddd7879..3896665 100644 --- a/test/utils/deploy.js +++ b/test/utils/deploy.js @@ -3,12 +3,12 @@ const HDWalletProvider = require("truffle-hdwallet-provider"); const solc = require('./solc'); -module.exports.deployContract = async (contractName, network, initParams = [] ) => { +module.exports.deployContract = async (contractName, network, initParams = [], optimize = false) => { var net = 'https://' + network +'.infura.io/'; var web3 = new Web3(new HDWalletProvider(process.env.SEED, net)); let contractPath = __dirname + "/../contracts/"+ contractName + ".sol"; try{ - let {bytecode, abi } = await solc.compile(contractPath, contractName); + let {bytecode, abi } = await solc.compile(contractPath, contractName, optimize); let myContract = new web3.eth.Contract(abi); let result = await myContract.deploy({ data: '0x' + bytecode, diff --git a/test/utils/solc.js b/test/utils/solc.js index c7781ce..578756c 100644 --- a/test/utils/solc.js +++ b/test/utils/solc.js @@ -1,7 +1,7 @@ const solc = require('solc'); const fs = require('fs'); -module.exports.compile = async (contractPath, contractName) => { +module.exports.compile = async (contractPath, contractName, enableOptimization) => { var input = { language: 'Solidity', sources: { @@ -17,6 +17,9 @@ module.exports.compile = async (contractPath, contractName) => { } } }; + + if(enableOptimization) + input.settings.optimizer = {enabled: true}; let compilationData = JSON.parse(solc.compile(JSON.stringify(input))).contracts['sample.sol'][contractName]; let result = {}; result.bytecode = compilationData.evm.bytecode.object;