Ragger domain names tests
@@ -19,6 +19,16 @@ ROOT_SCREENSHOT_PATH = Path(__file__).parent.parent
|
|||||||
WEI_IN_ETH = 1e+18
|
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):
|
class DOMAIN_NAME_TAG(IntEnum):
|
||||||
STRUCTURE_TYPE = 0x01
|
STRUCTURE_TYPE = 0x01
|
||||||
STRUCTURE_VERSION = 0x02
|
STRUCTURE_VERSION = 0x02
|
||||||
|
|||||||
1
tests/ragger/snapshots/nanosp
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
nanox/
|
||||||
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00000.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00001.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00002.png
Normal file
|
After Width: | Height: | Size: 585 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00003.png
Normal file
|
After Width: | Height: | Size: 383 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00004.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00005.png
Normal file
|
After Width: | Height: | Size: 472 B |
BIN
tests/ragger/snapshots/nanox/domain_name_non_mainnet/00006.png
Normal file
|
After Width: | Height: | Size: 382 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00000.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00001.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00002.png
Normal file
|
After Width: | Height: | Size: 394 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00003.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00004.png
Normal file
|
After Width: | Height: | Size: 472 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_False/00005.png
Normal file
|
After Width: | Height: | Size: 382 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00000.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00001.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00002.png
Normal file
|
After Width: | Height: | Size: 394 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00003.png
Normal file
|
After Width: | Height: | Size: 585 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00004.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00005.png
Normal file
|
After Width: | Height: | Size: 472 B |
BIN
tests/ragger/snapshots/nanox/domain_name_verbose_True/00006.png
Normal file
|
After Width: | Height: | Size: 382 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00000.png
Normal file
|
After Width: | Height: | Size: 414 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00001.png
Normal file
|
After Width: | Height: | Size: 368 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00002.png
Normal file
|
After Width: | Height: | Size: 588 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00003.png
Normal file
|
After Width: | Height: | Size: 436 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00004.png
Normal file
|
After Width: | Height: | Size: 472 B |
BIN
tests/ragger/snapshots/nanox/domain_name_wrong_addr/00005.png
Normal file
|
After Width: | Height: | Size: 382 B |
128
tests/ragger/test_domain_name.py
Normal 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
|
||||||