From 2227bcd543d25975fe488ce0ddf612d2fb276eac Mon Sep 17 00:00:00 2001 From: billy rennekamp Date: Fri, 10 Aug 2018 19:06:05 +0200 Subject: [PATCH] Revert "Fedekunze/1010 lcd stake" --- CHANGELOG.md | 2 - README.md | 2 +- .../renderer/components/common/AppHeader.vue | 5 +- .../renderer/components/staking/PageBond.vue | 20 +- .../components/wallet/PageTransactions.vue | 57 +---- .../wallet/TmLiStakingTransaction.vue | 160 ------------- .../components/wallet/TmLiTransaction.vue | 219 ------------------ app/src/renderer/connectors/lcdClient.js | 64 +---- app/src/renderer/connectors/lcdClientMock.js | 139 ++++------- app/src/renderer/vuex/getters.js | 1 - app/src/renderer/vuex/modules/delegates.js | 8 +- app/src/renderer/vuex/modules/delegation.js | 71 ++---- app/src/renderer/vuex/modules/node.js | 4 +- app/src/renderer/vuex/modules/user.js | 2 +- app/src/renderer/vuex/modules/validators.js | 25 +- app/src/renderer/vuex/modules/wallet.js | 2 +- app/src/renderer/vuex/store.js | 6 +- tasks/build/Gaia/COMMIT.sh | 2 +- test/e2e/launch.js | 3 - test/unit/helpers/vuex-setup.js | 11 +- .../__snapshots__/lcdClient.spec.js.snap | 46 +--- .../__snapshots__/lcdClientMock.spec.js.snap | 4 +- .../specs/components/common/AppHeader.spec.js | 3 +- .../specs/components/staking/PageBond.spec.js | 24 +- .../__snapshots__/PageBond.spec.js.snap | 12 +- .../__snapshots__/PageStaking.spec.js.snap | 4 +- .../wallet/PageTransactions.spec.js | 80 ++----- .../PageTransactions.spec.js.snap | 14 -- test/unit/specs/lcdClient.spec.js | 26 --- test/unit/specs/lcdClientMock.spec.js | 104 ++------- .../__snapshots__/delegation.spec.js.snap | 50 +--- test/unit/specs/store/delegation.spec.js | 68 +++--- test/unit/specs/store/json/txs.js | 6 +- test/unit/specs/store/node.spec.js | 2 +- test/unit/specs/store/store.spec.js | 5 +- test/unit/specs/store/validators.spec.js | 8 +- 36 files changed, 219 insertions(+), 1040 deletions(-) delete mode 100644 app/src/renderer/components/wallet/TmLiStakingTransaction.vue delete mode 100644 app/src/renderer/components/wallet/TmLiTransaction.vue diff --git a/CHANGELOG.md b/CHANGELOG.md index 4648ac5cb0..e2602e2dcf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,13 +14,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. * removed light theme option from preferences page @jolesbi * enabled staked balance on PageWallet in production @faboweb * removed unused xmlhttprequest dependency @faboweb -* LCD staking endpoints @fedekunze @faboweb ### Added * storing balance, tx history and delegations locally to serve an old state faster @faboweb * added error message for missing network config @faboweb -* showing staking txs in history @faboweb ### Fixed diff --git a/README.md b/README.md index 177f200e7d..5309ac70d6 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 = false/index_all_tags = true/g' ~/.gaiad-testnet/config/config.toml +$ sed -i.bak 's/index_all_tags = true/index_all_tags = false/g' ./builds/testnets/local-testnet/config.toml ``` Store the gaia version used in your local testnet: diff --git a/app/src/renderer/components/common/AppHeader.vue b/app/src/renderer/components/common/AppHeader.vue index 7c0a630be4..0e189ce8dc 100644 --- a/app/src/renderer/components/common/AppHeader.vue +++ b/app/src/renderer/components/common/AppHeader.vue @@ -44,7 +44,6 @@ export default { document.documentElement.clientWidth, window.innerWidth || 0 ) - if (w >= 1024) { this.close() this.$store.commit("setConfigDesktop", true) @@ -66,7 +65,6 @@ export default { #app-header z-index z(appHeader) - .container -webkit-app-region drag @@ -87,6 +85,7 @@ export default { top 0 left 0 width 100% + background var(--app-bg) > .container @@ -104,6 +103,7 @@ export default { align-items center justify-content center padding 0 1rem + color var(--link) cursor pointer @@ -131,7 +131,6 @@ export default { border-bottom px solid var(--bc) padding 2.5rem 1rem 1rem 1rem line-height normal - img height 1.75rem diff --git a/app/src/renderer/components/staking/PageBond.vue b/app/src/renderer/components/staking/PageBond.vue index 60fda33780..92c99c1970 100644 --- a/app/src/renderer/components/staking/PageBond.vue +++ b/app/src/renderer/components/staking/PageBond.vue @@ -152,17 +152,15 @@ export default { ToolBar }, computed: { - ...mapGetters(["shoppingCart", "user", "delegation", "config"]), + ...mapGetters(["shoppingCart", "user", "committedDelegations", "config"]), denom() { return this.config.bondingDenom.toUpperCase() }, totalAtoms() { - return ( - parseInt(this.user.atoms) + this.oldBondedAtoms + this.oldUnbondingAtoms - ) + return parseInt(this.user.atoms) + this.oldBondedAtoms }, oldBondedAtoms() { - return Object.values(this.delegation.committedDelegates).reduce( + return Object.values(this.committedDelegations).reduce( (sum, d) => sum + parseInt(d), 0 ) @@ -179,14 +177,6 @@ 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 @@ -194,7 +184,7 @@ export default { return atoms + delta } return atoms - }, this.oldUnbondingAtoms) + }, 0) }, newUnbondingAtomsDelta() { return this.delta(this.newUnbondingAtoms, 0) @@ -257,7 +247,7 @@ export default { } }, resetFields() { - let committedDelegations = this.delegation.committedDelegates + let committedDelegations = this.committedDelegations let totalAtoms = this.totalAtoms this.fields.bondConfirm = false this.fields.delegates = this.shoppingCart.map(c => diff --git a/app/src/renderer/components/wallet/PageTransactions.vue b/app/src/renderer/components/wallet/PageTransactions.vue index 546fbc1d1a..8bd0958c92 100644 --- a/app/src/renderer/components/wallet/PageTransactions.vue +++ b/app/src/renderer/components/wallet/PageTransactions.vue @@ -9,19 +9,14 @@ tm-page(title='Transactions') modal-search(type="transactions" v-if="somethingToSearch") tm-data-loading(v-if="wallet.historyLoading") - data-empty-tx(v-else-if='allTransactions.length === 0') + data-empty-tx(v-else-if='transactions.length === 0') data-empty-search(v-else-if="filteredTransactions.length === 0") - 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") + tm-li-transaction( + v-else + v-for="i in filteredTransactions" + :key="shortid.generate()" + :transaction="i" + :address="wallet.address") diff --git a/app/src/renderer/components/wallet/TmLiStakingTransaction.vue b/app/src/renderer/components/wallet/TmLiStakingTransaction.vue deleted file mode 100644 index e557cb4ddc..0000000000 --- a/app/src/renderer/components/wallet/TmLiStakingTransaction.vue +++ /dev/null @@ -1,160 +0,0 @@ - - - - - diff --git a/app/src/renderer/components/wallet/TmLiTransaction.vue b/app/src/renderer/components/wallet/TmLiTransaction.vue deleted file mode 100644 index 57e8f15a0a..0000000000 --- a/app/src/renderer/components/wallet/TmLiTransaction.vue +++ /dev/null @@ -1,219 +0,0 @@ - - - - - diff --git a/app/src/renderer/connectors/lcdClient.js b/app/src/renderer/connectors/lcdClient.js index 75974d5ec1..79d470fbd0 100644 --- a/app/src/renderer/connectors/lcdClient.js +++ b/app/src/renderer/connectors/lcdClient.js @@ -90,64 +90,12 @@ Object.assign(Client.prototype, { }, tx: argReq("GET", "/txs"), - /* ============ 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, 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 - getCandidates: req("GET", "/stake/validators"), - // Get information from a validator - getCandidate: 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, data) { - return req("POST", `/stake/delegators/${delegatorAddr}/delegations`).call( - this, - data - ) - }, - - // 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) + // staking + updateDelegations: req("POST", "/stake/delegations"), + candidates: req("GET", "/stake/validators"), + getValidators: req("GET", "/validatorsets/latest"), + queryDelegation: function(delegator, validator) { + return req("GET", `/stake/${delegator}/delegation/${validator}`).call(this) } }) diff --git a/app/src/renderer/connectors/lcdClientMock.js b/app/src/renderer/connectors/lcdClientMock.js index d5ccf0dcd7..a995f0ceb8 100644 --- a/app/src/renderer/connectors/lcdClientMock.js +++ b/app/src/renderer/connectors/lcdClientMock.js @@ -48,7 +48,6 @@ let state = { value: { msg: [ { - type: "cosmos-sdk/Send", value: { inputs: [ { @@ -85,7 +84,6 @@ let state = { value: { msg: [ { - type: "cosmos-sdk/Send", value: { inputs: [ { @@ -120,15 +118,12 @@ let state = { ], stake: { [addresses[0]]: { - delegations: [ - { - delegator_addr: addresses[0], - validator_addr: validators[0], - shares: "14", - height: 123 - } - ], - unbonding_delegations: [] + [validators[0]]: { + delegator_addr: addresses[0], + validator_addr: validators[0], + shares: "130", + height: 123 + } } }, candidates: [ @@ -241,8 +236,8 @@ module.exports = { ) }) }, - async tx(hash) { - return state.txs.find(tx => tx.hash === hash) + async tx() { + return {} }, async send(to, req) { let fromKey = state.keys.find(a => a.name === req.name) @@ -259,10 +254,7 @@ module.exports = { }, // staking - async updateDelegations( - delegatorAddr, - { name, sequence, delegations, begin_unbondings } - ) { + async updateDelegations({ name, sequence, delegations, begin_unbondings }) { let results = [] let fromKey = state.keys.find(a => a.name === name) @@ -302,15 +294,10 @@ module.exports = { // update stake let delegator = state.stake[fromKey.address] if (!delegator) { - state.stake[fromKey.address] = { - delegations: [], - unbonding_delegations: [] - } + state.stake[fromKey.address] = {} delegator = state.stake[fromKey.address] } - let delegation = delegator.delegations.find( - d => d.validator_addr === tx.validator_addr - ) + let delegation = delegator[tx.validator_addr] if (!delegation) { delegation = { delegator_addr: fromKey.address, @@ -318,9 +305,8 @@ module.exports = { shares: "0", height: 0 } - delegator.delegations.push(delegation) + delegator[tx.validator_addr] = delegation } - let shares = parseInt(delegation.shares) delegation.shares = (shares + amount).toString() @@ -330,7 +316,6 @@ module.exports = { parseInt(candidate.delegator_shares) + amount ).toString() - storeTx("cosmos-sdk/MsgDelegate", tx) results.push(txResult(0)) } @@ -349,9 +334,7 @@ module.exports = { results.push(txResult(2, "Nonexistent delegator")) return results } - let delegation = delegator.delegations.find( - d => d.validator_addr === tx.validator_addr - ) + let delegation = delegator[tx.validator_addr] if (!delegation) { results.push(txResult(2, "Nonexistent delegation")) return results @@ -362,59 +345,26 @@ 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( - Object.assign({}, tx, { - balance: { - amount: tx.shares - } - }) - ) - storeTx("cosmos-sdk/BeginUnbonding", tx) results.push(txResult(0)) } return results }, async queryDelegation(delegatorAddress, validatorAddress) { - let delegator = state.stake[delegatorAddress] - if (!delegator) return {} - return delegator.delegations.find( - ({ validator_addr }) => validator_addr === validatorAddress - ) - }, - async queryUnbonding(delegatorAddress, validatorAddress) { let delegator = state.stake[delegatorAddress] if (!delegator) return - 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(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) + return delegator[validatorAddress] }, - async getCandidates() { + async candidates() { return state.candidates }, - async getValidatorSet() { + async getValidators() { return { block_height: 1, validators: state.candidates } }, - async getCandidate(addr) { - return state.candidates.find(c => c.owner === addr) - }, // exports to be used in tests state, addresses, @@ -485,52 +435,43 @@ 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: [ { - type, - value: body + value: { + inputs: [ + { + coins: req.amount, + address: from + } + ], + outputs: [ + { + coins: req.amount, + address: to + } + ] + } } ] } }, hash: makeHash(), - height: getHeight(), + height: getHeight() + (from === botAddress ? 1 : 0), time: Date.now() }) -} -function getTxs(types) { - return state.txs.filter(tx => types.indexOf(tx.tx.value.msg[0].type) !== -1) + // 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 delegate (sender, { pub_key: { data: pubKey }, amount: delegation }) { diff --git a/app/src/renderer/vuex/getters.js b/app/src/renderer/vuex/getters.js index 78a1832cdf..a310805974 100644 --- a/app/src/renderer/vuex/getters.js +++ b/app/src/renderer/vuex/getters.js @@ -17,7 +17,6 @@ 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/delegates.js b/app/src/renderer/vuex/modules/delegates.js index 2ef8eca4a5..ab16ae8a83 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 candidates = await node.getCandidates() - let { validators } = await node.getValidatorSet() - for (let delegate of candidates) { + let delegates = await node.candidates() + let { validators } = await node.getValidators() + for (let delegate of delegates) { if (validators.find(v => v.pub_key === delegate.pub_key)) { delegate.isValidator = true } commit("addDelegate", delegate) } - commit("setDelegates", candidates) + commit("setDelegates", delegates) commit("setDelegateLoading", false) return state.delegates diff --git a/app/src/renderer/vuex/modules/delegation.js b/app/src/renderer/vuex/modules/delegation.js index 404d90eb16..6e51c627b6 100644 --- a/app/src/renderer/vuex/modules/delegation.js +++ b/app/src/renderer/vuex/modules/delegation.js @@ -6,9 +6,7 @@ export default ({ node }) => { delegates: [], // our delegations which are already on the blockchain - committedDelegates: {}, - unbondingDelegations: {}, - delegationTxs: [] + committedDelegates: {} } const mutations = { @@ -38,18 +36,6 @@ export default ({ node }) => { committedDelegates[candidateId] = value } state.committedDelegates = committedDelegates - }, - setUnbondingDelegations(state, { candidateId, value }) { - let unbondingDelegations = Object.assign({}, state.unbondingDelegations) - if (value === 0) { - delete unbondingDelegations[candidateId] - } else { - unbondingDelegations[candidateId] = value - } - state.unbondingDelegations = unbondingDelegations - }, - setDelegationTxs(state, txs) { - state.delegationTxs = txs } } @@ -60,44 +46,36 @@ export default ({ node }) => { } }, // load committed delegations from LCD - async getBondedDelegates( - { state, rootState, commit, dispatch }, - candidates - ) { + async getBondedDelegates({ state, rootState, dispatch }, candidates) { state.loading = true let address = rootState.user.address candidates = candidates || (await dispatch("getDelegates")) - let delegator = await node.getDelegator(address) - if (delegator.delegations) { - delegator.delegations.forEach(({ validator_addr, shares }) => { - commit("setCommittedDelegation", { - candidateId: validator_addr, - value: parseFloat(shares) + await Promise.all( + candidates.map(candidate => + dispatch("getBondedDelegate", { + delegator: address, + validator: candidate.owner }) - 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("setUnbondingDelegations", { - candidateId: validator_addr, - value: parseFloat(amount) - }) - } ) - } + ) state.loading = false }, - async getDelegationTxs({ commit, rootState }) { - let address = rootState.user.address - let txs = await node.getDelegatorTxs(address) - commit("setDelegationTxs", txs) + // 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 + }) + if (shares > 0) { + commit("addToCart", delegate) + } }, async updateDelegates({ dispatch }) { let candidates = await dispatch("getDelegates") @@ -139,7 +117,6 @@ export default ({ node }) => { await dispatch("sendTx", { type: "updateDelegations", - to: rootState.wallet.address, // TODO strange syntax delegations: delegate, begin_unbondings: unbond }) diff --git a/app/src/renderer/vuex/modules/node.js b/app/src/renderer/vuex/modules/node.js index ea585e6370..39f0b781b0 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 = { - async setLastHeader({ state, rootState, dispatch }, header) { + 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) } - await dispatch("maybeUpdateValidators", header) + dispatch("maybeUpdateValidators", header) }, async reconnect({ commit }) { if (state.stopConnecting) return diff --git a/app/src/renderer/vuex/modules/user.js b/app/src/renderer/vuex/modules/user.js index 60a37e9b63..391643beca 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", { address, password }) + commit("loadPersistedState", { account, 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 f74bfa7dfd..198e8de8ce 100644 --- a/app/src/renderer/vuex/modules/validators.js +++ b/app/src/renderer/vuex/modules/validators.js @@ -20,24 +20,25 @@ export default ({ node }) => { dispatch("getValidators") } }, - async getValidators({ state, commit }) { + getValidators({ state, commit }) { state.loading = true - try { - let validators = (await node.getValidatorSet()).validators + node.rpc.validators((err, { validators } = {}) => { + if (err) { + commit("notifyError", { + title: "Error fetching validator set", + body: err.message + }) + return + } commit("setValidators", validators) - } catch (err) { - commit("notifyError", { - title: "Error fetching validator set", - body: err.message - }) - } - state.loading = false + state.loading = false + }) }, - async maybeUpdateValidators({ state, commit, dispatch }, header) { + maybeUpdateValidators({ state, commit, dispatch }, header) { let validatorHash = header.validators_hash if (validatorHash === state.validatorHash) return commit("setValidatorHash", validatorHash) - await dispatch("getValidators") + dispatch("getValidators") } } diff --git a/app/src/renderer/vuex/modules/wallet.js b/app/src/renderer/vuex/modules/wallet.js index e7ceb8624e..b6e513a852 100644 --- a/app/src/renderer/vuex/modules/wallet.js +++ b/app/src/renderer/vuex/modules/wallet.js @@ -69,7 +69,7 @@ export default ({ node }) => { }, queryWalletState({ dispatch }) { dispatch("queryWalletBalances") - // dispatch("queryWalletHistory") // is done on mounting transactions + dispatch("queryWalletHistory") }, async queryWalletBalances({ state, rootState, commit }) { let res = await node.queryAccount(state.address) diff --git a/app/src/renderer/vuex/store.js b/app/src/renderer/vuex/store.js index 1ca4037985..6c6fa9a9ce 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.address, encryptedState) + localStorage.setItem("store_" + state.user.account, encryptedState) } -function loadPersistedState(state, { address, password }) { - const cachedState = localStorage.getItem("store_" + address) +function loadPersistedState(state, { account, password }) { + const cachedState = localStorage.getItem("store_" + account) if (cachedState) { const bytes = CryptoJS.AES.decrypt(cachedState, password) const plaintext = bytes.toString(CryptoJS.enc.Utf8) diff --git a/tasks/build/Gaia/COMMIT.sh b/tasks/build/Gaia/COMMIT.sh index f097f53326..61800138c4 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=6d95d1cef47ec6806fba26e17ac63c7d387bb771 +export COMMIT=23e3d5ac12145c02fcb4b4767d7dfccad782aee5 diff --git a/test/e2e/launch.js b/test/e2e/launch.js index 41e9524a91..1683776d15 100644 --- a/test/e2e/launch.js +++ b/test/e2e/launch.js @@ -253,9 +253,6 @@ 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() diff --git a/test/unit/helpers/vuex-setup.js b/test/unit/helpers/vuex-setup.js index b6c971a5e7..7fe8d0ae87 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, methods, doBefore = () => {} } // doBefore receives router and store + { stubs, getters = {}, propsData, doBefore = () => {} } // doBefore receives router and store ) { const node = Object.assign({}, require("../helpers/node_mock")) const modules = Modules({ node }) @@ -58,8 +58,7 @@ export default function vuexSetup() { store, router, stubs, - propsData, - methods + propsData }) } } @@ -68,24 +67,22 @@ export default function vuexSetup() { localVue, shallow: ( componentConstructor, - { stubs, getters, propsData, methods, doBefore } = {} + { stubs, getters, propsData, doBefore } = {} ) => init(componentConstructor, shallow, { stubs, getters, propsData, - methods, doBefore }), mount: ( componentConstructor, - { stubs, getters, propsData, methods, doBefore } = {} + { stubs, getters, propsData, doBefore } = {} ) => init(componentConstructor, mount, { stubs, getters, propsData, - methods, doBefore }) } diff --git a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap index 767113f074..72925727b2 100644 --- a/test/unit/specs/__snapshots__/lcdClient.spec.js.snap +++ b/test/unit/specs/__snapshots__/lcdClient.spec.js.snap @@ -1,53 +1,9 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`LCD Client queries for a candidate 1`] = ` -Array [ - Array [ - "http://localhost:8998/stake/validators/abc", - undefined, - ], -] -`; - -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 [ - "http://localhost:8998/stake/delegators/abc/delegations/efg", - undefined, - ], -] -`; - -exports[`LCD Client queries for undelegations between a delegator and a validator 1`] = ` -Array [ - Array [ - "http://localhost:8998/stake/delegators/abc/unbonding_delegations/def", + "http://localhost:8998/stake/abc/delegation/efg", undefined, ], ] diff --git a/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap b/test/unit/specs/__snapshots__/lcdClientMock.spec.js.snap index 3028ce00dc..cd6a39cd30 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`] = `"24"`; +exports[`LCD Client Mock delegates to multiple validators at once 2`] = `"140"`; exports[`LCD Client Mock deletes keys 1`] = `[Error: Passwords do not match]`; -exports[`LCD Client Mock queries bondings per delegator 1`] = `"14"`; +exports[`LCD Client Mock queries bondings per delegator 1`] = `"130"`; exports[`LCD Client Mock updates keys 1`] = `[Error: Passwords do not match]`; diff --git a/test/unit/specs/components/common/AppHeader.spec.js b/test/unit/specs/components/common/AppHeader.spec.js index 0da3326809..d03615efe3 100644 --- a/test/unit/specs/components/common/AppHeader.spec.js +++ b/test/unit/specs/components/common/AppHeader.spec.js @@ -8,7 +8,8 @@ describe("AppHeader", () => { beforeEach(() => { instance = mount(AppHeader, { - stubs: { "app-menu": "" } + stubs: { "app-menu": "" }, + methods: { watchWindowSize: () => {} } }) wrapper = instance.wrapper store = instance.store diff --git a/test/unit/specs/components/staking/PageBond.spec.js b/test/unit/specs/components/staking/PageBond.spec.js index 308ef74979..c467e4972e 100644 --- a/test/unit/specs/components/staking/PageBond.spec.js +++ b/test/unit/specs/components/staking/PageBond.spec.js @@ -37,10 +37,6 @@ describe("PageBond", () => { country: "Canada", moniker: "someOtherValidator" }) - store.commit("setUnbondingDelegations", { - candidateId: "pubkeyY", - value: 100 - }) } }) store = test.store @@ -62,7 +58,7 @@ describe("PageBond", () => { it("shows number of total atoms", () => { store.commit("setAtoms", 1337) - expect(wrapper.vm.totalAtoms).toBe(1437) // plus unbonding atoms + expect(wrapper.vm.totalAtoms).toBe(1337) }) it("shows old bonded atoms ", () => { @@ -79,14 +75,14 @@ describe("PageBond", () => { it("shows bond bar percent", () => { store.commit("setAtoms", 120) - expect(wrapper.vm.bondBarPercent(30)).toBe("14%") + expect(wrapper.vm.bondBarPercent(30)).toBe("25%") }) it("sets bond bar inner width and style", () => { store.commit("setAtoms", 120) wrapper.setData({ bondBarOuterWidth: 128 }) - expect(wrapper.vm.bondBarInnerWidth(80)).toBe("64px") - expect(wrapper.vm.styleBondBarInner(80)).toEqual({ width: "64px" }) + expect(wrapper.vm.bondBarInnerWidth(80)).toBe("95px") + expect(wrapper.vm.styleBondBarInner(80)).toEqual({ width: "95px" }) }) it("sets bond group class", () => { @@ -184,9 +180,9 @@ describe("PageBond", () => { ] } }) - expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("181") // plus unbonding atoms + expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("81") wrapper.find("#btn-reset").trigger("click") - expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("201") + expect(wrapper.find("#new-unbonded-atoms").element.value).toBe("101") }) it("shows an error when bonding too many atoms", () => { @@ -231,8 +227,8 @@ describe("PageBond", () => { ] } }) - expect(wrapper.vm.newUnbondedAtoms).toBe(181) // plus unbonding atoms - expect(wrapper.find("#new-unbonded-atoms").vnode.elm._value).toBe(181) + expect(wrapper.vm.newUnbondedAtoms).toBe(81) + expect(wrapper.find("#new-unbonded-atoms").vnode.elm._value).toBe(81) }) it("shows an appropriate amount of unbonding atoms", () => { @@ -259,8 +255,8 @@ describe("PageBond", () => { ] } }) - expect(wrapper.vm.newUnbondingAtoms).toBe(120) // plus old unbonding atoms - expect(wrapper.find("#new-unbonding-atoms").vnode.elm._value).toBe(120) + expect(wrapper.vm.newUnbondingAtoms).toBe(20) + expect(wrapper.find("#new-unbonding-atoms").vnode.elm._value).toBe(20) }) 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 c63efed253..17d00ca27e 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 201 STEAK + Start bonding your 101 STEAK
- Start bonding your 201 STEAK + Start bonding your 101 STEAK
- 14 + 130
Validator @@ -392,7 +392,7 @@ exports[`PageStaking should filter the delegates 1`] = ` class="li-delegate__value your-votes" > - 14 + 130
{ let wrapper, store let { mount } = setup() - beforeEach(async () => { + beforeEach(() => { let instance = mount(PageTransactions, { stubs: { "tm-li-transaction": "", - "tm-li-staking-transaction": "", "data-empty-tx": "" - }, - methods: { - refreshTransactions: jest.fn() } }) wrapper = instance.wrapper @@ -64,7 +17,6 @@ describe("PageTransactions", () => { store.commit("setWalletAddress", "tb1d4u5zerywfjhxuc9nudvw") store.commit("setWalletHistory", mockTransactions) - store.commit("setDelegationTxs", delegationTxs) wrapper.update() }) @@ -89,12 +41,11 @@ describe("PageTransactions", () => { }) it("should refresh the transaction history", () => { - wrapper.vm.refreshTransactions = jest.fn() wrapper .findAll(".tm-tool-bar i") .at(0) .trigger("click") - expect(wrapper.vm.refreshTransactions).toHaveBeenCalled() + expect(store.dispatch).toHaveBeenCalledWith("queryWalletHistory") }) it("should show transactions", () => { @@ -103,11 +54,9 @@ describe("PageTransactions", () => { it("should sort the transaction by time", () => { expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([ - 3438, - 3436, - 466, - 170, - 160 + "3466", + "3438", + "3436" ]) }) @@ -115,17 +64,25 @@ describe("PageTransactions", () => { store.commit("setSearchVisible", ["transactions", true]) store.commit("setSearchQuery", ["transactions", "fabo"]) wrapper.update() - expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual([466]) + expect(wrapper.vm.filteredTransactions.map(x => x.height)).toEqual(["3466"]) // 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([466]) + 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") }) 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) @@ -135,20 +92,19 @@ 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", []) - store.commit("setDelegationTxs", []) + store.commit("setWalletHistory", transactions) 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 592cfdcfe5..21d30ab532 100644 --- a/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap +++ b/test/unit/specs/components/wallet/__snapshots__/PageTransactions.spec.js.snap @@ -100,27 +100,14 @@ exports[`PageTransactions has the expected html structure 1`] = ` address="tb1d4u5zerywfjhxuc9nudvw" transaction="[object Object]" /> - - - - - - -
-
`; diff --git a/test/unit/specs/lcdClient.spec.js b/test/unit/specs/lcdClient.spec.js index 8ba59c1bc0..458caf6b90 100644 --- a/test/unit/specs/lcdClient.spec.js +++ b/test/unit/specs/lcdClient.spec.js @@ -158,30 +158,4 @@ describe("LCD Client", () => { 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() - }) - - 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/lcdClientMock.spec.js b/test/unit/specs/lcdClientMock.spec.js index 7e5fc4ad30..3c315d7716 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() }) - it("persists a sent tx", async () => { - let res = await client.txs(lcdClientMock.addresses[0]) + xit("persists a sent tx", async () => { + let res = await client.coinTxs(lcdClientMock.addresses[0]) expect(res.length).toBe(2) // predefined txs let { address: toAddr } = await client.storeKey({ @@ -96,15 +96,10 @@ describe("LCD Client Mock", () => { }) expect(res.height).toBeDefined() - res = await client.txs(lcdClientMock.addresses[0]) + res = await client.coinTxs(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") @@ -260,19 +255,10 @@ describe("LCD Client Mock", () => { }) it("queries for all candidates", async () => { - let data = await client.getCandidates() + let data = await client.candidates() 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], @@ -288,7 +274,7 @@ describe("LCD Client Mock", () => { ) expect(stake).toBeUndefined() - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -312,7 +298,7 @@ describe("LCD Client Mock", () => { }) it("executes an unbond tx", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -334,7 +320,7 @@ describe("LCD Client Mock", () => { ) expect(initialStake.shares).toBe("10") - res = await client.updateDelegations(lcdClientMock.addresses[0], { + res = await client.updateDelegations({ sequence: 2, name: "default", delegations: [], @@ -358,7 +344,7 @@ describe("LCD Client Mock", () => { }) it("can not stake fermions you dont have", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -376,7 +362,7 @@ describe("LCD Client Mock", () => { }) it("errors when delegating with incorrect nonce", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -392,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(lcdClientMock.addresses[0], { + res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -415,7 +401,7 @@ describe("LCD Client Mock", () => { password: "1234567890", address: lcdClientMock.addresses[1] }) - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "nonexistent_account", delegations: [ @@ -433,7 +419,7 @@ describe("LCD Client Mock", () => { }) it("delegates to multiple validators at once", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -470,7 +456,7 @@ describe("LCD Client Mock", () => { }) it("errors when delegating negative amount", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [ @@ -488,7 +474,7 @@ describe("LCD Client Mock", () => { }) it("errors when unbonding with no delegation", async () => { - let res = await client.updateDelegations(lcdClientMock.addresses[0], { + let res = await client.updateDelegations({ sequence: 1, name: "default", delegations: [], @@ -504,66 +490,4 @@ 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) - 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") - }) }) diff --git a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap index 3c0544b738..7d64413859 100644 --- a/test/unit/specs/store/__snapshots__/delegation.spec.js.snap +++ b/test/unit/specs/store/__snapshots__/delegation.spec.js.snap @@ -2,14 +2,8 @@ exports[`Module: Delegations fetches bonded delegates 1`] = ` Object { - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": 14, -} -`; - -exports[`Module: Delegations fetches current undelegations 1`] = ` -Object { - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au": 356, - "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": 73, + "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctplpn3au": "15", + "cosmosvaladdr15ky9du8a2wlstz6fpx3p4mqpjyrm5ctqzh8yqw": "10", } `; @@ -20,17 +14,15 @@ Array [ Array [ Object { "account_number": "1", - "begin_unbondings": Array [], - "chain_id": "test-chain", - "delegations": Array [ + "begin_unbondings": 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", @@ -48,31 +40,3 @@ 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 9f41a54caa..63803270c6 100644 --- a/test/unit/specs/store/delegation.spec.js +++ b/test/unit/specs/store/delegation.spec.js @@ -3,11 +3,12 @@ import setup from "../../helpers/vuex-setup" let instance = setup() describe("Module: Delegations", () => { - let store + let store, node beforeEach(async () => { let test = instance.shallow() store = test.store + node = test.node store.dispatch("signIn", { password: "bar", account: "default" }) await store.dispatch("getDelegates") @@ -63,7 +64,35 @@ 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() }) @@ -87,43 +116,6 @@ 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("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") diff --git a/test/unit/specs/store/json/txs.js b/test/unit/specs/store/json/txs.js index 44e06c1a7d..2d320b23c6 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() + 1000, // set by Voyager + time: Date.now(), // set by Voyager height: "3436", tx: { type: "8EFE47F0625DE8", @@ -79,7 +79,7 @@ module.exports = [ }, { hash: "not a real hash2", - time: Date.now() + 1010, // set by Voyager + time: Date.now() + 10, // 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: "466", + height: "3466", tx: { type: "8EFE47F0625DE8", value: { diff --git a/test/unit/specs/store/node.spec.js b/test/unit/specs/store/node.spec.js index 1ebbba4c5b..6dc96e2003 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.getValidatorSet = () => done() + node.rpc.validators = () => 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 63c5c0d039..fc47236755 100644 --- a/test/unit/specs/store/store.spec.js +++ b/test/unit/specs/store/store.spec.js @@ -1,6 +1,5 @@ import Store from "renderer/vuex/store" import node from "../../helpers/node_mock" -import lcdClientMock from "renderer/connectors/lcdClientMock.js" describe("Store", () => { let store @@ -19,9 +18,7 @@ describe("Store", () => { password: "1234567890" }) store.commit("setWalletBalances", [{ denom: "fabocoin", amount: 42 }]) - expect( - localStorage.getItem("store_" + lcdClientMock.addresses[0]) - ).toBeTruthy() + expect(localStorage.getItem("store_default")).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 3be4d6f714..946f8993f4 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 () => { - await store.dispatch("getValidators") - expect(store.state.validators.validators).toHaveLength(3) + store.dispatch("getValidators") + expect(store.state.validators.validators).toHaveLength(6) }) 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, "getValidatorSet") + jest.spyOn(node.rpc, "validators") store.dispatch("reconnected") - expect(node.getValidatorSet).toHaveBeenCalled() + expect(node.rpc.validators).toHaveBeenCalled() }) it("should not query validators on reconnection if not stuck in loading", () => {