Port 'test_eip2930' from 'speculos' to 'ragger'

This commit is contained in:
Charles-Edouard de la Vergne
2024-03-28 16:20:09 +01:00
parent 8d0f798ec0
commit 7a608c49df
24 changed files with 63 additions and 72 deletions

View File

Before

Width:  |  Height:  |  Size: 374 B

After

Width:  |  Height:  |  Size: 374 B

View File

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

View File

Before

Width:  |  Height:  |  Size: 489 B

After

Width:  |  Height:  |  Size: 489 B

View File

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 494 B

View File

Before

Width:  |  Height:  |  Size: 391 B

After

Width:  |  Height:  |  Size: 391 B

View File

Before

Width:  |  Height:  |  Size: 351 B

After

Width:  |  Height:  |  Size: 351 B

View File

Before

Width:  |  Height:  |  Size: 355 B

After

Width:  |  Height:  |  Size: 355 B

View File

Before

Width:  |  Height:  |  Size: 414 B

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

View File

@@ -0,0 +1 @@
../nanox/test_sign_eip_2930

View File

Before

Width:  |  Height:  |  Size: 414 B

After

Width:  |  Height:  |  Size: 414 B

View File

Before

Width:  |  Height:  |  Size: 370 B

After

Width:  |  Height:  |  Size: 370 B

View File

Before

Width:  |  Height:  |  Size: 766 B

After

Width:  |  Height:  |  Size: 766 B

View File

Before

Width:  |  Height:  |  Size: 409 B

After

Width:  |  Height:  |  Size: 409 B

View File

Before

Width:  |  Height:  |  Size: 416 B

After

Width:  |  Height:  |  Size: 416 B

View File

Before

Width:  |  Height:  |  Size: 472 B

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@@ -0,0 +1,62 @@
from web3 import Web3
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 ragger.backend import BackendInterface
from ragger.firmware import Firmware
from ragger.navigator import Navigator, NavInsID
from constants import ROOT_SNAPSHOT_PATH
BIP32_PATH = "m/44'/60'/0'/0/0"
NONCE = 21
GAS_PRICE = 5
GAS_LIMIT = 21000
ADDR = bytes.fromhex("b2bb2b958afa2e96dab3f3ce7162b87daea39017")
AMOUNT = 0.01
CHAIN_ID = 3
def test_sign_eip_2930(firmware: Firmware,
backend: BackendInterface,
navigator: Navigator,
test_name: str):
tx_params = {
"nonce": NONCE,
"gasPrice": Web3.to_wei(GAS_PRICE, "gwei"),
"gas": GAS_LIMIT,
"to": ADDR,
"value": Web3.to_wei(AMOUNT, "ether"),
"chainId": CHAIN_ID,
}
app_client = EthAppClient(backend)
with app_client.get_public_addr(bip32_path=BIP32_PATH, display=False):
pass
_, DEVICE_ADDR, _ = ResponseParser.pk_addr(app_client.response().data)
with app_client.sign(BIP32_PATH, tx_params):
if firmware.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"
navigator.navigate_until_text_and_compare(next_action,
[confirm_action],
end_text,
ROOT_SNAPSHOT_PATH,
test_name)
# verify signature
vrs = ResponseParser.signature(app_client.response().data)
addr = recover_transaction(tx_params, vrs)
assert addr == DEVICE_ADDR

View File

@@ -1,72 +0,0 @@
from time import sleep
from ethereum_client.utils import compare_screenshot, save_screenshot, PATH_IMG, parse_sign_response
def test_sign_eip_2930(cmd):
result: list = []
apdu_sign_eip_2930 = bytes.fromhex("e004000096058000002c8000003c80000000000000000000000001f886030685012a05f20082520894b2bb2b958afa2e96dab3f3ce7162b87daea39017872386f26fc1000080f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007")
with cmd.send_apdu_context(apdu_sign_eip_2930, result) as ex:
sleep(0.5)
if cmd.model == "nanos":
# Review transaction
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00000.png")
cmd.client.press_and_release('right')
# Amount
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00001.png")
cmd.client.press_and_release('right')
# Address 1/3, 2/3, 3/3
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00002.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00003.png")
cmd.client.press_and_release('right')
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00004.png")
cmd.client.press_and_release('right')
# Network
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00005.png")
cmd.client.press_and_release('right')
# Max Fees
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00006.png")
cmd.client.press_and_release('right')
# Accept and send
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00007.png")
cmd.client.press_and_release('both')
if cmd.model == "nanox" or cmd.model == "nanosp":
# Review transaction
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00000.png")
cmd.client.press_and_release('right')
# Amount
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00001.png")
cmd.client.press_and_release('right')
# Address
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00002.png")
cmd.client.press_and_release('right')
# Network
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00003.png")
cmd.client.press_and_release('right')
# Max Fees
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00004.png")
cmd.client.press_and_release('right')
# Accept and send
compare_screenshot(cmd, f"screenshots/eip2930/{PATH_IMG[cmd.model]}/sign_eip_2930/00005.png")
cmd.client.press_and_release('both')
response: bytes = result[0]
v, r, s = parse_sign_response(response)
assert v == 0x01
assert r.hex() == "a74d82400f49d1f9d85f734c22a1648d4ab74bb6367bef54c6abb0936be3d8b7"
assert s.hex() == "7a84a09673394c3c1bd76be05620ee17a2d0ff32837607625efa433cc017854e"