UNPKG

leap-node

Version:

[![codecov](https://codecov.io/gh/leapdao/leap-node/branch/master/graph/badge.svg)](https://codecov.io/gh/leapdao/leap-node) [![Docker Repository on Quay](https://quay.io/repository/leapdao/leap-node/status "Docker Repository on Quay")](https://quay.io/re

51 lines (44 loc) 1.28 kB
const getPeriodByBlockHeight = require('./getPeriodByBlockHeight'); const periods = { 0: { casBitmap: '0x123', slotId: 0, validatorAddress: '0xabc' }, 32: { casBitmap: '0x456', slotId: 1, validatorAddress: '0xdef' }, }; const db = { async getPeriodData(height) { return periods[height]; }, }; describe('getPeriodByBlockHeight', () => { test('no period for block height', async () => { expect(await getPeriodByBlockHeight({}, db, 64)).toBe(null); }); test('existing period for decimal height', async () => { expect(await getPeriodByBlockHeight({}, db, 10)).toEqual({ periodStart: 0, periodEnd: 31, casBitmap: '0x123', slotId: 0, validatorAddress: '0xabc', }); }); test('existing period for hex height', async () => { expect(await getPeriodByBlockHeight({}, db, '0x10')).toEqual({ periodStart: 0, periodEnd: 31, casBitmap: '0x123', slotId: 0, validatorAddress: '0xabc', }); }); test("existing period for 'latest' height", async () => { expect( await getPeriodByBlockHeight({ blockHeight: 20 }, db, 'latest') ).toEqual({ periodStart: 0, periodEnd: 31, casBitmap: '0x123', slotId: 0, validatorAddress: '0xabc', }); }); });