Skip to content

Commit

Permalink
optimization test
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniket-Engg committed Dec 21, 2018
1 parent 416d17c commit cf5c100
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 6 deletions.
65 changes: 64 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
test/
# 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
30 changes: 29 additions & 1 deletion test/sol-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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;
}
})
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/utils/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion test/utils/solc.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -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;
Expand Down

0 comments on commit cf5c100

Please sign in to comment.