1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-11 17:08:15 +00:00

style(core/tests): apply formatting

[no changelog]
This commit is contained in:
Ondřej Vejpustek 2024-11-15 15:02:47 +01:00
parent 97b2e6c751
commit 8bf23696e1
28 changed files with 649 additions and 184 deletions

View File

@ -43,9 +43,9 @@ def make_payload(
prefix: bytes = b"trzd1", prefix: bytes = b"trzd1",
data_type: EthereumDefinitionType = EthereumDefinitionType.NETWORK, data_type: EthereumDefinitionType = EthereumDefinitionType.NETWORK,
timestamp: int = 0xFFFF_FFFF, timestamp: int = 0xFFFF_FFFF,
message: messages.EthereumNetworkInfo message: (
| messages.EthereumTokenInfo messages.EthereumNetworkInfo | messages.EthereumTokenInfo | bytes
| bytes = make_network(), ) = make_network(),
) -> bytes: ) -> bytes:
payload = prefix payload = prefix
payload += data_type.to_bytes(1, "little") payload += data_type.to_bytes(1, "little")

View File

@ -283,7 +283,7 @@ vectors = [
[ [
"herald flea academic cage avoid space trend estate dryer hairy evoke eyebrow improve airline artwork garlic premium duration prevent oven", "herald flea academic cage avoid space trend estate dryer hairy evoke eyebrow improve airline artwork garlic premium duration prevent oven",
"herald flea academic client blue skunk class goat luxury deny presence impulse graduate clay join blanket bulge survive dish necklace", "herald flea academic client blue skunk class goat luxury deny presence impulse graduate clay join blanket bulge survive dish necklace",
"herald flea academic acne advance fused brother frozen broken game ranked ajar already believe check install theory angry exercise adult" "herald flea academic acne advance fused brother frozen broken game ranked ajar already believe check install theory angry exercise adult",
], ],
"ad6f2ad8b59bbbaa01369b9006208d9a", "ad6f2ad8b59bbbaa01369b9006208d9a",
], ],
@ -296,7 +296,7 @@ vectors = [
[ [
[ [
"enemy favorite academic acid cowboy phrase havoc level response walnut budget painting inside trash adjust froth kitchen learn tidy punish", "enemy favorite academic acid cowboy phrase havoc level response walnut budget painting inside trash adjust froth kitchen learn tidy punish",
"enemy favorite academic always academic sniff script carpet romp kind promise scatter center unfair training emphasis evening belong fake enforce" "enemy favorite academic always academic sniff script carpet romp kind promise scatter center unfair training emphasis evening belong fake enforce",
], ],
"48b1a4b80b8c209ad42c33672bdaa428", "48b1a4b80b8c209ad42c33672bdaa428",
], ],
@ -309,7 +309,7 @@ vectors = [
[ [
[ [
"western apart academic always artist resident briefing sugar woman oven coding club ajar merit pecan answer prisoner artist fraction amount desktop mild false necklace muscle photo wealthy alpha category unwrap spew losing making", "western apart academic always artist resident briefing sugar woman oven coding club ajar merit pecan answer prisoner artist fraction amount desktop mild false necklace muscle photo wealthy alpha category unwrap spew losing making",
"western apart academic acid answer ancient auction flip image penalty oasis beaver multiple thunder problem switch alive heat inherit superior teaspoon explain blanket pencil numb lend punish endless aunt garlic humidity kidney observe" "western apart academic acid answer ancient auction flip image penalty oasis beaver multiple thunder problem switch alive heat inherit superior teaspoon explain blanket pencil numb lend punish endless aunt garlic humidity kidney observe",
], ],
"8dc652d6d6cd370d8c963141f6d79ba440300f25c467302c1d966bff8f62300d", "8dc652d6d6cd370d8c963141f6d79ba440300f25c467302c1d966bff8f62300d",
], ],

View File

@ -48,9 +48,7 @@ class TestApprover(unittest.TestCase):
self.msg_auth = AuthorizeCoinJoin( self.msg_auth = AuthorizeCoinJoin(
coordinator=self.coordinator_name, coordinator=self.coordinator_name,
max_rounds=10, max_rounds=10,
max_coordinator_fee_rate=int( max_coordinator_fee_rate=int(self.fee_rate_percent * 10**FEE_RATE_DECIMALS),
self.fee_rate_percent * 10**FEE_RATE_DECIMALS
),
max_fee_per_kvbyte=7000, max_fee_per_kvbyte=7000,
address_n=[H_(10025), H_(0), H_(0), H_(1)], address_n=[H_(10025), H_(0), H_(0), H_(1)],
coin_name=self.coin.coin_name, coin_name=self.coin.coin_name,
@ -155,7 +153,11 @@ class TestApprover(unittest.TestCase):
if txo.address_n: if txo.address_n:
await_result(approver.add_change_output(txo, script_pubkey=bytes(22))) await_result(approver.add_change_output(txo, script_pubkey=bytes(22)))
else: else:
await_result(approver.add_external_output(txo, script_pubkey=bytes(22), tx_info=tx_info)) await_result(
approver.add_external_output(
txo, script_pubkey=bytes(22), tx_info=tx_info
)
)
await_result(approver.approve_tx(tx_info, [], None)) await_result(approver.approve_tx(tx_info, [], None))

View File

@ -1,14 +1,9 @@
from common import H_, unittest # isort:skip from common import H_, unittest # isort:skip
from ubinascii import unhexlify from ubinascii import unhexlify
from trezor.enums import InputScriptType, OutputScriptType, MultisigPubkeysOrder from trezor.enums import InputScriptType, MultisigPubkeysOrder, OutputScriptType
from trezor.enums.MultisigPubkeysOrder import LEXICOGRAPHIC, PRESERVED from trezor.enums.MultisigPubkeysOrder import LEXICOGRAPHIC, PRESERVED
from trezor.messages import ( from trezor.messages import HDNodeType, MultisigRedeemScriptType, TxInput, TxOutput
TxInput,
TxOutput,
HDNodeType,
MultisigRedeemScriptType,
)
from apps.bitcoin.sign_tx.change_detector import ChangeDetector from apps.bitcoin.sign_tx.change_detector import ChangeDetector
@ -17,8 +12,12 @@ xpub1 = HDNodeType(
depth=2, depth=2,
fingerprint=50263508, fingerprint=50263508,
child_num=0, child_num=0,
chain_code=unhexlify("8eb1f96a45dcb693dbad61f5184871d999127a37f1b0d4dae9964eaf3fb0e15b"), chain_code=unhexlify(
public_key=unhexlify("03922315cd2d2d874e4c55add2e0ea41af9c2957f02c0abe0f55285d364a067b61"), "8eb1f96a45dcb693dbad61f5184871d999127a37f1b0d4dae9964eaf3fb0e15b"
),
public_key=unhexlify(
"03922315cd2d2d874e4c55add2e0ea41af9c2957f02c0abe0f55285d364a067b61"
),
) )
# all all all all all all all all all all all all/45/1 # all all all all all all all all all all all all/45/1
@ -26,8 +25,12 @@ xpub2 = HDNodeType(
depth=2, depth=2,
fingerprint=50263508, fingerprint=50263508,
child_num=1, child_num=1,
chain_code=unhexlify("acad50a7e52e44841d42bec6886df516974f8d366bc471a8515dfc69a6692700"), chain_code=unhexlify(
public_key=unhexlify("02e6f3bf3093b45705e3d838490377e0d99eed911ca01990d1e94acd445dee59e8"), "acad50a7e52e44841d42bec6886df516974f8d366bc471a8515dfc69a6692700"
),
public_key=unhexlify(
"02e6f3bf3093b45705e3d838490377e0d99eed911ca01990d1e94acd445dee59e8"
),
) )
# all all all all all all all all all all all all/45/2 # all all all all all all all all all all all all/45/2
@ -35,12 +38,18 @@ xpub3 = HDNodeType(
depth=2, depth=2,
fingerprint=50263508, fingerprint=50263508,
child_num=2, child_num=2,
chain_code=unhexlify("5204b124a264b0bbf86360e365f0c9a0cb6e3ea57dda97196af015d64ccfa6b1"), chain_code=unhexlify(
public_key=unhexlify("021cd5d138ba442c7f8ee9a2b8f4e254dc599a57d42c69b7194074135a0ba82926"), "5204b124a264b0bbf86360e365f0c9a0cb6e3ea57dda97196af015d64ccfa6b1"
),
public_key=unhexlify(
"021cd5d138ba442c7f8ee9a2b8f4e254dc599a57d42c69b7194074135a0ba82926"
),
) )
def get_multisig(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> MultisigRedeemScriptType: def get_multisig(
path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder
) -> MultisigRedeemScriptType:
return MultisigRedeemScriptType( return MultisigRedeemScriptType(
nodes=xpubs, nodes=xpubs,
signatures=b"" * len(xpubs), signatures=b"" * len(xpubs),
@ -60,7 +69,9 @@ def get_singlesig_input(path: list[int]) -> TxInput:
) )
def get_multisig_input(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> TxInput: def get_multisig_input(
path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder
) -> TxInput:
return TxInput( return TxInput(
address_n=path, address_n=path,
amount=1_000_000, amount=1_000_000,
@ -71,7 +82,9 @@ def get_multisig_input(path: list[int], xpubs: list[HDNodeType], pubkeys_order:
) )
def get_internal_multisig_output(path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder) -> TxOutput: def get_internal_multisig_output(
path: list[int], xpubs: list[HDNodeType], pubkeys_order: MultisigPubkeysOrder
) -> TxOutput:
return TxOutput( return TxOutput(
address_n=path, address_n=path,
amount=1_000_000, amount=1_000_000,
@ -108,17 +121,42 @@ class TestChangeDetector(unittest.TestCase):
self.d.add_input(get_singlesig_input([H_(45), 0, 1, 1])) self.d.add_input(get_singlesig_input([H_(45), 0, 1, 1]))
# Same outputs as inputs # Same outputs as inputs
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is True assert (
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 1])) is True self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 0])) is True is True
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 1])) is True )
assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 1]))
is True
)
assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 0]))
is True
)
assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 1, 1]))
is True
)
# Different account index # Different account index
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0]))
is False
)
# Multisig instead of singlesig # Multisig instead of singlesig
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)
)
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
@ -129,150 +167,432 @@ class TestChangeDetector(unittest.TestCase):
self.d.add_input(get_singlesig_input([H_(45), 1, 0, 0])) self.d.add_input(get_singlesig_input([H_(45), 1, 0, 0]))
# Same outputs as inputs # Same outputs as inputs
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0]))
is False
)
# Multisig instead of singlesig # Multisig instead of singlesig
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], PRESERVED)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output([H_(45), 1, 0, 0], [xpub1], LEXICOGRAPHIC)
)
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_unsorted_multisig(self): def test_unsorted_multisig(self):
# Different change and account index # Different change and account index
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)
self.d.add_input(get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED)) )
self.d.add_input(get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED)) self.d.add_input(
get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED)
)
# Same outputs as inputs # Same outputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is True assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED)) is True self.d.output_is_change(
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED)) is True get_internal_multisig_output(
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED)) is True [H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 1], [xpub1, xpub2], PRESERVED
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 1, 0], [xpub1, xpub2], PRESERVED
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 1, 1], [xpub1, xpub2], PRESERVED
)
)
is True
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# Different account index # Different account index
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0]))
is False
)
# Different order of xpubs # Different order of xpubs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED
)
)
is False
)
# Sorted instead of unsorted # Sorted instead of unsorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is False
)
# Different xpubs # Different xpubs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED
)
)
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_sorted_multisig(self): def test_sorted_multisig(self):
# Different change and account index # Different change and account index
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)
self.d.add_input(get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC)) )
self.d.add_input(get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC)) self.d.add_input(
get_multisig_input([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC)
)
# Same outputs as inputs # Same outputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC)) is True self.d.output_is_change(
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True get_internal_multisig_output(
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC)) is True [H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 1], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 1, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 1, 1], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is True
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# Different account index # Different account index
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 1, 0, 0]))
is False
)
# Different order of xpubs # Different order of xpubs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is True assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC
)
)
is True
)
# Unsorted instead of sorted # Unsorted instead of sorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is False
)
# Different xpubs # Different xpubs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC
)
)
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_unsorted_multisig_different_xpubs_order(self): def test_unsorted_multisig_different_xpubs_order(self):
# Different order of xpubs # Different order of xpubs
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)
)
# Same ouputs as inputs # Same ouputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED
)
)
is False
)
# Sorted instead of unsorted # Sorted instead of unsorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC
)
)
is False
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_sorted_multisig_different_xpubs_order(self): def test_sorted_multisig_different_xpubs_order(self):
# Different order of xpubs # Different order of xpubs
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)
)
# Same ouputs as inputs # Same ouputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is True assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC)) is True self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is True
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], LEXICOGRAPHIC
)
)
is True
)
# Sorted instead of unsorted # Sorted instead of unsorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub2, xpub1], PRESERVED
)
)
is False
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_unsorted_multisig_different_xpubs(self): def test_unsorted_multisig_different_xpubs(self):
# Different xpubs # Different xpubs
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)
)
# Same ouputs as inputs # Same ouputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED
)
)
is False
)
# Sorted instead of unsorted # Sorted instead of unsorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC
)
)
is False
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
def test_sorted_multisig_different_xpubs(self): def test_sorted_multisig_different_xpubs(self):
# Different xpubs # Different xpubs
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) self.d.add_input(
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)
)
self.d.add_input(
get_multisig_input([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)
)
# Same ouputs as inputs # Same ouputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], LEXICOGRAPHIC
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], LEXICOGRAPHIC
)
)
is False
)
# Sorted instead of unsorted # Sorted instead of unsorted
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED)) is False self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub2], PRESERVED
)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output(
[H_(45), 0, 0, 0], [xpub1, xpub3], PRESERVED
)
)
is False
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False
@ -282,11 +602,24 @@ class TestChangeDetector(unittest.TestCase):
self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) self.d.add_input(get_multisig_input([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC))
# Same ouputs as inputs # Same ouputs as inputs
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)) is False assert (
assert self.d.output_is_change(get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)) is False self.d.output_is_change(
get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], PRESERVED)
)
is False
)
assert (
self.d.output_is_change(
get_internal_multisig_output([H_(45), 0, 0, 0], [xpub1], LEXICOGRAPHIC)
)
is False
)
# Singlesig instead of multisig # Singlesig instead of multisig
assert self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0])) is False assert (
self.d.output_is_change(get_internal_singlesig_output([H_(45), 0, 0, 0]))
is False
)
# External output # External output
assert self.d.output_is_change(get_external_singlesig_output()) is False assert self.d.output_is_change(get_external_singlesig_output()) is False

View File

@ -1,14 +1,13 @@
# flake8: noqa: F403,F405 # flake8: noqa: F403,F405
from common import * # isort:skip from common import * # isort:skip
from storage import cache_common from storage import cache_codec, cache_common
from trezor import wire from trezor import wire
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.wire import context from trezor.wire import context
from trezor.wire.codec.codec_context import CodecContext
from apps.bitcoin.keychain import _get_coin_by_name, _get_keychain_for_coin from apps.bitcoin.keychain import _get_coin_by_name, _get_keychain_for_coin
from trezor.wire.codec.codec_context import CodecContext
from storage import cache_codec
class TestBitcoinKeychain(unittest.TestCase): class TestBitcoinKeychain(unittest.TestCase):

View File

@ -113,7 +113,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,
@ -121,7 +123,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]
),
True, True,
helpers.UiConfirmTotal( helpers.UiConfirmTotal(
12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] 12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]
@ -310,7 +314,9 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,

View File

@ -124,7 +124,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,
@ -132,7 +134,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(84), H_(1), H_(0)]), helpers.UiConfirmOutput(
out2, coin, AmountUnit.BITCOIN, 1, False, [H_(84), H_(1), H_(0)]
),
True, True,
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True, True,
@ -333,7 +337,9 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(84), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,

View File

@ -115,7 +115,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,
@ -123,7 +125,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]
),
True, True,
helpers.UiConfirmTotal( helpers.UiConfirmTotal(
123445789 + 11000, 123445789 + 11000,
@ -318,7 +322,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,
@ -532,7 +538,9 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,

View File

@ -124,7 +124,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,
@ -132,7 +134,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)), TxAckOutput(tx=TxAckOutputWrapper(output=out2)),
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out2, coin, AmountUnit.BITCOIN, 1, False, [H_(49), H_(1), H_(0)]
),
True, True,
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True, True,
@ -337,7 +341,9 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(49), H_(1), H_(0)]
),
True, True,
TxRequest( TxRequest(
request_type=TXOUTPUT, request_type=TXOUTPUT,

View File

@ -181,7 +181,9 @@ class TestSignTxFeeThreshold(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, None), helpers.UiConfirmOutput(
out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, None
),
True, True,
helpers.UiConfirmMultipleAccounts(), helpers.UiConfirmMultipleAccounts(),
True, True,

View File

@ -112,7 +112,9 @@ class TestSignTx(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(0), H_(0)]), helpers.UiConfirmOutput(
out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(0), H_(0)]
),
True, True,
helpers.UiConfirmTotal( helpers.UiConfirmTotal(
3_801_747, 3_801_747,

View File

@ -1,7 +1,7 @@
# flake8: noqa: F403,F405 # flake8: noqa: F403,F405
from common import * # isort:skip from common import * # isort:skip
if utils.INTERNAL_MODEL in ("T2T1", ): # pylint: disable=internal-model-tuple-comparison if utils.INTERNAL_MODEL in ("T2T1",): # pylint: disable=internal-model-tuple-comparison
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.enums import AmountUnit, OutputScriptType from trezor.enums import AmountUnit, OutputScriptType
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
@ -113,7 +113,9 @@ class TestSignTxDecred(unittest.TestCase):
), ),
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_decred, AmountUnit.BITCOIN, 0, False, [H_(44), H_(1), H_(0)]), helpers.UiConfirmOutput(
out1, coin_decred, AmountUnit.BITCOIN, 0, False, [H_(44), H_(1), H_(0)]
),
True, True,
helpers.UiConfirmTotal( helpers.UiConfirmTotal(
200_000_000, 200_000_000,

View File

@ -113,7 +113,9 @@ class TestSignTx_GRS(unittest.TestCase):
serialized=EMPTY_SERIALIZED, serialized=EMPTY_SERIALIZED,
), ),
TxAckOutput(tx=TxAckOutputWrapper(output=out1)), TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(17), H_(0)]), helpers.UiConfirmOutput(
out1, coin, AmountUnit.BITCOIN, 0, False, [H_(44), H_(17), H_(0)]
),
True, True,
helpers.UiConfirmTotal( helpers.UiConfirmTotal(
210016, 192, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] 210016, 192, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]

View File

@ -192,7 +192,9 @@ class TestCardanoAddress(unittest.TestCase):
] ]
passphrase = b"TREZOR" passphrase = b"TREZOR"
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics)
master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) master_secret = slip39.decrypt(
ems, passphrase, exponent, identifier, extendable
)
node = cardano.from_seed_slip23(master_secret) node = cardano.from_seed_slip23(master_secret)
@ -266,7 +268,9 @@ class TestCardanoAddress(unittest.TestCase):
] ]
passphrase = b"TREZOR" passphrase = b"TREZOR"
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics)
master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) master_secret = slip39.decrypt(
ems, passphrase, exponent, identifier, extendable
)
node = cardano.from_seed_slip23(master_secret) node = cardano.from_seed_slip23(master_secret)

View File

@ -146,7 +146,9 @@ class TestCardanoGetPublicKey(unittest.TestCase):
] ]
passphrase = b"TREZOR" passphrase = b"TREZOR"
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics)
master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) master_secret = slip39.decrypt(
ems, passphrase, exponent, identifier, extendable
)
node = cardano.from_seed_slip23(master_secret) node = cardano.from_seed_slip23(master_secret)
@ -195,7 +197,9 @@ class TestCardanoGetPublicKey(unittest.TestCase):
] ]
passphrase = b"TREZOR" passphrase = b"TREZOR"
identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics) identifier, extendable, exponent, ems = slip39.recover_ems(mnemonics)
master_secret = slip39.decrypt(ems, passphrase, exponent, identifier, extendable) master_secret = slip39.decrypt(
ems, passphrase, exponent, identifier, extendable
)
node = cardano.from_seed_slip23(master_secret) node = cardano.from_seed_slip23(master_secret)

View File

@ -34,19 +34,19 @@ class TestCardanoCbor(unittest.TestCase):
def test_create_tagged_set_header(self): def test_create_tagged_set_header(self):
test_vectors = [ test_vectors = [
(0, 'd9010280'), (0, "d9010280"),
(23, 'd9010297'), (23, "d9010297"),
((2 ** 8) - 1, 'd9010298ff'), ((2**8) - 1, "d9010298ff"),
((2 ** 16) - 1, 'd9010299ffff'), ((2**16) - 1, "d9010299ffff"),
((2 ** 32) - 1, 'd901029affffffff'), ((2**32) - 1, "d901029affffffff"),
((2 ** 64) - 1, 'd901029bffffffffffffffff'), ((2**64) - 1, "d901029bffffffffffffffff"),
] ]
for val, header_hex in test_vectors: for val, header_hex in test_vectors:
header = unhexlify(header_hex) header = unhexlify(header_hex)
self.assertEqual(create_tagged_set_header(val), header) self.assertEqual(create_tagged_set_header(val), header)
with self.assertRaises(NotImplementedError): with self.assertRaises(NotImplementedError):
create_tagged_set_header(2 ** 64) create_tagged_set_header(2**64)
def test_create_map_header(self): def test_create_map_header(self):
test_vectors = [ test_vectors = [

View File

@ -2,17 +2,16 @@
from common import * # isort:skip from common import * # isort:skip
from mock_storage import mock_storage from mock_storage import mock_storage
from storage import cache, cache_common from storage import cache, cache_codec, cache_common
from trezor import wire from trezor import wire
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.enums import SafetyCheckLevel from trezor.enums import SafetyCheckLevel
from trezor.wire import context from trezor.wire import context
from trezor.wire.codec.codec_context import CodecContext
from apps.common import safety_checks from apps.common import safety_checks
from apps.common.keychain import Keychain, LRUCache, get_keychain, with_slip44_keychain from apps.common.keychain import Keychain, LRUCache, get_keychain, with_slip44_keychain
from apps.common.paths import PATTERN_SEP5, PathSchema from apps.common.paths import PATTERN_SEP5, PathSchema
from trezor.wire.codec.codec_context import CodecContext
from storage import cache_codec
class TestKeychain(unittest.TestCase): class TestKeychain(unittest.TestCase):

View File

@ -3,15 +3,14 @@ from common import * # isort:skip
import unittest import unittest
from storage import cache_common from storage import cache_codec, cache_common
from trezor import wire from trezor import wire
from trezor.crypto import bip39 from trezor.crypto import bip39
from trezor.wire import context from trezor.wire import context
from trezor.wire.codec.codec_context import CodecContext
from apps.common.keychain import get_keychain from apps.common.keychain import get_keychain
from apps.common.paths import HARDENED from apps.common.paths import HARDENED
from trezor.wire.codec.codec_context import CodecContext
from storage import cache_codec
if not utils.BITCOIN_ONLY: if not utils.BITCOIN_ONLY:
from ethereum_common import encode_network, make_network from ethereum_common import encode_network, make_network

View File

@ -10,6 +10,7 @@ if not utils.BITCOIN_ONLY:
ETH = networks.by_chain_id(1) ETH = networks.by_chain_id(1)
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestFormatEthereumAmount(unittest.TestCase): class TestFormatEthereumAmount(unittest.TestCase):
def test_denominations(self): def test_denominations(self):

View File

@ -1,12 +1,12 @@
# flake8: noqa: F403,F405 # flake8: noqa: F403,F405
from common import * # isort: skip from common import * # isort: skip
from trezor import config, utils from trezor import config, log, utils
from trezor import log
if utils.USE_THP: if utils.USE_THP:
from apps.thp import credential_manager
from trezor.messages import ThpCredentialMetadata from trezor.messages import ThpCredentialMetadata
from apps.thp import credential_manager
def _issue_credential(host_name: str, host_static_pubkey: bytes) -> bytes: def _issue_credential(host_name: str, host_static_pubkey: bytes) -> bytes:
metadata = ThpCredentialMetadata(host_name=host_name) metadata = ThpCredentialMetadata(host_name=host_name)
return credential_manager.issue_credential(host_static_pubkey, metadata) return credential_manager.issue_credential(host_static_pubkey, metadata)

View File

@ -4,6 +4,7 @@ from common import * # isort:skip
from storage import device from storage import device
from trezor import config, utils from trezor import config, utils
class TestConfig(unittest.TestCase): class TestConfig(unittest.TestCase):
def setUp(self): def setUp(self):
@ -39,7 +40,7 @@ class TestConfig(unittest.TestCase):
def test_cred_auth_key_counter_overflow(self): def test_cred_auth_key_counter_overflow(self):
from storage import common from storage import common
from storage.device import _NAMESPACE, _CRED_AUTH_KEY_COUNTER from storage.device import _CRED_AUTH_KEY_COUNTER, _NAMESPACE
common.set(_NAMESPACE, _CRED_AUTH_KEY_COUNTER, b"\xff\xff\xff\xfe") common.set(_NAMESPACE, _CRED_AUTH_KEY_COUNTER, b"\xff\xff\xff\xfe")
device.increment_cred_auth_key_counter() device.increment_cred_auth_key_counter()

View File

@ -116,7 +116,7 @@ class TestCryptoAes(unittest.TestCase):
# Decrypt by chunks and add authenticated data by chunks. # Decrypt by chunks and add authenticated data by chunks.
ctx = aesgcm(key, iv) ctx = aesgcm(key, iv)
returned = ctx.decrypt_in_place(memoryview(buffer)[: chunk1_length]) returned = ctx.decrypt_in_place(memoryview(buffer)[:chunk1_length])
self.assertEqual(returned, chunk1_length) self.assertEqual(returned, chunk1_length)
ctx.auth(aad[:17]) ctx.auth(aad[:17])
returned = ctx.decrypt_in_place(memoryview(buffer)[chunk1_length:]) returned = ctx.decrypt_in_place(memoryview(buffer)[chunk1_length:])
@ -128,7 +128,7 @@ class TestCryptoAes(unittest.TestCase):
# Encrypt by chunks and add authenticated data by chunks. # Encrypt by chunks and add authenticated data by chunks.
ctx.reset(iv) ctx.reset(iv)
ctx.auth(aad[:7]) ctx.auth(aad[:7])
returned = ctx.encrypt_in_place(memoryview(buffer)[: chunk1_length]) returned = ctx.encrypt_in_place(memoryview(buffer)[:chunk1_length])
self.assertEqual(returned, chunk1_length) self.assertEqual(returned, chunk1_length)
ctx.auth(aad[7:]) ctx.auth(aad[7:])
returned = ctx.encrypt_in_place(memoryview(buffer)[chunk1_length:]) returned = ctx.encrypt_in_place(memoryview(buffer)[chunk1_length:])

View File

@ -1,5 +1,5 @@
# flake8: noqa: F403,F405 # flake8: noqa: F403,F405
from common import * # isort:skip from common import * # isort:skip
from trezor.crypto import base32 from trezor.crypto import base32
@ -31,8 +31,10 @@ class TestCryptoBase32(unittest.TestCase):
("中文12".encode(), "4S4K3ZUWQ4YTE==="), ("中文12".encode(), "4S4K3ZUWQ4YTE==="),
("aécio".encode(), "MHB2SY3JN4======"), ("aécio".encode(), "MHB2SY3JN4======"),
("𠜎".encode(), "6CQJZDQ="), ("𠜎".encode(), "6CQJZDQ="),
("Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(), (
"IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V"), "Base64是一種基於64個可列印字元來表示二進制資料的表示方法".encode(),
"IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V",
),
] ]
def test_encode(self): def test_encode(self):

View File

@ -202,7 +202,7 @@ class TestCryptoBech32(unittest.TestCase):
def test_valid_address(self): def test_valid_address(self):
"""Test whether valid addresses decode to the correct output.""" """Test whether valid addresses decode to the correct output."""
for (address, hexscript) in VALID_ADDRESS: for address, hexscript in VALID_ADDRESS:
hrp = "tb" if address.startswith("tb1") else "bc" hrp = "tb" if address.startswith("tb1") else "bc"
witver, witprog = bech32.decode(hrp, address) witver, witprog = bech32.decode(hrp, address)
self.assertIsNotNone(witver) self.assertIsNotNone(witver)

View File

@ -11,30 +11,53 @@ class TestCryptoElligator2(unittest.TestCase):
# https://elligator.org/vectors/curve25519_direct.vec # https://elligator.org/vectors/curve25519_direct.vec
vectors = [ vectors = [
("0000000000000000000000000000000000000000000000000000000000000000", (
"0000000000000000000000000000000000000000000000000000000000000000"), "0000000000000000000000000000000000000000000000000000000000000000",
("66665895c5bc6e44ba8d65fd9307092e3244bf2c18877832bd568cb3a2d38a12", "0000000000000000000000000000000000000000000000000000000000000000",
"04d44290d13100b2c25290c9343d70c12ed4813487a07ac1176daa5925e7975e"), ),
("673a505e107189ee54ca93310ac42e4545e9e59050aaac6f8b5f64295c8ec02f", (
"242ae39ef158ed60f20b89396d7d7eef5374aba15dc312a6aea6d1e57cacf85e"), "66665895c5bc6e44ba8d65fd9307092e3244bf2c18877832bd568cb3a2d38a12",
("990b30e04e1c3620b4162b91a33429bddb9f1b70f1da6e5f76385ed3f98ab131", "04d44290d13100b2c25290c9343d70c12ed4813487a07ac1176daa5925e7975e",
"998e98021eb4ee653effaa992f3fae4b834de777a953271baaa1fa3fef6b776e"), ),
("341a60725b482dd0de2e25a585b208433044bc0a1ba762442df3a0e888ca063c", (
"683a71d7fca4fc6ad3d4690108be808c2e50a5af3174486741d0a83af52aeb01"), "673a505e107189ee54ca93310ac42e4545e9e59050aaac6f8b5f64295c8ec02f",
("922688fa428d42bc1fa8806998fbc5959ae801817e85a42a45e8ec25a0d7541a", "242ae39ef158ed60f20b89396d7d7eef5374aba15dc312a6aea6d1e57cacf85e",
"696f341266c64bcfa7afa834f8c34b2730be11c932e08474d1a22f26ed82410b"), ),
("0d3b0eb88b74ed13d5f6a130e03c4ad607817057dc227152827c0506a538bb3a", (
"0b00df174d9fb0b6ee584d2cf05613130bad18875268c38b377e86dfefef177f"), "990b30e04e1c3620b4162b91a33429bddb9f1b70f1da6e5f76385ed3f98ab131",
("01a3ea5658f4e00622eeacf724e0bd82068992fae66ed2b04a8599be16662e35", "998e98021eb4ee653effaa992f3fae4b834de777a953271baaa1fa3fef6b776e",
"7ae4c58bc647b5646c9f5ae4c2554ccbf7c6e428e7b242a574a5a9c293c21f7e"), ),
("1d991dff82a84afe97874c0f03a60a56616a15212fbe10d6c099aa3afcfabe35", (
"f81f235696f81df90ac2fc861ceee517bff611a394b5be5faaee45584642fb0a"), "341a60725b482dd0de2e25a585b208433044bc0a1ba762442df3a0e888ca063c",
("185435d2b005a3b63f3187e64a1ef3582533e1958d30e4e4747b4d1d3376c728", "683a71d7fca4fc6ad3d4690108be808c2e50a5af3174486741d0a83af52aeb01",
"f938b1b320abb0635930bd5d7ced45ae97fa8b5f71cc21d87b4c60905c125d34"), ),
(
"922688fa428d42bc1fa8806998fbc5959ae801817e85a42a45e8ec25a0d7541a",
"696f341266c64bcfa7afa834f8c34b2730be11c932e08474d1a22f26ed82410b",
),
(
"0d3b0eb88b74ed13d5f6a130e03c4ad607817057dc227152827c0506a538bb3a",
"0b00df174d9fb0b6ee584d2cf05613130bad18875268c38b377e86dfefef177f",
),
(
"01a3ea5658f4e00622eeacf724e0bd82068992fae66ed2b04a8599be16662e35",
"7ae4c58bc647b5646c9f5ae4c2554ccbf7c6e428e7b242a574a5a9c293c21f7e",
),
(
"1d991dff82a84afe97874c0f03a60a56616a15212fbe10d6c099aa3afcfabe35",
"f81f235696f81df90ac2fc861ceee517bff611a394b5be5faaee45584642fb0a",
),
(
"185435d2b005a3b63f3187e64a1ef3582533e1958d30e4e4747b4d1d3376c728",
"f938b1b320abb0635930bd5d7ced45ae97fa8b5f71cc21d87b4c60905c125d34",
),
] ]
for input, output in vectors: for input, output in vectors:
self.assertEqual(hexlify(elligator2.map_to_curve25519(unhexlify(input))).decode('ascii'), output) self.assertEqual(
hexlify(elligator2.map_to_curve25519(unhexlify(input))).decode("ascii"),
output,
)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -41,17 +41,24 @@ class TestCryptoSlip39(unittest.TestCase):
def test_basic_sharing_extend(self): def test_basic_sharing_extend(self):
identifier = slip39.generate_random_identifier() identifier = slip39.generate_random_identifier()
for extendable in (False, True): for extendable in (False, True):
mnemonics = slip39.split_ems(1, [(2, 3)], identifier, extendable, 1, self.EMS) mnemonics = slip39.split_ems(
1, [(2, 3)], identifier, extendable, 1, self.EMS
)
mnemonics = mnemonics[0] mnemonics = mnemonics[0]
extended_mnemonics = slip39.extend_mnemonics(4, mnemonics[1:]) extended_mnemonics = slip39.extend_mnemonics(4, mnemonics[1:])
self.assertEqual(mnemonics, extended_mnemonics[:3]) self.assertEqual(mnemonics, extended_mnemonics[:3])
for i in range(3): for i in range(3):
self.assertEqual(slip39.recover_ems([extended_mnemonics[3], mnemonics[i]])[3], self.EMS) self.assertEqual(
slip39.recover_ems([extended_mnemonics[3], mnemonics[i]])[3],
self.EMS,
)
def test_basic_sharing_fixed(self): def test_basic_sharing_fixed(self):
for extendable in (False, True): for extendable in (False, True):
generated_identifier = slip39.generate_random_identifier() generated_identifier = slip39.generate_random_identifier()
mnemonics = slip39.split_ems(1, [(3, 5)], generated_identifier, extendable, 1, self.EMS) mnemonics = slip39.split_ems(
1, [(3, 5)], generated_identifier, extendable, 1, self.EMS
)
mnemonics = mnemonics[0] mnemonics = mnemonics[0]
identifier, _, _, ems = slip39.recover_ems(mnemonics[:3]) identifier, _, _, ems = slip39.recover_ems(mnemonics[:3])
self.assertEqual(ems, self.EMS) self.assertEqual(ems, self.EMS)
@ -63,13 +70,17 @@ class TestCryptoSlip39(unittest.TestCase):
def test_iteration_exponent(self): def test_iteration_exponent(self):
for extendable in (False, True): for extendable in (False, True):
identifier = slip39.generate_random_identifier() identifier = slip39.generate_random_identifier()
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 1, self.EMS) mnemonics = slip39.split_ems(
1, [(3, 5)], identifier, extendable, 1, self.EMS
)
mnemonics = mnemonics[0] mnemonics = mnemonics[0]
identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4]) identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4])
self.assertEqual(ems, self.EMS) self.assertEqual(ems, self.EMS)
identifier = slip39.generate_random_identifier() identifier = slip39.generate_random_identifier()
mnemonics = slip39.split_ems(1, [(3, 5)], identifier, extendable, 2, self.EMS) mnemonics = slip39.split_ems(
1, [(3, 5)], identifier, extendable, 2, self.EMS
)
mnemonics = mnemonics[0] mnemonics = mnemonics[0]
identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4]) identifier, extendable, _, ems = slip39.recover_ems(mnemonics[1:4])
self.assertEqual(ems, self.EMS) self.assertEqual(ems, self.EMS)
@ -90,7 +101,9 @@ class TestCryptoSlip39(unittest.TestCase):
) )
# Test all valid combinations of mnemonics. # Test all valid combinations of mnemonics.
for groups in combinations(zip(mnemonics, member_thresholds), group_threshold): for groups in combinations(
zip(mnemonics, member_thresholds), group_threshold
):
for group1_subset in combinations(groups[0][0], groups[0][1]): for group1_subset in combinations(groups[0][0], groups[0][1]):
for group2_subset in combinations(groups[1][0], groups[1][1]): for group2_subset in combinations(groups[1][0], groups[1][1]):
mnemonic_subset = list(group1_subset + group2_subset) mnemonic_subset = list(group1_subset + group2_subset)
@ -104,7 +117,9 @@ class TestCryptoSlip39(unittest.TestCase):
) )
self.assertEqual(ems, self.EMS) self.assertEqual(ems, self.EMS)
self.assertEqual( self.assertEqual(
slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[3], slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[
3
],
ems, ems,
) )
@ -160,23 +175,33 @@ class TestCryptoSlip39(unittest.TestCase):
# Group threshold exceeds number of groups. # Group threshold exceeds number of groups.
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
slip39.split_ems(3, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS) slip39.split_ems(
3, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS
)
# Invalid group threshold. # Invalid group threshold.
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
slip39.split_ems(0, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS) slip39.split_ems(
0, [(3, 5), (2, 5)], identifier, extendable, 1, self.EMS
)
# Member threshold exceeds number of members. # Member threshold exceeds number of members.
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
slip39.split_ems(2, [(3, 2), (2, 5)], identifier, extendable, 1, self.EMS) slip39.split_ems(
2, [(3, 2), (2, 5)], identifier, extendable, 1, self.EMS
)
# Invalid member threshold. # Invalid member threshold.
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
slip39.split_ems(2, [(0, 2), (2, 5)], identifier, extendable, 1, self.EMS) slip39.split_ems(
2, [(0, 2), (2, 5)], identifier, extendable, 1, self.EMS
)
# Group with multiple members and threshold 1. # Group with multiple members and threshold 1.
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
slip39.split_ems(2, [(3, 5), (1, 3), (2, 5)], identifier, extendable, 1, self.EMS) slip39.split_ems(
2, [(3, 5), (1, 3), (2, 5)], identifier, extendable, 1, self.EMS
)
def test_vectors(self): def test_vectors(self):
for mnemonics, secret in vectors: for mnemonics, secret in vectors:

View File

@ -44,14 +44,54 @@ class TestStrings(unittest.TestCase):
def test_format_plural(self): def test_format_plural(self):
VECTORS = [ VECTORS = [
("You are about to sign {count} {plural}", 0, "action|actions", "You are about to sign 0 actions"), (
("You are about to sign {count} {plural}", 1, "action|actions", "You are about to sign 1 action"), "You are about to sign {count} {plural}",
("You are about to sign {count} {plural}", 3, "action|actions", "You are about to sign 3 actions"), 0,
("You are about to sign {count} {plural}", 15, "action|actions", "You are about to sign 15 actions"), "action|actions",
("Chystáte se podepsat {count} {plural}", 0, "akci|akce|akcí", "Chystáte se podepsat 0 akcí"), "You are about to sign 0 actions",
("Chystáte se podepsat {count} {plural}", 1, "akci|akce|akcí", "Chystáte se podepsat 1 akci"), ),
("Chystáte se podepsat {count} {plural}", 3, "akci|akce|akcí", "Chystáte se podepsat 3 akce"), (
("Chystáte se podepsat {count} {plural}", 15, "akci|akce|akcí", "Chystáte se podepsat 15 akcí"), "You are about to sign {count} {plural}",
1,
"action|actions",
"You are about to sign 1 action",
),
(
"You are about to sign {count} {plural}",
3,
"action|actions",
"You are about to sign 3 actions",
),
(
"You are about to sign {count} {plural}",
15,
"action|actions",
"You are about to sign 15 actions",
),
(
"Chystáte se podepsat {count} {plural}",
0,
"akci|akce|akcí",
"Chystáte se podepsat 0 akcí",
),
(
"Chystáte se podepsat {count} {plural}",
1,
"akci|akce|akcí",
"Chystáte se podepsat 1 akci",
),
(
"Chystáte se podepsat {count} {plural}",
3,
"akci|akce|akcí",
"Chystáte se podepsat 3 akce",
),
(
"Chystáte se podepsat {count} {plural}",
15,
"akci|akce|akcí",
"Chystáte se podepsat 15 akcí",
),
] ]
for v in VECTORS: for v in VECTORS:
self.assertEqual(strings.format_plural(v[0], v[1], v[2]), v[3]) self.assertEqual(strings.format_plural(v[0], v[1], v[2]), v[3])

View File

@ -77,6 +77,5 @@ class TestUtils(unittest.TestCase):
) )
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()