Skip to content

Commit 5715827

Browse files
New basic signature (+ verification) ragger tests
1 parent 72e2694 commit 5715827

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/ragger/test_sign.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from ragger.backend import BackendInterface
2+
from ragger.firmware import Firmware
3+
from ragger.navigator import Navigator, NavInsID
4+
from ledger_app_clients.ethereum.client import EthAppClient
5+
import ledger_app_clients.ethereum.response_parser as ResponseParser
6+
from ledger_app_clients.ethereum.utils import recover_transaction
7+
from web3 import Web3
8+
9+
10+
# Values used across all tests
11+
CHAIN_ID = 1
12+
ADDR = bytes.fromhex("0011223344556677889900112233445566778899")
13+
BIP32_PATH = "m/44'/60'/0'/0/0"
14+
NONCE = 21
15+
GAS_PRICE = 13
16+
GAS_LIMIT = 21000
17+
AMOUNT = 1.22
18+
19+
20+
def common(fw: Firmware,
21+
back: BackendInterface,
22+
nav: Navigator,
23+
tx_params: dict):
24+
app_client = EthAppClient(back)
25+
26+
with app_client.get_public_addr(display=False):
27+
pass
28+
_, DEVICE_ADDR, _ = ResponseParser.pk_addr(app_client.response().data)
29+
30+
with app_client.sign(BIP32_PATH, tx_params):
31+
if fw.device.startswith("nano"):
32+
next_action = NavInsID.RIGHT_CLICK
33+
confirm_action = NavInsID.BOTH_CLICK
34+
end_text = "Accept"
35+
else:
36+
next_action = NavInsID.USE_CASE_REVIEW_TAP
37+
confirm_action = NavInsID.USE_CASE_REVIEW_CONFIRM
38+
end_text = "Sign"
39+
nav.navigate_until_text(next_action, [confirm_action], end_text)
40+
41+
# verify signature
42+
vrs = ResponseParser.signature(app_client.response().data)
43+
addr = recover_transaction(tx_params, vrs)
44+
assert addr == DEVICE_ADDR
45+
46+
47+
def test_legacy(firmware: Firmware, backend: BackendInterface, navigator: Navigator):
48+
common(firmware, backend, navigator, {
49+
"nonce": NONCE,
50+
"gasPrice": Web3.to_wei(GAS_PRICE, "gwei"),
51+
"gas": GAS_LIMIT,
52+
"to": ADDR,
53+
"value": Web3.to_wei(AMOUNT, "ether"),
54+
"chainId": CHAIN_ID
55+
})
56+
57+
58+
def test_1559(firmware: Firmware, backend: BackendInterface, navigator: Navigator):
59+
common(firmware, backend, navigator, {
60+
"nonce": NONCE,
61+
"maxFeePerGas": Web3.to_wei(145, "gwei"),
62+
"maxPriorityFeePerGas": Web3.to_wei(1.5, "gwei"),
63+
"gas": GAS_LIMIT,
64+
"to": ADDR,
65+
"value": Web3.to_wei(AMOUNT, "ether"),
66+
"chainId": CHAIN_ID
67+
})

0 commit comments

Comments
 (0)