Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make verify synchronous #77

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions axelar-chains-config/src/utils/verifyContract.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const { exec } = require('child_process');
const { writeFile, writeFileSync, existsSync } = require('fs');
const { promisify } = require('util');

const execAsync = promisify(exec);
const writeFileAsync = promisify(writeFile);
const { writeFileSync } = require('fs');

/**
* Verifies a contract on etherscan-like explorer of the provided chain using hardhat.
Expand All @@ -14,31 +10,25 @@ const writeFileAsync = promisify(writeFile);
* @param {string} chain
* @param {string} contract
* @param {any[]} args
* @returns {Promise<void>}
* @returns {void}
*/
const verifyContract = async (env, chain, contract, args, options = {}) => {
const verifyContract = (env, chain, contract, args, options = {}) => {
const stringArgs = args.map((arg) => JSON.stringify(arg));
const content = `module.exports = [\n ${stringArgs.join(',\n ')}\n];`;
const file = options.dir ? `${options.dir}/temp-arguments.js` : 'temp-arguments.js';

if (!existsSync(file)) {
writeFileSync(file, '', 'utf-8');
}

const contractArg = options.contractPath ? `--contract ${options.contractPath}` : '';
const dirPrefix = options.dir ? `cd ${options.dir};` : '';
const cmd = `${dirPrefix} ENV=${env} npx hardhat verify --network ${chain.toLowerCase()} ${contractArg} --no-compile --constructor-args ${file} ${contract} --show-stack-traces`;

return writeFileAsync(file, content, 'utf-8')
.then(() => {
console.log(`Verifying contract ${contract} with args '${stringArgs.join(',')}'`);
console.log(cmd);
writeFileSync(file, content, 'utf-8');

console.log(`Verifying contract ${contract} with args '${stringArgs.join(',')}'`);
console.log(cmd);

exec(cmd, { stdio: 'inherit' });

return execAsync(cmd, { stdio: 'inherit' });
})
.then(() => {
console.log('Verified!');
});
console.log('Verified!');
};

module.exports = {
Expand Down