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(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
def test_cardano_sign_tx( client, protocol_magic, network_id, inputs, outputs, fee, ttl, 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 = [] withdrawals = [] metadata = bytes() expected_responses = [ messages.PassphraseRequest(), ] 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") client.use_passphrase("TREZOR") 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=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_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): 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( client, protocol_magic, network_id, inputs, outputs, fee, ttl, 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] 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, inputs, outputs, fee, ttl, protocol_magic, network_id ) assert response.tx_hash.hex() == tx_hash assert response.serialized_tx.hex() == serialized_tx