All files / src/validator handleSlotActivation.js

100% Statements 15/15
100% Branches 4/4
66.67% Functions 4/6
100% Lines 14/14

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 361x 1x 1x   1x 3x   2x     2x         2x   1x   2x 1x 1x 1x 1x                        
const { logValidators } = require('../utils/debug');
const activateSlot = require('../txHelpers/activateSlot');
const { getAuctionedByAddr } = require('../utils');
 
module.exports = (height, bridgeState) => {
  if (height % 32 !== 16) return;
 
  const { currentState } = bridgeState;
 
  // check if there is a validator slot that is "waiting for me"
  const myAuctionedSlots = getAuctionedByAddr(
    currentState.slots,
    bridgeState.account.address
  )
    .filter(
      ({ activationEpoch }) => currentState.epoch.epoch - activationEpoch >= 2
    )
    .map(({ id }) => id);
 
  if (myAuctionedSlots.length > 0) {
    logValidators('found some slots for activation', myAuctionedSlots);
    myAuctionedSlots.forEach(id => {
      const { receiptPromise } = activateSlot(id, bridgeState);
      receiptPromise
        .on('transactionHash', txHash => {
          // istanbul ignore next
          logValidators('activate', id, txHash);
        })
        .catch(err => {
          // istanbul ignore next
          logValidators('activation error', err.message);
        });
    });
  }
};