From 919f9c526c69f4110d1b96ea12e93430ccce42be Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 26 Feb 2019 18:19:03 +0100 Subject: [PATCH 1/6] fix screensaver mode edge case --- app/src/renderer/vuex/modules/ledger.js | 18 ++++++++- test/unit/specs/store/ledger.spec.js | 50 ++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/app/src/renderer/vuex/modules/ledger.js b/app/src/renderer/vuex/modules/ledger.js index 665d86c356..a7f3f2d769 100644 --- a/app/src/renderer/vuex/modules/ledger.js +++ b/app/src/renderer/vuex/modules/ledger.js @@ -50,25 +50,39 @@ export default () => { }, async pollLedgerDevice({ state }) { // poll device with low timeout to check if the device is connected - const secondsTimeout = 2 // with less than 2 secs it always timeouts + const secondsTimeout = 2 // a lower value it always timeouts const communicationMethod = await state.externals.comm_u2f.create_async( secondsTimeout, true ) const cosmosLedgerApp = new state.externals.App(communicationMethod) - const response = await cosmosLedgerApp.get_version() + let response = await cosmosLedgerApp.get_version() + // check if the device is connected switch (response.error_message) { case `U2F: Timeout`: throw new Error(`No Ledger found`) case `Cosmos app does not seem to be open`: throw new Error(`Cøsmos app is not open`) + case `No errors`: + // do nothing and continue + break + default: + throw new Error(response.error_message) + } + + // check if the device is on screensaver mode + response = await cosmosLedgerApp.publicKey(HDPATH) + switch (response.error_message) { + case `Unknown error code`: // TODO: create error for screensaver mode + throw new Error(`Ledger's screensaver mode is on`) case `No errors`: // do nothing break default: throw new Error(response.error_message) } + }, async createLedgerAppInstance({ commit, state }) { const communicationMethod = await state.externals.comm_u2f.create_async( diff --git a/test/unit/specs/store/ledger.spec.js b/test/unit/specs/store/ledger.spec.js index 190532b870..95e3e255b9 100644 --- a/test/unit/specs/store/ledger.spec.js +++ b/test/unit/specs/store/ledger.spec.js @@ -118,6 +118,10 @@ describe(`Module: Ledger`, () => { it(`when Ledger is connected and app is open`, async () => { state.externals.App = () => ({ get_version: () => + Promise.resolve({ + error_message: `No errors` + }), + publicKey: () => Promise.resolve({ error_message: `No errors` }) @@ -130,6 +134,10 @@ describe(`Module: Ledger`, () => { it(`when Ledger is connected but app is not open`, async () => { state.externals.App = () => ({ get_version: () => + Promise.resolve({ + error_message: `Cosmos app does not seem to be open` + }), + publicKey: () => Promise.resolve({ error_message: `Cosmos app does not seem to be open` }) @@ -142,6 +150,10 @@ describe(`Module: Ledger`, () => { it(`when Ledger not connected`, async () => { state.externals.App = () => ({ get_version: () => + Promise.resolve({ + error_message: `U2F: Timeout` + }), + publicKey: () => Promise.resolve({ error_message: `U2F: Timeout` }) @@ -151,17 +163,53 @@ describe(`Module: Ledger`, () => { ) }) - it(`fails due to other error`, async () => { + it(`when Ledger is on screensaver mode`, async () => { + state.externals.App = () => ({ + get_version: () => + Promise.resolve({ + error_message: `No errors` + }), + publicKey: () => + Promise.resolve({ + error_message: `Unknown error code` + }) + }) + await expect(actions.pollLedgerDevice({ state })).rejects.toThrow( + `Ledger's screensaver mode is on` + ) + }) + + it(`fails if get_version throws`, async () => { state.externals.App = () => ({ get_version: () => Promise.resolve({ error_message: `Device is busy` + }), + publicKey: () => + Promise.resolve({ + error_message: `Empty Buffer` }) }) await expect(actions.pollLedgerDevice({ state })).rejects.toThrow( `Device is busy` ) }) + + it(`fails if publicKey throws`, async () => { + state.externals.App = () => ({ + get_version: () => + Promise.resolve({ + error_message: `No errors` + }), + publicKey: () => + Promise.resolve({ + error_message: `Execution Error` + }) + }) + await expect(actions.pollLedgerDevice({ state })).rejects.toThrow( + `Execution Error` + ) + }) }) describe(`create ledger app`, () => { From 108bef46bca6cd88536fc1f79793c9e9763db958 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 26 Feb 2019 18:21:51 +0100 Subject: [PATCH 2/6] changelog and stuff --- CHANGELOG.md | 1 + test/unit/specs/components/staking/TableValidators.spec.js | 2 +- test/unit/specs/components/wallet/LiCoin.spec.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f3631ae79..68a15e152c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Fixed delegations not loaded on validator lists @faboweb +- [\#2015](https://github.com/cosmos/voyager/issues/2015) fixed error that showed wrong message when Ledger's screensaver mode was on @fedekunze ### Fixed diff --git a/test/unit/specs/components/staking/TableValidators.spec.js b/test/unit/specs/components/staking/TableValidators.spec.js index 504ec99223..5b0ac593ea 100644 --- a/test/unit/specs/components/staking/TableValidators.spec.js +++ b/test/unit/specs/components/staking/TableValidators.spec.js @@ -90,7 +90,7 @@ describe(`TableValidators`, () => { it(`queries delegations on signin`, () => { const updateDelegates = jest.fn() - TableValidators.watch.signedIn.call({updateDelegates}, true) + TableValidators.watch.signedIn.call({ updateDelegates }, true) expect(updateDelegates).toHaveBeenCalled() }) }) diff --git a/test/unit/specs/components/wallet/LiCoin.spec.js b/test/unit/specs/components/wallet/LiCoin.spec.js index 06320c3866..45473bd432 100644 --- a/test/unit/specs/components/wallet/LiCoin.spec.js +++ b/test/unit/specs/components/wallet/LiCoin.spec.js @@ -1,4 +1,4 @@ -import {shallowMount} from "@vue/test-utils" +import { shallowMount } from "@vue/test-utils" import num from "scripts/num" import LiCoin from "renderer/components/wallet/LiCoin" From 9d0ae58120f5beb2921889ff931bce61c95e52b0 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 26 Feb 2019 18:24:28 +0100 Subject: [PATCH 3/6] increased timeout to poll ledger --- app/src/renderer/vuex/modules/ledger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/renderer/vuex/modules/ledger.js b/app/src/renderer/vuex/modules/ledger.js index a7f3f2d769..ca2571afc8 100644 --- a/app/src/renderer/vuex/modules/ledger.js +++ b/app/src/renderer/vuex/modules/ledger.js @@ -50,7 +50,7 @@ export default () => { }, async pollLedgerDevice({ state }) { // poll device with low timeout to check if the device is connected - const secondsTimeout = 2 // a lower value it always timeouts + const secondsTimeout = 3 // a lower value it always timeouts const communicationMethod = await state.externals.comm_u2f.create_async( secondsTimeout, true From 175c0376d8a824d640d4abbfd0e5be2c25cc8a69 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Tue, 26 Feb 2019 18:24:48 +0100 Subject: [PATCH 4/6] comment --- app/src/renderer/vuex/modules/ledger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/renderer/vuex/modules/ledger.js b/app/src/renderer/vuex/modules/ledger.js index ca2571afc8..60202a5efe 100644 --- a/app/src/renderer/vuex/modules/ledger.js +++ b/app/src/renderer/vuex/modules/ledger.js @@ -50,7 +50,7 @@ export default () => { }, async pollLedgerDevice({ state }) { // poll device with low timeout to check if the device is connected - const secondsTimeout = 3 // a lower value it always timeouts + const secondsTimeout = 3 // a lower value always timeouts const communicationMethod = await state.externals.comm_u2f.create_async( secondsTimeout, true From 166fe453278dc58a3702655bebf89b22899ff3e7 Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 27 Feb 2019 12:07:23 +0100 Subject: [PATCH 5/6] use pubKey for polling --- app/src/renderer/vuex/modules/ledger.js | 14 ++-------- test/unit/specs/store/ledger.spec.js | 36 ------------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/app/src/renderer/vuex/modules/ledger.js b/app/src/renderer/vuex/modules/ledger.js index 60202a5efe..14e4cbe04f 100644 --- a/app/src/renderer/vuex/modules/ledger.js +++ b/app/src/renderer/vuex/modules/ledger.js @@ -56,24 +56,14 @@ export default () => { true ) const cosmosLedgerApp = new state.externals.App(communicationMethod) - let response = await cosmosLedgerApp.get_version() - // check if the device is connected + // check if the device is connected or on screensaver mode + const response = await cosmosLedgerApp.publicKey(HDPATH) switch (response.error_message) { case `U2F: Timeout`: throw new Error(`No Ledger found`) case `Cosmos app does not seem to be open`: throw new Error(`Cøsmos app is not open`) - case `No errors`: - // do nothing and continue - break - default: - throw new Error(response.error_message) - } - - // check if the device is on screensaver mode - response = await cosmosLedgerApp.publicKey(HDPATH) - switch (response.error_message) { case `Unknown error code`: // TODO: create error for screensaver mode throw new Error(`Ledger's screensaver mode is on`) case `No errors`: diff --git a/test/unit/specs/store/ledger.spec.js b/test/unit/specs/store/ledger.spec.js index 95e3e255b9..ef180e4208 100644 --- a/test/unit/specs/store/ledger.spec.js +++ b/test/unit/specs/store/ledger.spec.js @@ -117,10 +117,6 @@ describe(`Module: Ledger`, () => { describe(`poll Ledger device`, () => { it(`when Ledger is connected and app is open`, async () => { state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `No errors` - }), publicKey: () => Promise.resolve({ error_message: `No errors` @@ -133,10 +129,6 @@ describe(`Module: Ledger`, () => { it(`when Ledger is connected but app is not open`, async () => { state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `Cosmos app does not seem to be open` - }), publicKey: () => Promise.resolve({ error_message: `Cosmos app does not seem to be open` @@ -149,10 +141,6 @@ describe(`Module: Ledger`, () => { it(`when Ledger not connected`, async () => { state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `U2F: Timeout` - }), publicKey: () => Promise.resolve({ error_message: `U2F: Timeout` @@ -165,10 +153,6 @@ describe(`Module: Ledger`, () => { it(`when Ledger is on screensaver mode`, async () => { state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `No errors` - }), publicKey: () => Promise.resolve({ error_message: `Unknown error code` @@ -179,28 +163,8 @@ describe(`Module: Ledger`, () => { ) }) - it(`fails if get_version throws`, async () => { - state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `Device is busy` - }), - publicKey: () => - Promise.resolve({ - error_message: `Empty Buffer` - }) - }) - await expect(actions.pollLedgerDevice({ state })).rejects.toThrow( - `Device is busy` - ) - }) - it(`fails if publicKey throws`, async () => { state.externals.App = () => ({ - get_version: () => - Promise.resolve({ - error_message: `No errors` - }), publicKey: () => Promise.resolve({ error_message: `Execution Error` From afe62ace7b360f7bc661d2964b2f2f4f3761df3a Mon Sep 17 00:00:00 2001 From: Federico Kunze Date: Wed, 27 Feb 2019 12:09:48 +0100 Subject: [PATCH 6/6] spacing --- app/src/renderer/vuex/modules/ledger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/renderer/vuex/modules/ledger.js b/app/src/renderer/vuex/modules/ledger.js index 14e4cbe04f..6712c7f015 100644 --- a/app/src/renderer/vuex/modules/ledger.js +++ b/app/src/renderer/vuex/modules/ledger.js @@ -59,6 +59,7 @@ export default () => { // check if the device is connected or on screensaver mode const response = await cosmosLedgerApp.publicKey(HDPATH) + switch (response.error_message) { case `U2F: Timeout`: throw new Error(`No Ledger found`) @@ -72,7 +73,6 @@ export default () => { default: throw new Error(response.error_message) } - }, async createLedgerAppInstance({ commit, state }) { const communicationMethod = await state.externals.comm_u2f.create_async(