Skip to content

Commit

Permalink
Merge pull request #161 from LedgerHQ/fbe/ethereum_tests
Browse files Browse the repository at this point in the history
Use ETH client to write exchange tests for the test runner
  • Loading branch information
fbeutin-ledger authored Dec 5, 2023
2 parents 80acb0c + be486b3 commit 644ad2a
Show file tree
Hide file tree
Showing 829 changed files with 119 additions and 694 deletions.
87 changes: 0 additions & 87 deletions test/python/apps/bsc.py

This file was deleted.

10 changes: 6 additions & 4 deletions test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

from .signing_authority import SigningAuthority, LEDGER_SIGNER

# Eth family
from .ethereum import ETH_PACKED_DERIVATION_PATH, ETH_CONF
from .ethereum_classic import ETC_PACKED_DERIVATION_PATH, ETC_CONF
from .ethereum import ETC_PACKED_DERIVATION_PATH, ETC_CONF
from .ethereum import BSC_PACKED_DERIVATION_PATH, BSC_CONF

from .litecoin import LTC_PACKED_DERIVATION_PATH, LTC_CONF
from .bitcoin import BTC_PACKED_DERIVATION_PATH, BTC_CONF
from .stellar import XLM_PACKED_DERIVATION_PATH, XLM_CONF
from .solana_utils import SOL_PACKED_DERIVATION_PATH, SOL_CONF
from .xrp import XRP_PACKED_DERIVATION_PATH, XRP_CONF
from .tezos import XTZ_PACKED_DERIVATION_PATH, XTZ_CONF
from .bsc import BSC_PACKED_DERIVATION_PATH, BSC_CONF
from .polkadot import DOT_PACKED_DERIVATION_PATH, DOT_CONF
from .tron import TRX_PACKED_DERIVATION_PATH, TRX_CONF
from .tron import TRX_USDT_CONF, TRX_USDC_CONF, TRX_TUSD_CONF, TRX_USDD_CONF
Expand All @@ -26,7 +28,7 @@
"SOL": SOL_CONF,
"XRP": XRP_CONF,
"XTZ": XTZ_CONF,
"BSC": BSC_CONF,
"BNB": BSC_CONF,
"DOT": DOT_CONF,
"TRX": TRX_CONF,
"USDT": TRX_USDT_CONF,
Expand All @@ -44,7 +46,7 @@
"SOL": SOL_PACKED_DERIVATION_PATH,
"XRP": XRP_PACKED_DERIVATION_PATH,
"XTZ": XTZ_PACKED_DERIVATION_PATH,
"BSC": BSC_PACKED_DERIVATION_PATH,
"BNB": BSC_PACKED_DERIVATION_PATH,
"DOT": DOT_PACKED_DERIVATION_PATH,
"TRX": TRX_PACKED_DERIVATION_PATH,
"USDT": TRX_PACKED_DERIVATION_PATH,
Expand Down
90 changes: 8 additions & 82 deletions test/python/apps/ethereum.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,16 @@
from ragger.utils import pack_APDU, RAPDU
from ragger.error import ExceptionRAPDU

from ragger.utils import create_currency_config
from ragger.bip import pack_derivation_path

ETH_CONF = create_currency_config("ETH", "Ethereum", ("ETH", 18))

ETH_PACKED_DERIVATION_PATH = pack_derivation_path("m/44'/60'/0'/0/0")


class Command:
GET_PUBLIC_KEY = 0x02
SIGN = 0x04
GET_APP_CONFIGURATION = 0x06
SIGN_PERSONAL_MESSAGE = 0x08
PROVIDE_ERC20_TOKEN_INFORMATION = 0x0A
SIGN_EIP_712_MESSAGE = 0x0C
GET_ETH2_PUBLIC_KEY = 0x0E
SET_ETH2_WITHDRAWAL_INDEX = 0x10
SET_EXTERNAL_PLUGIN = 0x12
PROVIDE_NFT_INFORMATION = 0x14
SET_PLUGIN = 0x16
PERFORM_PRIVACY_OPERATION = 0x18


class P1:
NON_CONFIRM = 0x00
FIRST = 0x00
CONFIRM = 0x01
MORE = 0x80


class P2:
NO_CHAINCODE = 0x00
CHAINCODE = 0x01

ETH_PATH = "m/44'/60'/0'/0/0"

class TxType:
MIN = 0x00
EIP2930 = 0x01
EIP1559 = 0x02
LEGACY = 0xc0
MAX = 0x7f


ERR_SILENT_MODE_CHECK_FAILED = ExceptionRAPDU(0x6001, "ERR_SILENT_MODE_CHECK_FAILED")


class EthereumClient:
CLA = 0xE0
def __init__(self, client, derivation_path=b''):
self._client = client
self._derivation_path = derivation_path or ETH_PACKED_DERIVATION_PATH

@property
def client(self):
return self._client

@property
def derivation_path(self):
return self._derivation_path

def _forge_signature_payload(self, additional_payload: bytes):
return pack_APDU(self.CLA, Command.SIGN, data=(self.derivation_path + additional_payload))

def _exchange(self,
ins: int,
p1: int = P1.NON_CONFIRM,
p2: int = P2.NO_CHAINCODE,
payload: bytes = b''):
return self.client.exchange(self.CLA, ins=ins, p1=p1, p2=p2, data=payload)

def get_public_key(self):
return self._exchange(Command.GET_PUBLIC_KEY, payload=self.derivation_path)
ETH_CONF = create_currency_config("ETH", "Ethereum", ("ETH", 18))
ETH_PACKED_DERIVATION_PATH = pack_derivation_path(ETH_PATH)

def sign(self, extra_payload: bytes = bytes.fromhex('eb')):
# TODO: finish ETH signature with proper payload
payload = self.derivation_path + extra_payload
return self._exchange(Command.SIGN, payload=payload)

BSC_CONF = create_currency_config("BNB", "Binance Smart Chain", ("BNB", 18))
BSC_PACKED_DERIVATION_PATH = pack_derivation_path(ETH_PATH)

def eth_amount_to_wei(eth_amount: int) -> int:
return round(eth_amount * 10**18)
ETC_PATH = "m/44'/60'/0'/0/0"

def eth_amount_to_wei_hex_string(eth_amount: int) -> str:
hex = '{:x}'.format(eth_amount_to_wei(eth_amount))
if (len(hex) % 2 != 0):
hex = "0" + hex
return hex
ETC_CONF = create_currency_config("ETC", "Ethereum Classic", ("ETC", 18))
ETC_PACKED_DERIVATION_PATH = pack_derivation_path("m/44'/61'/0'/0/0")
6 changes: 0 additions & 6 deletions test/python/apps/ethereum_classic.py

This file was deleted.

6 changes: 4 additions & 2 deletions test/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
ragger[tests,speculos] >= 1.9.2
protobuf==3.20.0
protobuf
stellar_sdk
base58
xrpl-py
scalecodec
bip32
bip32
embit
--extra-index-url https://test.pypi.org/simple/
ledger_app_clients.ethereum
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Diff not rendered.
Diff not rendered.
Diff not rendered.
Loading

0 comments on commit 644ad2a

Please sign in to comment.