diff --git a/.github/workflows/build_and_functional_tests.yml b/.github/workflows/build_and_functional_tests.yml index 0aa6f42a..865cfa3b 100644 --- a/.github/workflows/build_and_functional_tests.yml +++ b/.github/workflows/build_and_functional_tests.yml @@ -31,7 +31,7 @@ jobs: with: app_repository: LedgerHQ/app-ethereum app_branch_name: develop - flags: "DEBUG=1 BYPASS_SIGNATURES=1" + flags: "DEBUG=1 CAL_TEST_KEY=1" upload_app_binaries_artifact: ethereum_build_develop ragger_tests_with_ethereum_develop: diff --git a/tests/abis/0x000102030405060708090a0b0c0d0e0f10111213.abi.json b/tests/abis/0x000102030405060708090a0b0c0d0e0f10111213.abi.json new file mode 100644 index 00000000..cb199761 --- /dev/null +++ b/tests/abis/0x000102030405060708090a0b0c0d0e0f10111213.abi.json @@ -0,0 +1,36 @@ +[ + { + "inputs" : [ + { + "internalType" : "uint256", + "name" : "amountOutMin", + "type" : "uint256" + }, + { + "internalType" : "address[]", + "name" : "path", + "type" : "address[]" + }, + { + "internalType" : "address", + "name" : "to", + "type" : "address" + }, + { + "internalType" : "uint256", + "name" : "deadline", + "type" : "uint256" + } + ], + "name" : "swapExactETHForTokens", + "outputs" : [ + { + "internalType" : "uint256[]", + "name" : "amounts", + "type" : "uint256[]" + } + ], + "stateMutability" : "payable", + "type" : "function" + } +] diff --git a/tests/requirements.txt b/tests/requirements.txt index b344083d..cb2af004 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,6 +1,4 @@ --extra-index-url https://test.pypi.org/simple/ ledger_app_clients.ethereum pytest -ragger[speculos,ledgerwallet]>=1.11.5 -ecdsa -simple-rlp +ragger[speculos,ledgercomm] diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00003.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00003.png index cb406157..7eb80fd6 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00003.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00003.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00004.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00004.png index 9d5f31b7..db2dd8c1 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00004.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00004.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00005.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00005.png index c36ac386..cb94c7fa 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00005.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00005.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00006.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00006.png index 9ef1c177..dda2fb66 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00006.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00006.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00007.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00007.png index e042ef25..96b0111e 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00007.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00007.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00008.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00008.png index f5bc9cf7..1c9156c3 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00008.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00008.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00009.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00009.png index 1595331e..ce795f34 100644 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00009.png and b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00009.png differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00010.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00010.png deleted file mode 100644 index 86807b07..00000000 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00010.png and /dev/null differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00011.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00011.png deleted file mode 100644 index 06513599..00000000 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00011.png and /dev/null differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00012.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00012.png deleted file mode 100644 index 1c9156c3..00000000 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00012.png and /dev/null differ diff --git a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00013.png b/tests/snapshots/nanos/test_swap_exact_eth_for_token/00013.png deleted file mode 100644 index ce795f34..00000000 Binary files a/tests/snapshots/nanos/test_swap_exact_eth_for_token/00013.png and /dev/null differ diff --git a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00003.png b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00003.png index 37d29cc5..18dac8ed 100644 Binary files a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00003.png and b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00003.png differ diff --git a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00004.png b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00004.png index 3783d673..d858b6f7 100644 Binary files a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00004.png and b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00004.png differ diff --git a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00005.png b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00005.png index 02884204..d3508954 100644 Binary files a/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00005.png and b/tests/snapshots/nanosp/test_swap_exact_eth_for_token/00005.png differ diff --git a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00003.png b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00003.png index 37d29cc5..18dac8ed 100644 Binary files a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00003.png and b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00003.png differ diff --git a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00004.png b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00004.png index 3783d673..d858b6f7 100644 Binary files a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00004.png and b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00004.png differ diff --git a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00005.png b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00005.png index f77cb889..3a1c8871 100644 Binary files a/tests/snapshots/nanox/test_swap_exact_eth_for_token/00005.png and b/tests/snapshots/nanox/test_swap_exact_eth_for_token/00005.png differ diff --git a/tests/snapshots/stax/test_swap_exact_eth_for_token/00001.png b/tests/snapshots/stax/test_swap_exact_eth_for_token/00001.png index 76b2e4f9..8cf15eb3 100644 Binary files a/tests/snapshots/stax/test_swap_exact_eth_for_token/00001.png and b/tests/snapshots/stax/test_swap_exact_eth_for_token/00001.png differ diff --git a/tests/snapshots/stax/test_swap_exact_eth_for_token/00002.png b/tests/snapshots/stax/test_swap_exact_eth_for_token/00002.png index 340f963b..b7c3410e 100644 Binary files a/tests/snapshots/stax/test_swap_exact_eth_for_token/00002.png and b/tests/snapshots/stax/test_swap_exact_eth_for_token/00002.png differ diff --git a/tests/test_swap.py b/tests/test_swap.py index dc9e0c85..059d2e89 100644 --- a/tests/test_swap.py +++ b/tests/test_swap.py @@ -1,51 +1,64 @@ from pathlib import Path +import json +import os + +import datetime + +from web3 import Web3 +from eth_typing import ChainId from ledger_app_clients.ethereum.client import EthAppClient, StatusWord +from ledger_app_clients.ethereum.utils import get_selector_from_data from ragger.navigator import NavInsID from .utils import get_appname_from_makefile ROOT_SCREENSHOT_PATH = Path(__file__).parent +ABIS_FOLDER = "%s/abis" % (os.path.dirname(__file__)) PLUGIN_NAME = get_appname_from_makefile() -PLACE_HOLDER_SIGNATURE = bytes.fromhex('3045022100f6e1a922c745e244fa3ed9a865491672808ef93f492ee0410861d748c5de201f0220160d6522499f3a84fa3e744b3b81e49e129e997b28495e58671a1169b16fa777') +with open("%s/0x000102030405060708090a0b0c0d0e0f10111213.abi.json" % (ABIS_FOLDER)) as file: + contract = Web3().eth.contract( + abi=json.load(file), + # Get address from filename + address=bytes.fromhex(os.path.basename(file.name).split(".")[0].split("x")[-1]) + ) -# In this test we verify "Swap Exact Eth For Tokens with beneficiary" -# Test from replayed transaction: https://etherscan.io/tx/0x0160b3aec12fd08e6be0040616c7c38248efb4413168a3372fc4d2db0e5961bb -# Function: swapExactETHForTokens(uint256 amountOutMin, address[] path, address to, uint256 deadline) -# -# MethodID: 0x7ff36ab5 -# [0]: 0000000000000000000000000000000000000000000000018b1dd9dc51b5a9f7 -# [1]: 0000000000000000000000000000000000000000000000000000000000000080 -# [2]: 00000000000000000000000015557c8b7246c38ee71ea6dc69e4347f5dac2104 -# [3]: 0000000000000000000000000000000000000000000000000000000061533610 -# [4]: 0000000000000000000000000000000000000000000000000000000000000002 -# [5]: 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 -# [6]: 0000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe2 # EDIT THIS: build your own test def test_swap_exact_eth_for_token(backend, firmware, navigator, test_name): - # EDIT THIS: Replace with your contract address - contract_address = bytes.fromhex('7a250d5630b4cf539739df2c5dacb4c659f2488d') - # EDIT THIS: Replace with your method selector - method_selector = bytes.fromhex('7ff36ab5') - # The rawTx of the tx up above is accessible through: https://etherscan.io/getRawTx?tx=0x0160b3aec12fd08e6be0040616c7c38248efb4413168a3372fc4d2db0e5961bb - # EDIT THIS: Replace with your Tx payload - tx_payload = bytes.fromhex('02f9015a0181d38459682f0085215d7c1e598302a4e9947a250d5630b4cf539739df2c5dacb4c659f2488d88016345785d8a0000b8e47ff36ab50000000000000000000000000000000000000000000000018b1dd9dc51b5a9f7000000000000000000000000000000000000000000000000000000000000008000000000000000000000000015557c8b7246c38ee71ea6dc69e4347f5dac210400000000000000000000000000000000000000000000000000000000615336100000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b3595068778dd592e39a122f4f5a5cf09c90fe2c001a089c5ce4ce199f7d93ea1d54c08133fab9407d8de63a9885d59d8ce69a59573dda045f6a0e0d3288dfdfddc23ad0afb9577c4011801f598d581a46cd0b0e2bd0571') - client = EthAppClient(backend) + data = contract.encodeABI("swapExactETHForTokens", [ + Web3.to_wei(28.5, "ether"), + [ + bytes.fromhex("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"), + bytes.fromhex("6B3595068778DD592e39A122f4f5a5cF09C90fE2") + ], + bytes.fromhex("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"), + int(datetime.datetime(2023, 12, 25, 0, 0).timestamp()) + ]) + # first setup the external plugin - with client.set_external_plugin(PLUGIN_NAME, contract_address, method_selector, PLACE_HOLDER_SIGNATURE): + with client.set_external_plugin(PLUGIN_NAME, + contract.address, + # Extract function selector from the encoded data + get_selector_from_data(data)): pass - assert client.response().status == StatusWord.OK - # send the transaction - # !!!! to be replaced by a dedicated plugin sign function !!! - with client._sign("m/44'/60'/1'/0/0", tx_payload): + with client.sign("m/44'/60'/1'/0/0", { + "nonce": 20, + "maxFeePerGas": Web3.to_wei(145, "gwei"), + "maxPriorityFeePerGas": Web3.to_wei(1.5, "gwei"), + "gas": 173290, + "to": contract.address, + "value": Web3.to_wei(0.1, "ether"), + "chainId": ChainId.ETH, + "data": data + }): # Validate the on-screen request by performing the navigation appropriate for this device if firmware.device.startswith("nano"): navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK, @@ -60,5 +73,3 @@ def test_swap_exact_eth_for_token(backend, firmware, navigator, test_name): "Hold to sign", ROOT_SCREENSHOT_PATH, test_name) - - assert client.response().status == StatusWord.OK