def test_cardano_sign_tx_failed(client, parameters, result): inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) 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, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, )
def test_cardano_sign_tx_failed(client: Client, parameters, result): client.init_device(new_session=True, derive_cardano=True) signing_mode = messages.CardanoTxSigningMode.__members__[ parameters["signing_mode"]] inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) mint = cardano.parse_mint(parameters["mint"]) script_data_hash = cardano.parse_script_data_hash( parameters["script_data_hash"]) collateral_inputs = [ cardano.parse_collateral_input(i) for i in parameters["collateral_inputs"] ] required_signers = [ cardano.parse_required_signer(s) for s in parameters["required_signers"] ] additional_witness_requests = [ cardano.parse_additional_witness_request(p) for p in parameters["additional_witness_requests"] ] 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: with pytest.raises(TrezorFailure, match=result["error_message"]): cardano.sign_tx( client=client, signing_mode=signing_mode, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get( "validity_interval_start"), certificates=certificates, withdrawals=withdrawals, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, mint=mint, script_data_hash=script_data_hash, collateral_inputs=collateral_inputs, required_signers=required_signers, additional_witness_requests=additional_witness_requests, include_network_id=parameters["include_network_id"], )
def test_cardano_sign_tx_with_multiple_chunks(client, parameters, result): inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) 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, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, ) assert response.tx_hash.hex() == result["tx_hash"] assert response.serialized_tx.hex() == result["serialized_tx"]
def test_cardano_sign_tx(client, parameters, result): client.init_device(new_session=True, derive_cardano=True) signing_mode = messages.CardanoTxSigningMode.__members__[ parameters["signing_mode"]] inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) mint = cardano.parse_mint(parameters["mint"]) additional_witness_requests = [ cardano.parse_additional_witness_request(p) for p in parameters["additional_witness_requests"] ] 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: response = cardano.sign_tx( client=client, signing_mode=signing_mode, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters.get("ttl"), validity_interval_start=parameters.get("validity_interval_start"), certificates=certificates, withdrawals=withdrawals, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, mint=mint, additional_witness_requests=additional_witness_requests, ) assert response == _transform_expected_result(result)
def test_cardano_sign_tx(client, parameters, result): inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) 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, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, ) assert response.tx_hash.hex() == result["tx_hash"] assert response.serialized_tx.hex() == result["serialized_tx"]
def call_sign_tx(client: Client, parameters, input_flow=None): client.init_device(new_session=True, derive_cardano=True) signing_mode = messages.CardanoTxSigningMode.__members__[ parameters["signing_mode"]] inputs = [cardano.parse_input(i) for i in parameters["inputs"]] outputs = [cardano.parse_output(o) for o in parameters["outputs"]] certificates = [ cardano.parse_certificate(c) for c in parameters["certificates"] ] withdrawals = [ cardano.parse_withdrawal(w) for w in parameters["withdrawals"] ] auxiliary_data = cardano.parse_auxiliary_data(parameters["auxiliary_data"]) mint = cardano.parse_mint(parameters["mint"]) script_data_hash = cardano.parse_script_data_hash( parameters["script_data_hash"]) collateral_inputs = [ cardano.parse_collateral_input(i) for i in parameters["collateral_inputs"] ] required_signers = [ cardano.parse_required_signer(s) for s in parameters["required_signers"] ] collateral_return = (cardano.parse_output(parameters["collateral_return"]) if parameters["collateral_return"] is not None else None) reference_inputs = [ cardano.parse_reference_input(i) for i in parameters["reference_inputs"] ] additional_witness_requests = [ cardano.parse_additional_witness_request(p) for p in parameters["additional_witness_requests"] ] 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: if input_flow is not None: client.watch_layout() client.set_input_flow(input_flow(client)) return cardano.sign_tx( client=client, signing_mode=signing_mode, inputs=inputs, outputs=outputs, fee=parameters["fee"], ttl=parameters["ttl"], validity_interval_start=parameters["validity_interval_start"], certificates=certificates, withdrawals=withdrawals, protocol_magic=parameters["protocol_magic"], network_id=parameters["network_id"], auxiliary_data=auxiliary_data, mint=mint, script_data_hash=script_data_hash, collateral_inputs=collateral_inputs, required_signers=required_signers, collateral_return=collateral_return, total_collateral=parameters["total_collateral"], reference_inputs=reference_inputs, additional_witness_requests=additional_witness_requests, include_network_id=parameters["include_network_id"], )