diff --git a/src/handle_finalize.c b/src/handle_finalize.c index 6b2e7a8..b08dfd7 100644 --- a/src/handle_finalize.c +++ b/src/handle_finalize.c @@ -2,13 +2,10 @@ void handle_finalize(void *parameters) { ethPluginFinalize_t *msg = (ethPluginFinalize_t *) parameters; - context_t *context = (context_t *) msg->pluginContext; msg->uiType = ETH_UI_TYPE_GENERIC; + // 2 additional screens are required to display the `token and `beneficiary` fields msg->numScreens = 2; - - // msg->tokenLookup1 = context->poap_token; - msg->result = ETH_PLUGIN_RESULT_OK; } diff --git a/src/handle_init_contract.c b/src/handle_init_contract.c index 96bd091..90788a0 100644 --- a/src/handle_init_contract.c +++ b/src/handle_init_contract.c @@ -1,5 +1,6 @@ #include "poap_plugin.h" +// Called once to init. void handle_init_contract(void *parameters) { ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters; @@ -32,7 +33,6 @@ void handle_init_contract(void *parameters) { // Set `next_param` to be the first field we expect to parse. switch (context->selectorIndex) { case MINT_TOKEN: - // context->skip = 1; context->next_param = EVENT_ID; break; default: diff --git a/src/handle_provide_parameter.c b/src/handle_provide_parameter.c index b7958f7..ec34e56 100644 --- a/src/handle_provide_parameter.c +++ b/src/handle_provide_parameter.c @@ -2,12 +2,13 @@ // Copies the whole parameter (32 bytes long) from `src` to `dst`. // Useful for numbers, data... -static void copy_parameter(uint8_t *dst, size_t dst_len, uint8_t *src) { +static void copy_parameter(uint8_t *dst, uint8_t *src) { memcpy(dst, src, PARAMETER_LENGTH); } -// Copy token sent parameter to poap_token + +// Copy token sent parameter to token_id static void handle_token(const ethPluginProvideParameter_t *msg, context_t *context) { - copy_parameter(context->poap_token, sizeof(context->poap_token), msg->parameter); + copy_parameter(context->token_id, msg->parameter); } static void handle_beneficiary(const ethPluginProvideParameter_t *msg, context_t *context) { @@ -23,14 +24,13 @@ static void handle_mint_token(ethPluginProvideParameter_t *msg, context_t *conte case EVENT_ID: context->next_param = TOKEN; break; - case TOKEN: // path[1] -> id of the token received + case TOKEN: // id of the token received handle_token(msg, context); context->next_param = BENEFICIARY; break; case BENEFICIARY: // to handle_beneficiary(msg, context); context->next_param = NONE; - // context->skip = 1; break; case NONE: break; @@ -58,7 +58,7 @@ void handle_provide_parameter(void *parameters) { msg->parameterOffset); return; } - context->offset = 0; + context->offset = 0; // Reset offset switch (context->selectorIndex) { case MINT_TOKEN: handle_mint_token(msg, context); diff --git a/src/handle_provide_token.c b/src/handle_provide_token.c deleted file mode 100644 index bf3986c..0000000 --- a/src/handle_provide_token.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "poap_plugin.h" - -void handle_provide_token(void *parameters) { - ethPluginProvideToken_t *msg = (ethPluginProvideToken_t *) parameters; - context_t *context = (context_t *) msg->pluginContext; - - PRINTF("POAP plugin provide token: 0x%p\n", msg->token1); - - if (msg->token1 != NULL) { - context->decimals = msg->token1->decimals; - strlcpy(context->ticker, (char *) msg->token1->ticker, sizeof(context->ticker)); - context->tokens_found |= TOKEN_FOUND; - } else { - context->decimals = DEFAULT_DECIMAL; - msg->additionalScreens++; - } - msg->result = ETH_PLUGIN_RESULT_OK; -} \ No newline at end of file diff --git a/src/handle_query_contract_ui.c b/src/handle_query_contract_ui.c index 4fa693c..2044f4f 100644 --- a/src/handle_query_contract_ui.c +++ b/src/handle_query_contract_ui.c @@ -4,12 +4,7 @@ static void set_token_ui(ethQueryContractUI_t *msg, context_t *context) { strlcpy(msg->title, "Token", msg->titleLength); - amountToString(context->poap_token, - sizeof(context->poap_token), - 0, - "", - msg->msg, - msg->msgLength); + amountToString(context->token_id, sizeof(context->token_id), 0, "", msg->msg, msg->msgLength); } // Set UI for "Beneficiary" screen. @@ -32,17 +27,23 @@ static void set_warning_ui(ethQueryContractUI_t *msg, // Helper function that returns the enum corresponding to the screen that should be displayed. static screens_t get_screen(const ethQueryContractUI_t *msg, const context_t *context) { uint8_t index = msg->screenIndex; + bool token_not_found = !context->token_id; switch (index) { case 0: - return TOKEN_SCREEN; + if (!token_not_found) { + return TOKEN_SCREEN; + } else if (token_not_found) { + return WARN_SCREEN; + } break; case 1: - return BENEFICIARY_SCREEN; + if (!token_not_found) { + return BENEFICIARY_SCREEN; + } else if (token_not_found) { + return WARN_SCREEN; + } break; - // case 2: - // return WARN_SCREEN; - // break; default: return ERROR; break; diff --git a/src/main.c b/src/main.c index 00015b2..b2d45af 100644 --- a/src/main.c +++ b/src/main.c @@ -43,9 +43,6 @@ void dispatch_plugin_calls(int message, void *parameters) { case ETH_PLUGIN_FINALIZE: handle_finalize(parameters); break; - case ETH_PLUGIN_PROVIDE_TOKEN: - handle_provide_token(parameters); - break; case ETH_PLUGIN_QUERY_CONTRACT_ID: handle_query_contract_id(parameters); break; diff --git a/src/poap_plugin.h b/src/poap_plugin.h index ef0e487..0863e1e 100644 --- a/src/poap_plugin.h +++ b/src/poap_plugin.h @@ -11,11 +11,6 @@ #define PARAMETER_LENGTH 32 #define RUN_APPLICATION 1 -// Number of decimals used when the token wasn't found in the CAL. -#define DEFAULT_DECIMAL WEI_TO_ETHER - -// Ticker used when the token wasn't found in the CAL. -#define DEFAULT_TICKER "" typedef enum { MINT_TOKEN, } selector_t; @@ -41,14 +36,14 @@ extern const uint8_t *const POAP_SELECTORS[NUM_SELECTORS]; typedef struct context_t { // For display. uint8_t beneficiary[ADDRESS_LENGTH]; - uint8_t poap_token[PARAMETER_LENGTH]; // not crypto token dedicated poap token value int number + uint8_t token_id[PARAMETER_LENGTH]; // not crypto token dedicated poap token value int number char ticker[MAX_TICKER_LEN]; - uint8_t decimals; // For parsing data. uint16_t offset; uint16_t checkpoint; uint8_t skip; + uint8_t decimals; uint8_t next_param; uint8_t tokens_found; @@ -64,5 +59,4 @@ void handle_provide_parameter(void *parameters); void handle_query_contract_ui(void *parameters); void handle_init_contract(void *parameters); void handle_finalize(void *parameters); -void handle_provide_token(void *parameters); void handle_query_contract_id(void *parameters); \ No newline at end of file diff --git a/tests/build_local_test_elfs.sh b/tests/build_local_test_elfs.sh index 7957afd..fe0533f 100755 --- a/tests/build_local_test_elfs.sh +++ b/tests/build_local_test_elfs.sh @@ -15,7 +15,7 @@ echo "*Building elfs for Nano S..." echo "**Building app-poap for Nano S..." make clean BOLOS_SDK=$NANOS_SDK -make -j DEBUG=10 BOLOS_SDK=$NANOS_SDK +make -j DEBUG=1 BOLOS_SDK=$NANOS_SDK cp bin/app.elf "tests/elfs/poap_nanos.elf" echo "**Building app-ethereum for Nano S..." @@ -27,18 +27,18 @@ cd - cp "${APP_ETHEREUM}/bin/app.elf" "tests/elfs/ethereum_nanos.elf" -# echo "*Building elfs for Nano X..." +echo "*Building elfs for Nano X..." -# echo "**Building app-poap for Nano X..." -# make clean BOLOS_SDK=$NANOX_SDK -# make -j DEBUG=1 BOLOS_SDK=$NANOX_SDK -# cp bin/app.elf "tests/elfs/poap_nanox.elf" +echo "**Building app-poap for Nano X..." +make clean BOLOS_SDK=$NANOX_SDK +make -j DEBUG=1 BOLOS_SDK=$NANOX_SDK +cp bin/app.elf "tests/elfs/poap_nanox.elf" -# echo "**Building app-ethereum for Nano X..." -# cd $APP_ETHEREUM -# make clean BOLOS_SDK=$NANOX_SDK -# make -j DEBUG=1 BOLOS_SDK=$NANOX_SDK CHAIN=ethereum BYPASS_SIGNATURES=1 ALLOW_DATA=1 -# cd - -# cp "${APP_ETHEREUM}/bin/app.elf" "tests/elfs/ethereum_nanox.elf" +echo "**Building app-ethereum for Nano X..." +cd $APP_ETHEREUM +make clean BOLOS_SDK=$NANOX_SDK +make -j DEBUG=1 BOLOS_SDK=$NANOX_SDK CHAIN=ethereum BYPASS_SIGNATURES=1 ALLOW_DATA=1 +cd - +cp "${APP_ETHEREUM}/bin/app.elf" "tests/elfs/ethereum_nanox.elf" echo "done" \ No newline at end of file diff --git a/tests/elfs/ethereum_nanox.elf b/tests/elfs/ethereum_nanox.elf index 24199fc..916a232 100755 Binary files a/tests/elfs/ethereum_nanox.elf and b/tests/elfs/ethereum_nanox.elf differ diff --git a/tests/elfs/poap_nanos.elf b/tests/elfs/poap_nanos.elf index e86ae63..245cf78 100755 Binary files a/tests/elfs/poap_nanos.elf and b/tests/elfs/poap_nanos.elf differ diff --git a/tests/elfs/poap_nanox.elf b/tests/elfs/poap_nanox.elf new file mode 100755 index 0000000..5d616fa Binary files /dev/null and b/tests/elfs/poap_nanox.elf differ diff --git a/tests/snapshots/nanos_mint_token/00000.png b/tests/snapshots/nanos_mint_token/00000.png new file mode 100644 index 0000000..2994983 Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00000.png differ diff --git a/tests/snapshots/nanos_mint_token/00001.png b/tests/snapshots/nanos_mint_token/00001.png new file mode 100644 index 0000000..cf9f3be Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00001.png differ diff --git a/tests/snapshots/nanos_mint_token/00002.png b/tests/snapshots/nanos_mint_token/00002.png new file mode 100644 index 0000000..faed6cc Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00002.png differ diff --git a/tests/snapshots/nanos_mint_token/00003.png b/tests/snapshots/nanos_mint_token/00003.png new file mode 100644 index 0000000..0a3e820 Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00003.png differ diff --git a/tests/snapshots/nanos_mint_token/00004.png b/tests/snapshots/nanos_mint_token/00004.png new file mode 100644 index 0000000..e9a617b Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00004.png differ diff --git a/tests/snapshots/nanos_mint_token/00005.png b/tests/snapshots/nanos_mint_token/00005.png new file mode 100644 index 0000000..7767353 Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00005.png differ diff --git a/tests/snapshots/nanos_mint_token/00006.png b/tests/snapshots/nanos_mint_token/00006.png new file mode 100644 index 0000000..c2fb5aa Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00006.png differ diff --git a/tests/snapshots/nanos_mint_token/00007.png b/tests/snapshots/nanos_mint_token/00007.png new file mode 100644 index 0000000..3158ea6 Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00007.png differ diff --git a/tests/snapshots/nanos_mint_token/00008.png b/tests/snapshots/nanos_mint_token/00008.png new file mode 100644 index 0000000..0bef4f3 Binary files /dev/null and b/tests/snapshots/nanos_mint_token/00008.png differ diff --git a/tests/src/mint_token.test.js b/tests/src/mint_token.test.js index 5eefe77..20a1eeb 100644 --- a/tests/src/mint_token.test.js +++ b/tests/src/mint_token.test.js @@ -13,11 +13,11 @@ const devices = [ label: "Nano S", steps: 7, // <= Define the number of steps for this test case and this device }, - // { - // name: "nanox", - // label: "Nano X", - // steps: 5, // <= Define the number of steps for this test case and this device - // }, + { + name: "nanox", + label: "Nano X", + steps: 5, // <= Define the number of steps for this test case and this device + }, ]; devices.forEach((device) => diff --git a/tests/src/test.fixture.js b/tests/src/test.fixture.js index 19c83eb..837d776 100644 --- a/tests/src/test.fixture.js +++ b/tests/src/test.fixture.js @@ -9,7 +9,7 @@ const sim_options_generic = { logging: true, X11: true, startDelay: 5000, - custom: "", + custom: "-k 2.0", }; const Resolve = require("path").resolve;