|
|
@ -1,27 +1,26 @@ |
|
|
|
import { reducer, initialState } from '../../js/pages/chain' |
|
|
|
import { reducer, initialState, placeHolderBlock } from '../../js/pages/chain' |
|
|
|
|
|
|
|
|
|
|
|
describe('PAGE_LOAD', () => { |
|
|
|
describe('ELEMENTS_LOAD', () => { |
|
|
|
test('loads block numbers', () => { |
|
|
|
|
|
|
|
const state = initialState |
|
|
|
|
|
|
|
const action = { |
|
|
|
|
|
|
|
type: 'PAGE_LOAD', |
|
|
|
|
|
|
|
blockNumbers: [2, 1] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(output.blockNumbers).toEqual([2, 1]) |
|
|
|
|
|
|
|
expect(output.skippedBlockNumbers).toEqual([]) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
test('loads with skipped blocks', () => { |
|
|
|
test('loads with skipped blocks', () => { |
|
|
|
|
|
|
|
window.localized = {} |
|
|
|
const state = initialState |
|
|
|
const state = initialState |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'PAGE_LOAD', |
|
|
|
type: 'ELEMENTS_LOAD', |
|
|
|
blockNumbers: [4, 1] |
|
|
|
blocks: [ |
|
|
|
|
|
|
|
{ blockNumber: 6, chainBlockHtml: 'test 6' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' }, |
|
|
|
|
|
|
|
{ blockNumber: 1, chainBlockHtml: 'test 1' } |
|
|
|
|
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.blockNumbers).toEqual([4, 3, 2, 1]) |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.skippedBlockNumbers).toEqual([3, 2]) |
|
|
|
{ blockNumber: 6, chainBlockHtml: 'test 6' }, |
|
|
|
|
|
|
|
{ blockNumber: 5, chainBlockHtml: placeHolderBlock(5) }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: placeHolderBlock(4) }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -44,8 +43,10 @@ describe('RECEIVED_NEW_BLOCK', () => { |
|
|
|
test('receives new block', () => { |
|
|
|
test('receives new block', () => { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
averageBlockTime: '6 seconds', |
|
|
|
averageBlockTime: '6 seconds', |
|
|
|
blockNumbers: [1], |
|
|
|
blocks: [ |
|
|
|
newBlock: 'last new block' |
|
|
|
{ blockNumber: 1, chainBlockHtml: 'test 1' }, |
|
|
|
|
|
|
|
{ blockNumber: 0, chainBlockHtml: 'test 0' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
@ -58,121 +59,138 @@ describe('RECEIVED_NEW_BLOCK', () => { |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.newBlock).toEqual('new block') |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.blockNumbers).toEqual([2, 1]) |
|
|
|
{ blockNumber: 2, chainBlockHtml: 'new block', averageBlockTime: '5 seconds' }, |
|
|
|
|
|
|
|
{ blockNumber: 1, chainBlockHtml: 'test 1' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
test('inserts place holders if block received out of order', () => { |
|
|
|
test('inserts place holders if block received out of order', () => { |
|
|
|
|
|
|
|
window.localized = {} |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
blockNumbers: [2] |
|
|
|
blocks: [ |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' }, |
|
|
|
|
|
|
|
{ blockNumber: 1, chainBlockHtml: 'test 1' }, |
|
|
|
|
|
|
|
{ blockNumber: 0, chainBlockHtml: 'test 0' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
averageBlockTime: '5 seconds', |
|
|
|
chainBlockHtml: 'test 6', |
|
|
|
chainBlockHtml: 'test5', |
|
|
|
blockNumber: 6 |
|
|
|
blockNumber: 5 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
|
|
|
|
expect(output.newBlock).toBe('test5') |
|
|
|
|
|
|
|
expect(output.blockNumbers).toEqual([5, 4, 3, 2]) |
|
|
|
|
|
|
|
expect(output.skippedBlockNumbers).toEqual([4, 3]) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
test('replaces skipped block', () => { |
|
|
|
|
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
|
|
|
|
blockNumbers: [4, 3, 2, 1], |
|
|
|
|
|
|
|
skippedBlockNumbers: [3, 2, 1] |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
const action = { |
|
|
|
|
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
|
|
|
|
msg: { |
|
|
|
|
|
|
|
averageBlockTime: '5 seconds', |
|
|
|
|
|
|
|
chainBlockHtml: 'test2', |
|
|
|
|
|
|
|
blockNumber: 2 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.newBlock).toBe('test2') |
|
|
|
{ blockNumber: 6, chainBlockHtml: 'test 6' }, |
|
|
|
expect(output.blockNumbers).toEqual([4, 3, 2, 1]) |
|
|
|
{ blockNumber: 5, chainBlockHtml: placeHolderBlock(5) }, |
|
|
|
expect(output.skippedBlockNumbers).toEqual([3, 1]) |
|
|
|
{ blockNumber: 4, chainBlockHtml: placeHolderBlock(4) }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
test('replaces duplicated block', () => { |
|
|
|
test('replaces duplicated block', () => { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
blockNumbers: [5, 4] |
|
|
|
blocks: [ |
|
|
|
|
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
averageBlockTime: '5 seconds', |
|
|
|
|
|
|
|
chainBlockHtml: 'test5', |
|
|
|
chainBlockHtml: 'test5', |
|
|
|
blockNumber: 5 |
|
|
|
blockNumber: 5 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.newBlock).toBe('test5') |
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test5' }, |
|
|
|
expect(output.blockNumbers).toEqual([5, 4]) |
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
test('skips if new block height is lower than lowest on page', () => { |
|
|
|
test('skips if new block height is lower than lowest on page', () => { |
|
|
|
|
|
|
|
window.localized = {} |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
averageBlockTime: '5 seconds', |
|
|
|
averageBlockTime: '5 seconds', |
|
|
|
blockNumbers: [5, 4, 3, 2] |
|
|
|
blocks: [ |
|
|
|
|
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
averageBlockTime: '9 seconds', |
|
|
|
averageBlockTime: '9 seconds', |
|
|
|
chainBlockHtml: 'test1', |
|
|
|
blockNumber: 1, |
|
|
|
blockNumber: 1 |
|
|
|
chainBlockHtml: 'test 1' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.averageBlockTime).toEqual('5 seconds') |
|
|
|
expect(output.newBlock).toBe(null) |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.blockNumbers).toEqual([5, 4, 3, 2]) |
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
test('only tracks 4 blocks based on page display limit', () => { |
|
|
|
test('only tracks 4 blocks based on page display limit', () => { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
blockNumbers: [5, 4, 3, 2], |
|
|
|
blocks: [ |
|
|
|
skippedBlockNumbers: [4, 3, 2] |
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
chainBlockHtml: 'test6', |
|
|
|
chainBlockHtml: 'test 6', |
|
|
|
blockNumber: 6 |
|
|
|
blockNumber: 6 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.newBlock).toBe('test6') |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.blockNumbers).toEqual([6, 5, 4, 3]) |
|
|
|
{ blockNumber: 6, chainBlockHtml: 'test 6' }, |
|
|
|
expect(output.skippedBlockNumbers).toEqual([4, 3]) |
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
test('skipped blocks list replaced when another block comes in with +3 blockheight', () => { |
|
|
|
test('skipped blocks list replaced when another block comes in with +3 blockheight', () => { |
|
|
|
|
|
|
|
window.localized = {} |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
blockNumbers: [5, 4, 3, 2], |
|
|
|
blocks: [ |
|
|
|
skippedBlockNumbers: [4, 3, 2] |
|
|
|
{ blockNumber: 5, chainBlockHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ blockNumber: 4, chainBlockHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ blockNumber: 3, chainBlockHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ blockNumber: 2, chainBlockHtml: 'test 2' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
type: 'RECEIVED_NEW_BLOCK', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
chainBlockHtml: 'test10', |
|
|
|
blockNumber: 10, |
|
|
|
blockNumber: 10 |
|
|
|
chainBlockHtml: 'test 10' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.newBlock).toBe('test10') |
|
|
|
expect(output.blocks).toEqual([ |
|
|
|
expect(output.blockNumbers).toEqual([10, 9, 8, 7]) |
|
|
|
{ blockNumber: 10, chainBlockHtml: 'test 10' }, |
|
|
|
expect(output.skippedBlockNumbers).toEqual([9, 8, 7]) |
|
|
|
{ blockNumber: 9, chainBlockHtml: placeHolderBlock(9) }, |
|
|
|
|
|
|
|
{ blockNumber: 8, chainBlockHtml: placeHolderBlock(8) }, |
|
|
|
|
|
|
|
{ blockNumber: 7, chainBlockHtml: placeHolderBlock(7) } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -201,26 +219,40 @@ describe('RECEIVED_NEW_TRANSACTION', () => { |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_TRANSACTION', |
|
|
|
type: 'RECEIVED_NEW_TRANSACTION', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
|
|
|
|
transactionHash: '0x01', |
|
|
|
transactionHtml: 'test' |
|
|
|
transactionHtml: 'test' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.newTransactions).toEqual(['test']) |
|
|
|
expect(output.transactions).toEqual([ |
|
|
|
|
|
|
|
{ transactionHash: '0x01', transactionHtml: 'test' } |
|
|
|
|
|
|
|
]) |
|
|
|
expect(output.transactionCount).toEqual(1) |
|
|
|
expect(output.transactionCount).toEqual(1) |
|
|
|
}) |
|
|
|
}) |
|
|
|
test('single transaction after single transaction', () => { |
|
|
|
test('single transaction after single transaction', () => { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
const state = Object.assign({}, initialState, { |
|
|
|
newTransactions: ['test 1'] |
|
|
|
transactions: [ |
|
|
|
|
|
|
|
{ transactionHash: '0x04', transactionHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x03', transactionHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x02', transactionHtml: 'test 2' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x01', transactionHtml: 'test 1' } |
|
|
|
|
|
|
|
] |
|
|
|
}) |
|
|
|
}) |
|
|
|
const action = { |
|
|
|
const action = { |
|
|
|
type: 'RECEIVED_NEW_TRANSACTION', |
|
|
|
type: 'RECEIVED_NEW_TRANSACTION', |
|
|
|
msg: { |
|
|
|
msg: { |
|
|
|
transactionHtml: 'test 2' |
|
|
|
transactionHash: '0x05', |
|
|
|
|
|
|
|
transactionHtml: 'test 5' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const output = reducer(state, action) |
|
|
|
const output = reducer(state, action) |
|
|
|
|
|
|
|
|
|
|
|
expect(output.newTransactions).toEqual(['test 1', 'test 2']) |
|
|
|
expect(output.transactions).toEqual([ |
|
|
|
|
|
|
|
{ transactionHash: '0x05', transactionHtml: 'test 5' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x04', transactionHtml: 'test 4' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x03', transactionHtml: 'test 3' }, |
|
|
|
|
|
|
|
{ transactionHash: '0x02', transactionHtml: 'test 2' } |
|
|
|
|
|
|
|
]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|