All files / scripts/deploy-service/preProcess compareConfigAndState.js

80% Statements 24/30
50% Branches 9/18
83.33% Functions 5/6
80% Lines 24/30

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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              1x 2x 2x   2x 2x   2x 11x 11x       2x       1x 4x 4x   4x         1x   1x 7x   3x       3x 4x                                                 2x 2x 7x       2x   2x          
/**
 * @dev Determine compilation targets and update stateClone from service.vvisp.json and state.vvisp.json
 * @param configContracts Contracts information from service.vvisp.json
 * @param stateClone Clone of deploying state
 * @return Object Information about compilation targets
 */
 
module.exports = function(configContracts, stateClone) {
  const path = require('path');
  const { forIn } = require('@haechi-labs/vvisp-utils');
 
  const { PENDING_STATE } = require('../constants');
  const targets = {};
 
  forIn(configContracts, (contract, name) => {
    Eif (!contract.name) {
      configContracts[name].name = path.parse(contract.path).name; // default contract name is file name
    }
  });
 
  if (stateClone.notUpgrading) {
    // When deploying DApp first time,
    // 1. If not paused, first copy from service.vvisp.json to stateClone and write PENDING_STATE
    // 2. Move all contracts from stateClone to compile targets.
    forIn(configContracts, (contract, name) => {
      Eif (!stateClone.paused) {
        stateClone.contracts[name] = { pending: PENDING_STATE[0], ...contract };
      }
      targets[name] = { ...stateClone.contracts[name] };
    });
  } else {
    // When upgrading DApp
    // Branch with paused state
    Eif (!stateClone.paused) {
      // When not paused, compare with state.vvisp.json and service.vvisp.json
      forIn(configContracts, (contract, name) => {
        if (!stateClone.contracts.hasOwnProperty(name)) {
          // get first-deploying contracts
          stateClone.contracts[name] = {
            pending: PENDING_STATE[0],
            ...contract
          };
          targets[name] = { ...stateClone.contracts[name] };
        } else Iif (contract.name !== stateClone.contracts[name].name) {
          // get upgrading contracts
          stateClone.contracts[name] = {
            ...stateClone.contracts[name],
            pending: PENDING_STATE[1],
            ...contract
          };
          targets[name] = { ...stateClone.contracts[name] };
        }
      });
    } else {
      // When paused,
      forIn(stateClone.contracts, (contract, name) => {
        if (
          contract.pending === PENDING_STATE[0] ||
          contract.pending === PENDING_STATE[1]
        ) {
          // deploy with proxy
          targets[name] = { ...contract };
        }
      });
    }
  }
 
  // Check if there is no upgradeable contract.
  let noProxy = true;
  forIn(targets, contract => {
    Iif (contract.upgradeable === true) {
      noProxy = false;
    }
  });
  stateClone.noProxy = noProxy;
 
  return {
    targets: targets,
    noProxy: noProxy
  };
};