Skip to content

Commit

Permalink
Test initial setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoccmartins committed Jan 14, 2025
1 parent 50e2c39 commit 550bac8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/python/apps/aptos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from ragger.utils import create_currency_config

APTOS_CONF = create_currency_config("APT", "Aptos")
APTOS_DERIVATION_PATH = "m/44'/607'/0'/0'/0'/0'"
APTOS_PACKED_DERIVATION_PATH = pack_derivation_path(APTOS_DERIVATION_PATH)

MAX_APDU_LEN: int = 255
2 changes: 2 additions & 0 deletions test/python/apps/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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 .cardano import ADA_BYRON_PACKED_DERIVATION_PATH, ADA_SHELLEY_PACKED_DERIVATION_PATH, ADA_CONF
from .aptos import APTOS_PACKED_DERIVATION_PATH, APTOS_CONF

@dataclass
class CurrencyConfiguration:
Expand Down Expand Up @@ -57,6 +58,7 @@ def get_conf_for_ticker(self, overload_signer: Optional[SigningAuthority]=None)
USDD_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="USDD", conf=TRX_USDD_CONF, packed_derivation_path=TRX_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)
APTOS_CURRENCY_CONFIGURATION = CurrencyConfiguration(ticker="APT", conf=APTOS_CONF, packed_derivation_path=APTOS_PACKED_DERIVATION_PATH)


# Helper that can be called from outside if we want to generate errors easily
Expand Down
65 changes: 65 additions & 0 deletions test/python/test_aptos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest
import os

from .apps.ton_application_client.ton_transaction import Transaction, SendMode, CommentPayload, Payload, JettonTransferPayload, NFTTransferPayload, CustomUnsafePayload, JettonBurnPayload, AddWhitelistPayload, SingleNominatorWithdrawPayload, ChangeValidatorPayload, TonstakersDepositPayload, JettonDAOVotePayload, ChangeDNSWalletPayload, ChangeDNSPayload, TokenBridgePaySwapPayload
from .apps.ton_application_client.ton_command_sender import BoilerplateCommandSender, Errors
from .apps.ton_application_client.ton_response_unpacker import unpack_sign_tx_response
from .apps.ton_utils import check_signature_validity

from .apps.exchange_test_runner import ExchangeTestRunner, ALL_TESTS_EXCEPT_MEMO_THORSWAP_AND_FEES
from .apps.aptos import SW_SWAP_FAILURE, APTOS_DERIVATION_PATH
from .apps import cal as cal

# ExchangeTestRunner implementation for Ton
class AptosTests(ExchangeTestRunner):
currency_configuration = cal.APTOS_CURRENCY_CONFIGURATION
valid_destination_1 = "EQD0sKn8DbS12U015TWOSpYmyJYYDC_7sxg1upaMxnBvTiX8"
valid_destination_2 = "EQANxfGN1EgFPawYB1fhPqebKe1Nb6FIsaiekEecJ6R-3kYF"
# valid_refund = craft_address(Bounceability.NON_BOUNCEABLE, WorkchainID.BASE_CHAIN, DEVICE_PUBLIC_KEY).decode('utf-8')
valid_refund = "UQDWey_FGPhd3phmerdVXi-zUIujfyO4-29y_VT1yD0meY1n"
valid_send_amount_1 = 12345670000
valid_send_amount_2 = 446739662
valid_fees_1 = 100000000
valid_fees_2 = 10000123
fake_refund = "EQD0sKn8DbS12U015TWOSpYmyJYYDC_7sxg1upaMxnBvTiX8"
fake_payout = "EQD0sKn8DbS12U015TWOSpYmyJYYDC_7sxg1upaMxnBvTiX8"
wrong_method_error_code = SW_SWAP_FAILURE
wrong_destination_error_code = SW_SWAP_FAILURE
wrong_amount_error_code = SW_SWAP_FAILURE

def perform_final_tx(self, destination, send_amount, fees, memo):
# Use the app interface instead of raw interface
client = BoilerplateCommandSender(self.backend)

# First we need to get the public key of the device in order to build the transaction
pubkey = client.get_public_key(path=APTOS_DERIVATION_PATH).data

# Create the transaction that will be sent to the device for signing
tx = Transaction(Address(destination), SendMode.PAY_GAS_SEPARATLY, 0, 1686176000, True, send_amount)
tx_bytes = tx.to_request_bytes()

# Send the sign device instruction.
# As it requires on-screen validation, the function is asynchronous.
# It will yield the result when the navigation is done
with client.sign_tx(path=APTOS_DERIVATION_PATH, transaction=tx_bytes):
pass

# The device as yielded the result, parse it and ensure that the signature is correct
response = client.get_async_response().data
sig, hash_b = unpack_sign_tx_response(response)
assert hash_b == tx.transfer_cell().bytes_hash()
assert check_signature_validity(pubkey, sig, hash_b)


# Use a class to reuse the same Speculos instance
class TestsAptos:

@pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO_THORSWAP_AND_FEES)
def test_ton(self, backend, exchange_navigation_helper, test_to_run):
if backend.firmware.device == "nanos":
pytest.skip("Polkadot swap is not supported on NanoS device")
AptosTests(backend, exchange_navigation_helper).run_test(test_to_run)

# @pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO_THORSWAP_AND_FEES)
# def test_ton_usdt(self, backend, exchange_navigation_helper, test_to_run):
# TonUSDTTests(backend, exchange_navigation_helper).run_test(test_to_run)

0 comments on commit 550bac8

Please sign in to comment.