diff --git a/CHANGELOG.md b/CHANGELOG.md index a4f335b6cb..141a40e2cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - [\#1894](https://github.com/cosmos/voyager/issues/1894) Added favicons for all the browsers and devices @jbibla - [\#1865](https://github.com/cosmos/voyager/issues/1865) Added Vuex blocks module @sabau - [\#1928](https://github.com/cosmos/voyager/issues/1928) Added Browserstack reference to README @sabau +- [\#1866](https://github.com/cosmos/voyager/issues/1866) Added blocks to network page and a page for viewing individual blocks @jbibla ### Changed diff --git a/app/src/renderer/components/common/TmConnectedNetwork.vue b/app/src/renderer/components/common/TmConnectedNetwork.vue index ada51eda26..2b10a5c674 100644 --- a/app/src/renderer/components/common/TmConnectedNetwork.vue +++ b/app/src/renderer/components/common/TmConnectedNetwork.vue @@ -14,10 +14,10 @@
- {{ blockHeight }}exit_to_app{{ blockHeight }}
@@ -38,33 +38,26 @@ diff --git a/app/src/renderer/components/network/PageNetwork.vue b/app/src/renderer/components/network/PageNetwork.vue index 0b393a2ade..863cb2c052 100644 --- a/app/src/renderer/components/network/PageNetwork.vue +++ b/app/src/renderer/components/network/PageNetwork.vue @@ -18,16 +18,13 @@ class="page-profile__status" />

{{ lastHeader.chain_id }}

-

- Proposer: {{ lastHeader.proposer_address }} -

-
Height
-
{{ lastHeader.height }}
+
Block Height
+
{{ `#` + num.prettyInt(lastHeader.height) }}
Last Block
@@ -61,6 +58,27 @@
+ + + + + + + + + + + +
+ {{ `#` + num.prettyInt(block.header.height) }} + {{ block.header.num_txs }}{{ block.header.proposer_address }}
@@ -68,7 +86,8 @@ - diff --git a/app/src/renderer/components/staking/PanelSort.vue b/app/src/renderer/components/staking/PanelSort.vue index 0f0fa224aa..007c36e339 100644 --- a/app/src/renderer/components/staking/PanelSort.vue +++ b/app/src/renderer/components/staking/PanelSort.vue @@ -3,15 +3,17 @@ {{ property.title }}arrow_drop_up + {{ property.title }} @@ -22,7 +24,7 @@ export default { props: { sort: { type: Object, - required: true + default: null }, properties: { type: Array, @@ -61,7 +63,7 @@ export default { padding: 1rem; } -.sort-by { +.panel-sort-table-header { font-size: var(--sm); } diff --git a/app/src/renderer/components/transactions/TmLiTransaction.vue b/app/src/renderer/components/transactions/TmLiTransaction.vue index 7336fb3aaa..b4cee28f10 100644 --- a/app/src/renderer/components/transactions/TmLiTransaction.vue +++ b/app/src/renderer/components/transactions/TmLiTransaction.vue @@ -18,8 +18,8 @@
- Block #{{ block }} Block #{{ block }} @ {{ date }}
@@ -46,10 +46,10 @@ export default { } }, computed: { - date() { - const time = moment(this.time) - return time.format( - `${moment().isSame(time, `day`) ? `` : `YYYY/MM/DD `}HH:mm` + date({ time } = this) { + const momentTime = moment(time) + return momentTime.format( + `${moment().isSame(momentTime, `day`) ? `` : `MMM Do YYYY `}HH:mm:ss` ) } } @@ -64,7 +64,7 @@ export default { border: 1px solid var(--bc-dim); background: var(--app-fg); width: 100%; - font-weight: 400; + font-weight: 300; } .tm-li-tx:hover { diff --git a/app/src/renderer/components/wallet/LiCoin.vue b/app/src/renderer/components/wallet/LiCoin.vue index 6a47ea6871..fe6e059cf1 100644 --- a/app/src/renderer/components/wallet/LiCoin.vue +++ b/app/src/renderer/components/wallet/LiCoin.vue @@ -53,7 +53,6 @@ export default { margin-bottom: 0.5rem; border: 1px solid var(--bc-dim); background: var(--app-fg); - min-width: 45rem; } .li-coin:hover { diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index abfeb0b7b1..d8a3d66b8f 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -202,6 +202,9 @@ const Client = (axios, remoteLcdURL) => { ]).then(([depositorTxs, proposerTxs]) => [].concat(depositorTxs, proposerTxs) ) + }, + getBlock: function(blockHeight) { + return req(`GET`, `/blocks/${blockHeight}`)() } } } diff --git a/app/src/renderer/routes.js b/app/src/renderer/routes.js index 41d22330c0..bbe8fda265 100644 --- a/app/src/renderer/routes.js +++ b/app/src/renderer/routes.js @@ -85,6 +85,11 @@ export default [ name: `network`, component: require(`./components/network/PageNetwork`).default }, + { + path: `/blocks/:height`, + name: `block`, + component: require(`./components/network/PageBlock`).default + }, { path: `/404`, component: require(`./components/common/Page404`).default }, { path: `*`, component: require(`./components/common/Page404`).default } ] diff --git a/app/src/renderer/styles/table.css b/app/src/renderer/styles/table.css index c39153dc68..1fb870fd97 100644 --- a/app/src/renderer/styles/table.css +++ b/app/src/renderer/styles/table.css @@ -21,14 +21,9 @@ .data-table td { padding: 0.5rem; position: relative; - vertical-align: bottom; color: var(--bright); } -.data-table td:not(:first-child) { - padding-bottom: 1.2rem; -} - .data-table__row__cell__separator:after { display: block; position: absolute; diff --git a/app/src/renderer/vuex/getters.js b/app/src/renderer/vuex/getters.js index 883a1b3fd8..d0f1ac9b98 100644 --- a/app/src/renderer/vuex/getters.js +++ b/app/src/renderer/vuex/getters.js @@ -84,9 +84,12 @@ export const depositDenom = getters => ? getters.governanceParameters.parameters.deposit.min_deposit[0].denom : `` -// status +// connection export const approvalRequired = state => state.connection.approvalRequired export const connected = state => state.connection.connected export const lastHeader = state => state.connection.lastHeader export const nodeUrl = state => state.connection.connected ? state.connection.nodeUrl : undefined + +export const blocks = state => (state.blocks ? state.blocks.blocks : []) +export const block = state => (state.blocks ? state.blocks.block : []) diff --git a/app/src/renderer/vuex/modules/blocks.js b/app/src/renderer/vuex/modules/blocks.js index d9eeaeef5d..09c3557d6b 100644 --- a/app/src/renderer/vuex/modules/blocks.js +++ b/app/src/renderer/vuex/modules/blocks.js @@ -1,7 +1,7 @@ import * as Sentry from "@sentry/browser" import Vue from "vue" -export const cache = (list, element, maxSize = 1000) => { +export const cache = (list, element, maxSize = 100) => { if (list.length >= maxSize) list.splice(-1, 1) list.unshift(element) return list @@ -18,7 +18,11 @@ export default ({ node }) => { loading: false, error: null, peers: [], - blocks: [] + blocks: [], + // one block, specified by height + block: { + block_meta: {} + } } const mutations = { @@ -29,6 +33,7 @@ export default ({ node }) => { setBlockMetas: (state, blockMetas) => (state.blockMetas = blockMetas), setPeers: (state, peers) => (state.peers = peers), setBlocks: (state, blocks) => (state.blocks = blocks), + setBlock: (state, block) => (state.block = block), addBlock: (state, block) => Vue.set(state, `blocks`, cache(state.blocks, block)), setSubscribedRPC: (state, subscribedRPC) => @@ -50,17 +55,16 @@ export default ({ node }) => { return blockMetaInfo } commit(`setLoading`, true) - const { block_metas } = await node.rpc.blockchain({ - minHeight: String(height), - maxHeight: String(height) - }) - blockMetaInfo = block_metas ? block_metas[0] : undefined + const block = await node.getBlock(height) + + blockMetaInfo = block.block_metas ? block.block_metas[0] : undefined commit(`setLoading`, false) commit(`setBlockMetas`, { ...state.blockMetas, [height]: blockMetaInfo }) + commit(`setBlock`, block) return blockMetaInfo } catch (error) { commit(`notifyError`, { diff --git a/test/unit/specs/components/common/TmConnectedNetwork.spec.js b/test/unit/specs/components/common/TmConnectedNetwork.spec.js index e2070a1992..591bd612c6 100644 --- a/test/unit/specs/components/common/TmConnectedNetwork.spec.js +++ b/test/unit/specs/components/common/TmConnectedNetwork.spec.js @@ -1,20 +1,31 @@ +import { shallowMount, createLocalVue } from "@vue/test-utils" import TmConnectedNetwork from "common/TmConnectedNetwork" -import setup from "../../../helpers/vuex-setup" + +const localVue = createLocalVue() +localVue.directive(`tooltip`, () => {}) describe(`TmConnectedNetwork`, () => { - let wrapper, store - const { mount } = setup() + let wrapper, $store - beforeEach(async () => { - const instance = mount(TmConnectedNetwork, { + beforeEach(() => { + $store = { getters: { - lastHeader: () => ({ chain_id: `Test Net`, height: 42 }), - nodeUrl: () => `https://faboNode.de`, - connected: () => true + lastHeader: { + chain_id: `gaia-20k`, + height: `6001` + }, + nodeUrl: `https://faboNode.de`, + connected: true } + } + + wrapper = shallowMount(TmConnectedNetwork, { + localVue, + mocks: { + $store + }, + stubs: [`router-link`] }) - store = instance.store - wrapper = instance.wrapper }) it(`has the expected html structure`, () => { @@ -36,7 +47,7 @@ describe(`TmConnectedNetwork`, () => { .find(`#tm-connected-network__string`) .text() .trim() - ).toBe(`Test Net`) + ).toBe(`gaia-20k`) }) it(`has a block string`, () => { @@ -45,53 +56,28 @@ describe(`TmConnectedNetwork`, () => { .find(`#tm-connected-network__block`) .text() .trim() - ).toContain(`#42`) - }) - - it(`has link to the external block explorer`, () => { - expect(wrapper.vm.explorerLink).toBe( - `https://explorecosmos.network/blocks/42` - ) + ).toBe(`#6,001`) }) it(`has a connecting state`, async () => { - const { wrapper } = mount(TmConnectedNetwork, { + $store = { getters: { - lastHeader: () => ({ chain_id: `Test Net`, height: 0 }), - connected: () => false + lastHeader: { + chain_id: ``, + height: `` + }, + nodeUrl: null, + connected: false } - }) - expect(wrapper.vm.$el).toMatchSnapshot() - }) + } - it(`shows a link to the preferences page if not on the preferences page`, () => { - expect(wrapper.find(`#tm-connected-network_preferences-link`)).toBeDefined() - wrapper.setData({ - $route: { - name: `preferences` - } - }) - expect( - wrapper.vm.$el.querySelector(`#tm-connected-network_preferences-link`) - ).toBeFalsy() - }) - - it(`shows the connected node`, async () => { - const instance = mount(TmConnectedNetwork) - store = instance.store - wrapper = instance.wrapper - - Object.assign(store.state.connection, { - mocked: false, - node: { - remoteLcdURL: `123.123.123.123` + wrapper = shallowMount(TmConnectedNetwork, { + localVue, + mocks: { + $store }, - lastHeader: Object.assign(store.state.connection.lastHeader, { - chain_id: `chain_id` - }), - connected: true + stubs: [`router-link`] }) - expect(wrapper.vm.$el).toMatchSnapshot() }) }) diff --git a/test/unit/specs/components/common/TmSession.spec.js b/test/unit/specs/components/common/TmSession.spec.js index 9b6c9c66a0..bc5d7c1cb8 100644 --- a/test/unit/specs/components/common/TmSession.spec.js +++ b/test/unit/specs/components/common/TmSession.spec.js @@ -31,7 +31,8 @@ describe(`TmSessionWelcome`, () => { "session-sign-in": true, "session-hardware": true, "session-import": true, - "session-account-delete": true + "session-account-delete": true, + "router-link": true } }) }) diff --git a/test/unit/specs/components/common/__snapshots__/TmConnectedNetwork.spec.js.snap b/test/unit/specs/components/common/__snapshots__/TmConnectedNetwork.spec.js.snap index b81ec70695..0714dfa86e 100644 --- a/test/unit/specs/components/common/__snapshots__/TmConnectedNetwork.spec.js.snap +++ b/test/unit/specs/components/common/__snapshots__/TmConnectedNetwork.spec.js.snap @@ -14,7 +14,7 @@ exports[`TmConnectedNetwork has a connecting state 1`] = ` class="tm-connected-network__string tm-connected-network__string--connecting" > - Connecting to Test Net… + Connecting to … @@ -46,7 +46,7 @@ exports[`TmConnectedNetwork has the expected html structure 1`] = ` - Test Net + gaia-20k @@ -55,65 +55,11 @@ exports[`TmConnectedNetwork has the expected html structure 1`] = ` class="tm-connected-network__string" id="tm-connected-network__block" > - - #42 - - exit_to_app - - - - -`; - -exports[`TmConnectedNetwork shows the connected node 1`] = ` -
-
-
- - lock - -
- -
- - chain_id - -
-
- -
- - #0 - - exit_to_app - - + #6,001 +
`; diff --git a/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap b/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap index 62a9037337..f37fd9e027 100644 --- a/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap +++ b/test/unit/specs/components/governance/__snapshots__/TabProposals.spec.js.snap @@ -10,7 +10,7 @@ exports[`TabProposals has the expected html structure 1`] = ` class="panel-sort-container" > {}) + +describe(`PageBlock`, () => { + let wrapper + + beforeEach(() => { + const getters = { + connected: true, + block: { + block_meta: { + block_id: { + hash: `ABCD1234` + } + }, + block: { + data: { + txs: `txs` + }, + header: { + height: `100`, + num_txs: 1200, + proposer_address: `ABCDEFG123456HIJKLMNOP`, + time: Date.now() + }, + evidence: { + evidence: `evidence` + }, + last_commit: { + precommits: [ + { + validator_address: `validator address`, + timestamp: Date.now(), + round: 0 + } + ] + } + } + } + } + + wrapper = shallowMount(PageBlock, { + localVue, + mocks: { + $store: { + getters, + dispatch: jest.fn() + }, + $route: { + params: { height: `100` } + } + }, + stubs: [`router-link`] + }) + }) + + it(`has the expected html structure`, () => { + expect(wrapper.vm.$el).toMatchSnapshot() + }) + + it(`sets properties for the block table`, () => { + expect(wrapper.vm.properties).toEqual([ + { + title: `Proposer` + }, + { + title: `Time` + }, + { + title: `Round` + } + ]) + }) +}) diff --git a/test/unit/specs/components/network/PageNetwork.spec.js b/test/unit/specs/components/network/PageNetwork.spec.js index 160a18f5c8..10e5ddad6e 100644 --- a/test/unit/specs/components/network/PageNetwork.spec.js +++ b/test/unit/specs/components/network/PageNetwork.spec.js @@ -35,7 +35,23 @@ describe(`PageNetwork`, () => { loose_tokens: 10 } }, - bondDenom: `stake` + bondDenom: `stake`, + blocks: [ + { + header: { + height: `100`, + num_txs: 1200, + proposer_address: `ABCDEFG123456HIJKLMNOP` + } + }, + { + header: { + height: `101`, + num_txs: 405, + proposer_address: `ZYXCRS123456HIJKLMNOPQ` + } + } + ] } } @@ -43,7 +59,8 @@ describe(`PageNetwork`, () => { localVue, mocks: { $store - } + }, + stubs: [`router-link`] }) }) @@ -67,7 +84,8 @@ describe(`PageNetwork`, () => { localVue, mocks: { $store - } + }, + stubs: [`router-link`] }) expect(wrapper.vm.status).toEqual({ @@ -75,4 +93,31 @@ describe(`PageNetwork`, () => { message: `Network is down` }) }) + + it(`sets last block to something human readable`, () => { + expect(wrapper.vm.lastBlock).toEqual(`a few seconds ago`) + }) + + it(`sets propertoes for the block table`, () => { + expect(wrapper.vm.properties).toEqual([ + { + title: `Block Number`, + value: `block_number`, + tooltip: `Block Number`, + class: `blockNumber` + }, + { + title: `Transactions`, + value: `transactions`, + tooltip: `Number of transactions per block`, + class: `transactions` + }, + { + title: `Proposer`, + value: `proposer`, + tooltip: `Validator responsible for block proposals`, + class: `proposer` + } + ]) + }) }) diff --git a/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap b/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap new file mode 100644 index 0000000000..3db175d2d6 --- /dev/null +++ b/test/unit/specs/components/network/__snapshots__/PageBlock.spec.js.snap @@ -0,0 +1,175 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`PageBlock has the expected html structure 1`] = ` + + + +
+
+
+
+

+ Block #100 +

+ +

+ + ABCD1234 + +

+
+
+
+ +
+
+
+ Time +
+ +
+ Jan 1st 1970, 00:00:42 +
+
+ +
+
+ Proposer +
+ +
+ ABCDEFG123456HIJKLMNOP +
+
+
+
+ +
+
+
+
+
+ Transactions +
+ +
+ txs +
+
+
+
+
+ +
+
+
+
+
+ Evidence +
+ +
+ evidence +
+
+
+
+
+ +
+
+
+
+
+ Pre Commits +
+ + + + + + + + + + + + + + + +
+ validator address + + + Jan 1st 1970, 00:00:42 + + + 0 +
+
+
+
+
+
+`; diff --git a/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap b/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap index c97acd7605..31675b345e 100644 --- a/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap +++ b/test/unit/specs/components/network/__snapshots__/PageNetwork.spec.js.snap @@ -37,12 +37,6 @@ exports[`PageNetwork has the expected html structure 1`] = ` > gaia-20k - -

- - Proposer: EFH47FH723HDHSH - -

@@ -54,11 +48,11 @@ exports[`PageNetwork has the expected html structure 1`] = ` class="info_dl colored_dl" >
- Height + Block Height
- 6001 + #6,001
@@ -143,5 +137,56 @@ exports[`PageNetwork has the expected html structure 1`] = ` + + + + + + + + + + + + + + + + + + + + + + +
+ + #100 + + + 1200 + + ABCDEFG123456HIJKLMNOP +
+ + #101 + + + 405 + + ZYXCRS123456HIJKLMNOPQ +
`; diff --git a/test/unit/specs/components/staking/__snapshots__/PanelSort.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/PanelSort.spec.js.snap index 84ea1ff826..dca5a118e8 100644 --- a/test/unit/specs/components/staking/__snapshots__/PanelSort.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/PanelSort.spec.js.snap @@ -5,7 +5,7 @@ exports[`PanelSort has the expected html structure 1`] = ` class="panel-sort-container" >
- Block #170  - + @ Invalid date diff --git a/test/unit/specs/components/staking/__snapshots__/TabValidators.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/TabValidators.spec.js.snap index e5f191c7d0..fb6c5014a2 100644 --- a/test/unit/specs/components/staking/__snapshots__/TabValidators.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/TabValidators.spec.js.snap @@ -11,7 +11,7 @@ exports[`TabValidators has the expected html structure 1`] = ` class="panel-sort-container" > { beforeEach(() => { wrapper = mount(TmLiAnyTransaction, { - propsData + propsData, + stubs: [`router-link`] }) }) diff --git a/test/unit/specs/components/transactions/TmLiBankTransaction.spec.js b/test/unit/specs/components/transactions/TmLiBankTransaction.spec.js index ae1fd5ae52..3c9b5218d7 100644 --- a/test/unit/specs/components/transactions/TmLiBankTransaction.spec.js +++ b/test/unit/specs/components/transactions/TmLiBankTransaction.spec.js @@ -11,7 +11,10 @@ describe(`TmLiBankTransaction`, () => { } beforeEach(() => { - wrapper = shallowMount(TmLiBankTransaction, { propsData }) + wrapper = shallowMount(TmLiBankTransaction, { + propsData, + stubs: [`router-link`] + }) }) it(`has the expected html structure`, () => { diff --git a/test/unit/specs/components/transactions/TmLiGovTransaction.spec.js b/test/unit/specs/components/transactions/TmLiGovTransaction.spec.js index 082b5fbbee..bea8c958d4 100644 --- a/test/unit/specs/components/transactions/TmLiGovTransaction.spec.js +++ b/test/unit/specs/components/transactions/TmLiGovTransaction.spec.js @@ -11,7 +11,7 @@ describe(`TmLiGovTransaction`, () => { } beforeEach(() => { - wrapper = mount(TmLiGovTransaction, { propsData }) + wrapper = mount(TmLiGovTransaction, { propsData, stubs: [`router-link`] }) }) describe(`proposals`, () => { @@ -26,6 +26,7 @@ describe(`TmLiGovTransaction`, () => { wrapper.setProps({ transaction: transactions[7] }) + expect(wrapper.vm.deposit).toBe(true) expect(wrapper.vm.$el).toMatchSnapshot() }) diff --git a/test/unit/specs/components/transactions/TmLiTransaction.spec.js b/test/unit/specs/components/transactions/TmLiTransaction.spec.js index 1bae0f994c..59c0336b88 100644 --- a/test/unit/specs/components/transactions/TmLiTransaction.spec.js +++ b/test/unit/specs/components/transactions/TmLiTransaction.spec.js @@ -5,7 +5,7 @@ describe(`TmLiTransaction`, () => { let wrapper const propsData = { color: `#FFFFFF`, - time: 0, + time: Date.now(), block: 500 } @@ -15,11 +15,24 @@ describe(`TmLiTransaction`, () => { slots: { caption: `Some Caption`, details: `Some Details` - } + }, + stubs: [`router-link`] }) }) it(`has the expected html structure`, () => { expect(wrapper.vm.$el).toMatchSnapshot() }) + + it(`Should print the hour only if the same day`, () => { + expect(TmLiTransaction.computed.date({ time: Date.now() })).toEqual( + `00:00:42` + ) + }) + + it(`Should print the datetime if we are in a different day`, () => { + expect( + TmLiTransaction.computed.date({ time: Date.now() + 999999999 }) + ).toEqual(`Jan 12th 1970 13:47:21`) + }) }) diff --git a/test/unit/specs/components/transactions/__snapshots__/TmLiAnyTransaction.spec.js.snap b/test/unit/specs/components/transactions/__snapshots__/TmLiAnyTransaction.spec.js.snap index 0d7c7e6449..4cd9f31ac4 100644 --- a/test/unit/specs/components/transactions/__snapshots__/TmLiAnyTransaction.spec.js.snap +++ b/test/unit/specs/components/transactions/__snapshots__/TmLiAnyTransaction.spec.js.snap @@ -50,12 +50,12 @@ exports[`TmLiAnyTransaction shows bank transactions 1`] = `
- Block #3436  - - @ 00:00 + + @ 00:00:02
@@ -106,11 +106,11 @@ exports[`TmLiAnyTransaction shows stake transactions 1`] = `
To  - mr_mounty - +
@@ -118,12 +118,12 @@ exports[`TmLiAnyTransaction shows stake transactions 1`] = `
- Block #568  - - @ 00:00 + + @ 00:00:42
@@ -168,12 +168,12 @@ exports[`TmLiAnyTransaction shows unknown transactions 1`] = `
- Block #3436  - - @ 00:00 + + @ 00:00:02
diff --git a/test/unit/specs/components/transactions/__snapshots__/TmLiGovTransaction.spec.js.snap b/test/unit/specs/components/transactions/__snapshots__/TmLiGovTransaction.spec.js.snap index 8ed7472bcf..de71022a4f 100644 --- a/test/unit/specs/components/transactions/__snapshots__/TmLiGovTransaction.spec.js.snap +++ b/test/unit/specs/components/transactions/__snapshots__/TmLiGovTransaction.spec.js.snap @@ -47,13 +47,13 @@ exports[`TmLiGovTransaction deposits should show deposits 1`] = ` On  - Proposal #1 - + @@ -61,12 +61,12 @@ exports[`TmLiGovTransaction deposits should show deposits 1`] = `
- Block #56675  - - @ 00:00 + + @ 00:00:42
@@ -128,12 +128,12 @@ exports[`TmLiGovTransaction proposals should show proposals submission transacti
- Block #56673  - - @ 00:00 + + @ 00:00:42
diff --git a/test/unit/specs/components/transactions/__snapshots__/TmLiStakeTransaction.spec.js.snap b/test/unit/specs/components/transactions/__snapshots__/TmLiStakeTransaction.spec.js.snap index 324403c9f5..ecf3e6ffab 100644 --- a/test/unit/specs/components/transactions/__snapshots__/TmLiStakeTransaction.spec.js.snap +++ b/test/unit/specs/components/transactions/__snapshots__/TmLiStakeTransaction.spec.js.snap @@ -56,12 +56,12 @@ exports[`TmLiStakeTransaction delegations should show delegations 1`] = `
- Block #568  - - @ 00:00 + + @ 00:00:42
@@ -131,12 +131,12 @@ exports[`TmLiStakeTransaction redelegations should show redelegations and calcul
- Block #567  - - @ 00:00 + + @ 00:00:42
@@ -200,12 +200,12 @@ exports[`TmLiStakeTransaction unbonding delegations should default to ended if n
- Block #569  - - @ 00:00 + + @ 00:00:42
@@ -269,12 +269,12 @@ exports[`TmLiStakeTransaction unbonding delegations should show unbonding delega
- Block #569  - - @ 00:00 + + @ 00:00:42
@@ -342,12 +342,12 @@ exports[`TmLiStakeTransaction unbonding delegations should show unbondings and c
- Block #569  - - @ 00:00 + + @ 00:00:42
diff --git a/test/unit/specs/components/transactions/__snapshots__/TmLiTransaction.spec.js.snap b/test/unit/specs/components/transactions/__snapshots__/TmLiTransaction.spec.js.snap index 95b1f409da..5aa46d15bd 100644 --- a/test/unit/specs/components/transactions/__snapshots__/TmLiTransaction.spec.js.snap +++ b/test/unit/specs/components/transactions/__snapshots__/TmLiTransaction.spec.js.snap @@ -43,12 +43,12 @@ exports[`TmLiTransaction has the expected html structure 1`] = `
- Block #500  - - @ 00:00 + + @ 00:00:42
diff --git a/test/unit/specs/connectors/lcdClient.spec.js b/test/unit/specs/connectors/lcdClient.spec.js index 33f8570b0d..8dc69f86cc 100644 --- a/test/unit/specs/connectors/lcdClient.spec.js +++ b/test/unit/specs/connectors/lcdClient.spec.js @@ -686,5 +686,20 @@ describe(`LCD Client`, () => { ] ]) }) + + it(`gets a block based on the height`, async () => { + axios.mockReturnValue({}) + await client.getBlock(`123`) + + expect(axios.mock.calls).toEqual([ + [ + { + data: undefined, + method: `GET`, + url: `http://remotehost/blocks/123` + } + ] + ]) + }) }) }) diff --git a/test/unit/specs/store/blocks.spec.js b/test/unit/specs/store/blocks.spec.js index 739baf0e1b..9a3ea92780 100644 --- a/test/unit/specs/store/blocks.spec.js +++ b/test/unit/specs/store/blocks.spec.js @@ -15,7 +15,36 @@ describe(`Module: Blocks`, () => { node = { rpc: { status: () => Promise.resolve({ sync_info: {} }) - } + }, + getBlock: () => ({ + block_meta: { + block_id: { + hash: `ABCD1234` + } + }, + block: { + data: { + txs: `txs` + }, + header: { + height: `100`, + num_txs: 1200, + proposer_address: `ABCDEFG123456HIJKLMNOP` + }, + evidence: { + evidence: `evidence` + }, + last_commit: { + precommits: [ + { + validator_address: `validator address`, + timestamp: `1990-10-19`, + round: 0 + } + ] + } + } + }) } module = blocks({ node @@ -26,7 +55,12 @@ describe(`Module: Blocks`, () => { it(`should query block info`, async () => { state.blockMetas = {} - node.rpc.blockchain = () => Promise.resolve({ block_metas: [blockMeta] }) + node.getBlock = () => ({ + block_metas: [blockMeta], + block: { + height: `42` + } + }) const output = await actions.queryBlockInfo( { state, commit: jest.fn() }, @@ -57,15 +91,34 @@ describe(`Module: Blocks`, () => { expect(node.rpc.blockchain).not.toHaveBeenCalled() }) - it(`should show an info if block info is unavailable`, async () => { - jest.spyOn(console, `error`).mockImplementation(() => {}) - const error = new Error(`Error`) + it(`should show an error if block info is unavailable`, async () => { + const error = new Error(`err`) + const getBlock = jest.fn().mockRejectedValue(error) const commit = jest.fn() - state.blockMetas = {} - node.rpc.blockchain = () => Promise.reject(error) - const output = await actions.queryBlockInfo({ state, commit }, 100) + const node = { + getBlock + } + const module = blocks({ + node + }) + const output = await module.actions.queryBlockInfo( + { + state: module.state, + commit + }, + 1000 + ) + expect(commit.mock.calls).toEqual([ + [`setLoading`, true], + [ + `notifyError`, + { body: `err`, title: `Error fetching block information` } + ], + [`setLoading`, false], + [`setError`, error] + ]) + expect(output).toBe(null) - expect(commit).toHaveBeenCalledWith(`setError`, error) }) it(`should not subscribe twice`, async () => { @@ -199,10 +252,12 @@ describe(`Module: Blocks`, () => { it(`should handle errors`, async () => { const error = new Error(`err`) + const getBlock = jest.fn().mockRejectedValue(error) const node = { rpc: { blockchain: () => Promise.reject(error) - } + }, + getBlock } const module = blocks({ node @@ -299,6 +354,15 @@ describe(`Module: Blocks mutations`, () => { expect(state.blocks).toEqual([1, 2, 3]) }) + it(`should set the blocks in the state`, async () => { + const { setBlock } = mutations + const state = {} + setBlock(state, {}) + expect(state.block).toEqual({}) + setBlock(state, [1, 2, 3]) + expect(state.block).toEqual([1, 2, 3]) + }) + it(`should add a block the blocks`, async () => { const { addBlock } = mutations const state = { blocks: [] } diff --git a/test/unit/specs/store/json/txs.js b/test/unit/specs/store/json/txs.js index 6169f7104f..83fcf27a3a 100644 --- a/test/unit/specs/store/json/txs.js +++ b/test/unit/specs/store/json/txs.js @@ -1,7 +1,7 @@ export default [ { hash: `not a real hash`, - time: 1042 + 1000, // set by Voyager + time: 2042, // set by Voyager height: `3436`, tx: { type: `8EFE47F0625DE8`, @@ -78,7 +78,7 @@ export default [ }, { hash: `not a real hash2`, - time: 1042 + 1010, // set by Voyager + time: 2052, // set by Voyager height: `3438`, tx: { type: `8EFE47F0625DE8`, @@ -156,8 +156,7 @@ export default [ }, { hash: `not a real hash3`, - - time: 1042 + 100, // set by Voyager + time: 1142, // set by Voyager height: `466`, tx: { type: `8EFE47F0625DE8`, @@ -251,7 +250,7 @@ export default [ { hash: `not a real hash4`, - time: 1042 + 150, // set by Voyager + time: 42000, // set by Voyager height: `568`, tx: { type: `8EFE47F0625DE8`, @@ -312,7 +311,7 @@ export default [ { hash: `not a real hash5`, - time: 1042 + 150, // set by Voyager + time: 42000, // set by Voyager height: `569`, tx: { type: `8EFE47F0625DE8`, @@ -369,8 +368,7 @@ export default [ }, { hash: `not a real hash6`, - - time: 1042 + 150, // set by Voyager + time: 42000, // set by Voyager height: `567`, tx: { type: `8EFE47F0625DE8`, @@ -428,7 +426,7 @@ export default [ }, { hash: `not a real hash7`, - time: 1042 + 150, // set by Voyager + time: 42000, // set by Voyager height: `56673`, tx: { type: `8EFE47F0625DE8`, @@ -493,7 +491,7 @@ export default [ }, { hash: `not a real hash8`, - time: 1042 + 150, // set by Voyager + time: 42000, // set by Voyager height: `56675`, tx: { type: `8EFE47F0625DE8`,