Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add polkadot tests #147

Merged
merged 3 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions .github/workflows/reusable_swap_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ on:
required: false
default: 'develop'
type: string
branch_for_polkadot:
required: false
default: 'develop'
type: string
test_filter:
required: false
default: '""'
Expand All @@ -62,33 +66,47 @@ jobs:
- name: stellar
repo: app-stellar
branch: ${{ inputs.branch_for_stellar }}
dir: .
- name: tezos
repo: app-tezos
branch: ${{ inputs.branch_for_tezos }}
dir: .
- name: xrp
repo: app-xrp
branch: ${{ inputs.branch_for_xrp }}
dir: .
- name: ethereum
repo: app-ethereum
branch: ${{ inputs.branch_for_ethereum }}
dir: .
- name: ethereum_classic
repo: app-ethereum
branch: ${{ inputs.branch_for_ethereum_classic }}
dir: .
- name: litecoin
repo: app-bitcoin
branch: ${{ inputs.branch_for_litecoin }}
dir: .
- name: bitcoin_legacy
repo: app-bitcoin
branch: ${{ inputs.branch_for_bitcoin_legacy }}
dir: .
- name: bitcoin
repo: app-bitcoin-new
branch: ${{ inputs.branch_for_bitcoin }}
dir: .
- name: solana
repo: app-solana
branch: ${{ inputs.branch_for_solana }}
dir: .
- name: bsc
repo: app-ethereum
branch: ${{ inputs.branch_for_bsc }}
dir: .
- name: DOT
repo: app-polkadot
branch: ${{ inputs.branch_for_polkadot }}
dir: ./app

uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
Expand All @@ -97,6 +115,7 @@ jobs:
flags: "COIN=${{ matrix.coin.name }} CHAIN=${{ matrix.coin.name }} DEBUG=1"
upload_app_binaries_artifact: libraries_binaries
upload_as_lib_artifact: ${{ matrix.coin.name }}
relative_app_directory: ${{ matrix.coin.dir }}

build_exchange_application:
name: Build application using the reusable workflow
Expand Down
15 changes: 3 additions & 12 deletions test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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

TICKER_ID_TO_CONF = {
"ETC": ETC_CONF,
Expand All @@ -24,6 +25,7 @@
"XRP": XRP_CONF,
"XTZ": XTZ_CONF,
"BSC": BSC_CONF,
"DOT": DOT_CONF,
}

TICKER_ID_TO_PACKED_DERIVATION_PATH = {
Expand All @@ -36,18 +38,7 @@
"XRP": XRP_PACKED_DERIVATION_PATH,
"XTZ": XTZ_PACKED_DERIVATION_PATH,
"BSC": BSC_PACKED_DERIVATION_PATH,
}

TICKER_ID_TO_PACKED_DERIVATION_PATH = {
"ETC": ETC_PACKED_DERIVATION_PATH,
"ETH": ETH_PACKED_DERIVATION_PATH,
"BTC": BTC_PACKED_DERIVATION_PATH,
"LTC": LTC_PACKED_DERIVATION_PATH,
"XLM": XLM_PACKED_DERIVATION_PATH,
"SOL": SOL_PACKED_DERIVATION_PATH,
"XRP": XRP_PACKED_DERIVATION_PATH,
"XTZ": XTZ_PACKED_DERIVATION_PATH,
"BSC": BSC_PACKED_DERIVATION_PATH,
"DOT": DOT_PACKED_DERIVATION_PATH,
}

# Helper that can be called from outside if we want to generate errors easily
Expand Down
50 changes: 38 additions & 12 deletions test/python/apps/exchange_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ class ExchangeTestRunner:
# fake_refund_memo: str
# fake_payout: str
# fake_payout_memo: str
#
# signature_refusal_error_code: int
#
# you can override signature_refusal_error_code with specific values
# wrong_method_error_code: int
# wrong_fees_error_code: int
# wrong_memo_error_code: int
# wrong_destination_error_code: int
# wrong_amount_error_code: int

# You can optionally overwrite the following default values if you want
partner_name = "Default name"
Expand All @@ -46,10 +54,28 @@ class ExchangeTestRunner:
sell_out_currency = "USD"
sell_out_amount = {"coefficient": b"\x01", "exponent": 3}

signature_refusal_error_code = None
wrong_method_error_code = None
wrong_fees_error_code = None
wrong_memo_error_code = None
wrong_destination_error_code = None
wrong_amount_error_code = None

def __init__(self, backend, exchange_navigation_helper):
self.backend = backend
self.exchange_navigation_helper = exchange_navigation_helper

if self.wrong_method_error_code is None:
self.wrong_method_error_code = self.signature_refusal_error_code
if self.wrong_fees_error_code is None:
self.wrong_fees_error_code = self.signature_refusal_error_code
if self.wrong_memo_error_code is None:
self.wrong_memo_error_code = self.signature_refusal_error_code
if self.wrong_destination_error_code is None:
self.wrong_destination_error_code = self.signature_refusal_error_code
if self.wrong_amount_error_code is None:
self.wrong_amount_error_code = self.signature_refusal_error_code

def run_test(self, function_to_test: str):
# Remove the flow suffix as the function is the same and the snapshot path is the same too
if function_to_test.endswith(TEST_LEGACY_SUFFIX):
Expand Down Expand Up @@ -236,7 +262,7 @@ def perform_test_swap_wrong_fees(self, legacy):
self.perform_valid_swap_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_2, self.valid_destination_memo_1)
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_fees_error_code
self.assert_exchange_is_started()

# Test swap with a malicious TX with tampered memo
Expand All @@ -245,7 +271,7 @@ def perform_test_swap_wrong_memo(self, legacy):
self.perform_valid_swap_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_2)
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_memo_error_code
self.assert_exchange_is_started()

# Test swap with a malicious TX with tampered destination
Expand All @@ -254,7 +280,7 @@ def perform_test_swap_wrong_destination(self, legacy):
self.perform_valid_swap_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_2, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1)
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_destination_error_code
self.assert_exchange_is_started()

# Test swap with a malicious TX with tampered amount
Expand All @@ -263,7 +289,7 @@ def perform_test_swap_wrong_amount(self, legacy):
self.perform_valid_swap_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, self.valid_destination_memo_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_2, self.valid_fees_1, self.valid_destination_memo_1)
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_amount_error_code
self.assert_exchange_is_started()

#########################################################
Expand All @@ -288,15 +314,15 @@ def perform_test_fund_wrong_fees(self, legacy):
self.perform_valid_fund_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_2, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_fees_error_code
self.assert_exchange_is_started()

# Test fund with a malicious TX with tampered memo
def perform_test_fund_wrong_memo(self, legacy):
self.perform_valid_fund_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "no memo expected")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_memo_error_code
self.assert_exchange_is_started()

# Test fund with a malicious TX with tampered destination
Expand All @@ -305,7 +331,7 @@ def perform_test_fund_wrong_destination(self, legacy):
self.perform_valid_fund_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_2, self.valid_send_amount_1, self.valid_fees_1, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_destination_error_code
self.assert_exchange_is_started()

# Test fund with a malicious TX with tampered amount
Expand All @@ -314,7 +340,7 @@ def perform_test_fund_wrong_amount(self, legacy):
self.perform_valid_fund_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_2, self.valid_fees_1, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_amount_error_code
self.assert_exchange_is_started()

#########################################################
Expand All @@ -339,15 +365,15 @@ def perform_test_sell_wrong_fees(self, legacy):
self.perform_valid_sell_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_2, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_fees_error_code
self.assert_exchange_is_started()

# Test sell with a malicious TX with tampered memo
def perform_test_sell_wrong_memo(self, legacy):
self.perform_valid_sell_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, "no memo expected")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_memo_error_code
self.assert_exchange_is_started()

# Test sell with a malicious TX with tampered destination
Expand All @@ -356,7 +382,7 @@ def perform_test_sell_wrong_destination(self, legacy):
self.perform_valid_sell_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_2, self.valid_send_amount_1, self.valid_fees_1, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_destination_error_code
self.assert_exchange_is_started()

# Test sell with a malicious TX with tampered amount
Expand All @@ -365,7 +391,7 @@ def perform_test_sell_wrong_amount(self, legacy):
self.perform_valid_sell_from_custom(self.valid_destination_1, self.valid_send_amount_1, self.valid_fees_1, legacy=legacy)
with pytest.raises(ExceptionRAPDU) as e:
self.perform_coin_specific_final_tx(self.valid_destination_1, self.valid_send_amount_2, self.valid_fees_1, "")
assert e.value.status == self.signature_refusal_error_code
assert e.value.status == self.wrong_amount_error_code
self.assert_exchange_is_started()

# Automatically collect all tests functions and export their name in ready-to-be-parametrized lists
Expand Down
Loading
Loading