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 13 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 @jolesbi
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
20 changes: 13 additions & 7 deletions app/src/renderer/connectors/lcdClientMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,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 +272,6 @@ module.exports = {
)
return results
}

for (let tx of delegations) {
let { denom } = tx.delegation
let amount = parseInt(tx.delegation.amount)
Expand All @@ -286,11 +283,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 +304,24 @@ 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()

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
2 changes: 1 addition & 1 deletion test/unit/helpers/vuex-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function vuexSetup() {
})

// execute some preparation logic on the store or router before mounting
doBefore({ store, router })
doBefore({ store, router, node })

return {
node,
Expand Down
42 changes: 39 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,14 @@ import setup from "../../../helpers/vuex-setup"
import htmlBeautify from "html-beautify"
import Vuelidate from "vuelidate"
import PageBond from "renderer/components/staking/PageBond"

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, node }) => {
store.commit("setAtoms", 101)

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

let candidates = await node.candidates()
Copy link
Collaborator

Choose a reason for hiding this comment

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

candidates are directly exported from lcdClientMock as validators, no need to query them like this. we can leave it like this, though.

store.commit(
"addToCart",
Object.assign(
{
id: "pubkeyZ",
voting_power: 20000,
shares: 75000,
moniker: "aChileanValidator"
},
candidates[2] // this is the revoked one
)
)
}
})
store = test.store
Expand Down Expand Up @@ -426,4 +439,27 @@ 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="101"
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
22 changes: 11 additions & 11 deletions test/unit/specs/lcdClientMock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ describe("LCD Client Mock", () => {
it("executes a delegate tx", async () => {
let stake = await client.queryDelegation(
lcdClientMock.addresses[0],
lcdClientMock.validators[2]
lcdClientMock.validators[1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

because the validators[2] is the one with status revoked, so all the other tests get the revoked error before anything else happens

)
expect(stake).toBeUndefined()

Expand All @@ -280,7 +280,7 @@ describe("LCD Client Mock", () => {
delegations: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
delegation: { denom: "mycoin", amount: "10" }
}
],
Expand All @@ -292,7 +292,7 @@ describe("LCD Client Mock", () => {

let updatedStake = await client.queryDelegation(
lcdClientMock.addresses[0],
lcdClientMock.validators[2]
lcdClientMock.validators[1]
)
expect(updatedStake.shares).toBe("10")
})
Expand All @@ -304,7 +304,7 @@ describe("LCD Client Mock", () => {
delegations: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
delegation: { denom: "mycoin", amount: "10" }
}
],
Expand All @@ -316,7 +316,7 @@ describe("LCD Client Mock", () => {

let initialStake = await client.queryDelegation(
lcdClientMock.addresses[0],
lcdClientMock.validators[2]
lcdClientMock.validators[1]
)
expect(initialStake.shares).toBe("10")

Expand All @@ -327,7 +327,7 @@ describe("LCD Client Mock", () => {
begin_unbondings: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
shares: "5"
}
]
Expand All @@ -338,7 +338,7 @@ describe("LCD Client Mock", () => {

let updatedStake = await client.queryDelegation(
lcdClientMock.addresses[0],
lcdClientMock.validators[2]
lcdClientMock.validators[1]
)
expect(updatedStake.shares).toBe("5")
})
Expand Down Expand Up @@ -368,7 +368,7 @@ describe("LCD Client Mock", () => {
delegations: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
delegation: { denom: "mycoin", amount: "10" }
}
],
Expand All @@ -384,7 +384,7 @@ describe("LCD Client Mock", () => {
delegations: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
delegation: { denom: "mycoin", amount: "10" }
}
],
Expand Down Expand Up @@ -425,7 +425,7 @@ describe("LCD Client Mock", () => {
delegations: [
{
delegator_addr: lcdClientMock.addresses[0],
validator_addr: lcdClientMock.validators[2],
validator_addr: lcdClientMock.validators[1],
delegation: { denom: "mycoin", amount: "10" }
},
{
Expand All @@ -444,7 +444,7 @@ describe("LCD Client Mock", () => {

let stake1 = await client.queryDelegation(
lcdClientMock.addresses[0],
lcdClientMock.validators[2]
lcdClientMock.validators[1]
)
expect(stake1.shares).toMatchSnapshot()

Expand Down