Ragger domain names tests

This commit is contained in:
Alexandre Paillier
2023-03-03 15:00:52 +01:00
parent c2eae8a7a2
commit f3d05f839b
29 changed files with 139 additions and 0 deletions

View File

@@ -19,6 +19,16 @@ ROOT_SCREENSHOT_PATH = Path(__file__).parent.parent
WEI_IN_ETH = 1e+18
class StatusWord(IntEnum):
OK = 0x9000
ERROR_NO_INFO = 0x6a00
INVALID_DATA = 0x6a80
INSUFFICIENT_MEMORY = 0x6a84
INVALID_INS = 0x6d00
INVALID_P1_P2 = 0x6b00
CONDITION_NOT_SATISFIED = 0x6985
REF_DATA_NOT_FOUND = 0x6a88
class DOMAIN_NAME_TAG(IntEnum):
STRUCTURE_TYPE = 0x01
STRUCTURE_VERSION = 0x02

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 588 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 436 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 B

View File

@@ -0,0 +1,128 @@
import pytest
from ragger.error import ExceptionRAPDU
from app.client import EthereumClient, StatusWord
from app.setting import SettingType
import struct
# Values used across all tests
CHAIN_ID = 1
NAME = "ledger.eth"
ADDR = bytes.fromhex("0011223344556677889900112233445566778899")
KEY_ID = 1
ALGO_ID = 1
BIP32_PATH = "m/44'/60'/0'/0/0"
NONCE = 21
GAS_PRICE = 13000000000
GAS_LIMIT = 21000
AMOUNT = 1.22
@pytest.fixture(params=[False, True])
def verbose(request) -> bool:
return request.param
def common(app_client: EthereumClient) -> int:
if app_client._client.firmware.device == "nanos":
pytest.skip("Not supported on LNS")
return app_client.get_challenge()
def test_send_fund(app_client: EthereumClient, verbose: bool):
challenge = common(app_client)
if verbose:
app_client.settings_set({
SettingType.VERBOSE_ENS: True
})
app_client.provide_domain_name(challenge, NAME, ADDR)
app_client.send_fund(BIP32_PATH,
NONCE,
GAS_PRICE,
GAS_LIMIT,
ADDR,
AMOUNT,
CHAIN_ID,
"domain_name_verbose_" + str(verbose))
def test_send_fund_wrong_challenge(app_client: EthereumClient):
caught = False
challenge = common(app_client)
try:
app_client.provide_domain_name(~challenge & 0xffffffff, NAME, ADDR)
except ExceptionRAPDU as e:
assert e.status == StatusWord.INVALID_DATA
else:
assert False # An exception should have been raised
def test_send_fund_wrong_addr(app_client: EthereumClient):
challenge = common(app_client)
app_client.provide_domain_name(challenge, NAME, ADDR)
addr = bytearray(ADDR)
addr.reverse()
app_client.send_fund(BIP32_PATH,
NONCE,
GAS_PRICE,
GAS_LIMIT,
addr,
AMOUNT,
CHAIN_ID,
"domain_name_wrong_addr")
def test_send_fund_non_mainnet(app_client: EthereumClient):
challenge = common(app_client)
app_client.provide_domain_name(challenge, NAME, ADDR)
app_client.send_fund(BIP32_PATH,
NONCE,
GAS_PRICE,
GAS_LIMIT,
ADDR,
AMOUNT,
5,
"domain_name_non_mainnet")
def test_send_fund_domain_too_long(app_client: EthereumClient):
challenge = common(app_client)
try:
app_client.provide_domain_name(challenge, "ledger" + "0"*25 + ".eth", ADDR)
except ExceptionRAPDU as e:
assert e.status == StatusWord.INVALID_DATA
else:
assert False # An exception should have been raised
def test_send_fund_domain_invalid_character(app_client: EthereumClient):
challenge = common(app_client)
try:
app_client.provide_domain_name(challenge, "l\xe8dger.eth", ADDR)
except ExceptionRAPDU as e:
assert e.status == StatusWord.INVALID_DATA
else:
assert False # An exception should have been raised
def test_send_fund_uppercase(app_client: EthereumClient):
challenge = common(app_client)
try:
app_client.provide_domain_name(challenge, NAME.upper(), ADDR)
except ExceptionRAPDU as e:
assert e.status == StatusWord.INVALID_DATA
else:
assert False # An exception should have been raised
def test_send_fund_domain_non_ens(app_client: EthereumClient):
challenge = common(app_client)
try:
app_client.provide_domain_name(challenge, "ledger.hte", ADDR)
except ExceptionRAPDU as e:
assert e.status == StatusWord.INVALID_DATA
else:
assert False # An exception should have been raised