Skip to content

Commit

Permalink
disable textual for nanoS
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Mar 5, 2024
1 parent e0af516 commit 40a11fa
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions app/src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -167,3 +168,4 @@ parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) {

return parser_ok;
}
#endif
2 changes: 2 additions & 0 deletions app/src/parser_txdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ typedef struct {

union {
tx_json_t tx_json;
#ifdef COMPILE_TEXTUAL
tx_textual_t tx_text;
#endif
};
} parser_tx_t;

Expand Down
24 changes: 24 additions & 0 deletions tests_zemu/tests/textual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down Expand Up @@ -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 })
Expand Down

0 comments on commit 40a11fa

Please sign in to comment.