Skip to content

Commit

Permalink
Merge pull request #9 from OriginProtocol/shah/sync-fork
Browse files Browse the repository at this point in the history
  • Loading branch information
shahthepro authored Apr 10, 2024
2 parents d4d4da9 + 137006c commit 4596769
Show file tree
Hide file tree
Showing 129 changed files with 199 additions and 133 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
- [ ] Target branch is `develop` <!-- unless you have a very good reason -->
- [ ] Application version has been bumped <!-- required if your changes are to be deployed -->

<!-- Make sure you followed the process described in https://developers.ledger.com/docs/embedded-app/maintenance/ before opening your Pull Request.
<!-- Make sure you followed the process described in https://developers.ledger.com/docs/device-app/deliver/maintenance before opening your Pull Request.
Don't hesitate to contact us directly on Discord if you have any questions ! https://developers.ledger.com/discord -->
2 changes: 1 addition & 1 deletion .github/workflows/build_and_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
with:
download_app_binaries_artifact: plugin_binaries
additional_app_binaries_artifact: ethereum_build_develop
additional_app_binaries_artifact_dir: ./tests/ethereum_build/build
additional_app_binaries_artifact_dir: ./tests/.test_dependencies/ethereum/build
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ ledger/
tests/snapshots-tmp/

# Directory storing the ethereum build output for tests run
tests/ethereum_build/build/
tests/.test_dependencies/*
!tests/.test_dependencies/ethereum/
tests/.test_dependencies/ethereum/*
!tests/.test_dependencies/ethereum/.ethereum_application_build_goes_there

.DS_Store
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "ethereum-plugin-sdk"]
path = ethereum-plugin-sdk
url = https://github.com/LedgerHQ/ethereum-plugin-sdk
url = https://github.com/LedgerHQ/ethereum-plugin-sdk
14 changes: 9 additions & 5 deletions fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ set(CMAKE_C_STANDARD_REQUIRED True)
# compatible with ClusterFuzzLite
if (NOT DEFINED ENV{LIB_FUZZING_ENGINE})
set(COMPILATION_FLAGS_ "-fsanitize=fuzzer,address,undefined,signed-integer-overflow")
else()
else()
set(COMPILATION_FLAGS_ "$ENV{LIB_FUZZING_ENGINE} $ENV{CFLAGS}")
endif()
endif()
string(REPLACE " " ";" COMPILATION_FLAGS ${COMPILATION_FLAGS_})

add_compile_options(-Wall -Wextra -g -pedantic)
Expand Down Expand Up @@ -65,6 +65,7 @@ add_compile_definitions(
HAVE_EDDSA
HAVE_HASH
HAVE_BLAKE2
HAVE_SHA224
HAVE_SHA256
HAVE_SHA3
HAVE_SHA512
Expand All @@ -75,7 +76,7 @@ include_directories(
${BOLOS_SDK}/lib_cxng/include
${BOLOS_SDK}/lib_cxng/src
${BOLOS_SDK}/target/nanox/include
${ETH_DIR}/include
${ETH_DIR}/src
${SRC_DIR}
)

Expand All @@ -92,8 +93,11 @@ add_executable(fuzz
${SRC_DIR}/handle_query_contract_id.c

# Ethereum SDK
${ETH_DIR}/include/eth_internals.c
${ETH_DIR}/include/plugin_utils.c
${ETH_DIR}/src/common_utils.c
${ETH_DIR}/src/plugin_utils.c

# sdk utils
${BOLOS_SDK}/src/ledger_assert.c

# cxng
${BOLOS_SDK}/lib_cxng/src/cx_hash.c
Expand Down
13 changes: 13 additions & 0 deletions fuzzing/mocks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "plugin.h"
#include "lcx_common.h"
#include "lcx_hash.h"
#include <stddef.h>

size_t strlcat(char *dst, const char *src, size_t size) {
size_t srclen; /* Length of source string */
Expand Down Expand Up @@ -33,3 +36,13 @@ size_t strlcpy(char *dst, const char *src, size_t size) {

return (srclen);
}

cx_err_t cx_keccak_256_hash_iovec(const cx_iovec_t *iovec,
size_t iovec_len,
uint8_t digest[static CX_KECCAK_256_SIZE]) {
return CX_OK;
}

void os_sched_exit(bolos_task_status_t exit_code) {
return;
}
9 changes: 9 additions & 0 deletions ledger_app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ devices = ["nanos", "nanox", "nanos+", "stax"]

[tests]
pytest_directory = "./tests/"

[tests.dependencies]
testing_with_latest = [
{url = "https://github.com/LedgerHQ/app-ethereum", ref = "develop", use_case = "use_test_keys"},
]

testing_with_prod = [
{url = "https://github.com/LedgerHQ/app-ethereum", ref = "master", use_case = "use_test_keys"},
]
1 change: 0 additions & 1 deletion src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
return getEthAddressStringFromBinary(
context->beneficiary,
msg->msg + 2, // +2 here because we've already prefixed with '0x'.
msg->pluginSharedRW->sha3,
chainid);
}

Expand Down
2 changes: 0 additions & 2 deletions src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#pragma once

#include <string.h>

#include "eth_internals.h"
#include "eth_plugin_interface.h"

// All possible selectors of your plugin.
Expand Down
17 changes: 9 additions & 8 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ In order to run the tests you need to provide the binaries for both the plugin a

Compiling the plugin will produce the binary for the targeted device. They will be used as-is by the test framework.

The binaries of the Ethereum application must be gathered and placed in the directory `tests/ethereum_build/`.
The binaries of the Ethereum application must be gathered and placed in the directory `tests/.test_dependencies/ethereum/`.
Example of the correct file tree with Ethereum compiled for all targets.
* `tests/ethereum_build/build/nanos/bin/app.elf`
* `tests/ethereum_build/build/nanos2/bin/app.elf`
* `tests/ethereum_build/build/nanox/bin/app.elf`
* `tests/ethereum_build/build/stax/bin/app.elf`

The first method is to go in the Ethereum project, compile the application, and dispatch the `build/` output directory.
A second method is to re-use the Ethereum build used in the CI, and available as artifact.
* `tests/.test_dependencies/ethereum/build/nanos/bin/app.elf`
* `tests/.test_dependencies/ethereum/build/nanos2/bin/app.elf`
* `tests/.test_dependencies/ethereum/build/nanox/bin/app.elf`
* `tests/.test_dependencies/ethereum/build/stax/bin/app.elf`

The first method is to use the Ledger VSCode extension to automatically manage dependencies
The second method is to go in the Ethereum project, compile the application, and dispatch the `build/` output directory.
A third method is to re-use the Ethereum build used in the CI, and available as artifact.
For example in the [plugin-boilerplate CI](https://github.com/LedgerHQ/app-plugin-boilerplate/actions/workflows/build_and_functional_tests.yml).


Expand Down
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import pytest

from ragger.conftest import configuration
from .utils import WalletAddr


###########################
### CONFIGURATION START ###
Expand All @@ -7,9 +11,7 @@
# You can configure optional parameters by overriding the value of ragger.configuration.OPTIONAL_CONFIGURATION
# Please refer to ragger/conftest/configuration.py for their descriptions and accepted values

configuration.OPTIONAL.APP_DIR = "tests/ethereum_build/"

configuration.OPTIONAL.LOAD_MAIN_APP_AS_LIBRARY = True
configuration.OPTIONAL.MAIN_APP_DIR = "tests/.test_dependencies/"

configuration.OPTIONAL.BACKEND_SCOPE = "class"

Expand All @@ -20,3 +22,7 @@

# Pull all features from the base ragger conftest using the overridden configuration
pytest_plugins = ("ragger.conftest.base_conftest", )

@pytest.fixture
def wallet_addr(backend):
return WalletAddr(backend)
Binary file removed tests/ethereum_build/.DS_Store
Binary file not shown.
Empty file.
28 changes: 14 additions & 14 deletions tests/oeth/test_oeth_curve_swap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@
"curve-router"
)

def test_oeth_curve_swap_from_oeth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_from_oeth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_pool.encodeABI("exchange", [
1,
0,
Web3.to_wei(1, "ether"),
Web3.to_wei(0.975, "ether")
])

run_test(contract_curve_pool, data, backend, firmware, navigator, test_name)
run_test(contract_curve_pool, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_to_oeth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_to_oeth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_pool.encodeABI("exchange", [
0,
1,
Web3.to_wei(1, "ether"),
Web3.to_wei(0.995, "ether")
])

run_test(contract_curve_pool, data, backend, firmware, navigator, test_name)
run_test(contract_curve_pool, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_multiple_oeth_to_reth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_multiple_oeth_to_reth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_router.encodeABI("exchange_multiple", [
[
bytes.fromhex("856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3"),
Expand All @@ -54,9 +54,9 @@ def test_oeth_curve_swap_multiple_oeth_to_reth(backend, firmware, navigator, tes
Web3.to_wei(0.941, "ether"),
])

run_test(contract_curve_router, data, backend, firmware, navigator, test_name)
run_test(contract_curve_router, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_multiple_reth_to_oeth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_multiple_reth_to_oeth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_router.encodeABI("exchange_multiple", [
[
bytes.fromhex("ae78736cd615f374d3085123a210448e74fc6393"),
Expand All @@ -79,9 +79,9 @@ def test_oeth_curve_swap_multiple_reth_to_oeth(backend, firmware, navigator, tes
Web3.to_wei(0.941, "ether"),
])

run_test(contract_curve_router, data, backend, firmware, navigator, test_name)
run_test(contract_curve_router, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_multiple_eth_to_oeth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_multiple_eth_to_oeth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_router.encodeABI("exchange_multiple", [
[
bytes.fromhex("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"),
Expand All @@ -104,9 +104,9 @@ def test_oeth_curve_swap_multiple_eth_to_oeth(backend, firmware, navigator, test
Web3.to_wei(0.941, "ether"),
])

run_test(contract_curve_router, data, backend, firmware, navigator, test_name)
run_test(contract_curve_router, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_multiple_oeth_to_eth(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_multiple_oeth_to_eth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_router.encodeABI("exchange_multiple", [
[
bytes.fromhex("856c4Efb76C1D1AE02e20CEB03A2A6a08b0b8dC3"),
Expand All @@ -129,9 +129,9 @@ def test_oeth_curve_swap_multiple_oeth_to_eth(backend, firmware, navigator, test
Web3.to_wei(0.941, "ether"),
])

run_test(contract_curve_router, data, backend, firmware, navigator, test_name)
run_test(contract_curve_router, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_curve_swap_multiple_eth_to_oeth_diff_route(backend, firmware, navigator, test_name):
def test_oeth_curve_swap_multiple_eth_to_oeth_diff_route(backend, firmware, navigator, test_name, wallet_addr):
data = contract_curve_router.encodeABI("exchange_multiple", [
[
bytes.fromhex("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"),
Expand All @@ -154,4 +154,4 @@ def test_oeth_curve_swap_multiple_eth_to_oeth_diff_route(backend, firmware, navi
Web3.to_wei(0.941, "ether"),
])

run_test(contract_curve_router, data, backend, firmware, navigator, test_name)
run_test(contract_curve_router, data, backend, firmware, navigator, test_name, wallet_addr)
20 changes: 10 additions & 10 deletions tests/oeth/test_oeth_vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@
"vault-core"
)

def test_oeth_vault_mint_weth(backend, firmware, navigator, test_name):
def test_oeth_vault_mint_weth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_oeth_vault.encodeABI("mint", [
bytes.fromhex("C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
Web3.to_wei(1, "ether"),
Web3.to_wei(1, "ether")
])

run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name)
run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_vault_mint_reth(backend, firmware, navigator, test_name):
def test_oeth_vault_mint_reth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_oeth_vault.encodeABI("mint", [
bytes.fromhex("ae78736cd615f374d3085123a210448e74fc6393"),
Web3.to_wei(1, "ether"),
Web3.to_wei(1, "ether")
])

run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name)
run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_vault_mint_steth(backend, firmware, navigator, test_name):
def test_oeth_vault_mint_steth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_oeth_vault.encodeABI("mint", [
bytes.fromhex("ae7ab96520de3a18e5e111b5eaab095312d7fe84"),
Web3.to_wei(1, "ether"),
Web3.to_wei(1, "ether")
])

run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name)
run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_vault_mint_frxeth(backend, firmware, navigator, test_name):
def test_oeth_vault_mint_frxeth(backend, firmware, navigator, test_name, wallet_addr):
data = contract_oeth_vault.encodeABI("mint", [
bytes.fromhex("5e8422345238f34275888049021821e8e08caa1f"),
Web3.to_wei(1, "ether"),
Web3.to_wei(1, "ether")
])

run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name)
run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_vault_redeem(backend, firmware, navigator, test_name):
def test_oeth_vault_redeem(backend, firmware, navigator, test_name, wallet_addr):
data = contract_oeth_vault.encodeABI("redeem", [
Web3.to_wei(1, "ether"),
Web3.to_wei(0.88, "ether")
])

run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name)
run_test(contract_oeth_vault, data, backend, firmware, navigator, test_name, wallet_addr)
16 changes: 8 additions & 8 deletions tests/oeth/test_oeth_wrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"4626-vault"
)

def test_oeth_wrap(backend, firmware, navigator, test_name):
def test_oeth_wrap(backend, firmware, navigator, test_name, wallet_addr):
client = EthAppClient(backend)

with client.get_public_addr(display=False):
Expand All @@ -21,17 +21,17 @@ def test_oeth_wrap(backend, firmware, navigator, test_name):
addr
])

run_test(contract_woeth, data, backend, firmware, navigator, test_name)
run_test(contract_woeth, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_wrap_different_beneficiary(backend, firmware, navigator, test_name):
def test_oeth_wrap_different_beneficiary(backend, firmware, navigator, test_name, wallet_addr):
data = contract_woeth.encodeABI("deposit", [
Web3.to_wei(1, "ether"),
bytes.fromhex("000000000000000000000000000000000000dEaD")
])

run_test(contract_woeth, data, backend, firmware, navigator, test_name)
run_test(contract_woeth, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_unwrap(backend, firmware, navigator, test_name):
def test_oeth_unwrap(backend, firmware, navigator, test_name, wallet_addr):
client = EthAppClient(backend)

with client.get_public_addr(display=False):
Expand All @@ -44,13 +44,13 @@ def test_oeth_unwrap(backend, firmware, navigator, test_name):
addr
])

run_test(contract_woeth, data, backend, firmware, navigator, test_name)
run_test(contract_woeth, data, backend, firmware, navigator, test_name, wallet_addr)

def test_oeth_unwrap_different_beneficiary(backend, firmware, navigator, test_name):
def test_oeth_unwrap_different_beneficiary(backend, firmware, navigator, test_name, wallet_addr):
data = contract_woeth.encodeABI("redeem", [
Web3.to_wei(1, "ether"),
bytes.fromhex("000000000000000000000000000000000000dEaD"),
bytes.fromhex("000000000000000000000000000000000002dEaD")
])

run_test(contract_woeth, data, backend, firmware, navigator, test_name)
run_test(contract_woeth, data, backend, firmware, navigator, test_name, wallet_addr)
Loading

0 comments on commit 4596769

Please sign in to comment.