From 550bac86001dd1c7bb6900bd67fb22072c574d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Martins?= Date: Tue, 14 Jan 2025 18:41:24 +0000 Subject: [PATCH] Test initial setup. --- test/python/apps/aptos.py | 7 +++++ test/python/apps/cal.py | 2 ++ test/python/test_aptos.py | 65 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 test/python/apps/aptos.py create mode 100644 test/python/test_aptos.py diff --git a/test/python/apps/aptos.py b/test/python/apps/aptos.py new file mode 100644 index 00000000..b4516c9a --- /dev/null +++ b/test/python/apps/aptos.py @@ -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 \ No newline at end of file diff --git a/test/python/apps/cal.py b/test/python/apps/cal.py index 17c20c33..50d58aea 100644 --- a/test/python/apps/cal.py +++ b/test/python/apps/cal.py @@ -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: @@ -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 diff --git a/test/python/test_aptos.py b/test/python/test_aptos.py new file mode 100644 index 00000000..7d3b3a09 --- /dev/null +++ b/test/python/test_aptos.py @@ -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)