All files / src/tests/integrationTests deploy.js

100% Statements 44/44
50% Branches 1/2
66.67% Functions 2/3
100% Lines 44/44
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 871x 1x 1x   1x 1x 1x 1x   1x 1x     1x 2x 2x       1x 1x 1x   1x     1x     1x     1x 1x 1x 1x   1x 1x         1x   1x     1x         1x   1x 1x             1x   1x 1x 1x   1x 1x   1x   1x   1x 1x   1x 1x 1x       1x  
const assert = require('assert')
const path = require('path')
const fs = require('fs-extra')
 
const interbit = require('../../')
const log = require('../../log')
const assertChainsConfigured = require('./assertChainsConfigured')
const prepareTestLocation = require('./prepareTestLocation')
 
const testDeploy = async () => {
  let interbitCleanup = () => {}
  let buildDbPath
  let deployDbPath
  const dbCleanup = async dbPath => {
    Eif (dbPath) {
      await fs.remove(dbPath)
    }
  }
 
  try {
    const { location, cleanup: locationCleanup } = prepareTestLocation('deploy')
    const artifacts = path.join(location, 'dist')
 
    const keysOptions = {
      filename: path.join(location, 'keys.json')
    }
    await interbit.keys(keysOptions)
 
    // eslint-disable-next-line
    const keyPair = require(path.join(process.cwd(), keysOptions.filename))
 
    // eslint-disable-next-line
    const config = require('./interbit.config')
    config.adminValidators = [keyPair.publicKey]
    config.staticChains.first.config.validators = [keyPair.publicKey]
    config.staticChains.second.config.validators = [keyPair.publicKey]
 
    buildDbPath = `./db-${Date.now()}`
    const buildOptions = {
      config,
      artifacts,
      dbPath: buildDbPath
    }
    await interbit.build(buildOptions)
 
    log.info('Pre-deploy build completed')
 
    // eslint-disable-next-line
    const manifest = require(path.join(
      process.cwd(),
      artifacts,
      'interbit.manifest.json'
    ))
    log.info(manifest)
 
    deployDbPath = `./db-${Date.now()}`
    const deployOptions = {
      manifest,
      location: artifacts,
      keyPair,
      dbPath: deployDbPath
    }
 
    log.info(deployOptions)
 
    const { cli, hypervisor, cleanup } = await interbit.deploy(deployOptions)
    interbitCleanup = cleanup
    log.info('Deploy finished')
 
    assert.ok(cli)
    assert.ok(hypervisor)
 
    log.success('Deploy returned cli and hypervisor')
 
    await assertChainsConfigured(cli, manifest.chains)
 
    log.success('Deployed chains were responsive and configured')
    locationCleanup()
  } finally {
    await interbitCleanup()
    await dbCleanup(buildDbPath)
    await dbCleanup(deployDbPath)
  }
}
 
module.exports = testDeploy