Skip to content

Commit

Permalink
Merge pull request #254 from LedgerHQ/fbe/integrate_zondax_cosmos_swa…
Browse files Browse the repository at this point in the history
…p_tests

Fbe/integrate zondax cosmos swap tests
  • Loading branch information
fbeutin-ledger authored Feb 3, 2025
2 parents 351bb59 + 80e164c commit b9afc71
Show file tree
Hide file tree
Showing 465 changed files with 160 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .github/workflows/reusable_swap_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ on:
default: 'LedgerHQ/app-cardano'
type: string

branch_for_cosmos:
required: false
default: 'develop'
type: string
repo_for_cosmos:
required: false
default: 'LedgerHQ/app-cosmos'
type: string

test_filter:
required: false
default: '""'
Expand Down Expand Up @@ -189,6 +198,9 @@ jobs:
- name: near
repo: ${{ inputs.repo_for_near }}
branch: ${{ inputs.branch_for_near }}
- name: ATOM
repo: ${{ inputs.repo_for_cosmos }}
branch: ${{ inputs.branch_for_cosmos }}

uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
Expand Down
3 changes: 2 additions & 1 deletion test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .ton import TON_PACKED_DERIVATION_PATH, TON_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
from .cosmos import COSMOS_PACKED_DERIVATION_PATH, COSMOS_CONF
from .cardano import ADA_BYRON_PACKED_DERIVATION_PATH, ADA_SHELLEY_PACKED_DERIVATION_PATH, ADA_CONF
from .near import NEAR_PACKED_DERIVATION_PATH, NEAR_CONF

Expand Down Expand Up @@ -60,11 +61,11 @@ def get_conf_for_ticker(self, overload_signer: Optional[SigningAuthority]=None)
USDC_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDC", conf=TRX_USDC_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
TUSD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="TUSD", conf=TRX_TUSD_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
USDD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDD", conf=TRX_USDD_CONF, packed_derivation_path=TRX_PACKED_DERIVATION_PATH)
COSMOS_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ATOM", conf=COSMOS_CONF, packed_derivation_path=COSMOS_PACKED_DERIVATION_PATH)
ADA_BYRON_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ADA", conf=ADA_CONF, packed_derivation_path=ADA_BYRON_PACKED_DERIVATION_PATH)
ADA_SHELLEY_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="ADA", conf=ADA_CONF, packed_derivation_path=ADA_SHELLEY_PACKED_DERIVATION_PATH)
NEAR_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="NEAR", conf=NEAR_CONF, packed_derivation_path=NEAR_PACKED_DERIVATION_PATH)


# Helper that can be called from outside if we want to generate errors easily
def sign_currency_conf(currency_conf: bytes, overload_signer: Optional[SigningAuthority]=None) -> bytes:
if overload_signer is not None:
Expand Down
108 changes: 108 additions & 0 deletions test/python/apps/cosmos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import traceback
import requests
import json
from enum import IntEnum

from nacl.encoding import HexEncoder
from nacl.signing import VerifyKey,SigningKey
from nacl.exceptions import BadSignatureError

from ragger.bip import pack_derivation_path
from ragger.error import ExceptionRAPDU
from scalecodec.base import RuntimeConfiguration
from scalecodec.type_registry import load_type_registry_preset
from scalecodec.utils.ss58 import ss58_decode

from ecdsa import VerifyingKey, SECP256k1
from ecdsa.util import string_to_number


def get_sub_config(hrp: str) -> bytes:
cfg = bytearray()
cfg.append(len(hrp))
cfg += hrp.encode()
return cfg

def create_currency_config(main_ticker: str,
application_name: str,
sub_config: bytes = bytes()) -> bytes:
cfg = bytearray()
for elem in [main_ticker.encode(), application_name.encode(), sub_config]:
cfg.append(len(elem))
cfg += elem
return cfg

COSMOS_CONF = create_currency_config("ATOM", "Cosmos", get_sub_config("cosmos"))
COSMOS_PACKED_DERIVATION_PATH = pack_derivation_path("m/44'/118'/5'/0'/3")
COSMOS_PACKED_DERIVATION_PATH_SIGN_INIT = bytes([0x2c, 0x00, 0x00, 0x80,
0x76, 0x00, 0x00, 0x80,
0x05, 0x00, 0x00, 0x80,
0x00, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00])
MAX_CHUNK_SIZE = 250

class Errors:
ERR_SWAP_CHECK_WRONG_METHOD = 0x6984
ERR_SWAP_CHECK_WRONG_METHOD_ARGS_CNT = 0x6984
ERR_SWAP_CHECK_WRONG_DEST_ADDR = 0x6984
ERR_SWAP_CHECK_WRONG_AMOUNT = 0x6984
ERR_SWAP_CHECK_WRONG_FEES = 0x6984
ERR_SWAP_CHECK_WRONG_MEMO = 0x6984

class Ins():
GET_PUBLIC_KEY = 0x04
SIGN = 0x02

class GetAddrP1:
NO_CONFIRM = 0x00
CONFIRM = 0x01

class SignP1:
INIT = 0x00
ADD = 0x01
LAST = 0x02

class SignP2:
JSON_MODE = 0x00
TEXTUAL_MODE = 0x01

class CosmosClient:
CLA = 0x55
def __init__(self, client):
self._client = client

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

def get_pubkey(self):
# sizeof(cosmos) + cosmos
data = bytes([0x06,0x63, 0x6f, 0x73, 0x6d, 0x6f, 0x73]) + COSMOS_PACKED_DERIVATION_PATH_SIGN_INIT
msg = self.client.exchange(self.CLA, ins=Ins.GET_PUBLIC_KEY, p1=GetAddrP1.NO_CONFIRM, data=data)
return msg.data[:32].hex().encode()


def perform_cosmos_transaction(self, destination, send_amount, fees, memo) -> bytes:
# Get public key.
key = self.get_pubkey()

#Amounts are in uatom for the app aprser to return ATOM ticker and format
tx = f'''{{"account_number":"0","chain_id":"cosmoshub-4","fee":{{"amount":[{{"amount":"{fees}","denom":"uatom"}}],"gas":"10000"}},"memo":"{memo}","msgs":[{{"inputs":[{{"address":"{destination}","coins":[{{"amount":"{send_amount}","denom":"uatom"}}]}}],"outputs":[{{"address":"{destination}","coins":[{{"amount":"{send_amount}","denom":"uatom"}}]}}]}}],"sequence":"1"}}'''

# Convert the JSON to bytes
tx_blob = tx.encode('utf-8')

# Send the first chunk of the transaction path
chunk_0 = COSMOS_PACKED_DERIVATION_PATH_SIGN_INIT
self.client.exchange(self.CLA, ins=Ins.SIGN, p1=SignP1.INIT, data=chunk_0)

message_splited = [tx_blob[x:x + MAX_CHUNK_SIZE] for x in range(0, len(tx_blob), MAX_CHUNK_SIZE)]
for index, chunk in enumerate(message_splited):
payload_type = SignP1.ADD
if index == len(message_splited) - 1:
payload_type = SignP1.LAST

response = self.client.exchange(self.CLA, ins=Ins.SIGN, p1=payload_type, p2=SignP2.JSON_MODE, data=chunk)

#TODO: Verify signature
return True
1 change: 1 addition & 0 deletions test/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"DOT": "Polkadot",
"tron": "Tron",
"ton": "TON",
"ATOM": "Cosmos",
"cardano": "Cardano ADA",
"near": "NEAR",
}
Expand Down
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.
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

0 comments on commit b9afc71

Please sign in to comment.