1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-10 15:30:55 +00:00

chore(tests): Add payment requests to test_msg_authorize_coinjoin device test.

This commit is contained in:
Andrew Kozlik 2021-01-20 19:32:26 +01:00 committed by Andrew Kozlik
parent f6154b311e
commit e5281b87b5
2 changed files with 260 additions and 170 deletions

View File

@ -21,7 +21,14 @@ from trezorlib.exceptions import TrezorFailure
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
from ...tx_cache import TxCache from ...tx_cache import TxCache
from ..signtx import request_finished, request_input, request_meta, request_output from ..signtx import (
request_finished,
request_input,
request_meta,
request_output,
request_payment_req,
)
from .payment_req import make_payment_request
B = messages.ButtonRequestType B = messages.ButtonRequestType
@ -87,7 +94,8 @@ def test_sign_tx(client):
preauthorized=True, preauthorized=True,
) )
inp1 = messages.TxInputType( inputs = [
messages.TxInputType(
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle" # seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0 # 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2 # tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
@ -100,45 +108,66 @@ def test_sign_tx(client):
"534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d" "534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d"
), ),
commitment_data=commitment_data, commitment_data=commitment_data,
) ),
inp2 = messages.TxInputType( messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"), address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000, amount=7289000,
prev_hash=TXHASH_65b811, prev_hash=TXHASH_65b811,
prev_index=1, prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS, script_type=messages.InputScriptType.SPENDWITNESS,
) ),
]
outputs = [
# Other's coinjoined output. # Other's coinjoined output.
out1 = messages.TxOutputType( messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml", address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our coinjoined output. # Our coinjoined output.
out2 = messages.TxOutputType( messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"), address_n=parse_path("84'/1'/0'/1/1"),
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our change output. # Our change output.
out3 = messages.TxOutputType( messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"), address_n=parse_path("84'/1'/0'/1/2"),
amount=7289000 - 50000 - 5 - 5000, amount=7289000 - 50000 - 5 - 5000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Other's change output. # Other's change output.
out4 = messages.TxOutputType( messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk", address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 50000 - 5 - 5000, amount=100000 - 50000 - 5 - 5000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Coordinator's output. # Coordinator's output.
out5 = messages.TxOutputType( messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q", address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=10, amount=10,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
]
payment_req = make_payment_request(
client,
recipient_name="www.example.com",
outputs=outputs,
change_addresses=[
"tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d",
"tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx",
],
) )
payment_req.amount = None
with client: with client:
client.set_expected_responses( client.set_expected_responses(
@ -147,6 +176,7 @@ def test_sign_tx(client):
request_input(0), request_input(0),
request_input(1), request_input(1),
request_output(0), request_output(0),
request_payment_req(0),
request_output(1), request_output(1),
request_output(2), request_output(2),
request_output(3), request_output(3),
@ -175,9 +205,10 @@ def test_sign_tx(client):
_, serialized_tx = btc.sign_tx( _, serialized_tx = btc.sign_tx(
client, client,
"Testnet", "Testnet",
[inp1, inp2], inputs,
[out1, out2, out3, out4, out5], outputs,
prev_txes=TX_CACHE_TESTNET, prev_txes=TX_CACHE_TESTNET,
payment_reqs=[payment_req],
preauthorized=True, preauthorized=True,
) )
@ -190,9 +221,10 @@ def test_sign_tx(client):
btc.sign_tx( btc.sign_tx(
client, client,
"Testnet", "Testnet",
[inp1, inp2], inputs,
[out1, out2, out3, out4, out5], outputs,
prev_txes=TX_CACHE_TESTNET, prev_txes=TX_CACHE_TESTNET,
payment_reqs=[payment_req],
preauthorized=True, preauthorized=True,
) )
@ -201,9 +233,10 @@ def test_sign_tx(client):
btc.sign_tx( btc.sign_tx(
client, client,
"Testnet", "Testnet",
[inp1, inp2], inputs,
[out1, out2, out3, out4, out5], outputs,
prev_txes=TX_CACHE_TESTNET, prev_txes=TX_CACHE_TESTNET,
payment_reqs=[payment_req],
preauthorized=True, preauthorized=True,
) )
@ -222,7 +255,8 @@ def test_unfair_fee(client):
script_type=messages.InputScriptType.SPENDWITNESS, script_type=messages.InputScriptType.SPENDWITNESS,
) )
inp1 = messages.TxInputType( inputs = [
messages.TxInputType(
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle" # seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0 # 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2 # tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
@ -235,53 +269,75 @@ def test_unfair_fee(client):
"534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d" "534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d"
), ),
commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"), commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"),
) ),
inp2 = messages.TxInputType( messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"), address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000, amount=7289000,
prev_hash=TXHASH_65b811, prev_hash=TXHASH_65b811,
prev_index=1, prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS, script_type=messages.InputScriptType.SPENDWITNESS,
) ),
]
outputs = [
# Other's coinjoined output. # Other's coinjoined output.
out1 = messages.TxOutputType( messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml", address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our coinjoined output. # Our coinjoined output.
out2 = messages.TxOutputType( messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"), address_n=parse_path("84'/1'/0'/1/1"),
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our change output. # Our change output.
out3 = messages.TxOutputType( messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"), address_n=parse_path("84'/1'/0'/1/2"),
amount=7289000 - 50000 - 5 - 6000, # unfair mining fee amount=7289000 - 50000 - 5 - 6000, # unfair mining fee
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Other's change output. # Other's change output.
out4 = messages.TxOutputType( messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk", address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 50000 - 5 - 4000, amount=100000 - 50000 - 5 - 4000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Coordinator's output. # Coordinator's output.
out5 = messages.TxOutputType( messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q", address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=10, amount=10,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
]
payment_req = make_payment_request(
client,
recipient_name="www.example.com",
outputs=outputs,
change_addresses=[
"tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d",
"tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx",
],
) )
payment_req.amount = None
with pytest.raises(TrezorFailure, match="fee over threshold"): with pytest.raises(TrezorFailure, match="fee over threshold"):
btc.sign_tx( btc.sign_tx(
client, client,
"Testnet", "Testnet",
[inp1, inp2], inputs,
[out1, out2, out3, out4, out5], outputs,
prev_txes=TX_CACHE_TESTNET, prev_txes=TX_CACHE_TESTNET,
payment_reqs=[payment_req],
preauthorized=True, preauthorized=True,
) )
@ -300,7 +356,8 @@ def test_no_anonymity(client):
script_type=messages.InputScriptType.SPENDWITNESS, script_type=messages.InputScriptType.SPENDWITNESS,
) )
inp1 = messages.TxInputType( inputs = [
messages.TxInputType(
# seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle" # seed "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"
# 84'/1'/0'/0/0 # 84'/1'/0'/0/0
# tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2 # tb1qnspxpr2xj9s2jt6qlhuvdnxw6q55jvygcf89r2
@ -313,65 +370,91 @@ def test_no_anonymity(client):
"534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d" "534c001901016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c4000247304402207c7e55f9ad25b03f27e0f51bba5140bafb20d2f29f27dce08e8d0d8d2c4c2efc022060623701649897a8068d5d44efad69e27368e0b5d968daa487139a1367cf2444012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d"
), ),
commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"), commitment_data=b"www.example.org" + (1).to_bytes(ROUND_ID_LEN, "big"),
) ),
inp2 = messages.TxInputType( messages.TxInputType(
address_n=parse_path("84'/1'/0'/1/0"), address_n=parse_path("84'/1'/0'/1/0"),
amount=7289000, amount=7289000,
prev_hash=TXHASH_65b811, prev_hash=TXHASH_65b811,
prev_index=1, prev_index=1,
script_type=messages.InputScriptType.SPENDWITNESS, script_type=messages.InputScriptType.SPENDWITNESS,
) ),
]
outputs = [
# Other's coinjoined output. # Other's coinjoined output.
out1 = messages.TxOutputType( messages.TxOutputType(
address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml", address="tb1qk7j3ahs2v6hrv4v282cf0tvxh0vqq7rpt3zcml",
amount=30000, amount=30000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Other's coinjoined output. # Other's coinjoined output.
out2 = messages.TxOutputType( messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk", address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=30000, amount=30000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our coinjoined output. # Our coinjoined output.
out3 = messages.TxOutputType( messages.TxOutputType(
# tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d
address_n=parse_path("84'/1'/0'/1/1"), address_n=parse_path("84'/1'/0'/1/1"),
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our coinjoined output. # Our coinjoined output.
out4 = messages.TxOutputType( messages.TxOutputType(
# tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx
address_n=parse_path("84'/1'/0'/1/2"), address_n=parse_path("84'/1'/0'/1/2"),
amount=50000, amount=50000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Our change output. # Our change output.
out5 = messages.TxOutputType( messages.TxOutputType(
address_n=parse_path("84'/1'/0'/1/2"), # tb1qwn0s88t9r39g72m78mcaxj72sy3ct4m404xsmq
address_n=parse_path("84'/1'/0'/1/3"),
amount=7289000 - 50000 - 50000 - 10 - 5000, amount=7289000 - 50000 - 50000 - 10 - 5000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Other's change output. # Other's change output.
out6 = messages.TxOutputType( messages.TxOutputType(
address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk", address="tb1q9cqhdr9ydetjzrct6tyeuccws9505hl96azwxk",
amount=100000 - 30000 - 30000 - 6 - 5000, amount=100000 - 30000 - 30000 - 6 - 5000,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
) payment_req_index=0,
),
# Coordinator's output. # Coordinator's output.
out7 = messages.TxOutputType( messages.TxOutputType(
address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q", address="mvbu1Gdy8SUjTenqerxUaZyYjmveZvt33q",
amount=16, amount=16,
script_type=messages.OutputScriptType.PAYTOWITNESS, script_type=messages.OutputScriptType.PAYTOWITNESS,
payment_req_index=0,
),
]
payment_req = make_payment_request(
client,
recipient_name="www.example.com",
outputs=outputs,
change_addresses=[
"tb1qze76uzqteg6un6jfcryrxhwvfvjj58ts0swg3d",
"tb1qr5p6f5sk09sms57ket074vywfymuthlgud7xyx",
"tb1qwn0s88t9r39g72m78mcaxj72sy3ct4m404xsmq",
],
) )
payment_req.amount = None
with pytest.raises(TrezorFailure, match="No anonymity gain"): with pytest.raises(TrezorFailure, match="No anonymity gain"):
btc.sign_tx( btc.sign_tx(
client, client,
"Testnet", "Testnet",
[inp1, inp2], inputs,
[out1, out2, out3, out4, out5, out6, out7], outputs,
prev_txes=TX_CACHE_TESTNET, prev_txes=TX_CACHE_TESTNET,
payment_reqs=[payment_req],
preauthorized=True, preauthorized=True,
) )

View File

@ -31,6 +31,13 @@ def request_orig_output(n: int, tx_hash: bytes) -> messages.TxRequest:
) )
def request_payment_req(n):
return messages.TxRequest(
request_type=T.TXPAYMENTREQ,
details=messages.TxRequestDetailsType(request_index=n),
)
def request_meta(tx_hash: bytes) -> messages.TxRequest: def request_meta(tx_hash: bytes) -> messages.TxRequest:
return messages.TxRequest( return messages.TxRequest(
request_type=T.TXMETA, request_type=T.TXMETA,