Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/ldg 651 implement method redeem #7

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void handle_finalize(ethPluginFinalize_t *msg) {
msg->numScreens = 1;
break;
case MINT:
case REDEEM:
msg->numScreens = 4;
break;
default:
Expand Down
1 change: 1 addition & 0 deletions src/handle_init_contract.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void handle_init_contract(ethPluginInitContract_t *msg) {
context->next_param = BENEFICIARY;
break;
case MINT:
case REDEEM:
context->next_param = ADDRESS;
break;
// Keep this
Expand Down
5 changes: 3 additions & 2 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static void handle_beneficiary(ethPluginProvideParameter_t *msg, context_t *cont
}
}

static void handle_mint(ethPluginProvideParameter_t *msg, context_t *context) {
static void handle_honey_functions(ethPluginProvideParameter_t *msg, context_t *context) {
switch (context->next_param) {
case ADDRESS:
copy_address(context->address, msg->parameter, sizeof(context->address));
Expand Down Expand Up @@ -64,7 +64,8 @@ void handle_provide_parameter(ethPluginProvideParameter_t *msg) {
handle_beneficiary(msg, context);
break;
case MINT:
handle_mint(msg, context);
case REDEEM:
handle_honey_functions(msg, context);
break;
default:
PRINTF("Selector Index not supported: %d\n", context->selectorIndex);
Expand Down
4 changes: 4 additions & 0 deletions src/handle_query_contract_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ void handle_query_contract_id(ethQueryContractID_t *msg) {
strlcpy(msg->version, "Mint", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
break;
case REDEEM:
strlcpy(msg->version, "Redeem", msg->versionLength);
msg->result = ETH_PLUGIN_RESULT_OK;
break;
default:
PRINTF("Selector index: %d not supported\n", context->selectorIndex);
msg->result = ETH_PLUGIN_RESULT_ERROR;
Expand Down
4 changes: 4 additions & 0 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
break;
case DELEGATE:
case MINT:
case REDEEM:
strlcpy(msg->title, "Beneficiary", msg->titleLength);
break;
default:
Expand All @@ -77,6 +78,7 @@ static bool set_beneficiary_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool set_address_ui(ethQueryContractUI_t *msg, context_t *context) {
switch (context->selectorIndex) {
case MINT:
case REDEEM:
strlcpy(msg->title, "Address", msg->titleLength);
break;
default:
Expand All @@ -101,6 +103,7 @@ static bool set_address_ui(ethQueryContractUI_t *msg, context_t *context) {
static bool set_boolean_ui(ethQueryContractUI_t *msg, context_t *context) {
switch (context->selectorIndex) {
case MINT:
case REDEEM:
strlcpy(msg->title, "Basket Mode", msg->titleLength);
break;
default:
Expand Down Expand Up @@ -143,6 +146,7 @@ void handle_query_contract_ui(ethQueryContractUI_t *msg) {
}
break;
case MINT:
case REDEEM:
switch (msg->screenIndex) {
case 0:
ret = set_address_ui(msg, context);
Expand Down
3 changes: 2 additions & 1 deletion src/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#define SELECTORS_LIST(X) \
X(CREATE_REWARD_VAULT, 0x577ee5c7) \
X(DELEGATE, 0x5c19a95c) \
X(MINT, 0x328ebaf7)
X(MINT, 0x328ebaf7) \
X(REDEEM, 0xed596315)

// Xmacro helpers to define the enum and map
// Do not modify !
Expand Down
Binary file added tests/snapshots/flex/test_redeem/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/flex/test_redeem/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/flex/test_redeem/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/flex/test_redeem/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/flex/test_redeem/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/flex/test_redeem/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_redeem/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_redeem/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/stax/test_redeem/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/stax/test_redeem/00001.png
Binary file added tests/snapshots/stax/test_redeem/00002.png
Binary file added tests/snapshots/stax/test_redeem/00003.png
Binary file added tests/snapshots/stax/test_redeem/00004.png
Binary file added tests/snapshots/stax/test_redeem/00005.png
76 changes: 76 additions & 0 deletions tests/test_redeem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from pathlib import Path
import json
import os

from web3 import Web3
from eth_typing import ChainId

from ledger_app_clients.ethereum.client import EthAppClient
import ledger_app_clients.ethereum.response_parser as ResponseParser
from ledger_app_clients.ethereum.utils import get_selector_from_data, recover_transaction
from ragger.navigator import NavInsID

from .utils import get_appname_from_makefile, DERIVATION_PATH


ROOT_SCREENSHOT_PATH = Path(__file__).parent
ABIS_FOLDER = "%s/abis" % (os.path.dirname(__file__))

PLUGIN_NAME = get_appname_from_makefile()


with open("%s/0xb05b8099d9de1e5cf07cd135d059d5a5ed484388.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])
)


# EDIT THIS: build your own test
def test_redeem(backend, firmware, navigator, test_name, wallet_addr):
client = EthAppClient(backend)

data = contract.encode_abi("redeem", [
bytes.fromhex("015fd589F4f1A33ce4487E12714e1B15129c9329"),
Web3.to_wei(2.0, "ether"),
bytes.fromhex("7437c4BDDFBad716DBf102E6C5a238Ce81cBac7a"),
True,
])

# first setup the external plugin
client.set_external_plugin(PLUGIN_NAME,
contract.address,
# Extract function selector from the encoded data
get_selector_from_data(data))

tx_params = {
"nonce": 20,
"maxFeePerGas": Web3.to_wei(145, "gwei"),
"maxPriorityFeePerGas": Web3.to_wei(1.5, "gwei"),
"gas": 173290,
"to": contract.address,
"value": 0,
"chainId": ChainId.ETH,
"data": data
}
# send the transaction
with client.sign(DERIVATION_PATH, tx_params):
# Validate the on-screen request by performing the navigation appropriate for this device
if firmware.is_nano:
navigator.navigate_until_text_and_compare(NavInsID.RIGHT_CLICK,
[NavInsID.BOTH_CLICK],
"Accept",
ROOT_SCREENSHOT_PATH,
test_name)
else:
navigator.navigate_until_text_and_compare(NavInsID.SWIPE_CENTER_TO_LEFT,
[NavInsID.USE_CASE_REVIEW_CONFIRM,
NavInsID.USE_CASE_STATUS_DISMISS],
"Hold to sign",
ROOT_SCREENSHOT_PATH,
test_name)
# verify signature
vrs = ResponseParser.signature(client.response().data)
addr = recover_transaction(tx_params, vrs)
assert addr == wallet_addr.get()
Loading