Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jordan/121 block tests #434

Merged
merged 30 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f2f75ab
add block hash to page block, use subscription for current block data…
jbibla Jan 25, 2018
f448955
page block spec
jbibla Jan 25, 2018
629208e
added snapshot
jbibla Jan 25, 2018
45c8063
trying to fix test errors
jbibla Jan 29, 2018
41f7501
fixed snapshot
jbibla Jan 29, 2018
ffe4906
update snapshot
nylira Jan 30, 2018
14be534
use hardcoded moment instead of Date.now() to resolve time zone diffe…
nylira Jan 30, 2018
970fcc7
use moment-timezone to resolve circleci error
nylira Jan 30, 2018
706d16b
fix test
nylira Jan 30, 2018
5fed21f
trying to fix test errors
jbibla Jan 29, 2018
123a539
update snapshot
nylira Jan 30, 2018
28791c9
use hardcoded moment instead of Date.now() to resolve time zone diffe…
nylira Jan 30, 2018
4b944f7
use moment-timezone to resolve circleci error
nylira Jan 30, 2018
b71d7c9
fix test
nylira Jan 30, 2018
8f06636
moved axios out of component and into blockchain.js
jbibla Jan 31, 2018
5eca5f7
removed unnecessary double function call, added a bunch of ifs
jbibla Feb 1, 2018
1b7fd26
fix lint
jbibla Feb 1, 2018
c05707d
added test
jbibla Feb 1, 2018
afbfa39
remove console.log, removed unused mutations, fixed test errors, upda…
jbibla Feb 1, 2018
4c4480d
remove console.log, removed unused mutations, fixed test errors, upda…
jbibla Feb 1, 2018
aa4a633
update snapshots
jbibla Feb 1, 2018
2b0dbb2
fixes from rebase
jbibla Feb 1, 2018
54d4baf
fix lint
jbibla Feb 1, 2018
68906a8
trigger rebuild
jbibla Feb 1, 2018
60bb701
fixes
jbibla Feb 1, 2018
78b483a
trying to fix tests
jbibla Feb 1, 2018
7dbcb2b
fix snaps
jbibla Feb 1, 2018
b1cbedb
remove timezone issue
jbibla Feb 1, 2018
145c490
please please please fix test
jbibla Feb 1, 2018
8e02cd3
Merge branch 'develop' into jordan/121-block-tests
nylira Feb 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 29 additions & 94 deletions app/src/renderer/components/monitor/PageBlock.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
page(:title="pageBlockTitle")
page(:title="pageBlockTitle" v-if="block.header")
div(slot="menu"): tool-bar
router-link(to="/blocks")
i.material-icons arrow_back
Expand All @@ -14,6 +14,9 @@ page(:title="pageBlockTitle")
i.material-icons chevron_right
.label Next Block

part(title='')
list-item(dt="Block Hash" :dd="blockMeta.block_id.hash")

part(title='Header')
list-item(dt="Chain ID" :dd="block.header.chain_id")
list-item(dt="Time" :dd="blockHeaderTime")
Expand Down Expand Up @@ -46,7 +49,6 @@ page(:title="pageBlockTitle")
import { mapGetters } from 'vuex'
import moment from 'moment'
import num from 'scripts/num'
import axios from 'axios'
import DataEmpty from 'common/NiDataEmpty'
import ToolBar from 'common/NiToolBar'
import ListItem from 'common/NiListItem'
Expand All @@ -63,108 +65,41 @@ export default {
},
computed: {
...mapGetters(['blockchain']),
block () {
if (this.blockchain.block.block) {
return this.blockchain.block.block
} else {
return {}
}
},
blockUrl () {
return this.blockchain.url
},
blockHeaderTime () {
return moment(this.block.header.time).format('MMMM Do YYYY — hh:mm:ss')
if (this.block.header.time) {
return moment(this.block.header.time).format('MMMM Do YYYY — hh:mm:ss')
} else {
return 'Loading...'
}
},
blockMeta () {
if (this.block) {
return this.blockchain.block.block_meta
} else {
return {}
}
},
pageBlockTitle () {
if (this.block.header.height) {
if (this.block.header) {
return 'Block #' + num.prettyInt(this.block.header.height)
} else {
return 'Loading Block…'
return 'Loading...'
}
}
},
data: () => ({
num: num,
moment: moment,
blockUrl: '',
block_meta: {
block_id: {
hash: '',
parts: {
total: 0,
hash: ''
}
},
header: {
chain_id: '',
height: 0,
time: '',
num_txs: 0,
last_block_id: {
hash: '',
parts: {
total: 0,
hash: ''
}
},
last_commit_hash: '',
data_hash: '',
validators_hash: '',
app_hash: ''
}
},
block: {
header: {
chain_id: '',
height: 0,
time: '',
num_txs: 0,
last_block_id: {
hash: '',
parts: {
total: 0,
hash: ''
}
},
last_commit_hash: '',
data_hash: '',
validators_hash: '',
app_hash: ''
},
data: {
txs: []
},
last_commit: {
blockID: {
hash: '',
parts: {
total: 0,
hash: ''
}
},
precommits: [
{
validator_address: '',
validator_index: 0,
height: 0,
round: 0,
type: 0,
block_id: {
hash: '',
parts: {
total: 0,
hash: ''
}
},
signature: [0, '']
}
]
}
}
}),
methods: {
fetchBlock () {
this.blockUrl = `https://${this.blockchain.blockchainName}-node0.testnets.interblock.io/block?height=${this.$route.params.block}`
axios(this.blockUrl).then(({data}) => {
if (data.err) {
console.log('err', data.err)
return
}
let blockData = data.result
this.block_meta = blockData.block_meta
this.block = blockData.block
})
this.$store.dispatch('getBlock', this.$route.params.block)
}
},
mounted () {
Expand Down
10 changes: 6 additions & 4 deletions app/src/renderer/components/monitor/PageBlocks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ page(title='Block Explorer')
part(title='Current Block')
list-item(dt='Block Height' :dd='num.prettyInt(lastHeader.height)' :to="{ name: 'block', params: { block: lastHeader.height} }")
list-item(dt='Block Time' :dd='latestBlockTime')
list-item(dt='Block Hash' :dd='status.latest_block_hash')
list-item(dt='Block Hash' :dd='latestBlockHash')

part(title='Latest Blocks')
list-item.column-header(dt="Block Height" dd="# of Transactions")
Expand Down Expand Up @@ -49,13 +49,15 @@ export default {
return this.blockchain.status
},
latestBlockTime () {
let blockTime = this.status.latest_block_time
if (blockTime) {
return moment(blockTime).format('MMMM Do YYYY — hh:mm:ss')
if (this.lastHeader.time) {
return moment(this.lastHeader.time).format('MMMM Do YYYY — hh:mm:ss')
} else {
return 'Loading…'
}
},
latestBlockHash () {
return this.lastHeader.last_block_id.hash
},
blocks () {
return this.blockchain.blocks
}
Expand Down
30 changes: 20 additions & 10 deletions app/src/renderer/vuex/modules/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,37 @@ export default ({ commit, node }) => {
urlSuffix: '-node0.testnets.interblock.io',
status: {},
abciInfo: {},
topAvgTxRate: 0,
blocks: []
blocks: [],
block: {},
url: ''
}

let url = state.urlPrefix + state.blockchainName + state.urlSuffix
const mutations = {
setBlockchainName (state, name) {
state.blockchainName = name
},
setTopAvgTxRate (state, value) {
state.topAvgTxRate = value
setUrl (state) {
console.log(url)
state.url = url
},
getStatus (state) {
let url = state.urlPrefix + state.blockchainName + state.urlSuffix
axios(url + '/status').then((res) => {
state.status = res.data.result
})
},
getAbciInfo (state) {
let url = state.urlPrefix + state.blockchainName + state.urlSuffix
axios(url + '/abci_info').then((res) => {
state.abciInfo = res.data.result
})
},
setBlock (state, block) {
state.block = block
}
}

const actions = {
async getBlock ({ state, commit }, height) {
const blockUrl = url + '/block?height=' + height
let block = (await axios.get(blockUrl)).data.result
commit('setBlock', block)
}
}

Expand All @@ -48,7 +57,8 @@ export default ({ commit, node }) => {
setTimeout(() => {
mutations.getStatus(state)
mutations.getAbciInfo(state)
mutations.setUrl(state)
}, 3000)

return { state, mutations }
return { state, mutations, actions }
}
2 changes: 1 addition & 1 deletion app/src/renderer/vuex/modules/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setTimeout } from 'timers'
'use strict'

export default function ({ node }) {
// get tendermint RPC client from basecon client
// get tendermint RPC client from basecoin client
const { nodeIP } = node

const state = {
Expand Down
65 changes: 65 additions & 0 deletions test/unit/specs/components/monitor/PageBlock.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import setup from '../../../helpers/vuex-setup'
import htmlBeautify from 'html-beautify'
import PageBlock from 'renderer/components/monitor/PageBlock'

const $route = {
params: {
block: 1234
}
}

describe('PageBlock', () => {
let wrapper, store
let {mount} = setup()

beforeEach(() => {
let instance = mount(PageBlock, {
mocks: {
$route
},
getters: {
blockchain: () => ({
url: 'https://the-url',
block: {
block: {
header: {
last_block_id: {
hash: 'last-hash',
parts: {
total: 0
}
},
num_txs: 0,
height: 10,
time: null
},
last_commit: {
precommits: []
},
data: {
txs: 0
}
},
block_meta: {
block_id: {
hash: 'hash'
}
}
}
})
}
})
wrapper = instance.wrapper
store = instance.store

wrapper.update()
})

it('has the expected html structure', () => {
expect(htmlBeautify(wrapper.html())).toMatchSnapshot()
})

it('should dispatch getBlock when mounted', () => {
expect(store.dispatch).toHaveBeenCalledWith('getBlock', wrapper.vm.$route.params.block)
})
})
16 changes: 14 additions & 2 deletions test/unit/specs/components/monitor/PageBlocks.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,32 @@ describe('PageBlocks', () => {
let instance = mount(PageBlocks, {
stubs: {
'modal-search': '<modal-search />'
},
getters: {
lastHeader: () => ({
time: null,
last_block_id: {
hash: '123'
},
height: 12345
})
}
})
wrapper = instance.wrapper
store = instance.store

store.commit('setSearchQuery', ['blocks', ''])

wrapper.update()
})

it('has the expected html structure', () => {
expect(htmlBeautify(wrapper.html())).toMatchSnapshot()
})

it('should call resetSearch on beforeDestroy', () => {
wrapper.destroy()
expect(store.commit).toHaveBeenCalledWith('resetSearch', 'blocks')
})

it('should show the search on click', () => {
wrapper.vm.setSearch(true)
expect(store.commit).toHaveBeenCalledWith('setSearchVisible', ['blocks', true])
Expand Down
Loading