From 333af87ce27af9bc40d43b490bf1b2c458a425e0 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Mon, 4 Feb 2019 01:13:31 +0100 Subject: [PATCH] tests: use simplified API for MultisigRedeemScriptType where possible This is possible when address_n is the same for all involved nodes --- .../tests/device_tests/test_msg_getaddress.py | 6 +- .../test_msg_getaddress_segwit.py | 10 +--- .../test_msg_getaddress_segwit_native.py | 20 ++----- .../device_tests/test_msg_signtx_bcash.py | 20 ++----- .../device_tests/test_msg_signtx_bgold.py | 20 ++----- .../device_tests/test_msg_signtx_decred.py | 6 +- .../device_tests/test_msg_signtx_segwit.py | 10 +--- .../test_msg_signtx_segwit_native.py | 60 ++++--------------- trezorlib/tests/device_tests/test_multisig.py | 20 ++----- .../device_tests/test_multisig_change.py | 49 +++++---------- vendor/trezor-common | 2 +- 11 files changed, 51 insertions(+), 172 deletions(-) diff --git a/trezorlib/tests/device_tests/test_msg_getaddress.py b/trezorlib/tests/device_tests/test_msg_getaddress.py index 4a9b014990..229220a300 100644 --- a/trezorlib/tests/device_tests/test_msg_getaddress.py +++ b/trezorlib/tests/device_tests/test_msg_getaddress.py @@ -25,10 +25,8 @@ from .common import TrezorTest def getmultisig(chain, nr, xpubs, signatures=[b"", b"", b""]): return proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=bip32.deserialize(xpub), address_n=[chain, nr]) - for xpub in xpubs - ], + nodes=[bip32.deserialize(xpub) for xpub in xpubs], + address_n=[chain, nr], signatures=signatures, m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_getaddress_segwit.py b/trezorlib/tests/device_tests/test_msg_getaddress_segwit.py index e505ea6252..769493245e 100644 --- a/trezorlib/tests/device_tests/test_msg_getaddress_segwit.py +++ b/trezorlib/tests/device_tests/test_msg_getaddress_segwit.py @@ -78,14 +78,8 @@ class TestMsgGetaddressSegwit(TrezorTest): range(1, 4), ) multisig1 = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=bip32.deserialize(n.xpub), address_n=[2, 0] - ), - nodes, - ) - ), + nodes=[bip32.deserialize(n.xpub) for n in nodes], + address_n=[2, 0], signatures=[b"", b"", b""], m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_getaddress_segwit_native.py b/trezorlib/tests/device_tests/test_msg_getaddress_segwit_native.py index 8b025cc0c0..c601cee841 100644 --- a/trezorlib/tests/device_tests/test_msg_getaddress_segwit_native.py +++ b/trezorlib/tests/device_tests/test_msg_getaddress_segwit_native.py @@ -76,26 +76,14 @@ class TestMsgGetaddressSegwitNative(TrezorTest): for index in range(1, 4) ] multisig1 = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=bip32.deserialize(n.xpub), address_n=[2, 0] - ), - nodes, - ) - ), + nodes=[bip32.deserialize(n.xpub) for n in nodes], + address_n=[2, 0], signatures=[b"", b"", b""], m=2, ) multisig2 = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=bip32.deserialize(n.xpub), address_n=[2, 1] - ), - nodes, - ) - ), + nodes=[bip32.deserialize(n.xpub) for n in nodes], + address_n=[2, 1], signatures=[b"", b"", b""], m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py index d5b645c1a0..772d89f114 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bcash.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bcash.py @@ -424,14 +424,8 @@ class TestMsgSigntxBch(TrezorTest): def getmultisig(chain, nr, signatures=[b"", b"", b""], xpubs=xpubs): return proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda xpub: proto.HDNodePathType( - node=deserialize(xpub), address_n=[chain, nr] - ), - xpubs, - ) - ), + nodes=[deserialize(xpub) for xpub in xpubs], + address_n=[chain, nr], signatures=signatures, m=2, ) @@ -524,14 +518,8 @@ class TestMsgSigntxBch(TrezorTest): def getmultisig(chain, nr, signatures=[b"", b"", b""], xpubs=xpubs): return proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda xpub: proto.HDNodePathType( - node=deserialize(xpub), address_n=[chain, nr] - ), - xpubs, - ) - ), + nodes=[deserialize(xpub) for xpub in xpubs], + address_n=[chain, nr], signatures=signatures, m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_bgold.py b/trezorlib/tests/device_tests/test_msg_signtx_bgold.py index d4bb4fe33a..b6dc12f453 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_bgold.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_bgold.py @@ -235,14 +235,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest): def getmultisig(chain, nr, signatures=[b"", b"", b""], xpubs=xpubs): return proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda xpub: proto.HDNodePathType( - node=deserialize(xpub), address_n=[chain, nr] - ), - xpubs, - ) - ), + nodes=[deserialize(xpub) for xpub in xpubs], + address_n=[chain, nr], signatures=signatures, m=2, ) @@ -509,14 +503,8 @@ class TestMsgSigntxBitcoinGold(TrezorTest): range(1, 4), ) multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_decred.py b/trezorlib/tests/device_tests/test_msg_signtx_decred.py index ceb1116dbc..76b1d603a6 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_decred.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_decred.py @@ -290,10 +290,8 @@ class TestMsgSigntxDecred(TrezorTest): def create_multisig(index, address, signatures=None): address_n = parse_path(address) multisig = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=node, address_n=address_n) - for node in nodes - ], + nodes=nodes, + address_n=address_n, signatures=signatures, m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py index 8688517120..48307727be 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit.py @@ -223,14 +223,8 @@ class TestMsgSigntxSegwit(TrezorTest): range(1, 4), ) multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) diff --git a/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py b/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py index 80fc3de2ea..81c796ea30 100644 --- a/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py +++ b/trezorlib/tests/device_tests/test_msg_signtx_segwit_native.py @@ -410,14 +410,8 @@ class TestMsgSigntxSegwitNative(TrezorTest): for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[0, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[0, 0], signatures=[b"", b"", b""], m=2, ) @@ -517,14 +511,8 @@ class TestMsgSigntxSegwitNative(TrezorTest): for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[0, 1] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[0, 1], signatures=[b"", b"", b""], m=2, ) @@ -624,26 +612,14 @@ class TestMsgSigntxSegwitNative(TrezorTest): for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) multisig2 = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 1] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 1], signatures=[b"", b"", b""], m=2, ) @@ -743,26 +719,14 @@ class TestMsgSigntxSegwitNative(TrezorTest): for index in range(1, 4) ] multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 1] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 1], signatures=[b"", b"", b""], m=2, ) multisig2 = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[1, 2] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[1, 2], signatures=[b"", b"", b""], m=2, ) diff --git a/trezorlib/tests/device_tests/test_multisig.py b/trezorlib/tests/device_tests/test_multisig.py index e679372738..41b48913a2 100644 --- a/trezorlib/tests/device_tests/test_multisig.py +++ b/trezorlib/tests/device_tests/test_multisig.py @@ -40,14 +40,8 @@ class TestMultisig(TrezorTest): ] multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[0, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[0, 0], signatures=[b"", b"", b""], m=2, ) @@ -131,14 +125,8 @@ class TestMultisig(TrezorTest): # Let's do second signature using 3rd key multisig = proto.MultisigRedeemScriptType( - pubkeys=list( - map( - lambda n: proto.HDNodePathType( - node=deserialize(n.xpub), address_n=[0, 0] - ), - nodes, - ) - ), + nodes=[deserialize(n.xpub) for n in nodes], + address_n=[0, 0], signatures=[ signatures1[0], b"", diff --git a/trezorlib/tests/device_tests/test_multisig_change.py b/trezorlib/tests/device_tests/test_multisig_change.py index 2676b61347..957e09c679 100644 --- a/trezorlib/tests/device_tests/test_multisig_change.py +++ b/trezorlib/tests/device_tests/test_multisig_change.py @@ -69,31 +69,22 @@ class TestMultisigChange(TrezorTest): # input 1: 0.001 BTC multisig_in1 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=node_ext2, address_n=[0, 0]), - proto.HDNodePathType(node=node_ext1, address_n=[0, 0]), - proto.HDNodePathType(node=node_int, address_n=[0, 0]), - ], + nodes=[node_ext2, node_ext1, node_int], + address_n=[0, 0], signatures=[b"", b"", b""], m=2, ) multisig_in2 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=node_ext1, address_n=[0, 1]), - proto.HDNodePathType(node=node_ext2, address_n=[0, 1]), - proto.HDNodePathType(node=node_int, address_n=[0, 1]), - ], + nodes=[node_ext1, node_ext2, node_int], + address_n=[0, 1], signatures=[b"", b"", b""], m=2, ) multisig_in3 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=node_ext1, address_n=[0, 1]), - proto.HDNodePathType(node=node_ext3, address_n=[0, 1]), - proto.HDNodePathType(node=node_int, address_n=[0, 1]), - ], + nodes=[node_ext1, node_ext3, node_int], + address_n=[0, 1], signatures=[b"", b"", b""], m=2, ) @@ -395,11 +386,8 @@ class TestMultisigChange(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() multisig_out1 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=self.node_ext2, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_ext1, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_int, address_n=[1, 0]), - ], + nodes=[self.node_ext2, self.node_ext1, self.node_int], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) @@ -439,11 +427,8 @@ class TestMultisigChange(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() multisig_out2 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=self.node_ext1, address_n=[1, 1]), - proto.HDNodePathType(node=self.node_ext2, address_n=[1, 1]), - proto.HDNodePathType(node=self.node_int, address_n=[1, 1]), - ], + nodes=[self.node_ext1, self.node_ext2, self.node_int], + address_n=[1, 1], signatures=[b"", b"", b""], m=2, ) @@ -483,11 +468,8 @@ class TestMultisigChange(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() multisig_out2 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=self.node_ext1, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_int, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_ext3, address_n=[1, 0]), - ], + nodes=[self.node_ext1, self.node_int, self.node_ext3], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) @@ -525,11 +507,8 @@ class TestMultisigChange(TrezorTest): self.setup_mnemonic_nopin_nopassphrase() multisig_out1 = proto.MultisigRedeemScriptType( - pubkeys=[ - proto.HDNodePathType(node=self.node_ext2, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_ext1, address_n=[1, 0]), - proto.HDNodePathType(node=self.node_int, address_n=[1, 0]), - ], + nodes=[self.node_ext2, self.node_ext1, self.node_int], + address_n=[1, 0], signatures=[b"", b"", b""], m=2, ) diff --git a/vendor/trezor-common b/vendor/trezor-common index 4b41d2e638..0735c7d6f5 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 4b41d2e63841517bf701618434c018acf4f1bca2 +Subproject commit 0735c7d6f524b4c5108d201c789612aad7ce7920