forked from input-output-hk/daedalus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDW-722] Change usb detection strategy
- Loading branch information
1 parent
b591026
commit 804ef8b
Showing
16 changed files
with
858 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
!source/ | ||
!features/ | ||
!storybook/ | ||
!hardware-wallet-tests/ | ||
|
||
# Now we ignore all files | ||
*.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
import expect from 'expect'; | ||
|
||
import { | ||
createAndRegisterHardwareWalletChannels, | ||
createHardwareWalletConnectionChannel, | ||
initLedgerChannel, | ||
createSequentialPromptMessages, | ||
createCardanoAppChannel, | ||
createGetPublicKeyChannel, | ||
ipcRenderer, | ||
} from './utils'; | ||
|
||
export const run = () => { | ||
expect.assertions(3); | ||
|
||
createSequentialPromptMessages([ | ||
'Plug Ledger Nano S to your computer', | ||
'Start Cardano APP on Nano S', | ||
'Run the test again with Cardano App opened', | ||
'Export the public key', | ||
]); | ||
|
||
createAndRegisterHardwareWalletChannels(); | ||
|
||
const cardanoAppChannel = createCardanoAppChannel(); | ||
const publicKeyChannel = createGetPublicKeyChannel(); | ||
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel(); | ||
|
||
return new Promise((resolve) => { | ||
hardwareWalletConnectionChannel.onReceive( | ||
async (params: { path: string }) => { | ||
expect(params).toEqual({ | ||
disconnected: expect.any(Boolean), | ||
deviceType: expect.any(String), | ||
deviceId: null, | ||
deviceModel: expect.any(String), | ||
deviceName: expect.any(String), | ||
path: expect.any(String), | ||
}); | ||
|
||
const cardanoAppChannelReply = await cardanoAppChannel.request( | ||
{ path: params.path }, | ||
ipcRenderer, | ||
ipcRenderer | ||
); | ||
|
||
expect(cardanoAppChannelReply).toEqual({ | ||
minor: expect.any(Number), | ||
major: expect.any(Number), | ||
patch: expect.any(Number), | ||
deviceId: expect.any(String), | ||
}); | ||
|
||
const extendedPublicKey = await publicKeyChannel.request( | ||
{ | ||
path: "1852'/1815'/0'", | ||
// Shelley 1852 ADA 1815 indicator for account '0' | ||
isTrezor: false, | ||
devicePath: params.path, | ||
}, | ||
ipcRenderer, | ||
ipcRenderer | ||
); | ||
|
||
expect(extendedPublicKey).toEqual({ | ||
chainCodeHex: expect.any(String), | ||
publicKeyHex: expect.any(String), | ||
deviceId: expect.any(String), | ||
}); | ||
|
||
resolve(null); | ||
} | ||
); | ||
|
||
initLedgerChannel(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
import expect from 'expect'; | ||
|
||
import { | ||
createAndRegisterHardwareWalletChannels, | ||
createHardwareWalletConnectionChannel, | ||
initLedgerChannel, | ||
createSequentialPromptMessages, | ||
createGetPublicKeyChannel, | ||
ipcRenderer, | ||
pollCardarnoApp, | ||
} from './utils'; | ||
|
||
export const run = () => { | ||
expect.assertions(3); | ||
|
||
createSequentialPromptMessages([ | ||
'Start test runner', | ||
'Plug Ledger Nano S to your computer', | ||
'Start Cardano APP on Nano S', | ||
'Nano S will prompt to export the public key', | ||
'Export the public key', | ||
]); | ||
|
||
createAndRegisterHardwareWalletChannels(); | ||
|
||
const publicKeyChannel = createGetPublicKeyChannel(); | ||
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel(); | ||
|
||
return new Promise((resolve) => { | ||
hardwareWalletConnectionChannel.onReceive( | ||
async (params: { path: string }) => { | ||
expect(params).toEqual({ | ||
disconnected: expect.any(Boolean), | ||
deviceType: expect.any(String), | ||
deviceId: null, | ||
deviceModel: expect.any(String), | ||
deviceName: expect.any(String), | ||
path: expect.any(String), | ||
}); | ||
|
||
try { | ||
const cardanoAppChannelReply = await pollCardarnoApp(params.path); | ||
|
||
expect(cardanoAppChannelReply).toEqual({ | ||
minor: expect.any(Number), | ||
major: expect.any(Number), | ||
patch: expect.any(Number), | ||
deviceId: expect.any(String), | ||
}); | ||
|
||
const extendedPublicKey = await publicKeyChannel.request( | ||
{ | ||
path: "1852'/1815'/0'", | ||
// Shelley 1852 ADA 1815 indicator for account '0' | ||
isTrezor: false, | ||
devicePath: params.path, | ||
}, | ||
ipcRenderer, | ||
ipcRenderer | ||
); | ||
|
||
expect(extendedPublicKey).toEqual({ | ||
chainCodeHex: expect.any(String), | ||
publicKeyHex: expect.any(String), | ||
deviceId: expect.any(String), | ||
}); | ||
|
||
resolve(null); | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
); | ||
|
||
initLedgerChannel(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import prompts from 'prompts'; | ||
|
||
import { run as runRemoveMultipleHardwareWallets } from './remove-multiple-hardware-wallets'; | ||
import { run as runCardanoAppAlreadyConnected } from './cardano-app-already-connected'; | ||
import { run as runCardanoAppNotStarted } from './cardano-app-not-started'; | ||
import { run as runRemoveSingleHardwareWallet } from './remove-single-hardware-wallet'; | ||
import { run as runMultipleHardwareWallets } from './multiple-hardware-wallets'; | ||
|
||
const CARDANO_APP_ALREADY_LAUNCHED = 'CARDANO_APP_ALREADY_LAUNCHED'; | ||
const CARDANO_APP_NOT_STARTED = 'CARDANO_APP_NOT_STARTED'; | ||
const SINGLE_LEDGER_REMOVED = 'SINGLE_LEDGER_REMOVED'; | ||
const MULTIPLE_HARDWARE_WALLETS = 'MULTIPLE_HARDWARE_WALLETS'; | ||
const MULTIPLE_HARDWARE_WALLETS_REMOVED = 'MULTIPLE_HARDWARE_WALLETS_REMOVED'; | ||
|
||
(async () => { | ||
const { testType } = await prompts({ | ||
type: 'select', | ||
name: 'testType', | ||
message: 'Ledger Hardware Wallets Channel', | ||
choices: [ | ||
{ | ||
title: 'export public key when Cardano APP is already connected', | ||
value: CARDANO_APP_ALREADY_LAUNCHED, | ||
}, | ||
{ | ||
title: | ||
'export public key when Cardano APP is launched after test runner already has started', | ||
value: CARDANO_APP_NOT_STARTED, | ||
}, | ||
{ title: 'detect when ledger is removed', value: SINGLE_LEDGER_REMOVED }, | ||
{ | ||
title: 'connect both Nano S and Nano X', | ||
value: MULTIPLE_HARDWARE_WALLETS, | ||
}, | ||
{ | ||
title: 'detect when multiple hardware wallets are removed', | ||
value: MULTIPLE_HARDWARE_WALLETS_REMOVED, | ||
}, | ||
{ title: 'exit', value: 'exit' }, | ||
], | ||
}); | ||
|
||
switch (testType) { | ||
case CARDANO_APP_ALREADY_LAUNCHED: | ||
await runCardanoAppAlreadyConnected(); | ||
break; | ||
|
||
case CARDANO_APP_NOT_STARTED: | ||
await runCardanoAppNotStarted(); | ||
break; | ||
|
||
case SINGLE_LEDGER_REMOVED: | ||
await runRemoveSingleHardwareWallet(); | ||
break; | ||
|
||
case MULTIPLE_HARDWARE_WALLETS: | ||
await runMultipleHardwareWallets(); | ||
break; | ||
|
||
case MULTIPLE_HARDWARE_WALLETS_REMOVED: | ||
await runRemoveMultipleHardwareWallets(); | ||
break; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
process.exit(0); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
import expect from 'expect'; | ||
|
||
import { | ||
createAndRegisterHardwareWalletChannels, | ||
createHardwareWalletConnectionChannel, | ||
createSequentialResult, | ||
initLedgerChannel, | ||
createSequentialPromptMessages, | ||
} from './utils'; | ||
|
||
export const run = () => { | ||
expect.assertions(2); | ||
|
||
createAndRegisterHardwareWalletChannels(); | ||
|
||
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel(); | ||
|
||
const promptMessages = createSequentialPromptMessages([ | ||
'Start test runner', | ||
'Plug Ledger Nano S to your computer', | ||
'Plug Ledger Nano X to your computer', | ||
]); | ||
|
||
promptMessages(); | ||
|
||
const expectedSequence = createSequentialResult([ | ||
{ | ||
disconnected: false, | ||
deviceModel: 'nanoS', | ||
}, | ||
{ | ||
disconnected: false, | ||
deviceModel: 'nanoX', | ||
}, | ||
]); | ||
|
||
return new Promise((resolve) => { | ||
hardwareWalletConnectionChannel.onReceive( | ||
async (params: { path: string; deviceModel: string }) => { | ||
const [expectedValue, isOver] = expectedSequence(); | ||
expect(params).toEqual(expectedValue); | ||
|
||
if (isOver) { | ||
resolve(null); | ||
} | ||
} | ||
); | ||
|
||
initLedgerChannel(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable jest/no-standalone-expect */ | ||
import expect from 'expect'; | ||
|
||
import { | ||
createAndRegisterHardwareWalletChannels, | ||
createHardwareWalletConnectionChannel, | ||
createSequentialResult, | ||
initLedgerChannel, | ||
createSequentialPromptMessages, | ||
} from './utils'; | ||
|
||
const expectedSequence = createSequentialResult([ | ||
{ | ||
disconnected: false, | ||
deviceModel: 'nanoS', | ||
}, | ||
{ | ||
disconnected: false, | ||
deviceModel: 'nanoX', | ||
}, | ||
{ | ||
disconnected: true, | ||
deviceModel: 'nanoS', | ||
}, | ||
{ | ||
disconnected: true, | ||
deviceModel: 'nanoX', | ||
}, | ||
]); | ||
|
||
export const run = () => { | ||
expect.assertions(4); | ||
|
||
createAndRegisterHardwareWalletChannels(); | ||
|
||
const hardwareWalletConnectionChannel = createHardwareWalletConnectionChannel(); | ||
|
||
const promptMessages = createSequentialPromptMessages([ | ||
'Connect Nano S', | ||
'Connect Nano X', | ||
'Disconnect Nano S', | ||
'Disconnect Nano X', | ||
]); | ||
|
||
promptMessages(); | ||
|
||
return new Promise((resolve) => { | ||
hardwareWalletConnectionChannel.onReceive( | ||
async (params: { path: string; deviceModel: string }) => { | ||
const [expectedValue, isOver] = expectedSequence(); | ||
|
||
expect(params).toEqual(expectedValue); | ||
|
||
if (isOver) { | ||
return resolve(null); | ||
} | ||
|
||
promptMessages(); | ||
} | ||
); | ||
|
||
initLedgerChannel(); | ||
}); | ||
}; |
Oops, something went wrong.