1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-29 09:38:08 +00:00
trezor-firmware/core/tests/test_apps.cardano.sign_tx.py
gabrielkerekes e1615e60ec Update Cardano to support Shelley era 1/3
Update protobuf

- Previous transactions don't need to be sent anymore, because fee is
  included in the transaction now. Thus transactions_count can be
  removed from CardanoSignTx message and the CardanoTxAck and
  CardanoTxRequest messages can be removed altogether.
- CardanoTxInputType.type is unused so remove it

Add NULL (None type) serialisation to CBOR

- Transaction metada must either have a valid structure or CBOR NULL
  must be used (if metadata is empty) - it can't be simply left out.

Add protocol_magics file

- Just to have a nicer way of representing protocol magics

Update transaction signing

- Previous transactions no longer need to be requested
- Output building is simplified, since fee doesn't need to be calculated
- Remove transaction class since it is no longer needed (only functions
  remained)
- Reorder functions so it reads top to bottom

Add protocol magic to byron address on testnet

- This has always been a part of the spec, but it hasn't been
  implemented before, because it wasn't really needed.

Update trezorlib

Update tests

- Transaction messages are no longer required
- Expected values are different since tx format changed
- Common values in test cases have been extracted

Remove unused file

- Progress was used when receiving previous transactions

Add CRC check to output address validation
2020-07-27 13:04:49 +02:00

88 lines
3.4 KiB
Python

from common import *
from apps.common import HARDENED
from trezor.messages.CardanoTxInputType import CardanoTxInputType
if not utils.BITCOIN_ONLY:
from apps.cardano.sign_tx import _should_hide_output
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
class TestCardanoSignTransaction(unittest.TestCase):
def test_should_show_outputs(self):
outputs_to_show = [
# output is from the same address as input
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
# output is from the same account but from different addresses
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
[
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 1],
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 2],
],
),
# both output and input are from account 2
(
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 0],
[
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 0],
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 1],
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 2],
],
),
]
outputs_to_hide = [
# output is from different account
(
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 0],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
# output path is not complete
(
[44 | HARDENED, 1815 | HARDENED],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
# output path is not complete
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
# one of the inputs has different account than output
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
[
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0],
[44 | HARDENED, 1815 | HARDENED, 2 | HARDENED, 0, 0],
],
),
# staking output path
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0,],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
# output address too large
(
[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 1000001],
[[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0]],
),
]
for output_path, input_paths in outputs_to_show:
inputs = [
CardanoTxInputType(input_path, "", 0) for input_path in input_paths
]
self.assertTrue(_should_hide_output(output_path, inputs))
for output_path, input_paths in outputs_to_hide:
inputs = [
CardanoTxInputType(input_path, "", 0) for input_path in input_paths
]
self.assertFalse(_should_hide_output(output_path, inputs))
if __name__ == "__main__":
unittest.main()