New basic signature (+ verification) ragger tests

This commit is contained in:
Alexandre Paillier
2024-03-08 17:39:18 +01:00
parent 72e26947c3
commit 5715827add

67
tests/ragger/test_sign.py Normal file
View File

@@ -0,0 +1,67 @@
from ragger.backend import BackendInterface
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID
from ledger_app_clients.ethereum.client import EthAppClient
import ledger_app_clients.ethereum.response_parser as ResponseParser
from ledger_app_clients.ethereum.utils import recover_transaction
from web3 import Web3
# Values used across all tests
CHAIN_ID = 1
ADDR = bytes.fromhex("0011223344556677889900112233445566778899")
BIP32_PATH = "m/44'/60'/0'/0/0"
NONCE = 21
GAS_PRICE = 13
GAS_LIMIT = 21000
AMOUNT = 1.22
def common(fw: Firmware,
back: BackendInterface,
nav: Navigator,
tx_params: dict):
app_client = EthAppClient(back)
with app_client.get_public_addr(display=False):
pass
_, DEVICE_ADDR, _ = ResponseParser.pk_addr(app_client.response().data)
with app_client.sign(BIP32_PATH, tx_params):
if fw.device.startswith("nano"):
next_action = NavInsID.RIGHT_CLICK
confirm_action = NavInsID.BOTH_CLICK
end_text = "Accept"
else:
next_action = NavInsID.USE_CASE_REVIEW_TAP
confirm_action = NavInsID.USE_CASE_REVIEW_CONFIRM
end_text = "Sign"
nav.navigate_until_text(next_action, [confirm_action], end_text)
# verify signature
vrs = ResponseParser.signature(app_client.response().data)
addr = recover_transaction(tx_params, vrs)
assert addr == DEVICE_ADDR
def test_legacy(firmware: Firmware, backend: BackendInterface, navigator: Navigator):
common(firmware, backend, navigator, {
"nonce": NONCE,
"gasPrice": Web3.to_wei(GAS_PRICE, "gwei"),
"gas": GAS_LIMIT,
"to": ADDR,
"value": Web3.to_wei(AMOUNT, "ether"),
"chainId": CHAIN_ID
})
def test_1559(firmware: Firmware, backend: BackendInterface, navigator: Navigator):
common(firmware, backend, navigator, {
"nonce": NONCE,
"maxFeePerGas": Web3.to_wei(145, "gwei"),
"maxPriorityFeePerGas": Web3.to_wei(1.5, "gwei"),
"gas": GAS_LIMIT,
"to": ADDR,
"value": Web3.to_wei(AMOUNT, "ether"),
"chainId": CHAIN_ID
})