diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b45a519..bd698708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,6 +151,7 @@ target_link_libraries(unittests PRIVATE add_compile_definitions(TESTVECTORS_DIR="${CMAKE_CURRENT_SOURCE_DIR}/tests/") add_compile_definitions(APP_TESTING=1) +add_compile_definitions(COMPILE_TEXTUAL=1) add_test(unittests ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittests) set_tests_properties(unittests PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests) diff --git a/app/Makefile b/app/Makefile index a18cb1b7..946673a5 100755 --- a/app/Makefile +++ b/app/Makefile @@ -61,6 +61,10 @@ ifndef ICONNAME $(error ICONNAME is not set) endif +ifneq ($(TARGET_NAME),TARGET_NANOS) + CFLAGS += -DCOMPILE_TEXTUAL +endif + include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform CFLAGS += -I$(MY_DIR)/../deps/tinycbor/src APP_SOURCE_PATH += $(MY_DIR)/../deps/tinycbor-ledger diff --git a/app/src/common/tx.c b/app/src/common/tx.c index 9a7c8a4e..bee6c3c1 100644 --- a/app/src/common/tx.c +++ b/app/src/common/tx.c @@ -78,9 +78,15 @@ static parser_tx_t tx_obj; const char *tx_parse(tx_type_e type) { +#ifndef COMPILE_TEXTUAL + if (type != tx_json) { + return parser_getErrorDescription(parser_unexpected_value); + } +#else if (type != tx_json && type != tx_textual) { return parser_getErrorDescription(parser_value_out_of_range); } +#endif MEMZERO(&tx_obj, sizeof(tx_obj)); tx_obj.tx_type = type; diff --git a/app/src/parser.c b/app/src/parser.c index c590eeb7..e8eb92ca 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -53,7 +53,9 @@ parser_error_t parser_parse(parser_context_t *ctx, CHECK_PARSER_ERR(parser_init_context(ctx, data, dataLen)) ctx->tx_obj = tx_obj; if (tx_obj->tx_type == tx_textual) { +#ifdef COMPILE_TEXTUAL CHECK_PARSER_ERR(_read_text_tx(ctx, tx_obj)) +#endif } else { CHECK_PARSER_ERR(_read_json_tx(ctx, tx_obj)) } @@ -82,11 +84,13 @@ parser_error_t parser_validate(const parser_context_t *ctx) { parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_items) { *num_items = 0; + if (ctx->tx_obj->tx_type == tx_textual) { +#ifdef COMPILE_TEXTUAL *num_items = app_mode_expert() ? (uint8_t) ctx->tx_obj->tx_text.n_containers : (uint8_t) (ctx->tx_obj->tx_text.n_containers - ctx->tx_obj->tx_text.n_expert); return parser_ok; +#endif } - return tx_display_numItems(num_items); } @@ -311,6 +315,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken, return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy); } +#ifdef COMPILE_TEXTUAL __Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx, Cbor_container *container, char *outKey, uint16_t outKeyLen, @@ -478,6 +483,7 @@ __Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx, return parser_ok; } +#endif __Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx, uint8_t displayIdx, @@ -535,11 +541,12 @@ parser_error_t parser_getItem(const parser_context_t *ctx, uint8_t pageIdx, uint8_t *pageCount) { if (ctx->tx_obj->tx_type == tx_textual) { +#ifdef COMPILE_TEXTUAL CHECK_PARSER_ERR(parser_getTextualItem(ctx,displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount)); - +#endif } else { CHECK_PARSER_ERR(parser_getJsonItem(ctx,displayIdx, outKey, outKeyLen, diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 0a3149d5..c937fb41 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -116,6 +116,7 @@ parser_error_t _read_json_tx(parser_context_t *c, __Z_UNUSED parser_tx_t *v) { return parser_ok; } +#ifdef COMPILE_TEXTUAL parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) { CborValue it; CborValue mapStruct_ptr; @@ -167,3 +168,4 @@ parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) { return parser_ok; } +#endif diff --git a/app/src/parser_txdef.h b/app/src/parser_txdef.h index c3c75146..693f3b70 100644 --- a/app/src/parser_txdef.h +++ b/app/src/parser_txdef.h @@ -103,7 +103,9 @@ typedef struct { union { tx_json_t tx_json; +#ifdef COMPILE_TEXTUAL tx_textual_t tx_text; +#endif }; } parser_tx_t; diff --git a/tests_zemu/tests/textual.test.ts b/tests_zemu/tests/textual.test.ts index 96532027..13b96dcf 100644 --- a/tests_zemu/tests/textual.test.ts +++ b/tests_zemu/tests/textual.test.ts @@ -29,6 +29,10 @@ jest.setTimeout(90000) describe('Textual', function () { // eslint-disable-next-line jest/expect-expect test.concurrent.each(DEVICE_MODELS)('can start and stop container', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) @@ -38,6 +42,10 @@ describe('Textual', function () { }) test.concurrent.each(DEVICE_MODELS)('sign basic textual', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) @@ -84,6 +92,10 @@ describe('Textual', function () { }) test.concurrent.each(DEVICE_MODELS)('sign basic textual expert', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) @@ -133,6 +145,10 @@ describe('Textual', function () { }) test.concurrent.each(DEVICE_MODELS)('sign basic textual eth ', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) @@ -182,6 +198,10 @@ describe('Textual', function () { }) test.concurrent.each(DEVICE_MODELS)('sign basic textual eth warning ', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name }) @@ -228,6 +248,10 @@ describe('Textual', function () { }) test.concurrent.each(DEVICE_MODELS)('sign basic textual evmos ', async function (m) { + if (m.name === 'nanos') { + // Skip the test for the nanos device + return; + } const sim = new Zemu(m.path) try { await sim.start({ ...defaultOptions, model: m.name })