Пример #1
0
def test_cardano_sign_tx(client, network, inputs, outputs, transactions,
                         tx_hash, tx_body):
    inputs = [cardano.create_input(i) for i in inputs]
    outputs = [cardano.create_output(o) for o in outputs]

    expected_responses = [
        messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions))
    ]
    expected_responses += [
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.CardanoSignedTx(),
    ]

    with client:
        client.set_expected_responses(expected_responses)
        response = cardano.sign_tx(client,
                                   inputs,
                                   outputs,
                                   transactions,
                                   network=network)
        assert response.tx_hash.hex() == tx_hash
        assert response.tx_body.hex() == tx_body
Пример #2
0
def test_cardano_sign_tx(client, protocol_magic, inputs, outputs, transactions,
                         tx_hash, tx_body):
    inputs = [cardano.create_input(i) for i in inputs]
    outputs = [cardano.create_output(o) for o in outputs]

    expected_responses = [
        messages.PassphraseRequest(),
        messages.PassphraseStateRequest(),
    ]
    expected_responses += [
        messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions))
    ]
    expected_responses += [
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.ButtonRequest(code=messages.ButtonRequestType.Other),
        messages.CardanoSignedTx(),
    ]

    def input_flow():
        yield
        client.debug.swipe_down()
        client.debug.press_yes()
        yield
        client.debug.swipe_down()
        client.debug.press_yes()

    client.set_passphrase("TREZOR")
    with client:
        client.set_expected_responses(expected_responses)
        client.set_input_flow(input_flow)
        response = cardano.sign_tx(client, inputs, outputs, transactions,
                                   protocol_magic)
        assert response.tx_hash.hex() == tx_hash
        assert response.tx_body.hex() == tx_body
def test_cardano_sign_tx_validation(client, protocol_magic, inputs, outputs,
                                    transactions, expected_error_message):
    inputs = [cardano.create_input(i) for i in inputs]
    outputs = [cardano.create_output(o) for o in outputs]

    expected_responses = [
        messages.CardanoTxRequest(tx_index=i) for i in range(len(transactions))
    ]
    expected_responses += [messages.Failure()]

    with client:
        client.set_expected_responses(expected_responses)

        with pytest.raises(TrezorFailure, match=expected_error_message):
            cardano.sign_tx(client, inputs, outputs, transactions,
                            protocol_magic)