From 40f8e6a1345ed4a2647eac8e61fa1317b9f28a33 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Wed, 4 Sep 2019 13:24:10 +0200 Subject: [PATCH] Add standar lint --- scripts/deploy/apm-open.js | 114 +++++++-------- scripts/deploy/apm-registries.js | 162 ++++++++++----------- src/commands/start.js | 234 +++++++++++++++---------------- src/helpers/ganache-vars.js | 3 +- 4 files changed, 256 insertions(+), 257 deletions(-) diff --git a/scripts/deploy/apm-open.js b/scripts/deploy/apm-open.js index 9210ad9..c019d2d 100644 --- a/scripts/deploy/apm-open.js +++ b/scripts/deploy/apm-open.js @@ -1,14 +1,14 @@ -const namehash = require("eth-ens-namehash").hash; -const keccak256 = require("js-sha3").keccak_256; +const namehash = require('eth-ens-namehash').hash +const keccak256 = require('js-sha3').keccak_256 -const deployAPM = require("./apm"); +const deployAPM = require('./apm') -const globalArtifacts = this.artifacts; // Not injected unless called directly via truffle -const globalWeb3 = this.web3; // Not injected unless called directly via truffle +const globalArtifacts = this.artifacts // Not injected unless called directly via truffle +const globalWeb3 = this.web3 // Not injected unless called directly via truffle -const defaultOwner = process.env.OWNER; -const defaultDaoFactoryAddress = process.env.DAO_FACTORY; -const defaultENSAddress = process.env.ENS; +const defaultOwner = process.env.OWNER +const defaultDaoFactoryAddress = process.env.DAO_FACTORY +const defaultENSAddress = process.env.ENS module.exports = async ( truffleExecCallback, @@ -18,24 +18,24 @@ module.exports = async ( ensAddress = defaultENSAddress, owner = defaultOwner, daoFactoryAddress = defaultDaoFactoryAddress, - verbose = true + verbose = true, } = {} ) => { const log = (...args) => { if (verbose) { - console.log(...args); + console.log(...args) } - }; + } - const APMRegistry = artifacts.require("APMRegistry"); - const ENSSubdomainRegistrar = artifacts.require("ENSSubdomainRegistrar"); - const Kernel = artifacts.require("Kernel"); - const ACL = artifacts.require("ACL"); + const APMRegistry = artifacts.require('APMRegistry') + const ENSSubdomainRegistrar = artifacts.require('ENSSubdomainRegistrar') + const Kernel = artifacts.require('Kernel') + const ACL = artifacts.require('ACL') - const tldName = "aragonpm.eth"; - const labelName = "open"; - const tldHash = namehash(tldName); - const labelHash = "0x" + keccak256(labelName); + const tldName = 'aragonpm.eth' + const labelName = 'open' + const tldHash = namehash(tldName) + const labelHash = '0x' + keccak256(labelName) // deploy `aragonpm.eth` const { apmFactory, ens, apm } = await deployAPM(null, { @@ -43,65 +43,65 @@ module.exports = async ( web3, ensAddress, daoFactoryAddress, - verbose - }); + verbose, + }) - ensAddress = ens.address; - const registrar = await apm.registrar(); - const apmENSSubdomainRegistrar = ENSSubdomainRegistrar.at(registrar); - const create_name_role = await apmENSSubdomainRegistrar.CREATE_NAME_ROLE(); + ensAddress = ens.address + const registrar = await apm.registrar() + const apmENSSubdomainRegistrar = ENSSubdomainRegistrar.at(registrar) + const create_name_role = await apmENSSubdomainRegistrar.CREATE_NAME_ROLE() - log("Managing permissions..."); - const kernel = Kernel.at(await apm.kernel()); - const acl = ACL.at(await kernel.acl()); + log('Managing permissions...') + const kernel = Kernel.at(await apm.kernel()) + const acl = ACL.at(await kernel.acl()) - log(`Remove manager for create_name_role`); + log(`Remove manager for create_name_role`) // We need to remove the manager of the role to add permissions await acl.removePermissionManager(registrar, create_name_role, { - from: owner - }); - log(`Create permission for root account on create_name_role`); + from: owner, + }) + log(`Create permission for root account on create_name_role`) await acl.createPermission(owner, registrar, create_name_role, owner, { - from: owner - }); - log("========="); + from: owner, + }) + log('=========') - log(`TLD: ${tldName} (${tldHash})`); - log(`Label: ${labelName} (${labelHash})`); - log("========="); + log(`TLD: ${tldName} (${tldHash})`) + log(`Label: ${labelName} (${labelHash})`) + log('=========') - log(`Assigning ENS name (${labelName}.${tldName}) to factory...`); + log(`Assigning ENS name (${labelName}.${tldName}) to factory...`) try { await apmENSSubdomainRegistrar.createName(labelHash, apmFactory.address, { - from: owner - }); + from: owner, + }) } catch (err) { console.error( `Error: could not set the owner of '${labelName}.${tldName}' on the given ENS instance`, `(${ensAddress}). Make sure you have ownership rights over the subdomain.` - ); - throw err; + ) + throw err } - log("Deploying Open APM..."); - const receipt = await apmFactory.newAPM(tldHash, labelHash, owner); + log('Deploying Open APM...') + const receipt = await apmFactory.newAPM(tldHash, labelHash, owner) - log("========="); - const openAPMAddr = receipt.logs.filter(l => l.event == "DeployAPM")[0].args - .apm; - log("# Open APM:"); - log("Address:", openAPMAddr); - log("Transaction hash:", receipt.tx); - log("========="); + log('=========') + const openAPMAddr = receipt.logs.filter(l => l.event == 'DeployAPM')[0].args + .apm + log('# Open APM:') + log('Address:', openAPMAddr) + log('Transaction hash:', receipt.tx) + log('=========') - if (typeof truffleExecCallback === "function") { + if (typeof truffleExecCallback === 'function') { // Called directly via `truffle exec` - truffleExecCallback(); + truffleExecCallback() } else { return { apmFactory, ens, - apm: APMRegistry.at(openAPMAddr) - }; + apm: APMRegistry.at(openAPMAddr), + } } -}; +} diff --git a/scripts/deploy/apm-registries.js b/scripts/deploy/apm-registries.js index e493814..b253665 100644 --- a/scripts/deploy/apm-registries.js +++ b/scripts/deploy/apm-registries.js @@ -1,14 +1,14 @@ -const namehash = require("eth-ens-namehash").hash; -const keccak256 = require("js-sha3").keccak_256; +const namehash = require('eth-ens-namehash').hash +const keccak256 = require('js-sha3').keccak_256 -const deployAPM = require("./apm"); +const deployAPM = require('./apm') -const globalArtifacts = this.artifacts; // Not injected unless called directly via truffle -const globalWeb3 = this.web3; // Not injected unless called directly via truffle +const globalArtifacts = this.artifacts // Not injected unless called directly via truffle +const globalWeb3 = this.web3 // Not injected unless called directly via truffle -const defaultOwner = process.env.OWNER; -const defaultDaoFactoryAddress = process.env.DAO_FACTORY; -const defaultENSAddress = process.env.ENS; +const defaultOwner = process.env.OWNER +const defaultDaoFactoryAddress = process.env.DAO_FACTORY +const defaultENSAddress = process.env.ENS module.exports = async ( truffleExecCallback, @@ -18,26 +18,26 @@ module.exports = async ( ensAddress = defaultENSAddress, owner = defaultOwner, daoFactoryAddress = defaultDaoFactoryAddress, - verbose = true + verbose = true, } = {} ) => { const log = (...args) => { if (verbose) { - console.log(...args); + console.log(...args) } - }; + } // const APMRegistry = artifacts.require("APMRegistry"); - const ENSSubdomainRegistrar = artifacts.require("ENSSubdomainRegistrar"); - const Kernel = artifacts.require("Kernel"); - const ACL = artifacts.require("ACL"); + const ENSSubdomainRegistrar = artifacts.require('ENSSubdomainRegistrar') + const Kernel = artifacts.require('Kernel') + const ACL = artifacts.require('ACL') - const tldName = "aragonpm.eth"; - const tldHash = namehash(tldName); - const openLabelName = "open"; - const hatchLabelName = "hatch"; - const openLabelHash = "0x" + keccak256(openLabelName); - const hatchLabelHash = "0x" + keccak256(hatchLabelName); + const tldName = 'aragonpm.eth' + const tldHash = namehash(tldName) + const openLabelName = 'open' + const hatchLabelName = 'hatch' + const openLabelHash = '0x' + keccak256(openLabelName) + const hatchLabelHash = '0x' + keccak256(hatchLabelName) // deploy `aragonpm.eth` const { apmFactory, ens, apm } = await deployAPM(null, { @@ -45,51 +45,51 @@ module.exports = async ( web3, ensAddress, daoFactoryAddress, - verbose - }); + verbose, + }) - ensAddress = ens.address; - const registrar = await apm.registrar(); - const apmENSSubdomainRegistrar = ENSSubdomainRegistrar.at(registrar); - const create_name_role = await apmENSSubdomainRegistrar.CREATE_NAME_ROLE(); + ensAddress = ens.address + const registrar = await apm.registrar() + const apmENSSubdomainRegistrar = ENSSubdomainRegistrar.at(registrar) + const create_name_role = await apmENSSubdomainRegistrar.CREATE_NAME_ROLE() - log("Managing permissions..."); - const kernel = Kernel.at(await apm.kernel()); - const acl = ACL.at(await kernel.acl()); + log('Managing permissions...') + const kernel = Kernel.at(await apm.kernel()) + const acl = ACL.at(await kernel.acl()) - log(`Remove manager for create_name_role`); + log(`Remove manager for create_name_role`) // We need to remove the manager of the role to add permissions await acl.removePermissionManager(registrar, create_name_role, { - from: owner - }); - log(`Create permission for root account on create_name_role`); + from: owner, + }) + log(`Create permission for root account on create_name_role`) await acl.createPermission(owner, registrar, create_name_role, owner, { - from: owner - }); - log("========="); + from: owner, + }) + log('=========') - log(`TLD: ${tldName} (${tldHash})`); - log(`Open Label: ${openLabelName} (${openLabelHash})`); - log(`Hatch Label: ${hatchLabelName} (${hatchLabelHash})`); - log("========="); + log(`TLD: ${tldName} (${tldHash})`) + log(`Open Label: ${openLabelName} (${openLabelHash})`) + log(`Hatch Label: ${hatchLabelName} (${hatchLabelHash})`) + log('=========') log( `Assigning ENS name (${openLabelName}.${tldName}) and (${hatchLabelName}.${tldName}) to factory...` - ); + ) try { await apmENSSubdomainRegistrar.createName( openLabelHash, apmFactory.address, { - from: owner + from: owner, } - ); + ) } catch (err) { console.error( `Error: could not set the owner of '${openLabelName}.${tldName}' on the given ENS instance`, `(${ensAddress}). Make sure you have ownership rights over the subdomain.` - ); - throw err; + ) + throw err } try { @@ -97,50 +97,50 @@ module.exports = async ( hatchLabelHash, apmFactory.address, { - from: owner + from: owner, } - ); + ) } catch (err) { console.error( `Error: could not set the owner of '${hatchLabelName}.${tldName}' on the given ENS instance`, `(${ensAddress}). Make sure you have ownership rights over the subdomain.` - ); - throw err; + ) + throw err } - log("========="); - - log("Deploying Open APM..."); - let receipt = await apmFactory.newAPM(tldHash, openLabelHash, owner); - - log("========="); - - log("========="); - const openAPMAddr = receipt.logs.filter(l => l.event == "DeployAPM")[0].args - .apm; - log("# Open APM:"); - log("Address:", openAPMAddr); - log("Transaction hash:", receipt.tx); - log("========="); - - log("========="); - log("Deploying Hatch APM..."); - receipt = await apmFactory.newAPM(tldHash, hatchLabelHash, owner); - - log("========="); - const hatchAPMAddr = receipt.logs.filter(l => l.event == "DeployAPM")[0].args - .apm; - log("# Hatch APM:"); - log("Address:", hatchAPMAddr); - log("Transaction hash:", receipt.tx); - log("========="); - - if (typeof truffleExecCallback === "function") { + log('=========') + + log('Deploying Open APM...') + let receipt = await apmFactory.newAPM(tldHash, openLabelHash, owner) + + log('=========') + + log('=========') + const openAPMAddr = receipt.logs.filter(l => l.event == 'DeployAPM')[0].args + .apm + log('# Open APM:') + log('Address:', openAPMAddr) + log('Transaction hash:', receipt.tx) + log('=========') + + log('=========') + log('Deploying Hatch APM...') + receipt = await apmFactory.newAPM(tldHash, hatchLabelHash, owner) + + log('=========') + const hatchAPMAddr = receipt.logs.filter(l => l.event == 'DeployAPM')[0].args + .apm + log('# Hatch APM:') + log('Address:', hatchAPMAddr) + log('Transaction hash:', receipt.tx) + log('=========') + + if (typeof truffleExecCallback === 'function') { // Called directly via `truffle exec` - truffleExecCallback(); + truffleExecCallback() } else { return { apmFactory, - ens - }; + ens, + } } -}; +} diff --git a/src/commands/start.js b/src/commands/start.js index e936255..20a0178 100644 --- a/src/commands/start.js +++ b/src/commands/start.js @@ -1,74 +1,74 @@ -const TaskList = require("listr"); -const ncp = require("ncp"); -const ganache = require("ganache-core"); -const Web3 = require("web3"); -const { promisify } = require("util"); -const os = require("os"); -const path = require("path"); -const rimraf = require("rimraf"); -const mkdirp = require("mkdirp"); -const chalk = require("chalk"); -const fs = require("fs"); -const listrOpts = require("@aragon/cli-utils/src/helpers/listr-options"); -const pjson = require("../../package.json"); -const devchainStatus = require("./status"); +const TaskList = require('listr') +const ncp = require('ncp') +const ganache = require('ganache-core') +const Web3 = require('web3') +const { promisify } = require('util') +const os = require('os') +const path = require('path') +const rimraf = require('rimraf') +const mkdirp = require('mkdirp') +const chalk = require('chalk') +const fs = require('fs') +const listrOpts = require('@aragon/cli-utils/src/helpers/listr-options') +const pjson = require('../../package.json') +const devchainStatus = require('./status') -const { BLOCK_GAS_LIMIT, MNEMONIC } = require("../helpers/ganache-vars"); +const { BLOCK_GAS_LIMIT, MNEMONIC } = require('../helpers/ganache-vars') -exports.command = "start"; +exports.command = 'start' exports.describe = - "Open a test chain for development and pass arguments to ganache"; + 'Open a test chain for development and pass arguments to ganache' exports.builder = yargs => { return yargs - .option("port", { - description: "The port to run the local chain on", + .option('port', { + description: 'The port to run the local chain on', default: 8545, - alias: "p" + alias: 'p', }) - .option("network-id", { - description: "Network id to connect with", - alias: "i" + .option('network-id', { + description: 'Network id to connect with', + alias: 'i', }) - .option("block-time", { - description: "Specify blockTime in seconds for automatic mining", - alias: "b" + .option('block-time', { + description: 'Specify blockTime in seconds for automatic mining', + alias: 'b', }) - .option("default-balance-ether", { - description: "The default account balance, specified in ether", + .option('default-balance-ether', { + description: 'The default account balance, specified in ether', default: 100, - alias: "e" + alias: 'e', }) - .option("mnemonic", { - type: "string", + .option('mnemonic', { + type: 'string', default: MNEMONIC, - description: "Mnemonic phrase", - alias: "m" + description: 'Mnemonic phrase', + alias: 'm', }) - .option("gas-limit", { + .option('gas-limit', { default: BLOCK_GAS_LIMIT, - description: "Block gas limit", - alias: "l" + description: 'Block gas limit', + alias: 'l', }) - .option("reset", { - type: "boolean", + .option('reset', { + type: 'boolean', default: false, - description: "Reset devchain to snapshot", - alias: "r" + description: 'Reset devchain to snapshot', + alias: 'r', }) - .option("accounts", { + .option('accounts', { default: 2, - description: "Number of accounts to print", - alias: "a" + description: 'Number of accounts to print', + alias: 'a', }) - .option("verbose", { + .option('verbose', { default: false, - type: "boolean", - description: "Enable verbose devchain output", - alias: "v" - }); -}; + type: 'boolean', + description: 'Enable verbose devchain output', + alias: 'v', + }) +} exports.task = async function({ port = 8545, @@ -82,54 +82,54 @@ exports.task = async function({ showAccounts = 2, reporter, silent, - debug + debug, }) { - const removeDir = promisify(rimraf); - const mkDir = promisify(mkdirp); - const recursiveCopy = promisify(ncp); + const removeDir = promisify(rimraf) + const mkDir = promisify(mkdirp) + const recursiveCopy = promisify(ncp) const snapshotPath = path.join( os.homedir(), `.aragon/aragen-db-${pjson.version}` - ); + ) const tasks = new TaskList( [ { - title: "Check devchain status", + title: 'Check devchain status', task: async ctx => { const task = await devchainStatus.task({ port, reset, silent, - debug - }); + debug, + }) - const { portTaken, processID } = await task.run(); + const { portTaken, processID } = await task.run() if (portTaken && !reset) { throw new Error( `Process with ID ${chalk.red( processID )} already running at port ${chalk.blue(port)}` - ); + ) } - } + }, }, { - title: "Setting up a new chain from latest Aragon snapshot", + title: 'Setting up a new chain from latest Aragon snapshot', task: async (ctx, task) => { - await removeDir(snapshotPath); - await mkDir(path.resolve(snapshotPath, "..")); - const snapshot = path.join(__dirname, "../../aragon-ganache"); - await recursiveCopy(snapshot, snapshotPath); + await removeDir(snapshotPath) + await mkDir(path.resolve(snapshotPath, '..')) + const snapshot = path.join(__dirname, '../../aragon-ganache') + await recursiveCopy(snapshot, snapshotPath) }, - enabled: () => !fs.existsSync(snapshotPath) || reset + enabled: () => !fs.existsSync(snapshotPath) || reset, }, { - title: "Starting a local chain from snapshot", + title: 'Starting a local chain from snapshot', task: async (ctx, task) => { - ctx.id = networkId || parseInt(1e8 * Math.random()); + ctx.id = networkId || parseInt(1e8 * Math.random()) const options = { network_id: ctx.id, @@ -139,85 +139,83 @@ exports.task = async function({ mnemonic, db_path: snapshotPath, logger: verbose ? { log: reporter.info.bind(reporter) } : undefined, - debug - }; + debug, + } - const server = ganache.server(options); + const server = ganache.server(options) const listen = () => new Promise((resolve, reject) => { server.listen(port, err => { - if (err) return reject(err); + if (err) return reject(err) - task.title = `Local chain started at port ${chalk.blue( - port - )}\n`; - resolve(); - }); - }); - await listen(); + task.title = `Local chain started at port ${chalk.blue(port)}\n` + resolve() + }) + }) + await listen() ctx.web3 = new Web3( new Web3.providers.WebsocketProvider(`ws://localhost:${port}`) - ); - const accounts = await ctx.web3.eth.getAccounts(); + ) + const accounts = await ctx.web3.eth.getAccounts() - ctx.accounts = accounts.slice(0, parseInt(showAccounts)); - ctx.mnemonic = MNEMONIC; + ctx.accounts = accounts.slice(0, parseInt(showAccounts)) + ctx.mnemonic = MNEMONIC - const ganacheAccounts = server.provider.manager.state.accounts; + const ganacheAccounts = server.provider.manager.state.accounts ctx.privateKeys = ctx.accounts.map(address => ({ key: ganacheAccounts[address.toLowerCase()].secretKey.toString( - "hex" + 'hex' ), - address - })); - } - } + address, + })) + }, + }, ], listrOpts(silent, debug) - ); + ) - return tasks; -}; + return tasks +} exports.printAccounts = (reporter, privateKeys) => { const firstAccountComment = - "(account used to deploy DAOs, has more permissions)"; + '(account used to deploy DAOs, has more permissions)' const formattedAccounts = privateKeys.map( ({ address, key }, i) => `Address #${i + 1}: ${chalk.green(address)} ${ - i === 0 ? firstAccountComment : "" + i === 0 ? firstAccountComment : '' }\nPrivate key: ` + chalk.blue(key) + - "\n" - ); + '\n' + ) reporter.info(`Here are some Ethereum accounts you can use. The first one will be used for all the actions the aragonCLI performs. You can use your favorite Ethereum provider or wallet to import their private keys. - \n${formattedAccounts.join("\n")}`); -}; + \n${formattedAccounts.join('\n')}`) +} exports.printMnemonic = (reporter, mnemonic) => { reporter.info( `The accounts were generated from the following mnemonic phrase:\n${chalk.blue( mnemonic )}\n` - ); -}; + ) +} exports.printResetNotice = (reporter, reset) => { if (reset) { reporter.warning(`${chalk.yellow( - "The devchain was reset, some steps need to be done to prevent issues:" + 'The devchain was reset, some steps need to be done to prevent issues:' )} - Reset the application cache in Aragon Client by going to Settings -> Troubleshooting. - If using Metamask: switch to a different network, and then switch back to the 'Private Network' (this will clear the nonce cache and prevent errors when sending transactions) - `); + `) } -}; +} exports.handler = async ({ reporter, @@ -231,7 +229,7 @@ exports.handler = async ({ verbose, accounts, silent, - debug + debug, }) => { const task = await exports.task({ port, @@ -245,22 +243,22 @@ exports.handler = async ({ reporter, showAccounts: accounts, silent, - debug - }); - const { privateKeys, id } = await task.run(); - exports.printAccounts(reporter, privateKeys); - exports.printMnemonic(reporter, mnemonic); - exports.printResetNotice(reporter, reset); + debug, + }) + const { privateKeys, id } = await task.run() + exports.printAccounts(reporter, privateKeys) + exports.printMnemonic(reporter, mnemonic) + exports.printResetNotice(reporter, reset) reporter.info( - "ENS instance deployed at:", - chalk.green("0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1"), - "\n" - ); + 'ENS instance deployed at:', + chalk.green('0x5f6f7e8cc7346a11ca2def8f827b7a0b612c56a1'), + '\n' + ) - reporter.info(`Network Id: ${chalk.blue(id)}`, "\n"); + reporter.info(`Network Id: ${chalk.blue(id)}`, '\n') reporter.info( - `Devchain running at: ${chalk.blue("http://localhost:" + port)}.` - ); -}; + `Devchain running at: ${chalk.blue('http://localhost:' + port)}.` + ) +} diff --git a/src/helpers/ganache-vars.js b/src/helpers/ganache-vars.js index 525d0ee..1363e22 100644 --- a/src/helpers/ganache-vars.js +++ b/src/helpers/ganache-vars.js @@ -1,4 +1,5 @@ module.exports = { BLOCK_GAS_LIMIT: 50e6, - MNEMONIC: 'explain tackle mirror kit van hammer degree position ginger unfair soup bonus' + MNEMONIC: + 'explain tackle mirror kit van hammer degree position ginger unfair soup bonus', }