Skip to content

Commit

Permalink
Merge pull request #7 from blooo-io/feat/LAPP-5-implement-minttoken-t…
Browse files Browse the repository at this point in the history
…ests-3

refactor: mint token code and test, deleted handle provide token method
  • Loading branch information
lisaoulmi authored Nov 25, 2021
2 parents cf597d3 + 6f91da4 commit 5baeebd
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 69 deletions.
5 changes: 1 addition & 4 deletions src/handle_finalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/handle_init_contract.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "poap_plugin.h"

// Called once to init.
void handle_init_contract(void *parameters) {
ethPluginInitContract_t *msg = (ethPluginInitContract_t *) parameters;

Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions src/handle_provide_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 0 additions & 18 deletions src/handle_provide_token.c

This file was deleted.

23 changes: 12 additions & 11 deletions src/handle_query_contract_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 2 additions & 8 deletions src/poap_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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);
24 changes: 12 additions & 12 deletions tests/build_local_test_elfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand All @@ -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"
Binary file modified tests/elfs/ethereum_nanox.elf
Binary file not shown.
Binary file modified tests/elfs/poap_nanos.elf
Binary file not shown.
Binary file added tests/elfs/poap_nanox.elf
Binary file not shown.
Binary file added tests/snapshots/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/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/nanos_mint_token/00008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions tests/src/mint_token.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test.fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const sim_options_generic = {
logging: true,
X11: true,
startDelay: 5000,
custom: "",
custom: "-k 2.0",
};

const Resolve = require("path").resolve;
Expand Down

0 comments on commit 5baeebd

Please sign in to comment.