All files / src/tests/integrationTests assertChainsConfigured.js

100% Statements 25/25
100% Branches 0/0
100% Functions 2/2
100% Lines 25/25
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 551x             1x 1x   1x 1x   1x   1x 2x 2x   2x 2x   2x 2x   2x 2x   2x 2x 2x   2x 2x           2x   4x       2x 2x             1x  
const assert = require('assert')
 
const {
  getChainId,
  logStateUpdates,
  dispatchAction,
  waitForState
} = require('./helpers')
const log = require('../../log')
 
const covenant = require('./covenant')
const { FIRST_CHAIN_ALIAS, SECOND_CHAIN_ALIAS } = require('./constants')
 
const JOIN_PROPAGATION_TIMEOUT = 5000
 
const assertChainsConfigured = async (cli, chainManifest) => {
  const firstChainId = getChainId(FIRST_CHAIN_ALIAS, chainManifest)
  const secondChainId = getChainId(SECOND_CHAIN_ALIAS, chainManifest)
 
  log.info(chainManifest)
  log.info(firstChainId)
 
  const firstChainInterface = cli.getChain(firstChainId)
  const secondChainInterface = cli.getChain(secondChainId)
 
  logStateUpdates(FIRST_CHAIN_ALIAS, firstChainInterface)
  logStateUpdates(SECOND_CHAIN_ALIAS, secondChainInterface)
 
  const testValue = 'meowmeowmeow'
  const testAction = covenant.actionCreators.addState(testValue)
  await dispatchAction(firstChainInterface, testAction)
 
  const firstState = firstChainInterface.getState()
  assert.strictEqual(
    firstState.shared,
    testValue,
    'First chain did not block ADD_STATE'
  )
 
  await waitForState(
    secondChainInterface,
    state => state.sharedWithMe === testValue,
    JOIN_PROPAGATION_TIMEOUT
  )
 
  const secondState = secondChainInterface.getState()
  assert.strictEqual(
    secondState.sharedWithMe,
    testValue,
    'Read join from first to second not functioning'
  )
}
 
module.exports = assertChainsConfigured