Skip to content

Commit 58437cd

Browse files
authored
Revert "clean up unused code and update documentation (#8)"
This reverts commit c289dba.
1 parent 67c44fd commit 58437cd

7 files changed

Lines changed: 59 additions & 6 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
- master
1212
- main
1313
- develop
14-
- for_new_models
1514
pull_request:
1615

1716
jobs:

doc/APP_SPECIFICATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ The following standard Status Words are returned for all APDUs.
184184

185185
| SW | SW name | Description |
186186
| --- | --- | --- |
187-
| 9000 | SW_OK | success |
188187
| 6985 | SW_DENY | Rejected by user |
189188
| 6A86 | SW_WRONG_P1P2 | Either P1 or P2 is incorrect |
190189
| 6A87 | SW_WRONG_DATA_LENGTH | Lc or minimum APDU length is incorrect |
@@ -201,4 +200,5 @@ The following standard Status Words are returned for all APDUs.
201200
| B008 | SW_SIGNATURE_FAIL | Signature of data(tx or personal msg) failed |
202201
| B009 | SW_PERSONAL_MSG_PARSING_FAIL | Failed to parse personal msg |
203202
| B00A | SW_INVALID_TRANSACTION | Invalid transaction |
204-
| B00B | SW_INVALID_PATH | Invalid path |
203+
| B00B | SW_HASH_FAILED | Msg hash failed |
204+
| B00C | SW_INVALID_PATH | Invalid path |

src/transaction/utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stddef.h>
66
#include <string.h>
77

8+
#include "types.h"
89
#include "../types.h"
910

1011
/**

src/ui/nbgl_display_transaction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static int ui_display_normal_transaction() {
263263
return io_send_sw(SW_INVALID_TRANSACTION);
264264
}
265265
if (!handle_params(&G_context.tx_info.transaction, method, g_pairs, &g_pairList.nbPairs)) {
266-
return io_send_sw(SW_INVALID_TRANSACTION);
266+
return io_send_sw(SW_INVALID_TRANSACTION); // todo : check all the words
267267
}
268268

269269
g_pairs[g_pairList.nbPairs].item = GAS_FEE;

unit-tests/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ include_directories($ENV{BOLOS_SDK}/target/nanos2/include)
5353
include_directories($ENV{BOLOS_SDK}/lib_cxng/include)
5454

5555
add_executable(test_tx_parser test_tx_parser.c)
56+
# add_executable(test_tx_utils test_tx_utils.c)
5657

5758
add_library(base58 SHARED $ENV{BOLOS_SDK}/lib_standard_app/base58.c)
5859
add_library(bip32 SHARED $ENV{BOLOS_SDK}/lib_standard_app/bip32.c)
@@ -84,5 +85,10 @@ target_link_libraries(test_tx_parser PUBLIC
8485
transaction_utils
8586
transaction_contract)
8687

88+
# target_link_libraries(test_tx_utils PUBLIC
89+
# cmocka
90+
# gcov
91+
# transaction_utils)
8792

88-
add_test(test_tx_parser test_tx_parser)
93+
add_test(test_tx_parser test_tx_parser)
94+
#add_test(test_tx_utils test_tx_utils)

unit-tests/test_tx_parser.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010

1111
#include "transaction/deserialize.h"
1212
#include "transaction/parse.h"
13-
13+
#include "types.h"
14+
15+
size_t strlcpy(char *dst, const char *src, size_t size) {
16+
size_t src_len = strlen(src);
17+
if (size == 0) return src_len;
18+
size_t copy_len = (src_len >= size) ? size - 1 : src_len;
19+
memcpy(dst, src, copy_len);
20+
dst[copy_len] = '\0';
21+
return src_len;
22+
}
1423

1524
static void test_tx_gov_withdraw_parser(void **state) {
1625
(void) state;

unit-tests/test_tx_utils.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <stdarg.h>
2+
#include <stddef.h>
3+
#include <setjmp.h>
4+
#include <stdint.h>
5+
#include <stdbool.h>
6+
#include <string.h>
7+
8+
#include <cmocka.h>
9+
10+
#include "transaction/utils.h"
11+
#include "types.h"
12+
13+
static void test_tx_utils(void **state) {
14+
(void) state;
15+
16+
const uint8_t good_ascii[] = {0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21}; // Hello!
17+
const uint8_t bad_ascii[] = {0x32, 0xc3, 0x97, 0x32, 0x3d, 0x34}; // 2×2=4
18+
19+
assert_true(transaction_utils_check_encoding(good_ascii, sizeof(good_ascii)));
20+
assert_false(transaction_utils_check_encoding(bad_ascii, sizeof(bad_ascii)));
21+
22+
char output[MAX_MEMO_LEN] = {0};
23+
assert_true(transaction_utils_format_memo(good_ascii, //
24+
sizeof(good_ascii), //
25+
output, //
26+
sizeof(output)));
27+
assert_string_equal(output, "Hello!");
28+
assert_false(transaction_utils_format_memo(good_ascii, //
29+
sizeof(good_ascii), //
30+
output, //
31+
sizeof(good_ascii))); // dst_len too small
32+
}
33+
34+
int main() {
35+
const struct CMUnitTest tests[] = {cmocka_unit_test(test_tx_utils)};
36+
37+
return cmocka_run_group_tests(tests, NULL, NULL);
38+
}

0 commit comments

Comments
 (0)