1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 15:38:11 +00:00

tests/signing: add more tests for incorrect script type

This commit is contained in:
Tomas Susanka 2020-03-23 12:37:26 +00:00
parent 47f104bceb
commit a0c8f8f00e

View File

@ -927,8 +927,64 @@ class TestMsgSigntx:
):
btc.sign_tx(client, "Bitcoin", [inp0], [out1], details, prev_txes=cache)
@pytest.mark.parametrize(
"script_type",
(proto.InputScriptType.SPENDADDRESS, proto.InputScriptType.EXTERNAL),
)
@pytest.mark.skip_ui
def test_incorrect_script_type(self, client):
def test_incorrect_input_script_type(self, client, script_type):
address_n = parse_path("44'/1'/0'/0/0")
attacker_multisig_public_key = bytes.fromhex(
"030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
)
multisig = proto.MultisigRedeemScriptType(
m=1,
nodes=[
btc.get_public_node(client, address_n).node,
proto.HDNodeType(
depth=0,
fingerprint=0,
child_num=0,
chain_code=bytes(32),
public_key=attacker_multisig_public_key,
),
],
address_n=[],
)
inp1 = proto.TxInputType(
address_n=address_n,
prev_index=1,
sequence=0xFFFFFFFF,
script_type=script_type, # incorrect script type
multisig=multisig,
prev_hash=TXHASH_e5040e,
)
out1 = proto.TxOutputType(
address_n=address_n,
amount=1000000 - 50000 - 10000,
script_type=proto.OutputScriptType.PAYTOMULTISIG,
multisig=multisig,
)
out2 = proto.TxOutputType(
address="mtkyndbpgv1G7nwggwKDVagRpxEJrwwyh6",
amount=50000,
script_type=proto.OutputScriptType.PAYTOADDRESS,
)
with pytest.raises(
TrezorFailure, match="Multisig field provided but not expected."
):
btc.sign_tx(
client, "Testnet", [inp1], [out1, out2], prev_txes=TxCache("Testnet")
)
@pytest.mark.parametrize(
"script_type",
(proto.OutputScriptType.PAYTOADDRESS, proto.OutputScriptType.PAYTOSCRIPTHASH),
)
@pytest.mark.skip_ui
def test_incorrect_output_script_type(self, client, script_type):
address_n = parse_path("44'/1'/0'/0/0")
attacker_multisig_public_key = bytes.fromhex(
"030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
@ -953,13 +1009,12 @@ class TestMsgSigntx:
prev_index=1,
sequence=0xFFFFFFFF,
script_type=proto.InputScriptType.SPENDADDRESS,
multisig=multisig,
prev_hash=TXHASH_e5040e,
)
out1 = proto.TxOutputType(
address_n=address_n,
amount=1000000 - 50000 - 10000,
script_type=proto.OutputScriptType.PAYTOMULTISIG,
script_type=script_type, # incorrect script type
multisig=multisig,
)
out2 = proto.TxOutputType(