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