From fc2e561dcb6251dc72e3707e1a9e990674b3068a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Thu, 2 Aug 2018 11:37:07 +0200 Subject: [PATCH 01/23] updated endpoints with newest refactor --- app/src/renderer/connectors/lcdClient.js | 56 ++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 79d470fbd0..0605535e0a 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -90,12 +90,60 @@ Object.assign(Client.prototype, { }, tx: argReq("GET", "/txs"), - // staking - updateDelegations: req("POST", "/stake/delegations"), + /* ============ STAKE ============ */ + + // Get all delegations information from a delegator + getDelegator: function(addr) { + return req("GET", `/stake/delegators/${addr}`).call(this) + }, + // Get all txs from a delegator + getDelegatorTxs: function(addr) { + return req("GET", `/stake/delegators/${addr}/txs`).call(this) + }, + // Get a specific tx from a delegator + getDelegatorTx: function(addr, id, types) { + if types === "" { + return req("GET", `/stake/delegators/${addr}/txs`).call(this) + } else { + return req("GET", `/stake/delegators/${addr}/txs?type=${types}`).call(this) + } + }, + // // Query all validators that a delegator is bonded to + // getDelegatorValidators: function(delegatorAddr) { + // return req("GET", `/stake/delegators/${delegatorAddr}/validators`).call(this) + // }, + // // Query a validator info that a delegator is bonded to + // getDelegatorValidator: function(delegatorAddr, validatorAddr) { + // return req("GET", `/stake/delegators/${delegatorAddr}/validators/${validatorAddr}`).call(this) + // }, + + // Get a list containing all the validator candidates + getValidators: req("GET", "/stakes/validators/"), + // Get information from a validator + getValidator: function(addr) { + return req("GET", `/stake/validators/${addr}`).call(this) + }, + // // Get all of the validator bonded delegators + // getValidatorDelegators: function(addr) { + // return req("GET", `/stake/validator/${addr}/delegators`).call(this) + // }, + + // Get the list of the validators in the latest validator set + getValidatorSet: req("GET", "/validatorsets/latest"), + + + updateDelegations: function(delegatorAddr) { + return req("POST", `/stake/delegators/${delegatorAddr}/delegations`) + } + candidates: req("GET", "/stake/validators"), getValidators: req("GET", "/validatorsets/latest"), - queryDelegation: function(delegator, validator) { - return req("GET", `/stake/${delegator}/delegation/${validator}`).call(this) + // Query a delegation between a delegator and a validator + queryDelegation: function(delegatorAddr, validatorAddr) { + return req("GET", `/stake/delegators/${delegatorAddr}/delegations/${validatorAddr}`).call(this) + } + queryUnbonding: function(delegatorAddr, validatorAddr) { + return req("GET", `/stake/delegators/${delegatorAddr}/unbonding_delegations/${validatorAddr}`).call(this) } }) From bbffa6d8963f7590c1e12eb94c6c52725afcff9e Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Thu, 2 Aug 2018 12:02:41 +0200 Subject: [PATCH 02/23] minor fixes --- CHANGELOG.md | 4 ++++ app/src/renderer/connectors/lcdClient.js | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5cec36b2c..5e280a2411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + +* LCD staking endpoints @fedekunze + ## [0.9.3] - 2018-08-02 ### Fixed diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 0605535e0a..ff50f3b092 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -102,10 +102,12 @@ Object.assign(Client.prototype, { }, // Get a specific tx from a delegator getDelegatorTx: function(addr, id, types) { - if types === "" { + if (types === "") { return req("GET", `/stake/delegators/${addr}/txs`).call(this) } else { - return req("GET", `/stake/delegators/${addr}/txs?type=${types}`).call(this) + return req("GET", `/stake/delegators/${addr}/txs?type=${types}`).call( + this + ) } }, // // Query all validators that a delegator is bonded to @@ -131,19 +133,24 @@ Object.assign(Client.prototype, { // Get the list of the validators in the latest validator set getValidatorSet: req("GET", "/validatorsets/latest"), - - updateDelegations: function(delegatorAddr) { + updateDelegations: function(delegatorAddr) { return req("POST", `/stake/delegators/${delegatorAddr}/delegations`) - } + }, candidates: req("GET", "/stake/validators"), getValidators: req("GET", "/validatorsets/latest"), // Query a delegation between a delegator and a validator queryDelegation: function(delegatorAddr, validatorAddr) { - return req("GET", `/stake/delegators/${delegatorAddr}/delegations/${validatorAddr}`).call(this) - } + return req( + "GET", + `/stake/delegators/${delegatorAddr}/delegations/${validatorAddr}` + ).call(this) + }, queryUnbonding: function(delegatorAddr, validatorAddr) { - return req("GET", `/stake/delegators/${delegatorAddr}/unbonding_delegations/${validatorAddr}`).call(this) + return req( + "GET", + `/stake/delegators/${delegatorAddr}/unbonding_delegations/${validatorAddr}` + ).call(this) } }) From db90be88192a486dab93ae1adfd77956e6b7c889 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 2 Aug 2018 14:31:54 +0200 Subject: [PATCH 03/23] switched to branch for testing staking --- tasks/build/Gaia/COMMIT.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index 61800138c4..94539f0a02 100755 --- a/tasks/build/Gaia/COMMIT.sh +++ b/tasks/build/Gaia/COMMIT.sh @@ -2,4 +2,4 @@ # This is the commit of the SDK version to use for building Gaia. We use an # explicit hash instead of a tag so we don't have to trust GitHub. -export COMMIT=23e3d5ac12145c02fcb4b4767d7dfccad782aee5 +export COMMIT=e2064a4df756d5dd2a2178b35f1ad28de0467513 From 4c2da75e0f82fed3497956d1db6eb18dcc3e4537 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 2 Aug 2018 14:32:10 +0200 Subject: [PATCH 04/23] typo --- app/src/renderer/connectors/lcdClient.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index ff50f3b092..6727a55086 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -120,7 +120,7 @@ Object.assign(Client.prototype, { // }, // Get a list containing all the validator candidates - getValidators: req("GET", "/stakes/validators/"), + getValidators: req("GET", "/stake/validators/"), // Get information from a validator getValidator: function(addr) { return req("GET", `/stake/validators/${addr}`).call(this) From b21b00b1311c7d7aecc16989a01abd86dfe985c3 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 2 Aug 2018 18:25:58 +0200 Subject: [PATCH 05/23] adjusting to new API --- app/src/renderer/vuex/modules/delegation.js | 40 ++++++++------------- app/src/renderer/vuex/modules/validators.js | 25 ++++++------- tasks/build/Gaia/COMMIT.sh | 2 +- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 6e51c627b6..65b9396d47 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -46,36 +46,24 @@ export default ({ node }) => { } }, // load committed delegations from LCD - async getBondedDelegates({ state, rootState, dispatch }, candidates) { + async getBondedDelegates({ state, rootState, commit }, candidates) { state.loading = true let address = rootState.user.address candidates = candidates || (await dispatch("getDelegates")) - await Promise.all( - candidates.map(candidate => - dispatch("getBondedDelegate", { - delegator: address, - validator: candidate.owner - }) - ) - ) - state.loading = false - }, - // load committed delegation from LCD - async getBondedDelegate({ commit, rootState }, { delegator, validator }) { - let bond = await node.queryDelegation(delegator, validator) - - let shares = bond ? bond.shares : 0 - let delegate = rootState.delegates.delegates.find( - d => d.owner === validator - ) - - commit("setCommittedDelegation", { - candidateId: validator, - value: shares + let delegator = await node.getDelegator(address) + delegator.delegations.forEach(({ validator_addr, shares }) => { + commit("setCommittedDelegation", { + candidateId: validator_addr, + value: parseFloat(shares) + }) + if (shares > 0) { + const delegate = candidates.find( + ({ owner }) => owner === validator_addr // this should change to address instead of owner + ) + commit("addToCart", delegate) + } }) - if (shares > 0) { - commit("addToCart", delegate) - } + state.loading = false }, async updateDelegates({ dispatch }) { let candidates = await dispatch("getDelegates") diff --git a/app/src/renderer/vuex/modules/validators.js b/app/src/renderer/vuex/modules/validators.js index 198e8de8ce..d464f038ab 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -1,3 +1,5 @@ +import b32 from "scripts/b32" + export default ({ node }) => { const state = { validators: [], @@ -20,19 +22,18 @@ export default ({ node }) => { dispatch("getValidators") } }, - getValidators({ state, commit }) { + async getValidators({ state, commit }) { state.loading = true - node.rpc.validators((err, { validators } = {}) => { - if (err) { - commit("notifyError", { - title: "Error fetching validator set", - body: err.message - }) - return - } - commit("setValidators", validators) - state.loading = false - }) + try { + let candidates = await node.candidates() + commit("setValidators", candidates) + } catch (err) { + commit("notifyError", { + title: "Error fetching validator set", + body: err.message + }) + } + state.loading = false }, maybeUpdateValidators({ state, commit, dispatch }, header) { let validatorHash = header.validators_hash diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index 94539f0a02..be3f4858ad 100755 --- a/tasks/build/Gaia/COMMIT.sh +++ b/tasks/build/Gaia/COMMIT.sh @@ -2,4 +2,4 @@ # This is the commit of the SDK version to use for building Gaia. We use an # explicit hash instead of a tag so we don't have to trust GitHub. -export COMMIT=e2064a4df756d5dd2a2178b35f1ad28de0467513 +export COMMIT=9ee3d47dc63cadaa3a6a375542f05f396277e70d From 61ba76e0df40571be2d13f92c61831668a84978f Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 2 Aug 2018 18:48:30 +0200 Subject: [PATCH 06/23] made delegation kind of work --- app/src/renderer/connectors/lcdClient.js | 7 +++++-- app/src/renderer/vuex/modules/delegation.js | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 6727a55086..a11a47b864 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -133,8 +133,11 @@ Object.assign(Client.prototype, { // Get the list of the validators in the latest validator set getValidatorSet: req("GET", "/validatorsets/latest"), - updateDelegations: function(delegatorAddr) { - return req("POST", `/stake/delegators/${delegatorAddr}/delegations`) + updateDelegations: function(delegatorAddr, data) { + return req("POST", `/stake/delegators/${delegatorAddr}/delegations`).call( + this, + data + ) }, candidates: req("GET", "/stake/validators"), diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 65b9396d47..d05a6ed2db 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -105,6 +105,7 @@ export default ({ node }) => { await dispatch("sendTx", { type: "updateDelegations", + to: rootState.wallet.address, // TODO strange syntax delegations: delegate, begin_unbondings: unbond }) From daef71f22e0be48f224e94c9580bec95e7961da0 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Fri, 3 Aug 2018 11:16:28 +0200 Subject: [PATCH 07/23] showing old unbonding in pagebond --- .../renderer/components/staking/PageBond.vue | 20 ++++++++++++++----- app/src/renderer/vuex/getters.js | 1 + app/src/renderer/vuex/modules/delegation.js | 20 ++++++++++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/src/renderer/components/staking/PageBond.vue b/app/src/renderer/components/staking/PageBond.vue index 56512d8b88..3eb803e8d1 100644 --- a/app/src/renderer/components/staking/PageBond.vue +++ b/app/src/renderer/components/staking/PageBond.vue @@ -152,15 +152,17 @@ export default { ToolBar }, computed: { - ...mapGetters(["shoppingCart", "user", "committedDelegations", "config"]), + ...mapGetters(["shoppingCart", "user", "delegation", "config"]), denom() { return this.config.bondingDenom.toUpperCase() }, totalAtoms() { - return parseInt(this.user.atoms) + this.oldBondedAtoms + return ( + parseInt(this.user.atoms) + this.oldBondedAtoms + this.oldUnbondingAtoms + ) }, oldBondedAtoms() { - return Object.values(this.committedDelegations).reduce( + return Object.values(this.delegation.committedDelegates).reduce( (sum, d) => sum + parseInt(d), 0 ) @@ -177,6 +179,14 @@ export default { return atoms }, this.oldUnbondedAtoms) }, + oldUnbondingAtoms() { + return Object.values(this.delegation.unbondingDelegations).reduce( + (atoms, value) => { + return atoms + value + }, + 0 + ) + }, newUnbondingAtoms() { return this.fields.delegates.reduce((atoms, d) => { let delta = d.oldAtoms - d.atoms @@ -184,7 +194,7 @@ export default { return atoms + delta } return atoms - }, 0) + }, this.oldUnbondingAtoms) }, newUnbondingAtomsDelta() { return this.delta(this.newUnbondingAtoms, 0) @@ -247,7 +257,7 @@ export default { } }, resetFields() { - let committedDelegations = this.committedDelegations + let committedDelegations = this.delegation.committedDelegates let totalAtoms = this.totalAtoms this.fields.bondConfirm = false this.fields.delegates = this.shoppingCart.map(c => diff --git a/app/src/renderer/vuex/getters.js b/app/src/renderer/vuex/getters.js index a310805974..78a1832cdf 100644 --- a/app/src/renderer/vuex/getters.js +++ b/app/src/renderer/vuex/getters.js @@ -17,6 +17,7 @@ export const transactions = state => state.wallet.history export const wallet = state => state.wallet // staking +export const delegation = state => state.delegation export const committedDelegations = state => state.delegation.committedDelegates export const delegates = state => state.delegates export const shoppingCart = state => state.delegation.delegates diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index d05a6ed2db..05a71510df 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -6,7 +6,8 @@ export default ({ node }) => { delegates: [], // our delegations which are already on the blockchain - committedDelegates: {} + committedDelegates: {}, + unbondingDelegations: {} } const mutations = { @@ -36,6 +37,15 @@ export default ({ node }) => { committedDelegates[candidateId] = value } state.committedDelegates = committedDelegates + }, + setUnbondingDelegation(state, { candidateId, value }) { + let unbondingDelegations = Object.assign({}, state.unbondingDelegations) + if (value === 0) { + delete unbondingDelegations[candidateId] + } else { + unbondingDelegations[candidateId] = value + } + state.unbondingDelegations = unbondingDelegations } } @@ -63,6 +73,14 @@ export default ({ node }) => { commit("addToCart", delegate) } }) + delegator.unbonding_delegations.forEach( + ({ validator_addr, balance: { amount } }) => { + commit("setUnbondingDelegation", { + candidateId: validator_addr, + value: parseFloat(amount) + }) + } + ) state.loading = false }, async updateDelegates({ dispatch }) { From 4ed25220b0ed1e4b75f7d7c698923789f45054dc Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Fri, 3 Aug 2018 17:10:04 +0200 Subject: [PATCH 08/23] compatible to lcd staking refactor --- .../components/wallet/PageTransactions.vue | 19 ++++- app/src/renderer/connectors/lcdClient.js | 14 ++-- app/src/renderer/connectors/lcdClientMock.js | 70 +++++++++++++++---- app/src/renderer/vuex/modules/delegates.js | 4 +- app/src/renderer/vuex/modules/delegation.js | 48 ++++++++----- app/src/renderer/vuex/modules/validators.js | 2 +- app/src/renderer/vuex/modules/wallet.js | 2 +- tasks/build/Gaia/COMMIT.sh | 2 +- 8 files changed, 113 insertions(+), 48 deletions(-) diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 8bd0958c92..15bf543776 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -41,12 +41,25 @@ export default { ToolBar }, computed: { - ...mapGetters(["filters", "transactions", "wallet", "config"]), + ...mapGetters([ + "filters", + "transactions", + "wallet", + "config", + "delegation" + ]), somethingToSearch() { return !this.wallet.historyLoading && !!this.transactions.length }, + allTransactions() { + return [].concat(this.transactions, this.delegation.delegationTxs) + }, orderedTransactions() { - return orderBy(this.transactions, [this.sort.property], [this.sort.order]) + return orderBy( + this.allTransactions, + [this.sort.property], + [this.sort.order] + ) }, filteredTransactions() { let query = this.filters.transactions.search.query @@ -70,6 +83,7 @@ export default { methods: { refreshTransactions() { this.$store.dispatch("queryWalletHistory") + this.$store.dispatch("getDelegationTxs") }, setSearch(bool = !this.filters["transactions"].search.visible) { if (!this.somethingToSearch) return false @@ -79,6 +93,7 @@ export default { mounted() { Mousetrap.bind(["command+f", "ctrl+f"], () => this.setSearch(true)) Mousetrap.bind("esc", () => this.setSearch(false)) + this.refreshTransactions() } } diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index a11a47b864..92886bbe6e 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -97,12 +97,8 @@ Object.assign(Client.prototype, { return req("GET", `/stake/delegators/${addr}`).call(this) }, // Get all txs from a delegator - getDelegatorTxs: function(addr) { - return req("GET", `/stake/delegators/${addr}/txs`).call(this) - }, - // Get a specific tx from a delegator - getDelegatorTx: function(addr, id, types) { - if (types === "") { + getDelegatorTxs: function(addr, types) { + if (!types) { return req("GET", `/stake/delegators/${addr}/txs`).call(this) } else { return req("GET", `/stake/delegators/${addr}/txs?type=${types}`).call( @@ -110,6 +106,10 @@ Object.assign(Client.prototype, { ) } }, + // Get a specific tx from a delegator + getDelegatorTx: function(addr, id) { + return req("GET", `/stake/delegators/${addr}/txs/${id}`).call(this) + }, // // Query all validators that a delegator is bonded to // getDelegatorValidators: function(delegatorAddr) { // return req("GET", `/stake/delegators/${delegatorAddr}/validators`).call(this) @@ -140,8 +140,6 @@ Object.assign(Client.prototype, { ) }, - candidates: req("GET", "/stake/validators"), - getValidators: req("GET", "/validatorsets/latest"), // Query a delegation between a delegator and a validator queryDelegation: function(delegatorAddr, validatorAddr) { return req( diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index a995f0ceb8..8b6f3e8677 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -118,12 +118,15 @@ let state = { ], stake: { [addresses[0]]: { - [validators[0]]: { - delegator_addr: addresses[0], - validator_addr: validators[0], - shares: "130", - height: 123 - } + delegations: [ + { + delegator_addr: addresses[0], + validator_addr: validators[0], + shares: "14", + height: 123 + } + ], + unbonding_delegations: [] } }, candidates: [ @@ -254,7 +257,10 @@ module.exports = { }, // staking - async updateDelegations({ name, sequence, delegations, begin_unbondings }) { + async updateDelegations( + delegatorAddr, + { name, sequence, delegations, begin_unbondings } + ) { let results = [] let fromKey = state.keys.find(a => a.name === name) @@ -294,10 +300,15 @@ module.exports = { // update stake let delegator = state.stake[fromKey.address] if (!delegator) { - state.stake[fromKey.address] = {} + state.stake[fromKey.address] = { + delegations: [], + unbonding_delegations: [] + } delegator = state.stake[fromKey.address] } - let delegation = delegator[tx.validator_addr] + let delegation = delegator.delegations.find( + d => d.validator_addr === tx.validator_addr + ) if (!delegation) { delegation = { delegator_addr: fromKey.address, @@ -305,8 +316,9 @@ module.exports = { shares: "0", height: 0 } - delegator[tx.validator_addr] = delegation + delegator.delegations.push(delegation) } + let shares = parseInt(delegation.shares) delegation.shares = (shares + amount).toString() @@ -334,7 +346,9 @@ module.exports = { results.push(txResult(2, "Nonexistent delegator")) return results } - let delegation = delegator[tx.validator_addr] + let delegation = delegator.delegations.find( + d => d.validator_addr === tx.validator_addr + ) if (!delegation) { results.push(txResult(2, "Nonexistent delegation")) return results @@ -345,6 +359,15 @@ module.exports = { let candidate = state.candidates.find(c => c.owner === tx.validator_addr) shares = parseInt(candidate.tokens) candidate.tokens = (+shares - amount).toString() + delegator.unbonding_delegations.push({ + validator_addr: tx.validator_addr, + delegator_addr: fromKey.address, + balance: { + // TODO + denom: "steak", + amount: amount + } + }) results.push(txResult(0)) } @@ -354,17 +377,36 @@ module.exports = { async queryDelegation(delegatorAddress, validatorAddress) { let delegator = state.stake[delegatorAddress] if (!delegator) return - return delegator[validatorAddress] + return delegator[validatorAddress].delegation }, - async candidates() { - return state.candidates + async queryUnbonding(delegatorAddress, validatorAddress) { + let delegator = state.stake[delegatorAddress] + if (!delegator) return + return delegator[validatorAddress].undelegation + }, + // Get all delegations information from a delegator + getDelegator(delegatorAddress) { + let delegator = state.stake[delegatorAddress] + return delegator + }, + getDelegatorTxs(addr, types) { + return [] // TODO + }, + async getDelegatorTx(addr, id) { + return {} // not used }, async getValidators() { + return state.candidates + }, + async getValidatorset() { return { block_height: 1, validators: state.candidates } }, + async getValidator(addr) { + return state.candidates.find(c => c.owner === addr) + }, // exports to be used in tests state, addresses, diff --git a/app/src/renderer/vuex/modules/delegates.js b/app/src/renderer/vuex/modules/delegates.js index ab16ae8a83..493bc0e789 100644 --- a/app/src/renderer/vuex/modules/delegates.js +++ b/app/src/renderer/vuex/modules/delegates.js @@ -38,8 +38,8 @@ export default ({ node }) => { }, async getDelegates({ state, commit }) { commit("setDelegateLoading", true) - let delegates = await node.candidates() - let { validators } = await node.getValidators() + let delegates = await node.getValidators() + let validators = await node.getValidators() for (let delegate of delegates) { if (validators.find(v => v.pub_key === delegate.pub_key)) { delegate.isValidator = true diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 05a71510df..83249e31b1 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -7,7 +7,8 @@ export default ({ node }) => { // our delegations which are already on the blockchain committedDelegates: {}, - unbondingDelegations: {} + unbondingDelegations: {}, + delegationTxs: [] } const mutations = { @@ -61,28 +62,37 @@ export default ({ node }) => { let address = rootState.user.address candidates = candidates || (await dispatch("getDelegates")) let delegator = await node.getDelegator(address) - delegator.delegations.forEach(({ validator_addr, shares }) => { - commit("setCommittedDelegation", { - candidateId: validator_addr, - value: parseFloat(shares) - }) - if (shares > 0) { - const delegate = candidates.find( - ({ owner }) => owner === validator_addr // this should change to address instead of owner - ) - commit("addToCart", delegate) - } - }) - delegator.unbonding_delegations.forEach( - ({ validator_addr, balance: { amount } }) => { - commit("setUnbondingDelegation", { + if (delegator.delegations) { + delegator.delegations.forEach(({ validator_addr, shares }) => { + commit("setCommittedDelegation", { candidateId: validator_addr, - value: parseFloat(amount) + value: parseFloat(shares) }) - } - ) + if (shares > 0) { + const delegate = candidates.find( + ({ owner }) => owner === validator_addr // this should change to address instead of owner + ) + commit("addToCart", delegate) + } + }) + } + if (delegator.unbonding_delegations) { + delegator.unbonding_delegations.forEach( + ({ validator_addr, balance: { amount } }) => { + commit("setUnbondingDelegation", { + candidateId: validator_addr, + value: parseFloat(amount) + }) + } + ) + } state.loading = false }, + async getDelegationTxs({ state, rootState }) { + let address = rootState.user.address + let txs = await node.getDelegatorTxs(address) + state.delegationTxs = txs + }, async updateDelegates({ dispatch }) { let candidates = await dispatch("getDelegates") return dispatch("getBondedDelegates", candidates) diff --git a/app/src/renderer/vuex/modules/validators.js b/app/src/renderer/vuex/modules/validators.js index d464f038ab..ac802cb299 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -25,7 +25,7 @@ export default ({ node }) => { async getValidators({ state, commit }) { state.loading = true try { - let candidates = await node.candidates() + let candidates = await node.getValidators() commit("setValidators", candidates) } catch (err) { commit("notifyError", { diff --git a/app/src/renderer/vuex/modules/wallet.js b/app/src/renderer/vuex/modules/wallet.js index 2c2f46670b..0577fbe04b 100644 --- a/app/src/renderer/vuex/modules/wallet.js +++ b/app/src/renderer/vuex/modules/wallet.js @@ -68,7 +68,7 @@ export default ({ node }) => { }, queryWalletState({ dispatch }) { dispatch("queryWalletBalances") - dispatch("queryWalletHistory") + // dispatch("queryWalletHistory") // is done on mounting transactions }, async queryWalletBalances({ state, rootState, commit }) { let res = await node.queryAccount(state.address) diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index be3f4858ad..80c7fe351a 100755 --- a/tasks/build/Gaia/COMMIT.sh +++ b/tasks/build/Gaia/COMMIT.sh @@ -2,4 +2,4 @@ # This is the commit of the SDK version to use for building Gaia. We use an # explicit hash instead of a tag so we don't have to trust GitHub. -export COMMIT=9ee3d47dc63cadaa3a6a375542f05f396277e70d +export COMMIT=e0a8f0414c6feb6fc551713df056b0d312b14884 From dd65b7cf3f324f44223bf9944ec18645aab70fec Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Mon, 6 Aug 2018 21:44:49 +0200 Subject: [PATCH 09/23] txs and other stuff working --- app/src/main/index.js | 20 +- .../components/wallet/PageTransactions.vue | 38 ++- .../wallet/TmLiStakingTransaction.vue | 160 +++++++++++++ .../components/wallet/TmLiTransaction.vue | 219 ++++++++++++++++++ app/src/renderer/connectors/lcdClient.js | 2 +- app/src/renderer/vuex/modules/delegates.js | 8 +- app/src/renderer/vuex/modules/user.js | 2 +- app/src/renderer/vuex/modules/validators.js | 2 +- app/src/renderer/vuex/store.js | 6 +- 9 files changed, 428 insertions(+), 29 deletions(-) create mode 100644 app/src/renderer/components/wallet/TmLiStakingTransaction.vue create mode 100644 app/src/renderer/components/wallet/TmLiTransaction.vue diff --git a/app/src/main/index.js b/app/src/main/index.js index 696fa6166c..8fb2fc3497 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -580,13 +580,13 @@ async function pickAndConnect(addressbook) { return await pickAndConnect(addressbook) } - if (!compatible) { - let message = `Node ${nodeIP} uses SDK version ${nodeVersion} which is incompatible to the version used in Voyager ${expectedGaiaCliVersion}` - log(message) - mainWindow.webContents.send("connection-status", message) + // if (!compatible) { + // let message = `Node ${nodeIP} uses SDK version ${nodeVersion} which is incompatible to the version used in Voyager ${expectedGaiaCliVersion}` + // log(message) + // mainWindow.webContents.send("connection-status", message) - return await pickAndConnect(addressbook) - } + // return await pickAndConnect(addressbook) + // } return nodeIP } @@ -708,10 +708,10 @@ async function main() { let compatible = semver.major(gaiacliVersion) == semver.major(expectedGaiaCliVersion) && semver.minor(gaiacliVersion) == semver.minor(expectedGaiaCliVersion) - if (!compatible) { - throw Error(`Requires gaia ${expectedGaiaCliVersion}, but got ${gaiacliVersion}. - Please update your gaiacli installation or build with a newer binary.`) - } + // if (!compatible) { + // throw Error(`Requires gaia ${expectedGaiaCliVersion}, but got ${gaiacliVersion}. + // Please update your gaiacli installation or build with a newer binary.`) + // } // read chainId from genesis.json let genesisText = fs.readFileSync(genesisPath, "utf8") diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 15bf543776..00d0d261db 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -11,12 +11,17 @@ tm-page(title='Transactions') tm-data-loading(v-if="wallet.historyLoading") data-empty-tx(v-else-if='transactions.length === 0') data-empty-search(v-else-if="filteredTransactions.length === 0") - tm-li-transaction( - v-else - v-for="i in filteredTransactions" - :key="shortid.generate()" - :transaction="i" - :address="wallet.address") + template(v-else v-for="i in filteredTransactions") + tm-li-transaction( + v-if="i.type === 'wallet'" + :key="shortid.generate()" + :transaction="i" + :address="wallet.address") + tm-li-staking-transaction( + v-if="i.type === 'staking'" + :key="shortid.generate()" + :transaction="i" + :address="wallet.address") + + diff --git a/app/src/renderer/components/wallet/TmLiTransaction.vue b/app/src/renderer/components/wallet/TmLiTransaction.vue new file mode 100644 index 0000000000..57e8f15a0a --- /dev/null +++ b/app/src/renderer/components/wallet/TmLiTransaction.vue @@ -0,0 +1,219 @@ + + + + + diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 92886bbe6e..35013d10e3 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -120,7 +120,7 @@ Object.assign(Client.prototype, { // }, // Get a list containing all the validator candidates - getValidators: req("GET", "/stake/validators/"), + getValidators: req("GET", "/stake/validators"), // Get information from a validator getValidator: function(addr) { return req("GET", `/stake/validators/${addr}`).call(this) diff --git a/app/src/renderer/vuex/modules/delegates.js b/app/src/renderer/vuex/modules/delegates.js index 493bc0e789..ec1c4fbe27 100644 --- a/app/src/renderer/vuex/modules/delegates.js +++ b/app/src/renderer/vuex/modules/delegates.js @@ -38,16 +38,16 @@ export default ({ node }) => { }, async getDelegates({ state, commit }) { commit("setDelegateLoading", true) - let delegates = await node.getValidators() - let validators = await node.getValidators() - for (let delegate of delegates) { + let candidates = await node.getValidators() + let { validators } = await node.getValidatorSet() + for (let delegate of candidates) { if (validators.find(v => v.pub_key === delegate.pub_key)) { delegate.isValidator = true } commit("addDelegate", delegate) } - commit("setDelegates", delegates) + commit("setDelegates", candidates) commit("setDelegateLoading", false) return state.delegates diff --git a/app/src/renderer/vuex/modules/user.js b/app/src/renderer/vuex/modules/user.js index 391643beca..60a37e9b63 100644 --- a/app/src/renderer/vuex/modules/user.js +++ b/app/src/renderer/vuex/modules/user.js @@ -109,7 +109,7 @@ export default ({ node }) => { let { address } = await node.getKey(account) state.address = address - commit("loadPersistedState", { account, password }) + commit("loadPersistedState", { address, password }) commit("setModalSession", false) dispatch("initializeWallet", address) dispatch("loadErrorCollection", account) diff --git a/app/src/renderer/vuex/modules/validators.js b/app/src/renderer/vuex/modules/validators.js index ac802cb299..0eef83a0ae 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -25,7 +25,7 @@ export default ({ node }) => { async getValidators({ state, commit }) { state.loading = true try { - let candidates = await node.getValidators() + let candidates = await node.getValidatorSet() commit("setValidators", candidates) } catch (err) { commit("notifyError", { diff --git a/app/src/renderer/vuex/store.js b/app/src/renderer/vuex/store.js index 6c6fa9a9ce..1ca4037985 100644 --- a/app/src/renderer/vuex/store.js +++ b/app/src/renderer/vuex/store.js @@ -47,11 +47,11 @@ function persistState(state) { state.user.password ) // Store the state object as a JSON string - localStorage.setItem("store_" + state.user.account, encryptedState) + localStorage.setItem("store_" + state.user.address, encryptedState) } -function loadPersistedState(state, { account, password }) { - const cachedState = localStorage.getItem("store_" + account) +function loadPersistedState(state, { address, password }) { + const cachedState = localStorage.getItem("store_" + address) if (cachedState) { const bytes = CryptoJS.AES.decrypt(cachedState, password) const plaintext = bytes.toString(CryptoJS.enc.Utf8) From 18fa2608030fd87925d53282e83c7ae84817c759 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 13:29:24 +0200 Subject: [PATCH 10/23] fixed some tests --- app/src/main/index.js | 20 ++++++------- .../components/wallet/PageTransactions.vue | 2 +- .../wallet/TmLiStakingTransaction.vue | 2 +- app/src/renderer/connectors/lcdClient.js | 2 +- app/src/renderer/connectors/lcdClientMock.js | 6 ++-- app/src/renderer/vuex/modules/delegates.js | 2 +- app/src/renderer/vuex/modules/delegation.js | 12 +++++--- app/src/renderer/vuex/modules/node.js | 4 +-- app/src/renderer/vuex/modules/validators.js | 8 +++--- .../__snapshots__/PageStaking.spec.js.snap | 4 +-- .../wallet/PageTransactions.spec.js | 2 ++ .../__snapshots__/delegation.spec.js.snap | 15 +++++----- test/unit/specs/store/delegation.spec.js | 28 ------------------- test/unit/specs/store/node.spec.js | 2 +- test/unit/specs/store/store.spec.js | 5 +++- test/unit/specs/store/validators.spec.js | 8 +++--- 16 files changed, 52 insertions(+), 70 deletions(-) diff --git a/app/src/main/index.js b/app/src/main/index.js index 8fb2fc3497..696fa6166c 100644 --- a/app/src/main/index.js +++ b/app/src/main/index.js @@ -580,13 +580,13 @@ async function pickAndConnect(addressbook) { return await pickAndConnect(addressbook) } - // if (!compatible) { - // let message = `Node ${nodeIP} uses SDK version ${nodeVersion} which is incompatible to the version used in Voyager ${expectedGaiaCliVersion}` - // log(message) - // mainWindow.webContents.send("connection-status", message) + if (!compatible) { + let message = `Node ${nodeIP} uses SDK version ${nodeVersion} which is incompatible to the version used in Voyager ${expectedGaiaCliVersion}` + log(message) + mainWindow.webContents.send("connection-status", message) - // return await pickAndConnect(addressbook) - // } + return await pickAndConnect(addressbook) + } return nodeIP } @@ -708,10 +708,10 @@ async function main() { let compatible = semver.major(gaiacliVersion) == semver.major(expectedGaiaCliVersion) && semver.minor(gaiacliVersion) == semver.minor(expectedGaiaCliVersion) - // if (!compatible) { - // throw Error(`Requires gaia ${expectedGaiaCliVersion}, but got ${gaiacliVersion}. - // Please update your gaiacli installation or build with a newer binary.`) - // } + if (!compatible) { + throw Error(`Requires gaia ${expectedGaiaCliVersion}, but got ${gaiacliVersion}. + Please update your gaiacli installation or build with a newer binary.`) + } // read chainId from genesis.json let genesisText = fs.readFileSync(genesisPath, "utf8") diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 00d0d261db..71e1a12c94 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -9,7 +9,7 @@ tm-page(title='Transactions') modal-search(type="transactions" v-if="somethingToSearch") tm-data-loading(v-if="wallet.historyLoading") - data-empty-tx(v-else-if='transactions.length === 0') + data-empty-tx(v-else-if='allTransactions.length === 0') data-empty-search(v-else-if="filteredTransactions.length === 0") template(v-else v-for="i in filteredTransactions") tm-li-transaction( diff --git a/app/src/renderer/components/wallet/TmLiStakingTransaction.vue b/app/src/renderer/components/wallet/TmLiStakingTransaction.vue index b2179585d7..e557cb4ddc 100644 --- a/app/src/renderer/components/wallet/TmLiStakingTransaction.vue +++ b/app/src/renderer/components/wallet/TmLiStakingTransaction.vue @@ -15,7 +15,7 @@ .tx-container .tx-element.tx-coins .tx-coin - .key Steak + .key STEAK .value {{ pretty(tx.shares_amount) }} div .tx-element.tx-date(v-if="devMode") {{ date }} diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 35013d10e3..c6b966c923 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -120,7 +120,7 @@ Object.assign(Client.prototype, { // }, // Get a list containing all the validator candidates - getValidators: req("GET", "/stake/validators"), + getCandidates: req("GET", "/stake/validators"), // Get information from a validator getValidator: function(addr) { return req("GET", `/stake/validators/${addr}`).call(this) diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index 8b6f3e8677..df77f90dae 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -386,7 +386,7 @@ module.exports = { }, // Get all delegations information from a delegator getDelegator(delegatorAddress) { - let delegator = state.stake[delegatorAddress] + let delegator = state.stake[delegatorAddress] || {} return delegator }, getDelegatorTxs(addr, types) { @@ -395,10 +395,10 @@ module.exports = { async getDelegatorTx(addr, id) { return {} // not used }, - async getValidators() { + async getCandidates() { return state.candidates }, - async getValidatorset() { + async getValidatorSet() { return { block_height: 1, validators: state.candidates diff --git a/app/src/renderer/vuex/modules/delegates.js b/app/src/renderer/vuex/modules/delegates.js index ec1c4fbe27..2ef8eca4a5 100644 --- a/app/src/renderer/vuex/modules/delegates.js +++ b/app/src/renderer/vuex/modules/delegates.js @@ -38,7 +38,7 @@ export default ({ node }) => { }, async getDelegates({ state, commit }) { commit("setDelegateLoading", true) - let candidates = await node.getValidators() + let candidates = await node.getCandidates() let { validators } = await node.getValidatorSet() for (let delegate of candidates) { if (validators.find(v => v.pub_key === delegate.pub_key)) { diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 83249e31b1..706e5d132d 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -47,7 +47,8 @@ export default ({ node }) => { unbondingDelegations[candidateId] = value } state.unbondingDelegations = unbondingDelegations - } + }, + setDelegationTxs(state, txs) {} } let actions = { @@ -57,7 +58,10 @@ export default ({ node }) => { } }, // load committed delegations from LCD - async getBondedDelegates({ state, rootState, commit }, candidates) { + async getBondedDelegates( + { state, rootState, commit, dispatch }, + candidates + ) { state.loading = true let address = rootState.user.address candidates = candidates || (await dispatch("getDelegates")) @@ -88,10 +92,10 @@ export default ({ node }) => { } state.loading = false }, - async getDelegationTxs({ state, rootState }) { + async getDelegationTxs({ commit, rootState }) { let address = rootState.user.address let txs = await node.getDelegatorTxs(address) - state.delegationTxs = txs + commit("setDelegationTxs", txs) }, async updateDelegates({ dispatch }) { let candidates = await dispatch("getDelegates") diff --git a/app/src/renderer/vuex/modules/node.js b/app/src/renderer/vuex/modules/node.js index 39f0b781b0..ea585e6370 100644 --- a/app/src/renderer/vuex/modules/node.js +++ b/app/src/renderer/vuex/modules/node.js @@ -36,7 +36,7 @@ export default function({ node }) { } const actions = { - setLastHeader({ state, rootState, dispatch }, header) { + async setLastHeader({ state, rootState, dispatch }, header) { state.lastHeader = header // TODO do this somewhere else probably @@ -44,7 +44,7 @@ export default function({ node }) { rootState.wallet.zoneIds.unshift(header.chain_id) } - dispatch("maybeUpdateValidators", header) + await dispatch("maybeUpdateValidators", header) }, async reconnect({ commit }) { if (state.stopConnecting) return diff --git a/app/src/renderer/vuex/modules/validators.js b/app/src/renderer/vuex/modules/validators.js index 0eef83a0ae..8e112531ea 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -25,8 +25,8 @@ export default ({ node }) => { async getValidators({ state, commit }) { state.loading = true try { - let candidates = await node.getValidatorSet() - commit("setValidators", candidates) + let validators = (await node.getValidatorSet()).validators + commit("setValidators", validators) } catch (err) { commit("notifyError", { title: "Error fetching validator set", @@ -35,11 +35,11 @@ export default ({ node }) => { } state.loading = false }, - maybeUpdateValidators({ state, commit, dispatch }, header) { + async maybeUpdateValidators({ state, commit, dispatch }, header) { let validatorHash = header.validators_hash if (validatorHash === state.validatorHash) return commit("setValidatorHash", validatorHash) - dispatch("getValidators") + await dispatch("getValidators") } } 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 21fa44acab..92faeb6bfb 100644 --- a/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/PageStaking.spec.js.snap @@ -100,7 +100,7 @@ exports[`PageStaking has the expected html structure 1`] = `
- 130 + 14
Validator @@ -392,7 +392,7 @@ exports[`PageStaking should filter the delegates 1`] = ` class="li-delegate__value your-votes" > - 130 + 14
{ let instance = mount(PageTransactions, { stubs: { "tm-li-transaction": "", + "tm-li-staking-transaction": "", "data-empty-tx": "" } }) @@ -17,6 +18,7 @@ describe("PageTransactions", () => { store.commit("setWalletAddress", "tb1d4u5zerywfjhxuc9nudvw") store.commit("setWalletHistory", mockTransactions) + store.commit("setDelegationTxs", []) wrapper.update() }) diff --git a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap index 7d64413859..fe32c9502c 100644 --- a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap +++ b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap @@ -2,8 +2,7 @@ exports[`Module: Delegations fetches bonded delegates 1`] = ` Object { - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au": "15", - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": "10", + "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": 14, } `; @@ -14,15 +13,17 @@ Array [ Array [ Object { "account_number": "1", - "begin_unbondings": Array [ + "begin_unbondings": Array [], + "chain_id": "test-chain", + "delegations": Array [ Object { + "delegation": Object { + "amount": "109", + "denom": "steak", + }, "delegator_addr": "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", - "shares": "7", "validator_addr": "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw", }, - ], - "chain_id": "test-chain", - "delegations": Array [ Object { "delegation": Object { "amount": "456", diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index 63803270c6..dfc9cad581 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -64,35 +64,7 @@ describe("Module: Delegations", () => { }) it("fetches bonded delegates", async () => { - node.queryDelegation = jest - .fn() - .mockReturnValueOnce({ - shares: "10" - }) - .mockReturnValueOnce({ - shares: "15" - }) - // no delegation for a delegate - .mockReturnValueOnce(null) - await store.dispatch("getBondedDelegates", store.state.delegates.delegates) - - // each is user account + validator owner - expect(node.queryDelegation.mock.calls).toEqual([ - [ - "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw" - ], - [ - "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au" - ], - [ - "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctgurrg7n" - ] - ]) - expect(store.state.delegation.committedDelegates).toMatchSnapshot() }) diff --git a/test/unit/specs/store/node.spec.js b/test/unit/specs/store/node.spec.js index 6dc96e2003..1ebbba4c5b 100644 --- a/test/unit/specs/store/node.spec.js +++ b/test/unit/specs/store/node.spec.js @@ -35,7 +35,7 @@ describe("Module: Node", () => { }) it("checks for new validators", done => { - node.rpc.validators = () => done() + node.getValidatorSet = () => done() store.dispatch("setLastHeader", { height: 5, chain_id: "test-chain", diff --git a/test/unit/specs/store/store.spec.js b/test/unit/specs/store/store.spec.js index fc47236755..63c5c0d039 100644 --- a/test/unit/specs/store/store.spec.js +++ b/test/unit/specs/store/store.spec.js @@ -1,5 +1,6 @@ import Store from "renderer/vuex/store" import node from "../../helpers/node_mock" +import lcdClientMock from "renderer/connectors/lcdClientMock.js" describe("Store", () => { let store @@ -18,7 +19,9 @@ describe("Store", () => { password: "1234567890" }) store.commit("setWalletBalances", [{ denom: "fabocoin", amount: 42 }]) - expect(localStorage.getItem("store_default")).toBeTruthy() + expect( + localStorage.getItem("store_" + lcdClientMock.addresses[0]) + ).toBeTruthy() }) it("should restore balances et al after logging in", async () => { diff --git a/test/unit/specs/store/validators.spec.js b/test/unit/specs/store/validators.spec.js index 946f8993f4..3be4d6f714 100644 --- a/test/unit/specs/store/validators.spec.js +++ b/test/unit/specs/store/validators.spec.js @@ -34,8 +34,8 @@ describe("Module: Validators", () => { }) it("should query validators", async () => { - store.dispatch("getValidators") - expect(store.state.validators.validators).toHaveLength(6) + await store.dispatch("getValidators") + expect(store.state.validators.validators).toHaveLength(3) }) it("should survive errors in querying validators", async () => { @@ -69,9 +69,9 @@ describe("Module: Validators", () => { jest.resetModules() store.state.node.stopConnecting = true store.state.validators.loading = true - jest.spyOn(node.rpc, "validators") + jest.spyOn(node, "getValidatorSet") store.dispatch("reconnected") - expect(node.rpc.validators).toHaveBeenCalled() + expect(node.getValidatorSet).toHaveBeenCalled() }) it("should not query validators on reconnection if not stuck in loading", () => { From 6fbd396430878b6ced8395e27aa3b7f19a0022f1 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 13:30:51 +0200 Subject: [PATCH 11/23] linted --- app/src/renderer/connectors/lcdClientMock.js | 6 ++++-- app/src/renderer/vuex/modules/delegation.js | 4 +++- app/src/renderer/vuex/modules/validators.js | 2 -- test/unit/specs/store/delegation.spec.js | 3 +-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index df77f90dae..60ebe5d4a2 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -389,10 +389,12 @@ module.exports = { let delegator = state.stake[delegatorAddress] || {} return delegator }, - getDelegatorTxs(addr, types) { + getDelegatorTxs() { + // input addr, types return [] // TODO }, - async getDelegatorTx(addr, id) { + async getDelegatorTx() { + // input addr, id return {} // not used }, async getCandidates() { diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 706e5d132d..4bbd06453d 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -48,7 +48,9 @@ export default ({ node }) => { } state.unbondingDelegations = unbondingDelegations }, - setDelegationTxs(state, txs) {} + setDelegationTxs(state, txs) { + state.delegationTxs = txs + } } let actions = { diff --git a/app/src/renderer/vuex/modules/validators.js b/app/src/renderer/vuex/modules/validators.js index 8e112531ea..f74bfa7dfd 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -1,5 +1,3 @@ -import b32 from "scripts/b32" - export default ({ node }) => { const state = { validators: [], diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index dfc9cad581..9239b24a59 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -3,12 +3,11 @@ import setup from "../../helpers/vuex-setup" let instance = setup() describe("Module: Delegations", () => { - let store, node + let store beforeEach(async () => { let test = instance.shallow() store = test.store - node = test.node store.dispatch("signIn", { password: "bar", account: "default" }) await store.dispatch("getDelegates") From 60d3bccfb9a7ac0207e9922bdf72f5c9b0303b66 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 13:40:00 +0200 Subject: [PATCH 12/23] fixed lcd mock tests --- app/src/renderer/connectors/lcdClientMock.js | 6 +++-- .../__snapshots__/lcdClientMock.spec.js.snap | 4 ++-- test/unit/specs/lcdClientMock.spec.js | 22 +++++++++---------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index 60ebe5d4a2..406310cf13 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -376,8 +376,10 @@ module.exports = { }, async queryDelegation(delegatorAddress, validatorAddress) { let delegator = state.stake[delegatorAddress] - if (!delegator) return - return delegator[validatorAddress].delegation + if (!delegator) return {} + return delegator.delegations.find( + ({ validator_addr }) => validator_addr === validatorAddress + ) }, async queryUnbonding(delegatorAddress, validatorAddress) { let delegator = state.stake[delegatorAddress] diff --git a/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap b/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap index cd6a39cd30..3028ce00dc 100644 --- a/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap +++ b/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap @@ -2,10 +2,10 @@ exports[`LCD Client Mock delegates to multiple validators at once 1`] = `"10"`; -exports[`LCD Client Mock delegates to multiple validators at once 2`] = `"140"`; +exports[`LCD Client Mock delegates to multiple validators at once 2`] = `"24"`; exports[`LCD Client Mock deletes keys 1`] = `[Error: Passwords do not match]`; -exports[`LCD Client Mock queries bondings per delegator 1`] = `"130"`; +exports[`LCD Client Mock queries bondings per delegator 1`] = `"14"`; exports[`LCD Client Mock updates keys 1`] = `[Error: Passwords do not match]`; diff --git a/test/unit/specs/lcdClientMock.spec.js b/test/unit/specs/lcdClientMock.spec.js index 3c315d7716..25c3347106 100644 --- a/test/unit/specs/lcdClientMock.spec.js +++ b/test/unit/specs/lcdClientMock.spec.js @@ -255,7 +255,7 @@ describe("LCD Client Mock", () => { }) it("queries for all candidates", async () => { - let data = await client.candidates() + let data = await client.getCandidates() expect(data.length).toBeGreaterThan(0) }) @@ -274,7 +274,7 @@ describe("LCD Client Mock", () => { ) expect(stake).toBeUndefined() - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -298,7 +298,7 @@ describe("LCD Client Mock", () => { }) it("executes an unbond tx", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -320,7 +320,7 @@ describe("LCD Client Mock", () => { ) expect(initialStake.shares).toBe("10") - res = await client.updateDelegations({ + res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 2, name: "default", delegations: [], @@ -344,7 +344,7 @@ describe("LCD Client Mock", () => { }) it("can not stake fermions you dont have", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -362,7 +362,7 @@ describe("LCD Client Mock", () => { }) it("errors when delegating with incorrect nonce", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -378,7 +378,7 @@ describe("LCD Client Mock", () => { expect(res[0].check_tx.log).toBe("") expect(res[0].check_tx.code).toBe(0) - res = await client.updateDelegations({ + res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -401,7 +401,7 @@ describe("LCD Client Mock", () => { password: "1234567890", address: lcdClientMock.addresses[1] }) - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "nonexistent_account", delegations: [ @@ -419,7 +419,7 @@ describe("LCD Client Mock", () => { }) it("delegates to multiple validators at once", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -456,7 +456,7 @@ describe("LCD Client Mock", () => { }) it("errors when delegating negative amount", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [ @@ -474,7 +474,7 @@ describe("LCD Client Mock", () => { }) it("errors when unbonding with no delegation", async () => { - let res = await client.updateDelegations({ + let res = await client.updateDelegations(lcdClientMock.addresses[0], { sequence: 1, name: "default", delegations: [], From 82e2d99eca1df31d8a4fc7c0b6c8bbec51055d43 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 13:40:52 +0200 Subject: [PATCH 13/23] fixed lcdclient test --- test/unit/specs/__snapshots__/lcdClient.spec.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap index 72925727b2..3d484c159a 100644 --- a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap +++ b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap @@ -3,7 +3,7 @@ exports[`LCD Client queries for shares for a validator and delegate 1`] = ` Array [ Array [ - "http://localhost:8998/stake/abc/delegation/efg", + "http://localhost:8998/stake/delegators/abc/delegations/efg", undefined, ], ] From d2ac59734df619e9e2f249692cb6538a012573f9 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 14:14:26 +0200 Subject: [PATCH 14/23] fixed pagetranscation test --- .../components/wallet/PageTransactions.vue | 2 +- test/unit/helpers/vuex-setup.js | 11 +++++--- .../wallet/PageTransactions.spec.js | 27 ++++++++----------- .../PageTransactions.spec.js.snap | 4 +++ test/unit/specs/store/json/txs.js | 6 ++--- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 71e1a12c94..546fbc1d1a 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -57,7 +57,7 @@ export default { "delegation" ]), somethingToSearch() { - return !this.wallet.historyLoading && !!this.transactions.length + return !this.wallet.historyLoading && !!this.allTransactions.length }, allTransactions() { return [].concat( diff --git a/test/unit/helpers/vuex-setup.js b/test/unit/helpers/vuex-setup.js index 7fe8d0ae87..b6c971a5e7 100644 --- a/test/unit/helpers/vuex-setup.js +++ b/test/unit/helpers/vuex-setup.js @@ -16,7 +16,7 @@ export default function vuexSetup() { function init( componentConstructor, testType = shallow, - { stubs, getters = {}, propsData, doBefore = () => {} } // doBefore receives router and store + { stubs, getters = {}, propsData, methods, doBefore = () => {} } // doBefore receives router and store ) { const node = Object.assign({}, require("../helpers/node_mock")) const modules = Modules({ node }) @@ -58,7 +58,8 @@ export default function vuexSetup() { store, router, stubs, - propsData + propsData, + methods }) } } @@ -67,22 +68,24 @@ export default function vuexSetup() { localVue, shallow: ( componentConstructor, - { stubs, getters, propsData, doBefore } = {} + { stubs, getters, propsData, methods, doBefore } = {} ) => init(componentConstructor, shallow, { stubs, getters, propsData, + methods, doBefore }), mount: ( componentConstructor, - { stubs, getters, propsData, doBefore } = {} + { stubs, getters, propsData, methods, doBefore } = {} ) => init(componentConstructor, mount, { stubs, getters, propsData, + methods, doBefore }) } diff --git a/test/unit/specs/components/wallet/PageTransactions.spec.js b/test/unit/specs/components/wallet/PageTransactions.spec.js index bc076c0da1..91758c87de 100644 --- a/test/unit/specs/components/wallet/PageTransactions.spec.js +++ b/test/unit/specs/components/wallet/PageTransactions.spec.js @@ -5,12 +5,15 @@ import mockTransactions from "../../store/json/txs.js" describe("PageTransactions", () => { let wrapper, store let { mount } = setup() - beforeEach(() => { + beforeEach(async () => { let instance = mount(PageTransactions, { stubs: { "tm-li-transaction": "", "tm-li-staking-transaction": "", "data-empty-tx": "" + }, + methods: { + refreshTransactions: jest.fn() } }) wrapper = instance.wrapper @@ -43,11 +46,12 @@ describe("PageTransactions", () => { }) it("should refresh the transaction history", () => { + wrapper.vm.refreshTransactions = jest.fn() wrapper .findAll(".tm-tool-bar i") .at(0) .trigger("click") - expect(store.dispatch).toHaveBeenCalledWith("queryWalletHistory") + expect(wrapper.vm.refreshTransactions).toHaveBeenCalled() }) it("should show transactions", () => { @@ -56,9 +60,9 @@ describe("PageTransactions", () => { it("should sort the transaction by time", () => { expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([ - "3466", - "3438", - "3436" + 3438, + 3436, + 466 ]) }) @@ -66,20 +70,11 @@ describe("PageTransactions", () => { store.commit("setSearchVisible", ["transactions", true]) store.commit("setSearchQuery", ["transactions", "fabo"]) wrapper.update() - expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual(["3466"]) + expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([466]) // reflects the filter in the view expect(wrapper.vm.$el).toMatchSnapshot() store.commit("setSearchQuery", ["transactions", "mattc"]) - expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual(["3466"]) - }) - - it("should refresh the transactions on click", () => { - wrapper - .findAll(".tm-tool-bar i") - .at(0) - .trigger("click") - - expect(store.dispatch).toHaveBeenCalledWith("queryWalletHistory") + expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([466]) }) it("should update 'somethingToSearch' when there's nothing to search", () => { diff --git a/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap b/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap index 21d30ab532..0465cef6c0 100644 --- a/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap +++ b/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap @@ -100,14 +100,17 @@ exports[`PageTransactions has the expected html structure 1`] = ` address="tb1d4u5zerywfjhxuc9nudvw" transaction="[object Object]" /> + + +
+
`; diff --git a/test/unit/specs/store/json/txs.js b/test/unit/specs/store/json/txs.js index 2d320b23c6..44e06c1a7d 100644 --- a/test/unit/specs/store/json/txs.js +++ b/test/unit/specs/store/json/txs.js @@ -1,7 +1,7 @@ module.exports = [ { hash: "not a real hash", - time: Date.now(), // set by Voyager + time: Date.now() + 1000, // set by Voyager height: "3436", tx: { type: "8EFE47F0625DE8", @@ -79,7 +79,7 @@ module.exports = [ }, { hash: "not a real hash2", - time: Date.now() + 10, // set by Voyager + time: Date.now() + 1010, // set by Voyager height: "3438", tx: { type: "8EFE47F0625DE8", @@ -160,7 +160,7 @@ module.exports = [ hash: "not a real hash3", time: Date.now() + 100, // set by Voyager - height: "3466", + height: "466", tx: { type: "8EFE47F0625DE8", value: { From e75045e8ab6b4e843fe0e795e53449ce6708bebb Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Tue, 7 Aug 2018 14:21:06 +0200 Subject: [PATCH 15/23] fixed app header tests (sideeffect) --- app/src/renderer/components/common/AppHeader.vue | 6 ++++-- test/unit/specs/components/common/AppHeader.spec.js | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/renderer/components/common/AppHeader.vue b/app/src/renderer/components/common/AppHeader.vue index 0e189ce8dc..d8f3c212b5 100644 --- a/app/src/renderer/components/common/AppHeader.vue +++ b/app/src/renderer/components/common/AppHeader.vue @@ -44,6 +44,8 @@ export default { document.documentElement.clientWidth, window.innerWidth || 0 ) + + console.log("called") if (w >= 1024) { this.close() this.$store.commit("setConfigDesktop", true) @@ -65,6 +67,7 @@ export default { #app-header z-index z(appHeader) + .container -webkit-app-region drag @@ -85,7 +88,6 @@ export default { top 0 left 0 width 100% - background var(--app-bg) > .container @@ -103,7 +105,6 @@ export default { align-items center justify-content center padding 0 1rem - color var(--link) cursor pointer @@ -131,6 +132,7 @@ export default { border-bottom px solid var(--bc) padding 2.5rem 1rem 1rem 1rem line-height normal + img height 1.75rem diff --git a/test/unit/specs/components/common/AppHeader.spec.js b/test/unit/specs/components/common/AppHeader.spec.js index d03615efe3..0da3326809 100644 --- a/test/unit/specs/components/common/AppHeader.spec.js +++ b/test/unit/specs/components/common/AppHeader.spec.js @@ -8,8 +8,7 @@ describe("AppHeader", () => { beforeEach(() => { instance = mount(AppHeader, { - stubs: { "app-menu": "" }, - methods: { watchWindowSize: () => {} } + stubs: { "app-menu": "" } }) wrapper = instance.wrapper store = instance.store From ed7042bb44c5c75b8761bb6498aaf1799403f52c Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 11:18:49 +0200 Subject: [PATCH 16/23] fixed wrong indexing command --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5309ac70d6..b7f1e9bf9f 100644 --- a/README.md +++ b/README.md @@ -182,7 +182,7 @@ $ sed -i.bak 's/seeds = ""/seeds = "localhost"/g' ./builds/testnets/local-testne Activate TX indexing in your local node: ```bash -$ sed -i.bak 's/index_all_tags = true/index_all_tags = false/g' ./builds/testnets/local-testnet/config.toml +$ sed -i.bak 's/index_all_tags = false/index_all_tags = true/g' ~/.gaiad-testnet/config/config.toml ``` Store the gaia version used in your local testnet: @@ -201,6 +201,7 @@ Then run Voyager for your local testnet: ```bash $ yarn start local-testnet +carry brush trumpet garbage raise host such worth power evolve coyote method bachelor sun isolate nominee infant reject away three detail olive opera document ``` Import the account with the 12 word seed phrase you wrote down earlier. From c01a5a8b61806c430b242ff7b134fa024d589d4d Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 11:19:12 +0200 Subject: [PATCH 17/23] added lcdclient mock tests --- .../renderer/components/common/AppHeader.vue | 1 - app/src/renderer/connectors/lcdClient.js | 2 +- app/src/renderer/connectors/lcdClientMock.js | 96 ++++++++++--------- test/unit/specs/lcdClientMock.spec.js | 72 ++++++++++++++ 4 files changed, 126 insertions(+), 45 deletions(-) diff --git a/app/src/renderer/components/common/AppHeader.vue b/app/src/renderer/components/common/AppHeader.vue index d8f3c212b5..7c0a630be4 100644 --- a/app/src/renderer/components/common/AppHeader.vue +++ b/app/src/renderer/components/common/AppHeader.vue @@ -45,7 +45,6 @@ export default { window.innerWidth || 0 ) - console.log("called") if (w >= 1024) { this.close() this.$store.commit("setConfigDesktop", true) diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index c6b966c923..9550f676fd 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -122,7 +122,7 @@ Object.assign(Client.prototype, { // Get a list containing all the validator candidates getCandidates: req("GET", "/stake/validators"), // Get information from a validator - getValidator: function(addr) { + getCandidate: function(addr) { return req("GET", `/stake/validators/${addr}`).call(this) }, // // Get all of the validator bonded delegators diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index 406310cf13..1ab789c15e 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -48,6 +48,7 @@ let state = { value: { msg: [ { + type: "cosmos-sdk/Send", value: { inputs: [ { @@ -84,6 +85,7 @@ let state = { value: { msg: [ { + type: "cosmos-sdk/Send", value: { inputs: [ { @@ -239,8 +241,8 @@ module.exports = { ) }) }, - async tx() { - return {} + async tx(hash) { + return state.txs.find(tx => tx.hash === hash) }, async send(to, req) { let fromKey = state.keys.find(a => a.name === req.name) @@ -328,6 +330,7 @@ module.exports = { parseInt(candidate.delegator_shares) + amount ).toString() + storeTx("cosmos-sdk/MsgDelegate", tx) results.push(txResult(0)) } @@ -359,16 +362,9 @@ module.exports = { let candidate = state.candidates.find(c => c.owner === tx.validator_addr) shares = parseInt(candidate.tokens) candidate.tokens = (+shares - amount).toString() - delegator.unbonding_delegations.push({ - validator_addr: tx.validator_addr, - delegator_addr: fromKey.address, - balance: { - // TODO - denom: "steak", - amount: amount - } - }) + delegator.unbonding_delegations.push(tx) + storeTx("cosmos-sdk/BeginUnbonding", tx) results.push(txResult(0)) } @@ -384,20 +380,25 @@ module.exports = { async queryUnbonding(delegatorAddress, validatorAddress) { let delegator = state.stake[delegatorAddress] if (!delegator) return - return delegator[validatorAddress].undelegation + return delegator.unbonding_delegations.find( + d => d.validator_addr === validatorAddress + ) }, // Get all delegations information from a delegator getDelegator(delegatorAddress) { let delegator = state.stake[delegatorAddress] || {} return delegator }, - getDelegatorTxs() { - // input addr, types - return [] // TODO + getDelegatorTxs(addr, types = []) { + if (types.length === 0) types = ["bonding", "unbonding"] + types = types.map(type => { + if (type === "bonding") return "cosmos-sdk/MsgDelegate" + if (type === "unbonding") return "cosmos-sdk/BeginUnbonding" + }) + return getTxs(types) }, - async getDelegatorTx() { - // input addr, id - return {} // not used + async getDelegatorTx(addr, hash) { + module.exports.tx(hash) }, async getCandidates() { return state.candidates @@ -408,7 +409,7 @@ module.exports = { validators: state.candidates } }, - async getValidator(addr) { + async getCandidate(addr) { return state.candidates.find(c => c.owner === addr) }, // exports to be used in tests @@ -481,43 +482,52 @@ function send(to, from, req) { } // log tx + storeTx("cosmos-sdk/Send", { + inputs: [ + { + coins: req.amount, + address: from + } + ], + outputs: [ + { + coins: req.amount, + address: to + } + ] + }) + + // if receiver is bot address, send money back + if (to === botAddress) { + send(from, botAddress, { + amount: req.amount, + sequence: state.accounts[botAddress].sequence + }) + } + + return txResult(0) +} + +function storeTx(type, body) { state.txs.push({ tx: { value: { msg: [ { - value: { - inputs: [ - { - coins: req.amount, - address: from - } - ], - outputs: [ - { - coins: req.amount, - address: to - } - ] - } + type, + value: body } ] } }, hash: makeHash(), - height: getHeight() + (from === botAddress ? 1 : 0), + height: getHeight(), time: Date.now() }) +} - // if receiver is bot address, send money back - if (to === botAddress) { - send(from, botAddress, { - amount: req.amount, - sequence: state.accounts[botAddress].sequence - }) - } - - return txResult(0) +function getTxs(types) { + return state.txs.filter(tx => types.indexOf(tx.tx.value.msg[0].type) !== -1) } // function delegate (sender, { pub_key: { data: pubKey }, amount: delegation }) { diff --git a/test/unit/specs/lcdClientMock.spec.js b/test/unit/specs/lcdClientMock.spec.js index 25c3347106..0117320a66 100644 --- a/test/unit/specs/lcdClientMock.spec.js +++ b/test/unit/specs/lcdClientMock.spec.js @@ -259,6 +259,15 @@ describe("LCD Client Mock", () => { expect(data.length).toBeGreaterThan(0) }) + it("queries for one candidate", async () => { + let validator = await client.getCandidate(lcdClientMock.validators[0]) + expect(validator).toBe( + lcdClientMock.state.candidates.find( + v => v.owner === lcdClientMock.validators[0] + ) + ) + }) + it("queries bondings per delegator", async () => { let res = await client.queryDelegation( lcdClientMock.addresses[0], @@ -490,4 +499,67 @@ describe("LCD Client Mock", () => { expect(res[0].check_tx.log).toBe("Nonexistent delegation") expect(res[0].check_tx.code).toBe(2) }) + + it("queries for summary of delegation information for a delegator", async () => { + let delegation = await client.getDelegator(lcdClientMock.addresses[0]) + expect(Object.keys(delegation)).toEqual([ + "delegations", + "unbonding_delegations" + ]) + }) + + it("queries for an unbonding delegation between a validator and a delegator", async () => { + await client.updateDelegations(lcdClientMock.addresses[0], { + sequence: 1, + name: "default", + delegations: [], + begin_unbondings: [ + { + delegator_addr: lcdClientMock.addresses[0], + validator_addr: lcdClientMock.validators[0], + shares: "10" + } + ] + }) + let undelegations = await client.queryUnbonding( + lcdClientMock.addresses[0], + lcdClientMock.validators[0] + ) + + expect(undelegations.shares).toBe("10") + }) + + it("queries for staking txs", async () => { + await client.updateDelegations(lcdClientMock.addresses[0], { + sequence: 1, + name: "default", + delegations: [ + { + delegator_addr: lcdClientMock.addresses[0], + validator_addr: lcdClientMock.validators[2], + delegation: { denom: "mycoin", amount: "10" } + } + ], + begin_unbondings: [ + { + delegator_addr: lcdClientMock.addresses[0], + validator_addr: lcdClientMock.validators[0], + shares: "10" + } + ] + }) + let txs = await client.getDelegatorTxs(lcdClientMock.addresses[0]) + expect(txs).toHaveLength(2) + + txs = await client.getDelegatorTxs(lcdClientMock.addresses[0], ["bonding"]) + expect(txs).toHaveLength(1) + console.log(JSON.stringify(txs)) + expect(txs[0].tx.value.msg[0].type).toBe("cosmos-sdk/MsgDelegate") + + txs = await client.getDelegatorTxs(lcdClientMock.addresses[0], [ + "unbonding" + ]) + expect(txs).toHaveLength(1) + expect(txs[0].tx.value.msg[0].type).toBe("cosmos-sdk/BeginUnbonding") + }) }) From 105a4b942f2d5065437472dedd7bb07118f5a681 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 11:19:23 +0200 Subject: [PATCH 18/23] added merged commit --- tasks/build/Gaia/COMMIT.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index 80c7fe351a..dbff12b754 100755 --- a/tasks/build/Gaia/COMMIT.sh +++ b/tasks/build/Gaia/COMMIT.sh @@ -2,4 +2,4 @@ # This is the commit of the SDK version to use for building Gaia. We use an # explicit hash instead of a tag so we don't have to trust GitHub. -export COMMIT=e0a8f0414c6feb6fc551713df056b0d312b14884 +export COMMIT=7ba479e57a31a266aae069855ae6e4e26f58553e From 28c660d4c2bbefb826ab72704ede26a1e3e67b9c Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 12:03:27 +0200 Subject: [PATCH 19/23] fix e2e tests --- test/e2e/launch.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/e2e/launch.js b/test/e2e/launch.js index 42f6608124..41e9524a91 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -10,9 +10,24 @@ let fs = require("fs-extra") const testDir = join(__dirname, "../../testArtifacts") let app, cliHome, nodeHome, started, crashed -let binary = process.env.BINARY_PATH || process.env.GOPATH + "/bin/gaiacli" + +const osFolderName = (function() { + switch (process.platform) { + case "win32": + return "windows_amd64" + case "darwin": + return "darwin_amd64" + case "linux": + return "linux_amd64" + } +})() +let binary = + process.env.BINARY_PATH || + join(__dirname, "../../builds/gaia/", osFolderName, "gaiacli") + let nodeBinary = - process.env.NODE_BINARY_PATH || process.env.GOPATH + "/bin/gaiad" + process.env.NODE_BINARY_PATH || + join(__dirname, "../../builds/gaia/", osFolderName, "gaiad") /* * NOTE: don't use a global `let client = app.client` as the client object changes when restarting the app @@ -238,6 +253,9 @@ function initLocalNode() { const localnodeProcess = spawn(command, { shell: true }) localnodeProcess.stderr.pipe(process.stderr) + // the init command now asks for a password for some default account we don't need + localnodeProcess.stdin.write("\n") + localnodeProcess.stdout.once("data", data => { let msg = data.toString() From 3bbe5da6f38265576c2bf42de997a131c6d472f2 Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 12:04:30 +0200 Subject: [PATCH 20/23] using the commit of the delegation endpoint fix --- tasks/build/Gaia/COMMIT.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index dbff12b754..f097f53326 100755 --- a/tasks/build/Gaia/COMMIT.sh +++ b/tasks/build/Gaia/COMMIT.sh @@ -2,4 +2,4 @@ # This is the commit of the SDK version to use for building Gaia. We use an # explicit hash instead of a tag so we don't have to trust GitHub. -export COMMIT=7ba479e57a31a266aae069855ae6e4e26f58553e +export COMMIT=6d95d1cef47ec6806fba26e17ac63c7d387bb771 From e58935b4983427e1c18455617d52ee0cf43e053e Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 13:09:05 +0200 Subject: [PATCH 21/23] increased coverage --- app/src/renderer/connectors/lcdClient.js | 4 -- app/src/renderer/connectors/lcdClientMock.js | 11 ++-- app/src/renderer/vuex/modules/delegation.js | 4 +- .../__snapshots__/lcdClient.spec.js.snap | 35 ++++++++++++ .../specs/components/staking/PageBond.spec.js | 24 ++++---- .../__snapshots__/PageBond.spec.js.snap | 12 ++-- .../wallet/PageTransactions.spec.js | 55 +++++++++++++++++-- .../PageTransactions.spec.js.snap | 10 ++++ test/unit/specs/lcdClient.spec.js | 20 +++++++ test/unit/specs/lcdClientMock.spec.js | 12 ++-- .../__snapshots__/delegation.spec.js.snap | 35 ++++++++++++ test/unit/specs/store/delegation.spec.js | 25 +++++++++ 12 files changed, 213 insertions(+), 34 deletions(-) diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 9550f676fd..75974d5ec1 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -106,10 +106,6 @@ Object.assign(Client.prototype, { ) } }, - // Get a specific tx from a delegator - getDelegatorTx: function(addr, id) { - return req("GET", `/stake/delegators/${addr}/txs/${id}`).call(this) - }, // // Query all validators that a delegator is bonded to // getDelegatorValidators: function(delegatorAddr) { // return req("GET", `/stake/delegators/${delegatorAddr}/validators`).call(this) diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index 1ab789c15e..d5ccf0dcd7 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -362,7 +362,13 @@ module.exports = { let candidate = state.candidates.find(c => c.owner === tx.validator_addr) shares = parseInt(candidate.tokens) candidate.tokens = (+shares - amount).toString() - delegator.unbonding_delegations.push(tx) + delegator.unbonding_delegations.push( + Object.assign({}, tx, { + balance: { + amount: tx.shares + } + }) + ) storeTx("cosmos-sdk/BeginUnbonding", tx) results.push(txResult(0)) @@ -397,9 +403,6 @@ module.exports = { }) return getTxs(types) }, - async getDelegatorTx(addr, hash) { - module.exports.tx(hash) - }, async getCandidates() { return state.candidates }, diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 4bbd06453d..404d90eb16 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -39,7 +39,7 @@ export default ({ node }) => { } state.committedDelegates = committedDelegates }, - setUnbondingDelegation(state, { candidateId, value }) { + setUnbondingDelegations(state, { candidateId, value }) { let unbondingDelegations = Object.assign({}, state.unbondingDelegations) if (value === 0) { delete unbondingDelegations[candidateId] @@ -85,7 +85,7 @@ export default ({ node }) => { if (delegator.unbonding_delegations) { delegator.unbonding_delegations.forEach( ({ validator_addr, balance: { amount } }) => { - commit("setUnbondingDelegation", { + commit("setUnbondingDelegations", { candidateId: validator_addr, value: parseFloat(amount) }) diff --git a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap index 3d484c159a..19f871d627 100644 --- a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap +++ b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`LCD Client queries for a delegation summary for a delegator 1`] = ` +Array [ + Array [ + "http://localhost:8998/stake/delegators/abc", + undefined, + ], +] +`; + +exports[`LCD Client queries for a delegation txs 1`] = ` +Array [ + Array [ + "http://localhost:8998/stake/delegators/abc/txs", + undefined, + ], + Array [ + "http://localhost:8998/stake/delegators/abc/txs?type=bonding", + undefined, + ], + Array [ + "http://localhost:8998/stake/delegators/abc/txs?type=unbonding", + undefined, + ], +] +`; + exports[`LCD Client queries for shares for a validator and delegate 1`] = ` Array [ Array [ @@ -8,3 +34,12 @@ Array [ ], ] `; + +exports[`LCD Client queries for undelegations between a delegator and a validator 1`] = ` +Array [ + Array [ + "http://localhost:8998/stake/delegators/abc/unbonding_delegations/def", + undefined, + ], +] +`; diff --git a/test/unit/specs/components/staking/PageBond.spec.js b/test/unit/specs/components/staking/PageBond.spec.js index c467e4972e..308ef74979 100644 --- a/test/unit/specs/components/staking/PageBond.spec.js +++ b/test/unit/specs/components/staking/PageBond.spec.js @@ -37,6 +37,10 @@ describe("PageBond", () => { country: "Canada", moniker: "someOtherValidator" }) + store.commit("setUnbondingDelegations", { + candidateId: "pubkeyY", + value: 100 + }) } }) store = test.store @@ -58,7 +62,7 @@ describe("PageBond", () => { it("shows number of total atoms", () => { store.commit("setAtoms", 1337) - expect(wrapper.vm.totalAtoms).toBe(1337) + expect(wrapper.vm.totalAtoms).toBe(1437) // plus unbonding atoms }) it("shows old bonded atoms ", () => { @@ -75,14 +79,14 @@ describe("PageBond", () => { it("shows bond bar percent", () => { store.commit("setAtoms", 120) - expect(wrapper.vm.bondBarPercent(30)).toBe("25%") + expect(wrapper.vm.bondBarPercent(30)).toBe("14%") }) it("sets bond bar inner width and style", () => { store.commit("setAtoms", 120) wrapper.setData({ bondBarOuterWidth: 128 }) - expect(wrapper.vm.bondBarInnerWidth(80)).toBe("95px") - expect(wrapper.vm.styleBondBarInner(80)).toEqual({ width: "95px" }) + expect(wrapper.vm.bondBarInnerWidth(80)).toBe("64px") + expect(wrapper.vm.styleBondBarInner(80)).toEqual({ width: "64px" }) }) it("sets bond group class", () => { @@ -180,9 +184,9 @@ describe("PageBond", () => { ] } }) - expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("81") + expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("181") // plus unbonding atoms wrapper.find("#btn-reset").trigger("click") - expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("101") + expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("201") }) it("shows an error when bonding too many atoms", () => { @@ -227,8 +231,8 @@ describe("PageBond", () => { ] } }) - expect(wrapper.vm.newUnbondedAtoms).toBe(81) - expect(wrapper.find("#new-unbonded-atoms").vnode.elm._value).toBe(81) + expect(wrapper.vm.newUnbondedAtoms).toBe(181) // plus unbonding atoms + expect(wrapper.find("#new-unbonded-atoms").vnode.elm._value).toBe(181) }) it("shows an appropriate amount of unbonding atoms", () => { @@ -255,8 +259,8 @@ describe("PageBond", () => { ] } }) - expect(wrapper.vm.newUnbondingAtoms).toBe(20) - expect(wrapper.find("#new-unbonding-atoms").vnode.elm._value).toBe(20) + expect(wrapper.vm.newUnbondingAtoms).toBe(120) // plus old unbonding atoms + expect(wrapper.find("#new-unbonding-atoms").vnode.elm._value).toBe(120) }) it("shows an error if confirmation is not checked", () => { diff --git a/test/unit/specs/components/staking/__snapshots__/PageBond.spec.js.snap b/test/unit/specs/components/staking/__snapshots__/PageBond.spec.js.snap index 17d00ca27e..c63efed253 100644 --- a/test/unit/specs/components/staking/__snapshots__/PageBond.spec.js.snap +++ b/test/unit/specs/components/staking/__snapshots__/PageBond.spec.js.snap @@ -96,7 +96,7 @@ exports[`PageBond has the expected html structure 1`] = `
- Start bonding your 101 STEAK + Start bonding your 201 STEAK
- Start bonding your 101 STEAK + Start bonding your 201 STEAK
{ let wrapper, store @@ -21,7 +64,7 @@ describe("PageTransactions", () => { store.commit("setWalletAddress", "tb1d4u5zerywfjhxuc9nudvw") store.commit("setWalletHistory", mockTransactions) - store.commit("setDelegationTxs", []) + store.commit("setDelegationTxs", delegationTxs) wrapper.update() }) @@ -62,7 +105,9 @@ describe("PageTransactions", () => { expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([ 3438, 3436, - 466 + 466, + 170, + 160 ]) }) @@ -80,6 +125,7 @@ describe("PageTransactions", () => { it("should update 'somethingToSearch' when there's nothing to search", () => { expect(wrapper.vm.somethingToSearch).toBe(true) store.commit("setWalletHistory", []) + store.commit("setDelegationTxs", []) expect(wrapper.vm.somethingToSearch).toBe(false) store.commit("setWalletHistory", mockTransactions) expect(wrapper.vm.somethingToSearch).toBe(true) @@ -89,19 +135,20 @@ describe("PageTransactions", () => { it("should show an error if there are no transactions", () => { store.commit("setWalletHistory", []) + store.commit("setDelegationTxs", []) wrapper.update() expect(wrapper.contains("data-empty-tx")).toBe(true) }) it("should not show search when there is nothing to search", () => { - let transactions = [] mount(PageTransactions, { stubs: { "tm-li-transaction": "", "data-empty-tx": "" } }) - store.commit("setWalletHistory", transactions) + store.commit("setWalletHistory", []) + store.commit("setDelegationTxs", []) wrapper.update() expect(wrapper.vm.setSearch()).toEqual(false) }) diff --git a/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap b/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap index 0465cef6c0..592cfdcfe5 100644 --- a/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap +++ b/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap @@ -111,6 +111,16 @@ exports[`PageTransactions has the expected html structure 1`] = ` transaction="[object Object]" /> + + + +
{ client.listKeys = () => Promise.resolve() expect(result).toEqual(["abc"]) }) + + it("queries for a delegation summary for a delegator", async () => { + axios.get = jest.fn().mockReturnValue({}) + client.getDelegator("abc") + expect(axios.get.mock.calls).toMatchSnapshot() + }) + + it("queries for a delegation txs", async () => { + axios.get = jest.fn().mockReturnValue({}) + client.getDelegatorTxs("abc") + client.getDelegatorTxs("abc", ["bonding"]) + client.getDelegatorTxs("abc", ["unbonding"]) + expect(axios.get.mock.calls).toMatchSnapshot() + }) + + it("queries for undelegations between a delegator and a validator", async () => { + axios.get = jest.fn().mockReturnValue({}) + client.queryUnbonding("abc", "def") + expect(axios.get.mock.calls).toMatchSnapshot() + }) }) diff --git a/test/unit/specs/lcdClientMock.spec.js b/test/unit/specs/lcdClientMock.spec.js index 0117320a66..7e5fc4ad30 100644 --- a/test/unit/specs/lcdClientMock.spec.js +++ b/test/unit/specs/lcdClientMock.spec.js @@ -74,8 +74,8 @@ describe("LCD Client Mock", () => { expect(res).toBeUndefined() }) - xit("persists a sent tx", async () => { - let res = await client.coinTxs(lcdClientMock.addresses[0]) + it("persists a sent tx", async () => { + let res = await client.txs(lcdClientMock.addresses[0]) expect(res.length).toBe(2) // predefined txs let { address: toAddr } = await client.storeKey({ @@ -96,10 +96,15 @@ describe("LCD Client Mock", () => { }) expect(res.height).toBeDefined() - res = await client.coinTxs(lcdClientMock.addresses[0]) + res = await client.txs(lcdClientMock.addresses[0]) expect(res.length).toBe(3) }) + it("queries a tx by it's hash", async () => { + let tx = await client.tx(lcdClientMock.state.txs[0].hash) + expect(tx.height).toBe(1) + }) + it("query and update the nonce", async () => { let { sequence } = await client.queryAccount(lcdClientMock.addresses[0]) expect(sequence).toBe("1") @@ -553,7 +558,6 @@ describe("LCD Client Mock", () => { txs = await client.getDelegatorTxs(lcdClientMock.addresses[0], ["bonding"]) expect(txs).toHaveLength(1) - console.log(JSON.stringify(txs)) expect(txs[0].tx.value.msg[0].type).toBe("cosmos-sdk/MsgDelegate") txs = await client.getDelegatorTxs(lcdClientMock.addresses[0], [ diff --git a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap index fe32c9502c..3c0544b738 100644 --- a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap +++ b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap @@ -6,6 +6,13 @@ Object { } `; +exports[`Module: Delegations fetches current undelegations 1`] = ` +Object { + "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au": 356, + "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": 73, +} +`; + exports[`Module: Delegations should query delegated atoms on reconnection 1`] = `Array []`; exports[`Module: Delegations submits delegation transaction 1`] = ` @@ -41,3 +48,31 @@ Array [ ], ] `; + +exports[`Module: Delegations submits undelegation transaction 1`] = ` +Array [ + Array [ + Object { + "account_number": "1", + "begin_unbondings": Array [ + Object { + "delegator_addr": "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", + "shares": "73", + "validator_addr": "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw", + }, + Object { + "delegator_addr": "cosmosaccaddr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctpesxxn9", + "shares": "356", + "validator_addr": "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au", + }, + ], + "chain_id": "test-chain", + "delegations": Array [], + "gas": "50000000", + "name": "default", + "password": "bar", + "sequence": "3", + }, + ], +] +`; diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index 9239b24a59..ae44722e26 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -87,6 +87,31 @@ describe("Module: Delegations", () => { expect(store._actions.sendTx[0].mock.calls).toMatchSnapshot() }) + it("submits undelegation transaction", async () => { + store.dispatch("setLastHeader", { + height: 42, + chain_id: "test-chain" + }) + await store.dispatch("getBondedDelegates") + + jest.spyOn(store._actions.sendTx, "0") + + let bondings = [50, 100, 0] + const delegations = store.state.delegates.delegates.map((delegate, i) => ({ + delegate, + atoms: bondings[i] + })) + + await store.dispatch("submitDelegation", delegations) + + expect(store._actions.sendTx[0].mock.calls).toMatchSnapshot() + }) + + it("fetches current undelegations", async () => { + await store.dispatch("getBondedDelegates", store.state.delegates.delegates) + expect(store.state.delegation.unbondingDelegations).toMatchSnapshot() + }) + it("should query delegated atoms on reconnection", () => { jest.resetModules() let axios = require("axios") From b3119adcc1227f28da9dfaa1c10ad1cbcd2d51df Mon Sep 17 00:00:00 2001 From: Fabian Date: Thu, 9 Aug 2018 13:12:32 +0200 Subject: [PATCH 22/23] removed notes --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b7f1e9bf9f..177f200e7d 100644 --- a/README.md +++ b/README.md @@ -201,7 +201,6 @@ Then run Voyager for your local testnet: ```bash $ yarn start local-testnet -carry brush trumpet garbage raise host such worth power evolve coyote method bachelor sun isolate nominee infant reject away three detail olive opera document ``` Import the account with the 12 word seed phrase you wrote down earlier. From f9c20b89ca31da255f058e00f63d36d0c969ad5a Mon Sep 17 00:00:00 2001 From: Voyager Bot Date: Thu, 9 Aug 2018 13:23:35 +0200 Subject: [PATCH 23/23] increased coverage --- test/unit/specs/lcdClient.spec.js | 6 ++++++ test/unit/specs/store/delegation.spec.js | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/test/unit/specs/lcdClient.spec.js b/test/unit/specs/lcdClient.spec.js index 3af2e48e28..8ba59c1bc0 100644 --- a/test/unit/specs/lcdClient.spec.js +++ b/test/unit/specs/lcdClient.spec.js @@ -178,4 +178,10 @@ describe("LCD Client", () => { client.queryUnbonding("abc", "def") expect(axios.get.mock.calls).toMatchSnapshot() }) + + it("queries for a candidate", async () => { + axios.get = jest.fn().mockReturnValue({}) + client.getCandidate("abc") + expect(axios.get.mock.calls).toMatchSnapshot() + }) }) diff --git a/test/unit/specs/store/delegation.spec.js b/test/unit/specs/store/delegation.spec.js index ae44722e26..9f41a54caa 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -112,6 +112,18 @@ describe("Module: Delegations", () => { expect(store.state.delegation.unbondingDelegations).toMatchSnapshot() }) + it("deletes undelegations that are 0", async () => { + await store.dispatch("getBondedDelegates", store.state.delegates.delegates) + store.commit("setUnbondingDelegations", { + candidateId: "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw", + value: 0 + }) + expect( + store.state.delegation.unbondingDelegations + .cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw + ).toBeUndefined() + }) + it("should query delegated atoms on reconnection", () => { jest.resetModules() let axios = require("axios")