Tests and fixes for remaining Ledger commands

Tests and fixes for promptpin, sendpin, setup, wipe, restore, backup,
and signmessage commands
This commit is contained in:
Andrew Chow 2019-02-04 17:47:49 -05:00
parent d627634ce6
commit a38e993607
2 changed files with 47 additions and 2 deletions

View File

@ -309,7 +309,7 @@ class LedgerClient(HardwareWalletClient):
raise UnavailableActionError('The Ledger Nano S does not need a PIN sent from the host')
# Send pin
def send_pin(self):
def send_pin(self, pin):
raise UnavailableActionError('The Ledger Nano S does not need a PIN sent from the host')
def enumerate(password=''):

View File

@ -10,7 +10,7 @@ import time
import unittest
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from test_device import DeviceTestCase, start_bitcoind, TestDeviceConnect, TestDisplayAddress, TestGetKeypool, TestSignTx
from test_device import DeviceTestCase, start_bitcoind, TestDeviceConnect, TestDisplayAddress, TestGetKeypool, TestSignMessage, TestSignTx
from hwilib.cli import process_commands
@ -28,12 +28,57 @@ def ledger_test_suite(rpc, userpass):
break
assert(path is not None and master_xpub is not None and fingerprint is not None)
# Ledger specific disabled command tests
class TestLedgerDisabledCommands(DeviceTestCase):
def test_pin(self):
result = process_commands(self.dev_args + ['promptpin'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not need a PIN sent from the host')
self.assertEqual(result['code'], -9)
result = process_commands(self.dev_args + ['sendpin', '1234'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not need a PIN sent from the host')
self.assertEqual(result['code'], -9)
def test_setup(self):
result = process_commands(self.dev_args + ['setup'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not support software setup')
self.assertEqual(result['code'], -9)
def test_wipe(self):
result = process_commands(self.dev_args + ['wipe'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not support wiping via software')
self.assertEqual(result['code'], -9)
def test_restore(self):
result = process_commands(self.dev_args + ['restore'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not support restoring via software')
self.assertEqual(result['code'], -9)
def test_backup(self):
result = process_commands(self.dev_args + ['backup'])
self.assertIn('error', result)
self.assertIn('code', result)
self.assertEqual(result['error'], 'The Ledger Nano S does not support creating a backup via software')
self.assertEqual(result['code'], -9)
# Generic Device tests
suite = unittest.TestSuite()
suite.addTest(DeviceTestCase.parameterize(TestLedgerDisabledCommands, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
suite.addTest(DeviceTestCase.parameterize(TestDeviceConnect, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
suite.addTest(DeviceTestCase.parameterize(TestGetKeypool, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
suite.addTest(DeviceTestCase.parameterize(TestDisplayAddress, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
suite.addTest(DeviceTestCase.parameterize(TestSignMessage, rpc, userpass, 'ledger', path, fingerprint, master_xpub))
return suite
if __name__ == '__main__':