All files / src/chainManagement deployCovenants.js

100% Statements 14/14
100% Branches 0/0
100% Functions 1/1
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 412x                       2x 1x 1x   1x   1x 1x   1x         1x 1x   1x           1x 1x     2x  
const log = require('../log')
 
/**
 * Deploys a set of covenants defined in config to a chain.
 * These covenant configurations should point to covenant package
 * file locations.
 * @param {Object} params - The params object.
 * @param {Object} params.cli - The cli of the node to deploy the covenants to.
 * @param {Object} params.covenantConfig - Configuration info for the covenants
 *    to deploy, typically out of a config file.
 * @returns {Object} - The covenant hashes mapped to the covenant aliases.
 */
const deployCovenants = async ({ cli, covenantConfig }) => {
  log.info('DEPLOYING COVENANTS')
  const covenants = Object.keys(covenantConfig)
 
  const covenantHashes = {}
 
  for (const covenantName of covenants) {
    const config = covenantConfig[covenantName]
 
    log.info('DEPLOYING COVENANT:', {
      covenantName,
      location: config.location
    })
    // eslint-disable-next-line no-await-in-loop
    const covenantHash = await cli.deployCovenant(config.location)
    covenantHashes[covenantName] = covenantHash
 
    log.info('DEPLOYED COVENANT:', {
      covenantName,
      covenantHash
    })
  }
 
  log.success('DEPLOYED COVENANTS')
  return covenantHashes
}
 
module.exports = deployCovenants