-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a8dac7
commit 18c9f58
Showing
273 changed files
with
75 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
from . import cal as cal | ||
from .signing_authority import SigningAuthority, LEDGER_SIGNER | ||
|
||
from ..utils import handle_lib_call_start_or_stop | ||
from ..utils import handle_lib_call_start_or_stop, int_to_minimally_sized_bytes | ||
|
||
# When adding a new test, have it prefixed by this string in order to have it automatically parametrized for currencies tests | ||
TEST_METHOD_PREFIX="perform_test_" | ||
|
@@ -36,6 +36,14 @@ class ExchangeTestRunner: | |
# fake_payout_memo: str | ||
# signature_refusal_error_code: int | ||
|
||
# You can optionnaly overwrite the following default values if you want | ||
partner_name = "Default name" | ||
fund_user_id = "Jon Wick" | ||
fund_account_name = "My account 00" | ||
sell_trader_email = "[email protected]" | ||
sell_out_currency = "USD" | ||
sell_out_amount = {"coefficient": b"\x01", "exponent": 3} | ||
|
||
# def __init__(self, backend, exchange_navigation_helper, function_to_test): | ||
def __init__(self, backend, exchange_navigation_helper): | ||
self.backend = backend | ||
|
@@ -57,7 +65,7 @@ def _perform_valid_exchange(self, subcommand, tx_infos, fees, ui_validation): | |
ex = ExchangeClient(self.backend, Rate.FIXED, subcommand) | ||
|
||
# The partner we will perform the exchange with | ||
partner = SigningAuthority(curve=get_partner_curve(subcommand), name="Default name") | ||
partner = SigningAuthority(curve=get_partner_curve(subcommand), name=self.partner_name) | ||
|
||
# Initialize a new transaction request | ||
transaction_id = ex.init_transaction().data | ||
|
@@ -105,7 +113,7 @@ def perform_valid_swap_from_custom(self, destination, send_amount, fees, memo, r | |
"payout_extra_id": b"", # Default | ||
"currency_from": self.currency_ticker, | ||
"currency_to": "ETH", # Default | ||
"amount_to_provider": int.to_bytes(send_amount, length=8, byteorder='big'), | ||
"amount_to_provider": int_to_minimally_sized_bytes(send_amount), | ||
"amount_to_wallet": b"\246\333t\233+\330\000", # Default | ||
} | ||
self._perform_valid_exchange(SubCommand.SWAP, tx_infos, fees, ui_validation=ui_validation) | ||
|
@@ -120,28 +128,28 @@ def perform_valid_swap_to_custom(self, destination, send_amount, fees, memo, ui_ | |
"payout_extra_id": memo.encode(), | ||
"currency_from": "ETH", # Default | ||
"currency_to": self.currency_ticker, | ||
"amount_to_provider": int.to_bytes(send_amount, length=8, byteorder='big'), | ||
"amount_to_provider": int_to_minimally_sized_bytes(send_amount), | ||
"amount_to_wallet": b"\246\333t\233+\330\000", # Default | ||
} | ||
self._perform_valid_exchange(SubCommand.SWAP, tx_infos, fees, ui_validation=ui_validation) | ||
|
||
def perform_valid_fund_from_custom(self, destination, send_amount, fees): | ||
tx_infos = { | ||
"user_id": "Jon Wick", # Default | ||
"account_name": "My account 00", # Default | ||
"user_id": self.fund_user_id, | ||
"account_name": self.fund_account_name, | ||
"in_currency": self.currency_ticker, | ||
"in_amount": int.to_bytes(send_amount, length=4, byteorder='big'), | ||
"in_amount": int_to_minimally_sized_bytes(send_amount), | ||
"in_address": destination, | ||
} | ||
self._perform_valid_exchange(SubCommand.FUND, tx_infos, fees, ui_validation=True) | ||
|
||
def perform_valid_sell_from_custom(self, destination, send_amount, fees): | ||
tx_infos = { | ||
"trader_email": "[email protected]", # Default | ||
"out_currency": "USD", # Default | ||
"out_amount": {"coefficient": b"\x01", "exponent": 3}, # Default | ||
"trader_email": self.sell_trader_email, | ||
"out_currency": self.sell_out_currency, | ||
"out_amount": self.sell_out_amount, | ||
"in_currency": self.currency_ticker, | ||
"in_amount": int.to_bytes(send_amount, length=4, byteorder='big'), | ||
"in_amount": int_to_minimally_sized_bytes(send_amount), | ||
"in_address": destination, | ||
} | ||
self._perform_valid_exchange(SubCommand.SELL, tx_infos, fees, ui_validation=True) | ||
|
@@ -338,6 +346,7 @@ def perform_test_sell_wrong_amount(self): | |
# Remove prefix to have nice snapshots directories | ||
ALL_TESTS = [str(i).replace(TEST_METHOD_PREFIX, '') for i in _all_test_methods_prefixed] | ||
ALL_TESTS_EXCEPT_MEMO = [test for test in ALL_TESTS if not "memo" in test] | ||
ALL_TESTS_EXCEPT_MEMO_AND_FEES = [test for test in ALL_TESTS if (not "memo" in test and not "fees" in test)] | ||
SWAP_TESTS = [test for test in ALL_TESTS if "swap" in test] | ||
FUND_TESTS = [test for test in ALL_TESTS if "fund" in test] | ||
SELL_TESTS = [test for test in ALL_TESTS if "sell" in test] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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.
File renamed without changes
File renamed without changes
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file removed
BIN
-352 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_cancel/00001.png
Diff not rendered.
Binary file removed
BIN
-310 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-313 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_cancel/00003.png
Diff not rendered.
Binary file removed
BIN
-340 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-352 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_ok/00001.png
Diff not rendered.
Binary file removed
BIN
-310 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_ok/00002.png
Diff not rendered.
Binary file removed
BIN
-313 Bytes
test/python/snapshots/nanos/test_solana_swap_recipient_ok/00003.png
Diff not rendered.
File renamed without changes
File renamed without changes
Binary file added
BIN
+355 Bytes
test/python/snapshots/nanos/test_solana_swap_refuse_double_sign/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed
BIN
-333 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-340 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-333 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_double_sign/00002.png
Diff not rendered.
Diff not rendered.
Binary file removed
BIN
-333 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_wrong_amount/00002.png
Diff not rendered.
Binary file removed
BIN
-320 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_wrong_destination/00001.png
Diff not rendered.
Binary file removed
BIN
-333 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_wrong_destination/00002.png
Diff not rendered.
Binary file removed
BIN
-329 Bytes
test/python/snapshots/nanos/test_solana_swap_sender_wrong_destination/00003.png
Diff not rendered.
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+355 Bytes
test/python/snapshots/nanos/test_solana_swap_wrong_amount/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+355 Bytes
test/python/snapshots/nanos/test_solana_swap_wrong_destination/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file removed
BIN
-398 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_cancel/00001.png
Diff not rendered.
Binary file removed
BIN
-353 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_cancel/00003.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-398 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_ok/00001.png
Diff not rendered.
Binary file removed
BIN
-353 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_ok/00002.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanosp/test_solana_swap_recipient_ok/00003.png
Diff not rendered.
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanosp/test_solana_swap_refuse_double_sign/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_double_sign/00002.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_ok/00002.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_wrong_amount/00002.png
Diff not rendered.
Binary file removed
BIN
-367 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_wrong_destination/00001.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanosp/test_solana_swap_sender_wrong_destination/00002.png
Diff not rendered.
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanosp/test_solana_swap_wrong_amount/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanosp/test_solana_swap_wrong_destination/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
Diff not rendered.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
Binary file removed
BIN
-396 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_cancel/00001.png
Diff not rendered.
Binary file removed
BIN
-353 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_cancel/00003.png
Diff not rendered.
Binary file removed
BIN
-366 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-396 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_ok/00001.png
Diff not rendered.
Binary file removed
BIN
-353 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_ok/00002.png
Diff not rendered.
Binary file removed
BIN
-365 Bytes
test/python/snapshots/nanox/test_solana_swap_recipient_ok/00003.png
Diff not rendered.
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanox/test_solana_swap_refuse_double_sign/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_cancel/00002.png
Diff not rendered.
Binary file removed
BIN
-366 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_cancel/00005.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_double_sign/00002.png
Diff not rendered.
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_wrong_amount/00002.png
Diff not rendered.
Binary file removed
BIN
-375 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_wrong_amount/00003.png
Diff not rendered.
Binary file removed
BIN
-367 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_wrong_destination/00001.png
Diff not rendered.
Binary file removed
BIN
-379 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_wrong_destination/00002.png
Diff not rendered.
Binary file removed
BIN
-375 Bytes
test/python/snapshots/nanox/test_solana_swap_sender_wrong_destination/00003.png
Diff not rendered.
File renamed without changes
File renamed without changes
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanox/test_solana_swap_wrong_amount/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added
BIN
+402 Bytes
test/python/snapshots/nanox/test_solana_swap_wrong_destination/00002.png
Oops, something went wrong.
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import pytest | ||
|
||
from .apps.exchange_test_runner import ExchangeTestRunner, ALL_TESTS_EXCEPT_MEMO_AND_FEES | ||
from .apps.solana import SolanaClient, ErrorType | ||
from .apps.solana_utils import SOL_PACKED_DERIVATION_PATH | ||
from .apps.solana_cmd_builder import SystemInstructionTransfer, Message, verify_signature | ||
from .apps import solana_utils as SOL | ||
|
||
# A bit hacky but way less hassle than actually writing an actual address decoder | ||
SOLANA_ADDRESS_DECODER = { | ||
SOL.FOREIGN_ADDRESS: SOL.FOREIGN_PUBLIC_KEY, | ||
SOL.FOREIGN_ADDRESS_2: SOL.FOREIGN_PUBLIC_KEY_2, | ||
} | ||
|
||
# ExchangeTestRunner implementation for Stellar | ||
class SolanaTests(ExchangeTestRunner): | ||
currency_ticker = "SOL" | ||
valid_destination_1 = SOL.FOREIGN_ADDRESS | ||
valid_destination_memo_1 = "" | ||
valid_destination_2 = SOL.FOREIGN_ADDRESS_2 | ||
valid_destination_memo_2 = "" | ||
valid_refund = SOL.OWNED_ADDRESS | ||
valid_refund_memo = "" | ||
valid_send_amount_1 = SOL.AMOUNT | ||
valid_send_amount_2 = SOL.AMOUNT_2 | ||
valid_fees_1 = SOL.FEES | ||
valid_fees_2 = SOL.FEES_2 | ||
fake_refund = SOL.FOREIGN_ADDRESS | ||
fake_refund_memo = "" | ||
fake_payout = SOL.FOREIGN_ADDRESS | ||
fake_payout_memo = "" | ||
signature_refusal_error_code = ErrorType.SOLANA_SUMMARY_FINALIZE_FAILED | ||
|
||
partner_name = "Partner name" | ||
fund_user_id = "Daft Punk" | ||
fund_account_name = "Account 0" | ||
|
||
def perform_final_tx(self, destination, send_amount, fees, memo): | ||
decoded_destination = SOLANA_ADDRESS_DECODER[destination] | ||
instruction: SystemInstructionTransfer = SystemInstructionTransfer(SOL.OWNED_PUBLIC_KEY, decoded_destination, send_amount) | ||
message: bytes = Message([instruction]).serialize() | ||
sol = SolanaClient(self.backend) | ||
with sol.send_async_sign_message(SOL_PACKED_DERIVATION_PATH, message): | ||
pass | ||
signature: bytes = sol.get_async_response().data | ||
verify_signature(SOL.OWNED_PUBLIC_KEY, message, signature) | ||
|
||
|
||
# Use a class to reuse the same Speculos instance | ||
@pytest.mark.parametrize('test_to_run', ALL_TESTS_EXCEPT_MEMO_AND_FEES) | ||
def test_solana(backend, exchange_navigation_helper, test_to_run): | ||
SolanaTests(backend, exchange_navigation_helper).run_test(test_to_run) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.