Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Parsed Err msg #1094

Merged
merged 18 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

* delegations error message properly parsed @fedekunze
* testnets not properly available after download @faboweb
* Tell the main process when we switch to the mock network. @NodeGuy
* improved tooltip styling @jbibla
Expand Down
19 changes: 14 additions & 5 deletions app/src/renderer/components/staking/PageBond.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ tm-page.page-bond(:title="`Bond ${denom}`")

tm-form-group(field-id="bond-confirm" field-label=''
:error='$v.fields.bondConfirm.$error')
tm-form-msg(v-if="showsRevokedValidators") A revoked validator is not validating and therefor is not producing rewards. The revoked state may be temporary.
tm-form-msg(v-if="showsRevokedValidators") A revoked validator is not validating and therefore is not producing rewards. The revoked state may be temporary.
.tm-field-checkbox
.tm-field-checkbox-input
input#bond-confirm(type="checkbox" v-model="fields.bondConfirm")
Expand Down Expand Up @@ -237,10 +237,19 @@ export default {
})
this.$router.push("/staking")
} catch (err) {
this.$store.commit("notifyError", {
title: "Error While Bonding Atoms",
body: err.message
})
let errData = err.message.split("\n")[5]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably be used more often (like with sending coins). Can we implement this somehow in send.js like changing the error message there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to figure out which types of errors are encountered while transferring tokens

if (errData) {
let parsedErr = errData.split('"')[1]
this.$store.commit("notifyError", {
title: "Error While Bonding Atoms",
body: parsedErr[0].toUpperCase() + parsedErr.slice(1)
})
} else {
this.$store.commit("notifyError", {
title: "Error While Bonding Atoms",
body: err.message
})
}
} finally {
this.delegating = false
}
Expand Down
23 changes: 17 additions & 6 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ let state = {
}

module.exports = {
candidates: state.candidates,

async lcdConnected() {
return true
},
Expand Down Expand Up @@ -256,14 +258,12 @@ module.exports = {
// staking
async updateDelegations({ name, sequence, delegations, begin_unbondings }) {
let results = []

let fromKey = state.keys.find(a => a.name === name)
let fromAccount = state.accounts[fromKey.address]
if (fromAccount == null) {
results.push(txResult(1, "Nonexistent account"))
return results
}

// check nonce
if (parseInt(fromAccount.sequence) !== parseInt(sequence)) {
results.push(
Expand All @@ -274,7 +274,6 @@ module.exports = {
)
return results
}

for (let tx of delegations) {
let { denom } = tx.delegation
let amount = parseInt(tx.delegation.amount)
Expand All @@ -286,11 +285,9 @@ module.exports = {
results.push(txResult(1, "Not enough coins in your account"))
return results
}

// update sender account
incrementSequence(fromAccount)
fromAccount.coins.find(c => c.denom === denom).amount -= amount

// update stake
let delegator = state.stake[fromKey.address]
if (!delegator) {
Expand All @@ -309,13 +306,27 @@ module.exports = {
}
let shares = parseInt(delegation.shares)
delegation.shares = (shares + amount).toString()

let candidate = state.candidates.find(c => c.owner === tx.validator_addr)
if (candidate.revoked) {
throw new Error(`checkTx failed: (262245) Msg 0 failed: === ABCI Log ===
Codespace: 4
Code: 101
ABCICode: 262245
Error: --= Error =--
Data: common.FmtError{format:"validator for this address is currently revoked", args:[]interface {}(nil)}
Msg Traces:
--= /Error =--

=== /ABCI Log ===`)
}

candidate.tokens = (parseInt(candidate.tokens) + amount).toString()
candidate.delegator_shares = (
parseInt(candidate.delegator_shares) + amount
).toString()

// storeTx("cosmos-sdk/MsgDelegate", tx) // do we need this anymore?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this stores the txs in the txs list to be able to show them in the transaction history


results.push(txResult(0))
}

Expand Down
1 change: 0 additions & 1 deletion app/src/renderer/vuex/modules/delegation.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export default ({ node }) => {
let amountChange = parseInt(delegation.atoms) - currentlyDelegated

let isBond = amountChange > 0

// skip if no change
if (amountChange === 0) continue
if (isBond) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/renderer/vuex/modules/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export default ({ node }) => {
let to = args.to
delete args.to
args.gas = "50000000"

// submit to LCD to build, sign, and broadcast
let req = to ? node[type](to, args) : node[type](args)

let res = await req.catch(err => {
throw new Error(err.message)
})
Expand Down
50 changes: 47 additions & 3 deletions test/unit/specs/components/staking/PageBond.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import setup from "../../../helpers/vuex-setup"
import htmlBeautify from "html-beautify"
import Vuelidate from "vuelidate"
import PageBond from "renderer/components/staking/PageBond"

import { candidates } from "renderer/connectors/lcdClientMock.js"
describe("PageBond", () => {
let wrapper, store, router
let { mount, localVue } = setup()
localVue.use(Vuelidate)

beforeEach(() => {
beforeEach(async () => {
let test = mount(PageBond, {
doBefore: ({ store }) => {
doBefore: async ({ store }) => {
store.commit("setAtoms", 101)

store.commit("addToCart", {
Expand All @@ -37,6 +37,25 @@ describe("PageBond", () => {
country: "Canada",
moniker: "someOtherValidator"
})

store.commit(
"addToCart",
Object.assign(
{
id: "pubkeyZ",
voting_power: 20000,
shares: 75000,
moniker: "aChileanValidator"
},
candidates[2] // this is the revoked one
)
)

store.commit("setUnbondingDelegations", {
candidateId: "pubkeyY",
value: 100
})

}
})
store = test.store
Expand All @@ -53,6 +72,7 @@ describe("PageBond", () => {
// this has occured across multiple tests
await wrapper.vm.$nextTick()
wrapper.update()
console.log(wrapper.vm.totalAtoms)
expect(wrapper.vm.$el).toMatchSnapshot()
})

Expand Down Expand Up @@ -426,4 +446,28 @@ describe("PageBond", () => {
expect(wrapper.vm.showsRevokedValidators).toBe(true)
expect(wrapper.vm.$el).toMatchSnapshot()
})

it("shows an error if trying to bond to revoked candidates", async () => {
await store.dispatch("signIn", {
account: "default",
password: "1234567890"
})

wrapper.update()
wrapper.vm.fields.bondConfirm = true
wrapper.vm.fields.delegates[2].revoked = true
wrapper.vm.fields.delegates[2].atoms = 1

wrapper.findAll("#btn-bond").trigger("click")
await sleep(1000)
let lastErr =
store.state.notifications[store.state.notifications.length - 1]
expect(lastErr.body).toContain(
"Validator for this address is currently revoked"
)
})
})

function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,80 @@ exports[`PageBond has the expected html structure 1`] = `
<!---->
<!---->
</div>
<div
class="bond-group bond-candidate bond-group--neutral"
>
<div
class="bond-group__fields"
>
<div
class="bond-bar"
>
<!---->
<label
class="bond-bar__label revoked"
>
aChileanValidator
</label>
<label
class="bond-bar__revoked"
>
REVOKED
</label>
<div
class="bond-bar__input"
>
<div
class="bond-bar-old__outer"
>
<!---->
</div>
<div
class="bond-bar__outer"
>
<div
class="bond-bar__inner"
id="delegate-pubkeyZ"
style="width: 0px;"
/>
</div>
</div>
</div>
<div
class="bond-percent"
>
<label
class="bond-delta"
>
<!---->
</label>
<input
class="bond-percent__input tm-field"
disabled="disabled"
placeholder="0%"
/>
</div>
<div
class="bond-value"
>
<label
class="bond-delta"
>
<!---->
</label>
<input
class="bond-value__input tm-field"
max="201"
min="0"
placeholder="Atoms"
step="1"
type="number"
/>
</div>
</div>
<!---->
<!---->
</div>
<!---->
<div
class="tm-form-group"
Expand All @@ -333,7 +407,11 @@ exports[`PageBond has the expected html structure 1`] = `
<div
class="tm-form-group__field"
>
<!---->
<div
class="tm-form-msg sm tm-form-msg--desc"
>
A revoked validator is not validating and therefore is not producing rewards. The revoked state may be temporary.
</div>
<div
class="tm-field-checkbox"
>
Expand Down Expand Up @@ -775,7 +853,7 @@ exports[`PageBond shows a message if there are revoked candidates 1`] = `
<div
class="tm-form-msg sm tm-form-msg--desc"
>
A revoked validator is not validating and therefor is not producing rewards. The revoked state may be temporary.
A revoked validator is not validating and therefore is not producing rewards. The revoked state may be temporary.
</div>
<div
class="tm-field-checkbox"
Expand Down
Loading