Use sync or async exchange calls in ethereum client
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import json
|
||||
import pytest
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ledger_app_clients.ethereum.client import EthAppClient
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
from web3 import Web3
|
||||
from constants import ROOT_SNAPSHOT_PATH, ABIS_FOLDER
|
||||
|
||||
@@ -35,13 +36,10 @@ def test_blind_sign(firmware: Firmware,
|
||||
"data": data,
|
||||
"chainId": 1
|
||||
}
|
||||
try:
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
with app_client.sign("m/44'/60'/0'/0/0", tx_params):
|
||||
pass
|
||||
except ExceptionRAPDU:
|
||||
pass
|
||||
else:
|
||||
assert False
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
moves = list()
|
||||
if firmware.device.startswith("nano"):
|
||||
|
||||
@@ -33,9 +33,8 @@ def verbose(request) -> bool:
|
||||
def common(app_client: EthAppClient) -> int:
|
||||
if app_client._client.firmware.device == "nanos":
|
||||
pytest.skip("Not supported on LNS")
|
||||
with app_client.get_challenge():
|
||||
pass
|
||||
return ResponseParser.challenge(app_client.response().data)
|
||||
challenge = app_client.get_challenge()
|
||||
return ResponseParser.challenge(challenge.data)
|
||||
|
||||
|
||||
def test_send_fund(firmware: Firmware,
|
||||
@@ -49,8 +48,7 @@ def test_send_fund(firmware: Firmware,
|
||||
if verbose:
|
||||
settings_toggle(firmware, navigator, [SettingID.VERBOSE_ENS])
|
||||
|
||||
with app_client.provide_domain_name(challenge, NAME, ADDR):
|
||||
pass
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
with app_client.sign(BIP32_PATH,
|
||||
{
|
||||
@@ -83,13 +81,9 @@ def test_send_fund_wrong_challenge(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
try:
|
||||
with app_client.provide_domain_name(~challenge & 0xffffffff, NAME, ADDR):
|
||||
pass
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.INVALID_DATA
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(~challenge & 0xffffffff, NAME, ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_wrong_addr(firmware: Firmware,
|
||||
@@ -99,8 +93,7 @@ def test_send_fund_wrong_addr(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
with app_client.provide_domain_name(challenge, NAME, ADDR):
|
||||
pass
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
addr = bytearray(ADDR)
|
||||
addr.reverse()
|
||||
@@ -133,8 +126,7 @@ def test_send_fund_non_mainnet(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
with app_client.provide_domain_name(challenge, NAME, ADDR):
|
||||
pass
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
with app_client.sign(BIP32_PATH,
|
||||
{
|
||||
@@ -164,8 +156,7 @@ def test_send_fund_unknown_chain(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
with app_client.provide_domain_name(challenge, NAME, ADDR):
|
||||
pass
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
with app_client.sign(BIP32_PATH,
|
||||
{
|
||||
@@ -194,13 +185,9 @@ def test_send_fund_domain_too_long(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
try:
|
||||
with app_client.provide_domain_name(challenge, "ledger" + "0"*25 + ".eth", ADDR):
|
||||
pass
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.INVALID_DATA
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "ledger" + "0"*25 + ".eth", ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_domain_invalid_character(firmware: Firmware,
|
||||
@@ -209,13 +196,9 @@ def test_send_fund_domain_invalid_character(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
try:
|
||||
with app_client.provide_domain_name(challenge, "l\xe8dger.eth", ADDR):
|
||||
pass
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.INVALID_DATA
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "l\xe8dger.eth", ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_uppercase(firmware: Firmware,
|
||||
@@ -224,13 +207,9 @@ def test_send_fund_uppercase(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
try:
|
||||
with app_client.provide_domain_name(challenge, NAME.upper(), ADDR):
|
||||
pass
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.INVALID_DATA
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, NAME.upper(), ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_domain_non_ens(firmware: Firmware,
|
||||
@@ -239,10 +218,6 @@ def test_send_fund_domain_non_ens(firmware: Firmware,
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
|
||||
try:
|
||||
with app_client.provide_domain_name(challenge, "ledger.hte", ADDR):
|
||||
pass
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.INVALID_DATA
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "ledger.hte", ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
@@ -204,19 +204,15 @@ def test_eip712_address_substitution(firmware: Firmware,
|
||||
with open("%s/address_substitution.json" % (eip712_json_path())) as file:
|
||||
data = json.load(file)
|
||||
|
||||
with app_client.provide_token_metadata("DAI",
|
||||
bytes.fromhex(data["message"]["token"][2:]),
|
||||
18,
|
||||
1):
|
||||
pass
|
||||
app_client.provide_token_metadata("DAI",
|
||||
bytes.fromhex(data["message"]["token"][2:]),
|
||||
18,
|
||||
1)
|
||||
|
||||
with app_client.get_challenge():
|
||||
pass
|
||||
challenge = ResponseParser.challenge(app_client.response().data)
|
||||
with app_client.provide_domain_name(challenge,
|
||||
"vitalik.eth",
|
||||
bytes.fromhex(data["message"]["to"][2:])):
|
||||
pass
|
||||
challenge = ResponseParser.challenge(app_client.get_challenge().data)
|
||||
app_client.provide_domain_name(challenge,
|
||||
"vitalik.eth",
|
||||
bytes.fromhex(data["message"]["to"][2:]))
|
||||
|
||||
if verbose:
|
||||
settings_toggle(firmware, navigator, [SettingID.VERBOSE_EIP712])
|
||||
|
||||
@@ -52,15 +52,12 @@ def test_get_pk_rejected(firmware: Firmware,
|
||||
navigator: Navigator):
|
||||
app_client = EthAppClient(backend)
|
||||
|
||||
try:
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
with app_client.get_public_addr():
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
"get_pk_rejected",
|
||||
get_moves(firmware, navigator, reject=True))
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
|
||||
|
||||
def test_get_pk(firmware: Firmware,
|
||||
|
||||
@@ -96,13 +96,11 @@ def common_test_nft(fw: Firmware,
|
||||
_, DEVICE_ADDR, _ = ResponseParser.pk_addr(app_client.response().data)
|
||||
|
||||
data = collec.contract.encodeABI(action.fn_name, action.fn_args)
|
||||
with app_client.set_plugin(plugin_name,
|
||||
collec.addr,
|
||||
get_selector_from_data(data),
|
||||
collec.chain_id):
|
||||
pass
|
||||
with app_client.provide_nft_metadata(collec.name, collec.addr, collec.chain_id):
|
||||
pass
|
||||
app_client.set_plugin(plugin_name,
|
||||
collec.addr,
|
||||
get_selector_from_data(data),
|
||||
collec.chain_id)
|
||||
app_client.provide_nft_metadata(collec.name, collec.addr, collec.chain_id)
|
||||
tx_params = {
|
||||
"nonce": NONCE,
|
||||
"gasPrice": Web3.to_wei(GAS_PRICE, "gwei"),
|
||||
@@ -133,12 +131,9 @@ def common_test_nft_reject(test_fn: Callable,
|
||||
nav: Navigator,
|
||||
collec: NFTCollection,
|
||||
action: Action):
|
||||
try:
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
test_fn(fw, back, nav, collec, action, True)
|
||||
except ExceptionRAPDU as e:
|
||||
assert e.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
else:
|
||||
assert False # An exception should have been raised
|
||||
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
|
||||
# ERC-721
|
||||
|
||||
|
||||
Reference in New Issue
Block a user