# All files / src/period/utils checkEnoughVotes.js

100% Statements 6/6
66.67% Branches 4/6
100% Functions 1/1
100% Lines 6/6

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

    3x
    12x
    12x

    12x
    12x

    12x

     /**
     * Copyright (c) 2019-present, Leap DAO (leapdao.org)
     *
     * This source code is licensed under the Mozilla Public License Version 2.0
     * found in the LICENSE file in the root directory of this source tree.
     */

    /**
     * Checks if a given period root voted for by at least 2/3 of validator set
     * @returns {Object} Object with results like
     * { result:boolean, votes:number, needed:number }
     * where
     * - `votes` is a number of votes for a given period,
     * - `needed` is a minimum number of votes needed for consensus
     */
    module.exports = (periodRoot, state) => {
      const periodVotes = state.periodVotes || {};
      const slots = state.slots || [];

      const votes = (periodVotes[periodRoot] || []).length;
      const needed = Math.floor((slots.length * 2) / 3) + 1;

      return {
        result: votes >= needed,
        votes,
        needed,
      };
    };