Skip to content

Commit

Permalink
feat(core,legacy): show fee rate when signing transaction - tests upd…
Browse files Browse the repository at this point in the history
…ated
  • Loading branch information
Martin Novak committed May 19, 2022
1 parent 07050da commit a1d2289
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 14 deletions.
11 changes: 9 additions & 2 deletions core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def test_send_native_p2wpkh(self):
)
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)

# precomputed tx weight is 566
fee_rate = 11000 / (566 / 4)

messages = [
None,

Expand All @@ -101,7 +104,7 @@ def test_send_native_p2wpkh(self):
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN),
True,

helpers.UiConfirmTotal(12300000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down Expand Up @@ -202,13 +205,17 @@ def test_send_native_p2wpkh_change(self):
)
out2 = TxOutput(
address=None,
# 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX
address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000,
multisig=None,
)
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)

# precomputed tx weight is 566
fee_rate = 11000 / (566 / 4)

messages = [
None,

Expand All @@ -228,7 +235,7 @@ def test_send_native_p2wpkh_change(self):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),

helpers.UiConfirmTotal(5000000 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(5000000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down
11 changes: 9 additions & 2 deletions core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def test_send_native_p2wpkh(self):
)
tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2)

# precomputed tx weight is 566
fee_rate = 11000 / (566 / 4)

messages = [
None,

Expand All @@ -102,7 +105,7 @@ def test_send_native_p2wpkh(self):
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True,

helpers.UiConfirmTotal(12300000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down Expand Up @@ -203,13 +206,17 @@ def test_send_native_p2wpkh_change(self):
)
out2 = TxOutput(
address=None,
# 84'/1'/0'/1/0" - tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57
address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0],
script_type=OutputScriptType.PAYTOWITNESS,
amount=12300000 - 11000 - 5000000,
multisig=None,
)
tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2)

# precomputed tx weight is 566
fee_rate = 11000 / (566 / 4)

messages = [
None,

Expand All @@ -229,7 +236,7 @@ def test_send_native_p2wpkh_change(self):
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True,

helpers.UiConfirmTotal(5000000 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(5000000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down
15 changes: 12 additions & 3 deletions core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def test_send_p2wpkh_in_p2sh(self):
)
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)

# precomputed tx weight is 670
fee_rate = 11000 / (670 / 4)

messages = [
None,

Expand All @@ -98,7 +101,7 @@ def test_send_p2wpkh_in_p2sh(self):
helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN),
True,

helpers.UiConfirmTotal(123445789 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(123445789 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down Expand Up @@ -206,6 +209,9 @@ def test_send_p2wpkh_in_p2sh_change(self):
)
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)

# precomputed tx weight is 670
fee_rate = 11000 / (670 / 4)

messages = [
None,

Expand All @@ -223,7 +229,7 @@ def test_send_p2wpkh_in_p2sh_change(self):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),

helpers.UiConfirmTotal(12300000 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(12300000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down Expand Up @@ -352,6 +358,9 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self):
)
tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2)

# precomputed tx weight is 670
fee_rate = (9 - 8 - 1) / (670 / 4)

messages = [
None,

Expand All @@ -368,7 +377,7 @@ def test_send_p2wpkh_in_p2sh_attack_amount(self):
TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAckOutput(tx=TxAckOutputWrapper(output=out2)),

helpers.UiConfirmTotal(9 - 1, 9 - 8 - 1, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(9 - 1, 9 - 8 - 1, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down
10 changes: 8 additions & 2 deletions core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ def test_send_p2wpkh_in_p2sh(self):
)
tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2)

# precomputed tx weight is 670
fee_rate = 11000 / (670 / 4)

messages = [
None,

Expand All @@ -102,7 +105,7 @@ def test_send_p2wpkh_in_p2sh(self):
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True,

helpers.UiConfirmTotal(123445789 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(123445789 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down Expand Up @@ -210,6 +213,9 @@ def test_send_p2wpkh_in_p2sh_change(self):
)
tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2)

# precomputed tx weight is 670
fee_rate = 11000 / (670 / 4)

messages = [
None,

Expand All @@ -229,7 +235,7 @@ def test_send_p2wpkh_in_p2sh_change(self):
helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False),
True,

helpers.UiConfirmTotal(12300000 + 11000, 11000, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(12300000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN),
True,

# check prev tx
Expand Down
5 changes: 4 additions & 1 deletion core/tests/test_apps.bitcoin.signtx.fee_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def test_under_threshold(self):
address_n=[])
tx = SignTx(coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1)

# precomputed tx weight is 768
fee_rate = 90000 / (768 / 4)

messages = [
None,

Expand All @@ -145,7 +148,7 @@ def test_under_threshold(self):
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN),
True,
helpers.UiConfirmTotal(300000 + 90000, 90000, coin_bitcoin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(300000 + 90000, 90000, fee_rate, coin_bitcoin, AmountUnit.BITCOIN),
True,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
Expand Down
5 changes: 4 additions & 1 deletion core/tests/test_apps.bitcoin.signtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def test_one_one_fee(self):
coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1
)

# precomputed tx weight is 768
fee_rate = 50_000 / (768 / 4)

messages = [
None,
TxRequest(
Expand All @@ -110,7 +113,7 @@ def test_one_one_fee(self):
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN),
True,
helpers.UiConfirmTotal(3_801_747, 50_000, coin_bitcoin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(3_801_747, 50_000, fee_rate, coin_bitcoin, AmountUnit.BITCOIN),
True,
# ButtonRequest(code=ButtonRequest_ConfirmOutput),
# ButtonRequest(code=ButtonRequest_SignTx),
Expand Down
10 changes: 8 additions & 2 deletions core/tests/test_apps.bitcoin.signtx_decred.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ def test_one_one_fee(self):
outputs_count=1,
)

# precomputed tx weight is 768
fee_rate = 100_000 / (768 / 4)

messages = [
None,
TxRequest(
Expand All @@ -109,7 +112,7 @@ def test_one_one_fee(self):
helpers.UiConfirmOutput(out1, coin_decred, AmountUnit.BITCOIN),
True,
helpers.UiConfirmTotal(
200_000_000, 100_000, coin_decred, AmountUnit.BITCOIN
200_000_000, 100_000, fee_rate, coin_decred, AmountUnit.BITCOIN
),
True,
TxRequest(
Expand Down Expand Up @@ -243,6 +246,9 @@ def test_purchase_ticket(self):
decred_staking_ticket=True,
)

# precomputed tx weight is 1076
fee_rate = 100_000 / (1076 / 4)

messages = [
None,
TxRequest(
Expand Down Expand Up @@ -288,7 +294,7 @@ def test_purchase_ticket(self):
),
TxAckOutput(tx=TxAckOutputWrapper(output=out3)),
helpers.UiConfirmTotal(
200_000_000, 100_000, coin_decred, AmountUnit.BITCOIN
200_000_000, 100_000, fee_rate, coin_decred, AmountUnit.BITCOIN
),
True,
TxRequest(
Expand Down
5 changes: 4 additions & 1 deletion core/tests/test_apps.bitcoin.signtx_grs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ def test_one_one_fee(self):
address_n=[])
tx = SignTx(coin_name='Groestlcoin', version=1, lock_time=0, inputs_count=1, outputs_count=1)

# precomputed tx weight is 768
fee_rate = 192 / (768 / 4)

messages = [
None,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
Expand All @@ -69,7 +72,7 @@ def test_one_one_fee(self):
TxAckOutput(tx=TxAckOutputWrapper(output=out1)),
helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN),
True,
helpers.UiConfirmTotal(210016, 192, coin, AmountUnit.BITCOIN),
helpers.UiConfirmTotal(210016, 192, fee_rate, coin, AmountUnit.BITCOIN),
True,
TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED),
TxAckInput(tx=TxAckInputWrapper(input=inp1)),
Expand Down

0 comments on commit a1d2289

Please sign in to comment.