Coldcard: send keypresses to the simulator for user input things

signtx, signmessage, and displayaddress need user input which can't
be sent on the headless simulator. So instead send the keypresses
in those commands if it's the simulator.
This commit is contained in:
Andrew Chow 2019-01-06 15:48:46 -05:00
parent 942969cfb7
commit bdadd8e19e
2 changed files with 7 additions and 3 deletions

View File

@ -74,6 +74,8 @@ class ColdcardClient(HardwareWalletClient):
# start the signing process
ok = self.device.send_recv(CCProtocolPacker.sign_transaction(sz, expect), timeout=None)
assert ok == None
if self.device.is_simulator:
self.device.send_recv(CCProtocolPacker.sim_keypress(b'y'))
print("Waiting for OK on the Coldcard...")
@ -102,6 +104,8 @@ class ColdcardClient(HardwareWalletClient):
try:
ok = self.device.send_recv(CCProtocolPacker.sign_message(message.encode(), keypath, AF_CLASSIC), timeout=None)
assert ok == None
if self.device.is_simulator:
self.device.send_recv(CCProtocolPacker.sim_keypress(b'y'))
except CCProtoError as e:
raise ValueError(str(e))
@ -134,6 +138,8 @@ class ColdcardClient(HardwareWalletClient):
else:
format = AF_CLASSIC
address = self.device.send_recv(CCProtocolPacker.show_address(keypath, format), timeout=None)
if self.device.is_simulator:
self.device.send_recv(CCProtocolPacker.sim_keypress(b'y'))
return {'address': address}
# Setup a new device

View File

@ -50,9 +50,7 @@ def coldcard_test_suite(simulator, rpc, userpass):
suite.addTest(DeviceTestCase.parameterize(TestGetKeypool, rpc, userpass, 'coldcard', '/tmp/ckcc-simulator.sock', '0f056943', 'tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd'))
suite.addTest(DeviceTestCase.parameterize(TestDisplayAddress, rpc, userpass, 'coldcard', '/tmp/ckcc-simulator.sock', '0f056943', 'tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd'))
suite.addTest(DeviceTestCase.parameterize(TestSignMessage, rpc, userpass, 'coldcard', '/tmp/ckcc-simulator.sock', '0f056943', 'tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd'))
# HACK: Skip this in headless simulator because it requires user input
if not simulator.endswith('headless.py'):
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, 'coldcard', '/tmp/ckcc-simulator.sock', '0f056943', 'tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd'))
suite.addTest(DeviceTestCase.parameterize(TestSignTx, rpc, userpass, 'coldcard', '/tmp/ckcc-simulator.sock', '0f056943', 'tpubDDpWvmUrPZrhSPmUzCMBHffvC3HyMAPnWDSAQNBTnj1iZeJa7BZQEttFiP4DS4GCcXQHezdXhn86Hj6LHX5EDstXPWrMaSneRWM8yUf6NFd'))
return suite
if __name__ == '__main__':