test uses BitkeyClient

pull/25/head
slush 12 years ago
parent 437d88db1b
commit fdd090b67e

@ -6,50 +6,16 @@ from transport_pipe import PipeTransport
from transport_serial import SerialTransport
from bitkey_proto import bitkey_pb2 as proto
def pprint(msg):
return "<%s>:\n%s" % (msg.__class__.__name__, msg)
from client import BitkeyClient
def call(msg, tries=3):
print '----------------------'
print "Sending", pprint(msg)
d.write(msg)
resp = d.read()
if isinstance(resp, proto.OtpRequest):
if resp.message:
print "Message:", resp.message
otp = raw_input("OTP required: ")
d.write(proto.OtpAck(otp=otp))
resp = d.read()
bitkey = BitkeyClient('../bitkey-python/device.socket', debug=True)
bitkey.open()
bitkey.call(proto.Ping(message='ahoj!'))
bitkey.call(proto.SetMaxFeeKb(maxfee_kb=200000))
bitkey.close()
if isinstance(resp, proto.PinRequest):
if resp.message:
print "Message:", resp.message
pin = raw_input("PIN required: ")
d.write(proto.PinAck(pin=pin))
resp = d.read()
if isinstance(resp, proto.Failure) and resp.code in (3, 6):
if tries <= 1 and resp.code == 3:
raise Exception("OTP is invalid, too many retries")
if tries <= 1 and resp.code == 6:
raise Exception("PIN is invalid, too many retries")
# Invalid OTP or PIN, try again
if resp.code == 3:
print "OTP is invalid, let's try again..."
elif resp.code == 6:
print "PIN is invalid, let's try again..."
return call(msg, tries-1)
if isinstance(resp, proto.Failure):
raise Exception(resp.code, resp.message)
print "Received", pprint(resp)
return resp
d = PipeTransport('../../bitkey-python/device.socket', is_device=False)
'''
d = PipeTransport('../bitkey-python/device.socket', is_device=False)
#d = SerialTransport('../../bitkey-python/COM9')
#start = time.time()
@ -66,5 +32,6 @@ call(proto.GetUUID())
#call(proto.ResetDevice())
call(proto.GetMasterPublicKey(algo=proto.ELECTRUM))
#call(proto.ResetDevice())
'''
#print 10000 / (time.time() - start)

Loading…
Cancel
Save