def test_cardano_sign_tx_failed(client, parameters, result): inputs = [cardano.create_input(i) for i in parameters["inputs"]] outputs = [cardano.create_output(o) for o in parameters["outputs"]] certificates = [ cardano.create_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.create_withdrawal(w) for w in parameters["withdrawals"] ] expected_responses = [messages.PassphraseRequest(), messages.Failure()] with client: client.set_expected_responses(expected_responses) with pytest.raises(TrezorFailure, match=result["error_message"]): cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters["ttl"], certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(parameters["metadata"]), protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], )
def test_cardano_sign_tx_failed(client, parameters, result): inputs = [cardano.create_input(i) for i in parameters["inputs"]] outputs = [cardano.create_output(o) for o in parameters["outputs"]] certificates = [ cardano.create_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.create_withdrawal(w) for w in parameters["withdrawals"] ] input_flow = parameters.get("input_flow", ()) with client: client.set_input_flow(_to_device_actions(client, input_flow)) with pytest.raises(TrezorFailure, match=result["error_message"]): cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get( "validity_interval_start"), certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(parameters["metadata"]), protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], )
def test_cardano_sign_tx( client, protocol_magic, network_id, inputs, outputs, fee, ttl, certificates, withdrawals, metadata, input_flow_sequences, tx_hash, serialized_tx, ): inputs = [cardano.create_input(i) for i in inputs] outputs = [cardano.create_output(o) for o in outputs] certificates = [cardano.create_certificate(c) for c in certificates] withdrawals = [cardano.create_withdrawal(w) for w in withdrawals] expected_responses = [ messages.ButtonRequest(code=messages.ButtonRequestType.Other) for i in range(len(input_flow_sequences)) ] expected_responses.append(messages.CardanoSignedTx()) def input_flow(): for sequence in input_flow_sequences: yield for action in sequence: if action == InputAction.SWIPE: client.debug.swipe_up() elif action == InputAction.YES: client.debug.press_yes() else: raise ValueError("Invalid input action") with client: client.set_expected_responses(expected_responses) client.set_input_flow(input_flow) response = cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=fee, ttl=ttl, certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(metadata), protocol_magic=protocol_magic, network_id=network_id, ) assert response.tx_hash.hex() == tx_hash assert response.serialized_tx.hex() == serialized_tx
def test_cardano_sign_tx(client, parameters, result): inputs = [cardano.create_input(i) for i in parameters["inputs"]] outputs = [cardano.create_output(o) for o in parameters["outputs"]] certificates = [ cardano.create_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.create_withdrawal(w) for w in parameters["withdrawals"] ] expected_responses = [messages.PassphraseRequest()] expected_responses += [ messages.ButtonRequest(code=messages.ButtonRequestType.Other) for i in range(len(parameters["input_flow"])) ] expected_responses.append(messages.CardanoSignedTx()) def input_flow(): for sequence in parameters["input_flow"]: yield for action in sequence: if action == "SWIPE": client.debug.swipe_up() elif action == "YES": client.debug.press_yes() else: raise ValueError("Invalid input action") with client: client.set_expected_responses(expected_responses) client.set_input_flow(input_flow) response = cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get("validity_interval_start"), certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(parameters["metadata"]), protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], ) assert response.tx_hash.hex() == result["tx_hash"] assert response.serialized_tx.hex() == result["serialized_tx"]
def test_cardano_sign_tx_with_multiple_chunks(client, parameters, result): inputs = [cardano.create_input(i) for i in parameters["inputs"]] outputs = [cardano.create_output(o) for o in parameters["outputs"]] certificates = [ cardano.create_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.create_withdrawal(w) for w in parameters["withdrawals"] ] input_flow = parameters.get("input_flow", ()) expected_responses = [ messages.PassphraseRequest(), messages.ButtonRequest(), messages.ButtonRequest(), ] expected_responses += [ messages.CardanoSignedTxChunk( signed_tx_chunk=bytes.fromhex(signed_tx_chunk)) for signed_tx_chunk in result["signed_tx_chunks"] ] expected_responses += [ messages.CardanoSignedTx(tx_hash=bytes.fromhex(result["tx_hash"])) ] with client: client.set_input_flow(_to_device_actions(client, input_flow)) client.set_expected_responses(expected_responses) response = cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get("validity_interval_start"), certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(parameters["metadata"]), protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], ) assert response.tx_hash.hex() == result["tx_hash"] assert response.serialized_tx.hex() == result["serialized_tx"]
def test_cardano_sign_tx(client, parameters, result): inputs = [cardano.create_input(i) for i in parameters["inputs"]] outputs = [cardano.create_output(o) for o in parameters["outputs"]] certificates = [ cardano.create_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.create_withdrawal(w) for w in parameters["withdrawals"] ] input_flow = parameters.get("input_flow", ()) if parameters.get("security_checks") == "prompt": device.apply_settings( client, safety_checks=messages.SafetyCheckLevel.PromptTemporarily) else: device.apply_settings(client, safety_checks=messages.SafetyCheckLevel.Strict) with client: client.set_input_flow(_to_device_actions(client, input_flow)) response = cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get("validity_interval_start"), certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(parameters["metadata"]), protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], ) assert response.tx_hash.hex() == result["tx_hash"] assert response.serialized_tx.hex() == result["serialized_tx"]
def test_cardano_sign_tx_validation( client, protocol_magic, network_id, inputs, outputs, fee, ttl, certificates, withdrawals, metadata, expected_error_message, ): inputs = [cardano.create_input(i) for i in inputs] outputs = [cardano.create_output(o) for o in outputs] certificates = [cardano.create_certificate(c) for c in certificates] withdrawals = [cardano.create_withdrawal(w) for w in withdrawals] expected_responses = [messages.Failure()] with client: client.set_expected_responses(expected_responses) with pytest.raises(TrezorFailure, match=expected_error_message): cardano.sign_tx( client=client, inputs=inputs, outputs=outputs, fee=fee, ttl=ttl, certificates=certificates, withdrawals=withdrawals, metadata=bytes.fromhex(metadata), protocol_magic=protocol_magic, network_id=network_id, )