From 4401156b79068e4aa7129fcffbd18eb1175e9329 Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Wed, 12 Dec 2018 16:58:23 +0100 Subject: [PATCH 01/14] Added undelegation transactions to TabMyDelegation --- CHANGELOG.md | 1 + .../components/staking/TabMyDelegations.vue | 57 +++++++++++++++++-- .../staking/TabMyDelegations.spec.js | 17 ++++++ .../TabMyDelegations.spec.js.snap | 38 +++++++++++++ 4 files changed, 108 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed884b77d7..a07435bf42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - [\#1690](https://github.com/cosmos/voyager/issues/1690) Feedbacks when Amount is not between valid thresholds @sabau - [\#1673](https://github.com/cosmos/voyager/issues/1673) Documentation and single command to run one or all tests with fallback for end to end test @sabau - [\#1683](https://github.com/cosmos/voyager/issues/1683) Governance: block voting twice for the same option @sabau +- [\#1387](https://github.com/cosmos/voyager/issues/1387) Staking: Added list of undelegation transactions @sabau ### Changed diff --git a/app/src/renderer/components/staking/TabMyDelegations.vue b/app/src/renderer/components/staking/TabMyDelegations.vue index 40f8f0f9c9..2bbacd7a3f 100644 --- a/app/src/renderer/components/staking/TabMyDelegations.vue +++ b/app/src/renderer/components/staking/TabMyDelegations.vue @@ -31,23 +31,51 @@ +
+

+ Unbounding transactions + + info_outline + +

+ +
@@ -77,6 +121,9 @@ export default { font-weight: 500; margin: 1rem 1rem 0 2rem; } +.tab-header.transactions { + margin: 2rem; +} .info-button { color: var(--link); diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js index a0bcec3bb9..1b4b03aded 100644 --- a/test/unit/specs/components/staking/TabMyDelegations.spec.js +++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js @@ -132,6 +132,23 @@ describe(`Component: TabMyDelegations`, () => { ).toEqual([delegates[1], delegates[2]]) }) + it(`unbondingTransactions`, async () => { + const address = delegates[0].operator_address + const transactions = await lcdClientMock.getDelegatorTxs( + lcdClientMock.addresses[0] + ) + expect( + TabMyDelegations.computed.unbondingTransactions({ + delegation: { + unbondingDelegations: { + [address]: 1 + } + }, + transactions: { staking: transactions } + }) + ).toHaveLength(1) + }) + it(`yourValidators`, () => { expect( TabMyDelegations.computed.yourValidators({ diff --git a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap index df007a3f33..849e7a0aa1 100644 --- a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap @@ -51,6 +51,8 @@ exports[`Component: TabMyDelegations should show a message if not staked yet to + + `; @@ -546,6 +548,24 @@ exports[`Component: TabMyDelegations should show committed validators 1`] = ` + +
+

+ + Unbounding transactions + + + + info_outline + + +

+ +
`; @@ -890,5 +910,23 @@ exports[`Component: TabMyDelegations should show unbonding validators 1`] = ` + +
+

+ + Unbounding transactions + + + + info_outline + + +

+ +
`; From f7a4dd5b5e81be1ec842972c571d80c84f0288a5 Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Thu, 13 Dec 2018 12:15:49 +0100 Subject: [PATCH 02/14] simplified logic for modifiers, updated tests - setUnbondingDelegations now takes as input an array instead of doing that from outside Signed-off-by: Karoly Albert Szabo --- CHANGELOG.md | 1 + app/src/renderer/vuex/modules/delegation.js | 57 ++++++------------- .../__snapshots__/PageGovernance.spec.js.snap | 4 +- .../__snapshots__/PageStaking.spec.js.snap | 4 +- .../__snapshots__/PageWallet.spec.js.snap | 4 +- .../__snapshots__/delegation.spec.js.snap | 8 +-- test/unit/specs/store/delegation.spec.js | 32 ++++++----- test/unit/specs/store/store.spec.js | 12 ++-- 8 files changed, 54 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a07435bf42..5b22bd7dc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -81,6 +81,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - [\#1638](https://github.com/cosmos/voyager/issues/1638) removed account password from the state and now user has to input it on every transaction @fedekunze - [\#1655](https://github.com/cosmos/voyager/issues/1655) Text and Textarea fields trimmed @sabau - [\#1686](https://github.com/cosmos/voyager/issues/1686) Changed proposals from array to object @sabau +- [\#1387](https://github.com/cosmos/voyager/issues/1387) Delegation: modifiers simplified, setUnbondingDelegations takes an array as input now as the name suggest and replace the current dictionary with a new one @sabau ### Fixed diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 44beb52700..2e99c275d8 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -33,32 +33,26 @@ export default ({ node }) => { state.delegates = state.delegates.filter(c => c.id !== delegate) }, setCommittedDelegation(state, { candidateId, value }) { - let committedDelegates = Object.assign({}, state.committedDelegates) + state.committedDelegates[candidateId] = value if (value === 0) { - delete committedDelegates[candidateId] - } else { - committedDelegates[candidateId] = value + delete state.committedDelegates[candidateId] } - state.committedDelegates = committedDelegates }, - setUnbondingDelegations( - state, - { validator_addr, min_time, balance, creation_height } - ) { - let unbondingDelegations = Object.assign({}, state.unbondingDelegations) - if (balance.amount === 0) { - delete unbondingDelegations[validator_addr] - } else { - unbondingDelegations[validator_addr] = { - min_time, - balance, - creation_height - } - } + setUnbondingDelegations(state, unbondingDelegations) { state.unbondingDelegations = unbondingDelegations + // building a dict from the array and taking out the transactions with amount 0 + .reduce( + (dict, { validator_addr, ...delegation }) => ({ + ...dict, + // filtering out the transactions with amount 0 + ...(delegation.balance.amount > 0 && { + [validator_addr]: delegation + }) + }), + {} + ) } } - let actions = { reconnected({ state, dispatch }) { if (state.loading) { @@ -82,11 +76,11 @@ export default ({ node }) => { try { let delegations = await node.getDelegations(address) - let unbonding_delegations = await node.getUndelegations(address) + let unbondingDelegations = await node.getUndelegations(address) let redelegations = await node.getRedelegations(address) let delegator = { delegations, - unbonding_delegations, + unbondingDelegations, redelegations } state.error = null @@ -126,24 +120,7 @@ export default ({ node }) => { }) }) - if (delegator.unbonding_delegations) { - delegator.unbonding_delegations.forEach(ubd => { - commit(`setUnbondingDelegations`, ubd) - }) - } - // delete undelegations not present anymore - Object.keys(state.unbondingDelegations).forEach(validatorAddr => { - if ( - !delegator.unbonding_delegations || - !delegator.unbonding_delegations.find( - ({ validator_addr }) => validator_addr === validatorAddr - ) - ) - commit(`setUnbondingDelegations`, { - validator_addr: validatorAddr, - balance: { amount: 0 } - }) - }) + commit(`setUnbondingDelegations`, unbondingDelegations) } catch (error) { commit(`notifyError`, { title: `Error fetching delegations`, diff --git a/test/unit/specs/components/governance/__snapshots__/PageGovernance.spec.js.snap b/test/unit/specs/components/governance/__snapshots__/PageGovernance.spec.js.snap index 2220316dd8..ef93570342 100644 --- a/test/unit/specs/components/governance/__snapshots__/PageGovernance.spec.js.snap +++ b/test/unit/specs/components/governance/__snapshots__/PageGovernance.spec.js.snap @@ -153,7 +153,7 @@ exports[`PageGovernance has the expected html structure 1`] = ` Total Steak

- 1,351.0000… + 1,337.0000…

@@ -213,7 +213,7 @@ exports[`PageGovernance has the expected html structure 1`] = ` Total Steak

- 1,351.0000… + 1,337.0000…

diff --git a/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap index 6f92c944aa..c81241b8ab 100644 --- a/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap @@ -18,7 +18,7 @@ exports[`PageStaking has the expected html structure 1`] = ` Total Steak

- 1,351.0000… + 1,337.0000…

@@ -79,7 +79,7 @@ exports[`PageStaking has the expected html structure 1`] = ` Total Steak

- 1,351.0000… + 1,337.0000…

diff --git a/test/unit/specs/components/wallet/__snapshots__/PageWallet.spec.js.snap b/test/unit/specs/components/wallet/__snapshots__/PageWallet.spec.js.snap index 93443e839b..957febc5ae 100644 --- a/test/unit/specs/components/wallet/__snapshots__/PageWallet.spec.js.snap +++ b/test/unit/specs/components/wallet/__snapshots__/PageWallet.spec.js.snap @@ -44,7 +44,7 @@ exports[`PageWallet has the expected html structure 1`] = `

- 1,014.0000… + 1,000.0000…

@@ -423,7 +423,7 @@ exports[`PageWallet should filter the balances 1`] = `

- 1,014.0000… + 1,000.0000…

diff --git a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap index c65c64535d..e1a410e445 100644 --- a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap +++ b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap @@ -12,15 +12,15 @@ Object { "balance": Object { "amount": "356.0000000000", }, - "creation_height": undefined, - "min_time": undefined, + "delegator_addr": "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", + "shares": "356.0000000000", }, "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": Object { "balance": Object { "amount": "113.0000000000", }, - "creation_height": undefined, - "min_time": undefined, + "delegator_addr": "cosmos15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", + "shares": "113.0000000000", }, } `; diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index 331349df39..d7b7024ff4 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -141,10 +141,12 @@ describe(`Module: Delegations`, () => { it(`deletes undelegations that are 0`, async () => { await store.dispatch(`getBondedDelegates`, store.state.delegates.delegates) - store.commit(`setUnbondingDelegations`, { - validator_addr: `cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw`, - balance: { amount: 0 } - }) + store.commit(`setUnbondingDelegations`, [ + { + validator_addr: `cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw`, + balance: { amount: 0 } + } + ]) expect( store.state.delegation.unbondingDelegations .cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw @@ -227,10 +229,12 @@ describe(`Module: Delegations`, () => { ] await store.dispatch(`submitDelegation`, { stakingTransactions }) - store.commit(`setUnbondingDelegations`, { - validator_addr: lcdClientMock.validators[0], - balance: { amount: `100` } - }) + store.commit(`setUnbondingDelegations`, [ + { + validator_addr: lcdClientMock.validators[0], + balance: { amount: `100` } + } + ]) expect( store.state.delegation.unbondingDelegations[lcdClientMock.validators[0]] ).toBeTruthy() @@ -241,12 +245,14 @@ describe(`Module: Delegations`, () => { candidateId: lcdClientMock.validators[1], value: 1 }) - store.commit(`setUnbondingDelegations`, { - validator_addr: lcdClientMock.validators[1], - balance: { - amount: 1 + store.commit(`setUnbondingDelegations`, [ + { + validator_addr: lcdClientMock.validators[1], + balance: { + amount: 1 + } } - }) + ]) expect( store.state.delegation.committedDelegates[lcdClientMock.validators[1]] ).toBeTruthy() diff --git a/test/unit/specs/store/store.spec.js b/test/unit/specs/store/store.spec.js index f8e18d5d64..ac4ba7e498 100644 --- a/test/unit/specs/store/store.spec.js +++ b/test/unit/specs/store/store.spec.js @@ -64,11 +64,13 @@ describe(`Store`, () => { candidateId: lcdClientMock.validators[0], value: 1 }) - store.commit(`setUnbondingDelegations`, { - validator_addr: lcdClientMock.validators[1], - balance: { amount: 1 }, - min_time: new Date().toUTCString() - }) + store.commit(`setUnbondingDelegations`, [ + { + validator_addr: lcdClientMock.validators[1], + balance: { amount: 1 }, + min_time: new Date().toUTCString() + } + ]) jest.runAllTimers() // updating is waiting if more updates coming in, this skips the waiting await store.dispatch(`signOut`) From 21c669d23287fe8415af3bd54c5caae7f753c8fe Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Thu, 13 Dec 2018 12:48:11 +0100 Subject: [PATCH 03/14] update e2e test and fix modifier behaviour value in case of null Signed-off-by: Karoly Albert Szabo --- app/src/renderer/vuex/modules/delegation.js | 24 +++++++++++---------- test/e2e/delegation.js | 8 ++++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 3b46a24d15..fd751d0271 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -40,17 +40,19 @@ export default ({ node }) => { }, setUnbondingDelegations(state, unbondingDelegations) { state.unbondingDelegations = unbondingDelegations - // building a dict from the array and taking out the transactions with amount 0 - .reduce( - (dict, { validator_addr, ...delegation }) => ({ - ...dict, - // filtering out the transactions with amount 0 - ...(delegation.balance.amount > 0 && { - [validator_addr]: delegation - }) - }), - {} - ) + ? unbondingDelegations + // building a dict from the array and taking out the transactions with amount 0 + .reduce( + (dict, { validator_addr, ...delegation }) => ({ + ...dict, + // filtering out the transactions with amount 0 + ...(delegation.balance.amount > 0 && { + [validator_addr]: delegation + }) + }), + {} + ) + : {} } } let actions = { diff --git a/test/e2e/delegation.js b/test/e2e/delegation.js index e3823b200c..e4d3d7a1f4 100644 --- a/test/e2e/delegation.js +++ b/test/e2e/delegation.js @@ -65,11 +65,13 @@ test(`delegation`, async function(t) { t.test(`Stake`, async t => { let totalAtoms = (await app.client .$(`.header-balance .total-atoms h2`) - .getText()).split(`.`)[0] // 130.000... + .getText()).split(`.`)[0] // 30.000... let unbondedAtoms = (await app.client .$(`.header-balance .unbonded-atoms h2`) .getText()).split(`.`)[0] // 30.000... + await t.equal(totalAtoms, `30`, `i have 30 Atoms`) + await t.equal(unbondedAtoms, `30`, `i have 30 unbbounded Atoms`) // Select the second validator. await app.client.click(`//*[. = 'local_2']`) @@ -101,11 +103,11 @@ test(`delegation`, async function(t) { // then the users has await waitForText( () => app.client.$(`.header-balance .total-atoms h2`), - `${totalAtoms}.0000…` + `${parseInt(totalAtoms) - 10}.0000…` ) await waitForText( () => app.client.$(`.header-balance .unbonded-atoms h2`), - `${unbondedAtoms - 10}.0000…` + `${parseInt(unbondedAtoms) - 10}.0000…` ) await closeNotifications(app) From c18670a8f3bd9ecaf02fab36a17184026eb8079d Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Thu, 13 Dec 2018 13:10:19 +0100 Subject: [PATCH 04/14] test timeDiff Signed-off-by: Karoly Albert Szabo --- .../specs/components/staking/TabMyDelegations.spec.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js index 1b4b03aded..b73c13ab0b 100644 --- a/test/unit/specs/components/staking/TabMyDelegations.spec.js +++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js @@ -1,6 +1,7 @@ import setup from "../../../helpers/vuex-setup" import lcdClientMock from "renderer/connectors/lcdClientMock.js" import TabMyDelegations from "renderer/components/staking/TabMyDelegations" +import moment from "moment" const delegates = lcdClientMock.candidates @@ -149,6 +150,13 @@ describe(`Component: TabMyDelegations`, () => { ).toHaveLength(1) }) + it(`should return the time diff`, () => { + const now = new Date() + expect(TabMyDelegations.methods.timeDiff(now)).toEqual( + moment(now).fromNow() + ) + }) + it(`yourValidators`, () => { expect( TabMyDelegations.computed.yourValidators({ From 26503d6d658439c93a9ab739bd0e18482b05da31 Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Thu, 13 Dec 2018 13:29:17 +0100 Subject: [PATCH 05/14] add header to first table, change title on second one (shall we just remove it?) Signed-off-by: Karoly Albert Szabo --- .../components/staking/TabMyDelegations.vue | 8 +++++++- .../staking/TabMyDelegations.spec.js | 2 +- .../TabMyDelegations.spec.js.snap | 19 +++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/app/src/renderer/components/staking/TabMyDelegations.vue b/app/src/renderer/components/staking/TabMyDelegations.vue index 2bbacd7a3f..ba62170176 100644 --- a/app/src/renderer/components/staking/TabMyDelegations.vue +++ b/app/src/renderer/components/staking/TabMyDelegations.vue @@ -1,6 +1,12 @@ @@ -128,7 +121,7 @@ export default { margin: 1rem 1rem 0 2rem; } .tab-header.transactions { - margin: 2rem; + margin: 2rem 0 1rem 2rem; } .info-button { @@ -140,9 +133,24 @@ export default { border: 1px solid var(--bc-dim); border-radius: 0.25rem; font-size: var(--sm); - margin-bottom: 4rem; margin-left: 2rem; padding: 0.5rem; text-align: center; } + +.transactions { + margin-left: 2rem; + counter-reset: transaction; +} +.transactions .tm-li-tx { + counter-increment: transaction; +} +.tm-li-tx::before { + content: counter(transaction); + position: absolute; + width: 2rem; + text-align: right; + color: var(--dim); + left: 0; +} From 10df4d27225adc4178901b4260a2c62c48f053e4 Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Fri, 28 Dec 2018 11:48:56 +0100 Subject: [PATCH 10/14] fix label for MuyDelegation spec Signed-off-by: Karoly Albert Szabo --- .../staking/TabMyDelegations.spec.js | 2 +- .../TabMyDelegations.spec.js.snap | 680 ++---------------- 2 files changed, 51 insertions(+), 631 deletions(-) diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js index cb1f791c4d..d320160b5b 100644 --- a/test/unit/specs/components/staking/TabMyDelegations.spec.js +++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js @@ -51,7 +51,7 @@ describe(`Component: TabMyDelegations`, () => { } }) - expect(instance.wrapper.html()).toContain(`Unbonding validators`) + expect(instance.wrapper.html()).toContain(`Unbonding transactions`) expect(instance.wrapper.vm.$el).toMatchSnapshot() }) diff --git a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap index fd9c28118e..4c714fde6e 100644 --- a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap @@ -51,8 +51,6 @@ exports[`Component: TabMyDelegations should show a message if not staked yet to - - `; @@ -274,353 +272,64 @@ exports[`Component: TabMyDelegations should show committed validators 1`] = `

- Unbonding validators + Unbonding transactions + info_outline +

-
- + + +`; + +exports[`Component: TabMyDelegations should show unbonding validators 1`] = ` +
+ + +
+
+ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Moniker - - - - Delegated stake - - - - Rewards - - - - Voting Power - - - - Uptime - - - - Commission - - - - Slashes - -
- - -
- - - - good_greg - - -
-
-
- - cosmosvaladdr…n3au - -
- -
- - check - - - Copied - -
-
-
-
-
- - 0.0000… - - - n/a - - - 0.00% - - - n/a - - 0.00% - - n/a -
- - -
- - - - herr_schmidt_revoked - - -
-
-
- - cosmosvaladdr…rg7n - -
- -
- - check - - - Copied - -
-
-
-
-
- - 0.0000… - - - n/a - - - 0.00% - - - n/a - - 0.00% - - n/a -
-
-
- -
-

- - Unbonding transactions - - - - info_outline - - -

- -
- -`; - -exports[`Component: TabMyDelegations should show unbonding validators 1`] = ` -
- - -
-
- - info_outline - -
-
-
-
- No Active Delegations -
-
-
-
- - Looks like you haven't delegated any stakes yet. Head over - to the - - +
+
+
+
+ No Active Delegations +
+
+
+
+ + Looks like you haven't delegated any stakes yet. Head over + to the + + validator list @@ -634,298 +343,6 @@ exports[`Component: TabMyDelegations should show unbonding validators 1`] = ` -
-

- - Unbonding validators - - - info_outline - -

- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - Moniker - - - - Delegated stake - - - - Rewards - - - - Voting Power - - - - Uptime - - - - Commission - - - - Slashes - -
- - -
- - - - good_greg - - -
-
-
- - cosmosvaladdr…n3au - -
- -
- - check - - - Copied - -
-
-
-
-
- - 0.0000… - - - n/a - - - 0.00% - - - n/a - - 0.00% - - n/a -
- - -
- - - - herr_schmidt_revoked - - -
-
-
- - cosmosvaladdr…rg7n - -
- -
- - check - - - Copied - -
-
-
-
-
- - 0.0000… - - - n/a - - - 0.00% - - - n/a - - 0.00% - - n/a -
-
-
-

+
`; From e0d302e4ef74c0dc3ede12b5797f4c9aa9b8c0ee Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Wed, 2 Jan 2019 16:57:53 +0100 Subject: [PATCH 11/14] remove unnecessary undelegatedValidators - adjust tests - dirty fix: shares and shares_amount have to be fixed in the mock Signed-off-by: Karoly Albert Szabo --- .../components/staking/TabMyDelegations.vue | 19 +- .../staking/TabMyDelegations.spec.js | 36 +- .../TabMyDelegations.spec.js.snap | 311 +++++++++++++++--- 3 files changed, 282 insertions(+), 84 deletions(-) diff --git a/app/src/renderer/components/staking/TabMyDelegations.vue b/app/src/renderer/components/staking/TabMyDelegations.vue index ab5cfd673b..9d295647ee 100644 --- a/app/src/renderer/components/staking/TabMyDelegations.vue +++ b/app/src/renderer/components/staking/TabMyDelegations.vue @@ -28,7 +28,7 @@ the validator list to find other validators to delegate to.
-
+

Unbonding transactions @@ -53,7 +53,7 @@ @@ -135,14 +145,14 @@ export default { text-align: center; } -.transactions { +.unbonding-transactions { margin-left: 2rem; counter-reset: transaction; } -.transactions .tm-li-tx { +.unbonding-transactions .tm-li-tx { counter-increment: transaction; } -.tm-li-tx::before { +.unbonding-transactions .tm-li-tx::before { content: counter(transaction); position: absolute; width: 2rem; diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 959a9e2702..ab0366d56c 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -35,7 +35,9 @@ :transaction="tx" :address="wallet.address" :bonding-denom="bondingDenom" - :unbonding-time="getUnbondingTime(tx)" + :unbonding-time=" + time.getUnbondingTime(tx, delegation.unbondingDelegations) + " /> @@ -56,6 +58,8 @@ import TmPage from "common/TmPage" import TmDataLoading from "common/TmDataLoading" import TmLiAnyTransaction from "transactions/TmLiAnyTransaction" import ToolBar from "common/ToolBar" +import time from "scripts/time" + export default { name: `page-transactions`, components: { @@ -77,7 +81,8 @@ export default { order: `desc` }, validatorURL: `/staking/validators`, - proposalsURL: `/governance/proposals` + proposalsURL: `/governance/proposals`, + time }), computed: { ...mapState([`transactions`]), @@ -124,22 +129,6 @@ export default { refreshTransactions() { this.$store.dispatch(`getAllTxs`) }, - getUnbondingTime(transaction) { - let copiedTransaction = JSON.parse(JSON.stringify(transaction)) - let type = copiedTransaction.tx.value.msg[0].type - if (type === `cosmos-sdk/BeginUnbonding`) { - let tx = copiedTransaction.tx.value.msg[0].value - let unbondingDelegation = this.delegation.unbondingDelegations[ - tx.validator_addr - ] - if ( - unbondingDelegation && - unbondingDelegation.creation_height === - String(copiedTransaction.height) - ) - return new Date(unbondingDelegation.min_time).getTime() - } - }, setSearch(bool = !this.filters[`transactions`].search.visible) { if (!this.somethingToSearch) return false this.$store.commit(`setSearchVisible`, [`transactions`, bool]) diff --git a/app/src/renderer/scripts/time.js b/app/src/renderer/scripts/time.js new file mode 100644 index 0000000000..c60dea373c --- /dev/null +++ b/app/src/renderer/scripts/time.js @@ -0,0 +1,18 @@ +"use strict" + +const getUnbondingTime = ({ height, tx }, unbondingDelegations) => { + let { type, value } = tx.value.msg[0] + if (type === `cosmos-sdk/BeginUnbonding`) { + let unbondingDelegation = unbondingDelegations[value.validator_addr] + if ( + unbondingDelegation && + unbondingDelegation.creation_height === String(height) + ) { + return new Date(unbondingDelegation.min_time).getTime() + } + } + return NaN +} +module.exports = { + getUnbondingTime +} diff --git a/test/unit/specs/components/staking/TabMyDelegations.spec.js b/test/unit/specs/components/staking/TabMyDelegations.spec.js index a908cd40eb..6c5c29ff8d 100644 --- a/test/unit/specs/components/staking/TabMyDelegations.spec.js +++ b/test/unit/specs/components/staking/TabMyDelegations.spec.js @@ -1,7 +1,6 @@ import setup from "../../../helpers/vuex-setup" import lcdClientMock from "renderer/connectors/lcdClientMock.js" import TabMyDelegations from "renderer/components/staking/TabMyDelegations" -import moment from "moment" const delegates = lcdClientMock.candidates @@ -40,18 +39,22 @@ describe(`Component: TabMyDelegations`, () => { }) it(`should show unbonding validators and the current committed validator`, () => { + const address = delegates[0].operator_address let instance = mount(TabMyDelegations, { getters: { // We decided that is should not be possible to undelegate from something that is not committed committedDelegations: () => ({ - [delegates[0].operator_address]: 1 + [address]: 1 }), delegates: () => ({ delegates }), delegation: () => ({ unbondingDelegations: { - [delegates[0].operator_address]: 1 + [address]: { + creation_height: `170`, + min_time: new Date().toISOString() + } }, loaded: true }), @@ -134,11 +137,15 @@ describe(`Component: TabMyDelegations`, () => { const transactions = await lcdClientMock.getDelegatorTxs( lcdClientMock.addresses[0] ) + expect( TabMyDelegations.computed.unbondingTransactions({ delegation: { unbondingDelegations: { - [address]: 1 + [address]: { + creation_height: `170`, + min_time: new Date().toISOString() + } } }, allTransactions: transactions @@ -146,13 +153,6 @@ describe(`Component: TabMyDelegations`, () => { ).toHaveLength(1) }) - it(`should return the time diff`, () => { - const now = new Date() - expect(TabMyDelegations.methods.timeDiff(now)).toEqual( - moment(now).fromNow() - ) - }) - it(`yourValidators`, () => { expect( TabMyDelegations.computed.yourValidators({ diff --git a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap index 5dab443d15..f9309074b5 100644 --- a/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/TabMyDelegations.spec.js.snap @@ -506,7 +506,7 @@ exports[`Component: TabMyDelegations should show unbonding validators and the cu

@@ -189,6 +190,7 @@ exports[`PageTransactions has the expected html structure 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> @@ -197,6 +199,7 @@ exports[`PageTransactions has the expected html structure 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> @@ -205,6 +208,7 @@ exports[`PageTransactions has the expected html structure 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> @@ -213,6 +217,7 @@ exports[`PageTransactions has the expected html structure 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> @@ -221,6 +226,7 @@ exports[`PageTransactions has the expected html structure 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> @@ -409,6 +415,7 @@ exports[`PageTransactions should filter the transactions 1`] = ` bondingdenom="STAKE" proposalsurl="/governance/proposals" transaction="[object Object]" + unbondingtime="NaN" validators="" validatorsurl="/staking/validators" /> diff --git a/test/unit/specs/scripts/time.spec.js b/test/unit/specs/scripts/time.spec.js new file mode 100644 index 0000000000..8847aa728b --- /dev/null +++ b/test/unit/specs/scripts/time.spec.js @@ -0,0 +1,45 @@ +import time from "renderer/scripts/time" +import lcdClientMock from "renderer/connectors/lcdClientMock.js" +const delegates = lcdClientMock.candidates +const transaction = lcdClientMock.state.txs[0] +const unbondingTransaction = lcdClientMock.state.txs[5] + +describe(`time helper`, () => { + describe(`getUnbondingTime`, () => { + it(`should return NaN with wrong transactions`, () => { + const address = delegates[0].operator_address + expect( + time.getUnbondingTime(transaction, { + [address]: { + creation_height: `170`, + min_time: new Date().toISOString() + } + }) + ).toBe(NaN) + }) + + it(`should return NaN for unbonding transactions when height does not match`, () => { + const address = delegates[0].operator_address + expect( + time.getUnbondingTime(unbondingTransaction, { + [address]: { + creation_height: `171`, + min_time: new Date().toISOString() + } + }) + ).toBe(NaN) + }) + + it(`should return time for unbonding transactions when height match`, () => { + const address = delegates[0].operator_address + expect( + time.getUnbondingTime(unbondingTransaction, { + [address]: { + creation_height: `170`, + min_time: new Date().toISOString() + } + }) + ).toBe(42000) + }) + }) +})