1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 07:18:09 +00:00

test: Add device test for RBF finalization.

This commit is contained in:
Andrew Kozlik 2020-11-19 18:40:07 +01:00 committed by Andrew Kozlik
parent f421a213fd
commit 65a9636bb5
4 changed files with 119 additions and 0 deletions

View File

@ -68,6 +68,9 @@ TXHASH_6673b7 = bytes.fromhex(
TXHASH_927784 = bytes.fromhex(
"927784e07bbcefc4c738f5c31c7a739978fc86f35514edf7e7da25d53d83030b"
)
TXHASH_43d273 = bytes.fromhex(
"43d273d3caf41759ad843474f960fbf80ff2ec961135d018b61e9fab3ad1fc06"
)
@pytest.mark.skip_t1
@ -138,6 +141,78 @@ def test_p2pkh_fee_bump(client):
)
@pytest.mark.skip_t1
def test_p2wpkh_finalize(client):
# Original input with disabled RBF opt-in, i.e. we finalize the transaction.
inp1 = messages.TxInputType(
address_n=parse_path("84h/1h/0h/0/2"),
amount=20000000,
script_type=messages.InputScriptType.SPENDWITNESS,
prev_hash=TXHASH_43d273,
prev_index=1,
orig_hash=TXHASH_70f987,
orig_index=0,
sequence=4294967294,
)
# Original external output (actually 84h/1h/0h/0/0).
out1 = messages.TxOutputType(
address="tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
amount=100000,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=0,
)
# Change output. We bump the fee from 141 to 200.
out2 = messages.TxOutputType(
address_n=parse_path("84h/1h/0h/1/1"),
amount=20000000 - 100000 - 200,
script_type=messages.OutputScriptType.PAYTOWITNESS,
orig_hash=TXHASH_70f987,
orig_index=1,
)
with client:
client.set_expected_responses(
[
request_input(0),
request_meta(TXHASH_70f987),
request_orig_input(0, TXHASH_70f987),
request_output(0),
request_orig_output(0, TXHASH_70f987),
request_output(1),
request_orig_output(1, TXHASH_70f987),
messages.ButtonRequest(code=B.SignTx),
messages.ButtonRequest(code=B.SignTx),
request_input(0),
request_meta(TXHASH_43d273),
request_input(0, TXHASH_43d273),
request_output(0, TXHASH_43d273),
request_output(1, TXHASH_43d273),
request_output(2, TXHASH_43d273),
request_input(0),
request_output(0),
request_output(1),
request_input(0),
request_finished(),
]
)
_, serialized_tx = btc.sign_tx(
client,
"Testnet",
[inp1],
[out1, out2],
lock_time=1348713,
prev_txes=TX_CACHE_TESTNET,
)
assert (
serialized_tx.hex()
== "0100000000010106fcd13aab9f1eb618d0351196ecf20ff8fb60f9743484ad5917f4cad373d2430100000000feffffff02a086010000000000160014b31dc2a236505a6cb9201fa0411ca38a254a7bf198a52f0100000000160014167dae080bca35c9ea49c0c8335dcc4b252a1d700247304402201ee1828ab0ca7f8113989399edda8394c65e5c3c9fe597a78890c5d2c9bd2aeb022010e76ad6abe171e5cded6b374a344ee18a51d38477b76a4b6fb30289ed24beff01210357cb3a5918d15d224f14a89f0eb54478272108f6cbb9c473c1565e55260f6e9369941400"
)
@pytest.mark.skip_t1
@pytest.mark.parametrize(
"out1_amount, out2_amount, copayer_witness, fee_confirm, expected_tx",

View File

@ -0,0 +1,27 @@
{
"bin_outputs": [
{
"amount": 10000000,
"script_pubkey": "a914051877a0cc43165e48975c1e62bdef3b6c942a3887"
},
{
"amount": 20000000,
"script_pubkey": "00142fde3b3d1644fd16bd18a78138ae3873398eca37"
},
{
"amount": 99999694,
"script_pubkey": "0014cc8067093f6f843d6d3e22004a4290cd0c0f336b"
}
],
"inputs": [
{
"prev_hash": "e294c4c172c3d87991b0369e45d6af8584be92914d01e3060fad1ed31d12ff00",
"prev_index": 0,
"script_sig": "",
"script_type": "SPENDADDRESS",
"sequence": 4294967293
}
],
"lock_time": 1287124,
"version": 1
}

View File

@ -13,10 +13,26 @@
{
"prev_hash": "43d273d3caf41759ad843474f960fbf80ff2ec961135d018b61e9fab3ad1fc06",
"prev_index": 1,
"address_n": [2147483732, 2147483649, 2147483648, 0, 2],
"amount": 20000000,
"script_type": 3,
"script_sig": "",
"witness": "0247304402207da4ce78bf9175ad4764794013360be569d3902861a54922aad6239659422f86022050145fc897a806b4ef06777a58471d39e9a10482cd8e61819ee18d6d22eaa6be01210357cb3a5918d15d224f14a89f0eb54478272108f6cbb9c473c1565e55260f6e93",
"sequence": 4294967293
}
],
"lock_time": 1348713,
"outputs": [
{
"address": "tb1qkvwu9g3k2pdxewfqr7syz89r3gj557l3uuf9r9",
"amount": 100000,
"script_type": 4
},
{
"address_n": [2147483732, 2147483649, 2147483648, 1, 1],
"amount": 19899859,
"script_type": 4
}
],
"version": 1
}

View File

@ -342,6 +342,7 @@
"test_msg_signtx_komodo.py-test_one_one_rewards_claim": "751e83d63bf01c6c57047b5e004629d613df75342371cd43a7b4b80a07f4b88d",
"test_msg_signtx_peercoin.py::test_timestamp_included": "825b9bdf5238c5c6415a254a6bae4b2bd9df8fc5cb31f66f0c20145cb4e60bbb",
"test_msg_signtx_replacement.py::test_p2pkh_fee_bump": "881f6491e9f4417cd747dda2dc0eaafdf1a4769a5e53aa303bb06547d6a9133b",
"test_msg_signtx_replacement.py::test_p2wpkh_finalize": "1147c6996c193b904b72d38def07c692cf48d7bdbe244343c9e98ee0db497d11",
"test_msg_signtx_replacement.py::test_p2wpkh_in_p2sh_remove_change": "f66437cc88d016ddb0b3fd4e6d2c6536d9a1745dfc92ce9cd334c3cbaaefb4a9",
"test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909659-90000-02483045022100aa1b91fb25cc9a0ace4": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1",
"test_msg_signtx_replacement.py::test_p2wpkh_payjoin[19909718-90000-024730440220753f53049ca43d55f6563": "a5473b5f3931fb6530a991e45aa32507069a7b402878d1eda2ce6e8be1a673e1",