From 45e5a20755f479e1591dd15c7ef6dfa92742dc0f Mon Sep 17 00:00:00 2001 From: Yehor Popovych Date: Fri, 31 May 2024 09:50:34 +0100 Subject: [PATCH] fixed unit tests --- unit-tests/test_address.c | 23 +- unit-tests/test_bip32.c | 16 +- unit-tests/test_ergo_tree.c | 29 +- unit-tests/test_full_tx.c | 666 ++++++++++++--------------------- unit-tests/test_input_frame.c | 105 ++---- unit-tests/test_tx_ser_box.c | 572 ++++++++++++---------------- unit-tests/test_tx_ser_input.c | 383 +++++++------------ unit-tests/test_tx_ser_table.c | 265 +++++-------- 8 files changed, 744 insertions(+), 1315 deletions(-) diff --git a/unit-tests/test_address.c b/unit-tests/test_address.c index e790b013..8dca0f62 100644 --- a/unit-tests/test_address.c +++ b/unit-tests/test_address.c @@ -13,21 +13,16 @@ static void test_ergo_address_from_pubkey(void **state) { uint8_t network = 0; const uint8_t public_key[65] = { - 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, - 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, - 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, - 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, 0x59, - 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, - 0x1a, 0x60, 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, - 0xe5, 0xcf, 0xf1, 0x0a, 0xe7 - }; + 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, + 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, + 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, + 0x59, 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, 0x1a, 0x60, + 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, 0xe5, 0xcf, 0xf1, 0x0a, 0xe7}; uint8_t address[38]; - uint8_t expected[38] = { - 0x01, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, - 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, - 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, - 0x5a, 0xbd, 0xcb, 0x2a, 0xb5, 0x2d, 0xca, 0xce - }; + uint8_t expected[38] = {0x01, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, + 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, + 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, + 0x5a, 0xbd, 0xcb, 0x2a, 0xb5, 0x2d, 0xca, 0xce}; assert_true(ergo_address_from_pubkey(network, public_key, address)); assert_memory_equal(address, expected, sizeof(expected)); } diff --git a/unit-tests/test_bip32.c b/unit-tests/test_bip32.c index e59b7bf4..5daa5cc9 100644 --- a/unit-tests/test_bip32.c +++ b/unit-tests/test_bip32.c @@ -12,20 +12,12 @@ #define ARRAYLEN(array) (sizeof(array) / sizeof(array[0])) -#define BIP32_VALIDATE_OK(tvar, type) \ - b = bip32_path_validate(tvar, \ - ARRAYLEN(tvar), \ - BIP32_HARDENED(44), \ - BIP32_HARDENED(429), \ - type); \ +#define BIP32_VALIDATE_OK(tvar, type) \ + b = bip32_path_validate(tvar, ARRAYLEN(tvar), BIP32_HARDENED(44), BIP32_HARDENED(429), type); \ assert_true(b); -#define BIP32_VALIDATE_ERR(tvar, type) \ - b = bip32_path_validate(tvar, \ - ARRAYLEN(tvar), \ - BIP32_HARDENED(44), \ - BIP32_HARDENED(429), \ - type); \ +#define BIP32_VALIDATE_ERR(tvar, type) \ + b = bip32_path_validate(tvar, ARRAYLEN(tvar), BIP32_HARDENED(44), BIP32_HARDENED(429), type); \ assert_false(b); static void test_bip32_validate_account(void **state) { diff --git a/unit-tests/test_ergo_tree.c b/unit-tests/test_ergo_tree.c index 87f7e1da..d8c0331e 100644 --- a/unit-tests/test_ergo_tree.c +++ b/unit-tests/test_ergo_tree.c @@ -12,22 +12,17 @@ static void test_ergo_tree_generate_p2pk(void **state) { (void) state; const uint8_t raw_public_key[PUBLIC_KEY_LEN] = { - 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, - 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, - 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, - 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, 0x59, - 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, - 0x1a, 0x60, 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, - 0xe5, 0xcf, 0xf1, 0x0a, 0xe7 - }; + 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, + 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, + 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, + 0x59, 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, 0x1a, 0x60, + 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, 0xe5, 0xcf, 0xf1, 0x0a, 0xe7}; uint8_t tree[ERGO_TREE_P2PK_LEN] = {0}; ergo_tree_generate_p2pk(raw_public_key, tree); - uint8_t expected[ERGO_TREE_P2PK_LEN] = { - 0x00, 0x08, 0xcd, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, - 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, - 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, - 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a - }; + uint8_t expected[ERGO_TREE_P2PK_LEN] = {0x00, 0x08, 0xcd, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, + 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, + 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, + 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a}; assert_memory_equal(tree, expected, sizeof(expected)); } @@ -45,8 +40,7 @@ static void test_ergo_tree_miners_fee_tree_mainnet(void **state) { 0xf8, 0x17, 0x98, 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, 0x8c, 0xc7, 0xa7, 0x01, 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, 0x73, 0x00, 0x00, 0x01, 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, 0x00, 0x74, - 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04 - }; + 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04}; assert_int_equal(size, sizeof(expected)); assert_memory_equal(tree, expected, sizeof(expected)); } @@ -65,8 +59,7 @@ static void test_ergo_tree_miners_fee_tree_testnet(void **state) { 0xf8, 0x17, 0x98, 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, 0x8c, 0xc7, 0xa7, 0x01, 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, 0x73, 0x00, 0x00, 0x01, 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, 0x00, 0x74, - 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04 - }; + 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04}; assert_int_equal(size, sizeof(expected)); assert_memory_equal(tree, expected, sizeof(expected)); } diff --git a/unit-tests/test_full_tx.c b/unit-tests/test_full_tx.c index 75136014..86678b56 100644 --- a/unit-tests/test_full_tx.c +++ b/unit-tests/test_full_tx.c @@ -89,8 +89,6 @@ static void test_simple_send_tx(void** state) { 0xc7, 0x18, 0x6d, 0x8d, 0x41, 0x78, 0x01, 0x58, 0xd5, 0xb3, 0xbe, 0x56, 0x45, 0x56, 0x4a, 0x5d}; - - // Calculating hash assert_true(blake2b_256_finalize(&hash, tx_id)); @@ -116,31 +114,17 @@ static void test_ergo_tx_serializer_full_init(void** state) { uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - assert_int_equal( - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + token_table_t tokens_table = {0}; + assert_int_equal(ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table), + ERGO_TX_SERIALIZER_FULL_RES_OK); uint8_t expected_hash[] = {0x01}; - uint8_t *data; + uint8_t* data; size_t data_len; _cx_blake2b_get_data(context.hash, &data, &data_len); assert_int_equal(data_len, sizeof(expected_hash)); @@ -150,9 +134,8 @@ static void test_ergo_tx_serializer_full_init(void** state) { assert_int_equal(context.data_inputs_count, data_inputs_count); assert_int_equal(context.outputs_count, outputs_count); assert_int_equal(tokens_table.count, 0); - assert_memory_equal(context.tokens_table, &tokens_table, sizeof(tokens_table)); - assert_int_equal(context.table_ctx.tokens_count, tokens_count); - assert_memory_equal(context.table_ctx.tokens_table, &tokens_table, sizeof(tokens_table)); + assert_int_equal(context.table_ctx.distinct_tokens_count, tokens_count); + assert_ptr_equal(context.table_ctx.tokens_table, &tokens_table); assert_int_equal(context.state, ERGO_TX_SERIALIZER_FULL_STATE_TOKENS_STARTED); } @@ -166,31 +149,17 @@ static void test_ergo_tx_serializer_full_init_zero_tokens(void** state) { uint8_t tokens_count = 0; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - assert_int_equal( - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + token_table_t tokens_table = {0}; + assert_int_equal(ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table), + ERGO_TX_SERIALIZER_FULL_RES_OK); uint8_t expected_hash[] = {0x01}; - uint8_t *data; + uint8_t* data; size_t data_len; _cx_blake2b_get_data(context.hash, &data, &data_len); assert_int_equal(data_len, sizeof(expected_hash)); @@ -200,8 +169,8 @@ static void test_ergo_tx_serializer_full_init_zero_tokens(void** state) { assert_int_equal(context.data_inputs_count, data_inputs_count); assert_int_equal(context.outputs_count, outputs_count); assert_int_equal(tokens_table.count, 0); - assert_memory_equal(context.tokens_table, &tokens_table, sizeof(tokens_table)); - assert_int_equal(context.table_ctx.tokens_count, tokens_count); + assert_ptr_equal(context.table_ctx.tokens_table, &tokens_table); + assert_int_equal(context.table_ctx.distinct_tokens_count, tokens_count); assert_int_equal(context.state, ERGO_TX_SERIALIZER_FULL_STATE_INPUTS_STARTED); assert_int_equal(context.input_ctx.state, ERGO_TX_SERIALIZER_INPUT_STATE_FINISHED); } @@ -216,40 +185,21 @@ static void test_ergo_tx_serializer_full_add_tokens(void** state) { uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - assert_int_equal( - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + token_table_t tokens_table = {0}; + assert_int_equal(ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table), + ERGO_TX_SERIALIZER_FULL_RES_OK); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - assert_int_equal( - ergo_tx_serializer_full_add_tokens(&context, &tokens), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_tokens(&context, &tokens), + ERGO_TX_SERIALIZER_FULL_RES_OK); assert_int_equal(context.state, ERGO_TX_SERIALIZER_FULL_STATE_INPUTS_STARTED); assert_int_equal(context.input_ctx.state, ERGO_TX_SERIALIZER_INPUT_STATE_FINISHED); } @@ -264,51 +214,29 @@ static void test_ergo_tx_serializer_full_add_input(void** state) { uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + token_table_t tokens_table = {0}; + ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); ergo_tx_serializer_full_add_tokens(&context, &tokens); - uint8_t box_id[32] = { - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03 - }; + uint8_t box_id[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; uint8_t token_frames_count = 1; uint32_t context_extension_data_size = 2; - assert_int_equal( - ergo_tx_serializer_full_add_input( - &context, - box_id, - token_frames_count, - context_extension_data_size - ), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_input(&context, + box_id, + token_frames_count, + context_extension_data_size), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_input_tokens(void** state) { @@ -321,61 +249,39 @@ static void test_ergo_tx_serializer_full_add_input_tokens(void** state) { uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + token_table_t tokens_table = {0}; + ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); ergo_tx_serializer_full_add_tokens(&context, &tokens); - uint8_t box_id[32] = { - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03 - }; + uint8_t box_id[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; uint8_t token_frames_count = 1; uint32_t context_extension_data_size = 2; - ergo_tx_serializer_full_add_input( - &context, - box_id, - token_frames_count, - context_extension_data_size - ); + ergo_tx_serializer_full_add_input(&context, + box_id, + token_frames_count, + context_extension_data_size); uint8_t token_frame_index = 0; - uint8_t input_tokens_array[40] = { - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 - }; + uint8_t input_tokens_array[] = {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; BUFFER_FROM_ARRAY(input_tokens, input_tokens_array, sizeof(input_tokens_array)); - assert_int_equal( - ergo_tx_serializer_full_add_input_tokens(&context, box_id, token_frame_index, &input_tokens), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_input_tokens(&context, + box_id, + token_frame_index, + &input_tokens), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_input_context_extension(void** state) { @@ -388,66 +294,40 @@ static void test_ergo_tx_serializer_full_add_input_context_extension(void** stat uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + token_table_t tokens_table = {0}; + ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); ergo_tx_serializer_full_add_tokens(&context, &tokens); - uint8_t box_id[32] = { - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03 - }; + uint8_t box_id[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; uint8_t token_frames_count = 1; uint32_t context_extension_data_size = 2; - ergo_tx_serializer_full_add_input( - &context, - box_id, - token_frames_count, - context_extension_data_size - ); + ergo_tx_serializer_full_add_input(&context, + box_id, + token_frames_count, + context_extension_data_size); uint8_t token_frame_index = 0; - uint8_t input_tokens_array[40] = { - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 - }; + uint8_t input_tokens_array[] = {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; BUFFER_FROM_ARRAY(input_tokens, input_tokens_array, sizeof(input_tokens_array)); ergo_tx_serializer_full_add_input_tokens(&context, box_id, token_frame_index, &input_tokens); - uint8_t extension_chunk_array[2] = { - 0x01, 0x02 - }; + uint8_t extension_chunk_array[2] = {0x01, 0x02}; BUFFER_FROM_ARRAY(extension_chunk, extension_chunk_array, sizeof(extension_chunk_array)); assert_int_equal( ergo_tx_serializer_full_add_input_context_extension(&context, &extension_chunk), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_data_inputs(void** state) { @@ -460,164 +340,102 @@ static void test_ergo_tx_serializer_full_add_data_inputs(void** state) { uint8_t tokens_count = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - ergo_tx_serializer_full_init( - &context, - inputs_count, - data_inputs_count, - outputs_count, - tokens_count, - &hash, - &tokens_table - ); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + token_table_t tokens_table = {0}; + ergo_tx_serializer_full_init(&context, + inputs_count, + data_inputs_count, + outputs_count, + tokens_count, + &hash, + &tokens_table); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); ergo_tx_serializer_full_add_tokens(&context, &tokens); - uint8_t box_id[32] = { - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, - 0x03, 0x03 - }; + uint8_t box_id[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; uint8_t token_frames_count = 1; uint32_t context_extension_data_size = 2; - ergo_tx_serializer_full_add_input( - &context, - box_id, - token_frames_count, - context_extension_data_size - ); + ergo_tx_serializer_full_add_input(&context, + box_id, + token_frames_count, + context_extension_data_size); uint8_t token_frame_index = 0; - uint8_t input_tokens_array[40] = { - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 - }; + uint8_t input_tokens_array[] = {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; BUFFER_FROM_ARRAY(input_tokens, input_tokens_array, sizeof(input_tokens_array)); ergo_tx_serializer_full_add_input_tokens(&context, box_id, token_frame_index, &input_tokens); - uint8_t extension_chunk_array[2] = { - 0x01, 0x02 - }; + uint8_t extension_chunk_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(extension_chunk, extension_chunk_array, sizeof(extension_chunk_array)); ergo_tx_serializer_full_add_input_context_extension(&context, &extension_chunk); - uint8_t inputs_array[32] = { - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, - 0x05, 0x05 - }; + uint8_t inputs_array[] = {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; BUFFER_FROM_ARRAY(inputs, inputs_array, sizeof(inputs_array)); - assert_int_equal( - ergo_tx_serializer_full_add_data_inputs(&context, &inputs), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_data_inputs(&context, &inputs), + ERGO_TX_SERIALIZER_FULL_RES_OK); } -#define ERGO_TX_SERIALIZER_FULL_ADD_BOX() \ - ergo_tx_serializer_full_context_t context; \ - uint16_t inputs_count = 1; \ - uint16_t data_inputs_count = 1; \ - uint16_t outputs_count = 1; \ - uint8_t tokens_count = 1; \ - cx_blake2b_t hash; \ - blake2b_256_init(&hash); \ - token_table_t tokens_table = { \ - 1, \ - { \ - { \ - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, \ - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, \ - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, \ - 0x01, 0x01 \ - } \ - } \ - }; \ - ergo_tx_serializer_full_init( \ - &context, \ - inputs_count, \ - data_inputs_count, \ - outputs_count, \ - tokens_count, \ - &hash, \ - &tokens_table \ - ); \ - uint8_t tokens_array[32] = { \ - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \ - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \ - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \ - 0x02, 0x02 \ - }; \ - BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); \ - ergo_tx_serializer_full_add_tokens(&context, &tokens); \ - uint8_t box_id[32] = { \ - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, \ - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, \ - 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, \ - 0x03, 0x03 \ - }; \ - uint8_t token_frames_count = 1; \ - uint32_t context_extension_data_size = 2; \ - ergo_tx_serializer_full_add_input( \ - &context, \ - box_id, \ - token_frames_count, \ - context_extension_data_size \ - ); \ - uint8_t token_frame_index = 0; \ - uint8_t input_tokens_array[40] = { \ - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ - 0x04, 0x04, \ - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 \ - }; \ - BUFFER_FROM_ARRAY(input_tokens, input_tokens_array, sizeof(input_tokens_array)); \ +#define ERGO_TX_SERIALIZER_FULL_ADD_BOX() \ + ergo_tx_serializer_full_context_t context; \ + uint16_t inputs_count = 1; \ + uint16_t data_inputs_count = 1; \ + uint16_t outputs_count = 1; \ + uint8_t tokens_count = 1; \ + cx_blake2b_t hash; \ + blake2b_256_init(&hash); \ + token_table_t tokens_table = {0}; \ + ergo_tx_serializer_full_init(&context, \ + inputs_count, \ + data_inputs_count, \ + outputs_count, \ + tokens_count, \ + &hash, \ + &tokens_table); \ + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \ + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, \ + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; \ + BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); \ + ergo_tx_serializer_full_add_tokens(&context, &tokens); \ + uint8_t box_id[] = {0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, \ + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, \ + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; \ + uint8_t token_frames_count = 1; \ + uint32_t context_extension_data_size = 2; \ + ergo_tx_serializer_full_add_input(&context, \ + box_id, \ + token_frames_count, \ + context_extension_data_size); \ + uint8_t token_frame_index = 0; \ + uint8_t input_tokens_array[] = {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ + 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, \ + 0x04, 0x04, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}; \ + BUFFER_FROM_ARRAY(input_tokens, input_tokens_array, sizeof(input_tokens_array)); \ ergo_tx_serializer_full_add_input_tokens(&context, box_id, token_frame_index, &input_tokens); \ - uint8_t extension_chunk_array[2] = { \ - 0x01, 0x02 \ - }; \ - BUFFER_FROM_ARRAY(extension_chunk, extension_chunk_array, sizeof(extension_chunk_array)); \ - ergo_tx_serializer_full_add_input_context_extension(&context, &extension_chunk); \ - uint8_t inputs_array[32] = { \ - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, \ - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, \ - 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, \ - 0x05, 0x05 \ - }; \ - BUFFER_FROM_ARRAY(inputs, inputs_array, sizeof(inputs_array)); \ - ergo_tx_serializer_full_add_data_inputs(&context, &inputs); \ - uint64_t value = 12345; \ - uint32_t ergo_tree_size = 1; \ - uint32_t creation_height = 1; \ - uint32_t registers_size = 1; \ - assert_int_equal( \ - ergo_tx_serializer_full_add_box( \ - &context, \ - value, \ - ergo_tree_size, \ - creation_height, \ - tokens_count, \ - registers_size \ - ), \ - ERGO_TX_SERIALIZER_FULL_RES_OK \ - ); + uint8_t extension_chunk_array[] = {0x01, 0x02}; \ + BUFFER_FROM_ARRAY(extension_chunk, extension_chunk_array, sizeof(extension_chunk_array)); \ + ergo_tx_serializer_full_add_input_context_extension(&context, &extension_chunk); \ + uint8_t inputs_array[] = {0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, \ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, \ + 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05}; \ + BUFFER_FROM_ARRAY(inputs, inputs_array, sizeof(inputs_array)); \ + ergo_tx_serializer_full_add_data_inputs(&context, &inputs); \ + uint64_t value = 12345; \ + uint32_t ergo_tree_size = 1; \ + uint32_t creation_height = 1; \ + uint32_t registers_size = 1; \ + assert_int_equal(ergo_tx_serializer_full_add_box(&context, \ + value, \ + ergo_tree_size, \ + creation_height, \ + tokens_count, \ + registers_size), \ + ERGO_TX_SERIALIZER_FULL_RES_OK); static void test_ergo_tx_serializer_full_add_box(void** state) { (void) state; @@ -629,33 +447,24 @@ static void test_ergo_tx_serializer_full_add_box_ergo_tree(void** state) { (void) state; ERGO_TX_SERIALIZER_FULL_ADD_BOX(); - uint8_t tree_chunk_array[1] = { - 0x01 - }; + uint8_t tree_chunk_array[] = {0x01}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); - assert_int_equal( - ergo_tx_serializer_full_add_box_ergo_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_box_ergo_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_box_change_tree(void** state) { (void) state; ERGO_TX_SERIALIZER_FULL_ADD_BOX(); - const uint8_t raw_pub_key[65] = { - 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, - 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, - 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, - 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, 0x59, - 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, - 0x1a, 0x60, 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, - 0xe5, 0xcf, 0xf1, 0x0a, 0xe7 - }; - assert_int_equal( - ergo_tx_serializer_full_add_box_change_tree(&context, raw_pub_key), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + const uint8_t raw_pub_key[] = {0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, + 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, + 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, + 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, 0x59, 0x50, 0x0f, 0x5d, 0x31, + 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, 0x1a, 0x60, 0x53, 0xa1, 0x1d, + 0x53, 0x5d, 0x2d, 0x04, 0x3c, 0xe5, 0xcf, 0xf1, 0x0a, 0xe7}; + assert_int_equal(ergo_tx_serializer_full_add_box_change_tree(&context, raw_pub_key), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_box_miners_fee_tree(void** state) { @@ -663,72 +472,57 @@ static void test_ergo_tx_serializer_full_add_box_miners_fee_tree(void** state) { ERGO_TX_SERIALIZER_FULL_ADD_BOX(); bool is_mainnet = true; - assert_int_equal( - ergo_tx_serializer_full_add_box_miners_fee_tree(&context, is_mainnet), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_box_miners_fee_tree(&context, is_mainnet), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_box_tokens(void** state) { (void) state; ERGO_TX_SERIALIZER_FULL_ADD_BOX(); - uint8_t tree_chunk_array[1] = { - 0x01 - }; + uint8_t tree_chunk_array[] = {0x01}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); ergo_tx_serializer_full_add_box_ergo_tree(&context, &tree_chunk); - uint8_t box_tokens_array[12] = { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t box_tokens_array[] = + {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(box_tokens, box_tokens_array, sizeof(box_tokens_array)); - assert_int_equal( - ergo_tx_serializer_full_add_box_tokens(&context, &box_tokens), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_box_tokens(&context, &box_tokens), + ERGO_TX_SERIALIZER_FULL_RES_OK); } static void test_ergo_tx_serializer_full_add_box_registers(void** state) { (void) state; ERGO_TX_SERIALIZER_FULL_ADD_BOX(); - uint8_t tree_chunk_array[1] = { - 0x01 - }; + uint8_t tree_chunk_array[1] = {0x01}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); ergo_tx_serializer_full_add_box_ergo_tree(&context, &tree_chunk); - uint8_t box_tokens_array[12] = { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t box_tokens_array[12] = + {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(box_tokens, box_tokens_array, sizeof(box_tokens_array)); ergo_tx_serializer_full_add_box_tokens(&context, &box_tokens); - uint8_t registers_chunk_array[1] = { - 0x01 - }; + uint8_t registers_chunk_array[1] = {0x01}; BUFFER_FROM_ARRAY(registers_chunk, registers_chunk_array, sizeof(registers_chunk_array)); - assert_int_equal( - ergo_tx_serializer_full_add_box_registers(&context, ®isters_chunk), - ERGO_TX_SERIALIZER_FULL_RES_OK - ); + assert_int_equal(ergo_tx_serializer_full_add_box_registers(&context, ®isters_chunk), + ERGO_TX_SERIALIZER_FULL_RES_OK); } int main() { - const struct CMUnitTest tests[] = {cmocka_unit_test(test_simple_send_tx), - cmocka_unit_test(test_ergo_tx_serializer_full_init), - cmocka_unit_test(test_ergo_tx_serializer_full_init_zero_tokens), - cmocka_unit_test(test_ergo_tx_serializer_full_add_tokens), - cmocka_unit_test(test_ergo_tx_serializer_full_add_input), - cmocka_unit_test(test_ergo_tx_serializer_full_add_input_tokens), - cmocka_unit_test(test_ergo_tx_serializer_full_add_input_context_extension), - cmocka_unit_test(test_ergo_tx_serializer_full_add_data_inputs), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box_ergo_tree), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box_change_tree), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box_miners_fee_tree), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box_tokens), - cmocka_unit_test(test_ergo_tx_serializer_full_add_box_registers)}; + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_simple_send_tx), + cmocka_unit_test(test_ergo_tx_serializer_full_init), + cmocka_unit_test(test_ergo_tx_serializer_full_init_zero_tokens), + cmocka_unit_test(test_ergo_tx_serializer_full_add_tokens), + cmocka_unit_test(test_ergo_tx_serializer_full_add_input), + cmocka_unit_test(test_ergo_tx_serializer_full_add_input_tokens), + cmocka_unit_test(test_ergo_tx_serializer_full_add_input_context_extension), + cmocka_unit_test(test_ergo_tx_serializer_full_add_data_inputs), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box_ergo_tree), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box_change_tree), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box_miners_fee_tree), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box_tokens), + cmocka_unit_test(test_ergo_tx_serializer_full_add_box_registers)}; return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/unit-tests/test_input_frame.c b/unit-tests/test_input_frame.c index cc5d6f6c..efa687d6 100644 --- a/unit-tests/test_input_frame.c +++ b/unit-tests/test_input_frame.c @@ -14,21 +14,14 @@ static void test_input_frame_data_length(void **state) { (void) state; - uint8_t input_array[99] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t input_array[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(input, input_array, sizeof(input_array)); uint8_t data_len = input_frame_data_length(&input); assert_int_equal(data_len, 83); @@ -37,14 +30,11 @@ static void test_input_frame_data_length(void **state) { static void test_input_frame_data_length_bad_size(void **state) { (void) state; - uint8_t input_array[58] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; + uint8_t input_array[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; BUFFER_FROM_ARRAY(input, input_array, sizeof(input_array)); uint8_t data_len = input_frame_data_length(&input); assert_int_equal(data_len, 0); @@ -53,21 +43,14 @@ static void test_input_frame_data_length_bad_size(void **state) { static void test_input_frame_data_length_bad_size_2(void **state) { (void) state; - uint8_t input_array[98] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t input_array[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(input, input_array, sizeof(input_array)); uint8_t data_len = input_frame_data_length(&input); assert_int_equal(data_len, 0); @@ -76,21 +59,14 @@ static void test_input_frame_data_length_bad_size_2(void **state) { static void test_input_frame_signature_ptr(void **state) { (void) state; - uint8_t input_array[99] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t input_array[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(input, input_array, sizeof(input_array)); assert_ptr_equal(input_frame_signature_ptr(&input), buffer_read_ptr(&input) + 83); } @@ -98,21 +74,14 @@ static void test_input_frame_signature_ptr(void **state) { static void test_input_frame_signature_ptr_null(void **state) { (void) state; - uint8_t input_array[98] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t input_array[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(input, input_array, sizeof(input_array)); assert_ptr_equal(input_frame_signature_ptr(&input), NULL); } diff --git a/unit-tests/test_tx_ser_box.c b/unit-tests/test_tx_ser_box.c index e460b088..4ea8a48e 100644 --- a/unit-tests/test_tx_ser_box.c +++ b/unit-tests/test_tx_ser_box.c @@ -11,33 +11,29 @@ #include "common/rwbuffer.h" #include "macro_helpers.h" -#define ERGO_TX_SERIALIZER_BOX_INIT(name) \ - ergo_tx_serializer_box_context_t name; \ - uint64_t value = 12345; \ - uint32_t ergo_tree_size = 2; \ - uint32_t creation_height = 3; \ - uint8_t tokens_count = 2; \ - uint32_t registers_size = 2; \ - cx_blake2b_t hash; \ - assert_true(ergo_tx_serializer_box_id_hash_init(&hash)); \ - assert_int_equal( \ - ergo_tx_serializer_box_init( \ - &name, \ - value, \ - ergo_tree_size, \ - creation_height, \ - tokens_count, \ - registers_size, \ - &hash \ - ), \ - ERGO_TX_SERIALIZER_BOX_RES_OK \ - ); - -#define VERIFY_HASH(hash, expected) \ - uint8_t *data; \ - size_t data_len; \ - _cx_blake2b_get_data(hash, &data, &data_len); \ - assert_int_equal(data_len, sizeof(expected)); \ +#define ERGO_TX_SERIALIZER_BOX_INIT(name) \ + ergo_tx_serializer_box_context_t name; \ + uint64_t value = 12345; \ + uint32_t ergo_tree_size = 2; \ + uint32_t creation_height = 3; \ + uint8_t tokens_count = 2; \ + uint32_t registers_size = 2; \ + cx_blake2b_t hash; \ + assert_true(ergo_tx_serializer_box_id_hash_init(&hash)); \ + assert_int_equal(ergo_tx_serializer_box_init(&name, \ + value, \ + ergo_tree_size, \ + creation_height, \ + tokens_count, \ + registers_size, \ + &hash), \ + ERGO_TX_SERIALIZER_BOX_RES_OK); + +#define VERIFY_HASH(hash, expected) \ + uint8_t *data; \ + size_t data_len; \ + _cx_blake2b_get_data(hash, &data, &data_len); \ + assert_int_equal(data_len, sizeof(expected)); \ assert_memory_equal(data, expected, sizeof(expected)); \ _cx_blake2b_free_data(hash); @@ -49,9 +45,7 @@ static void test_ergo_tx_serializer_box_init(void **state) { assert_int_equal(context.creation_height, creation_height); assert_int_equal(context.tokens_count, tokens_count); assert_int_equal(context.registers_size, registers_size); - uint8_t expected_hash[2] = { - 0xb9, 0x60 - }; + uint8_t expected_hash[2] = {0xb9, 0x60}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.value, value); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_TREE); @@ -69,18 +63,14 @@ static void test_ergo_tx_serializer_box_init_too_many_tokens(void **state) { uint32_t registers_size = 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - assert_int_equal( - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ), - ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MANY_TOKENS - ); + assert_int_equal(ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash), + ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MANY_TOKENS); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -95,18 +85,14 @@ static void test_ergo_tx_serializer_box_init_too_much_data_ergo_tree_size(void * uint32_t registers_size = 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - assert_int_equal( - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ), - ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA - ); + assert_int_equal(ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash), + ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -121,18 +107,14 @@ static void test_ergo_tx_serializer_box_init_too_much_data_registers_size(void * uint32_t registers_size = MAX_TX_DATA_PART_LEN + 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - assert_int_equal( - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ), - ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA - ); + assert_int_equal(ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash), + ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -146,18 +128,14 @@ static void test_ergo_tx_serializer_box_init_bad_hash(void **state) { uint8_t tokens_count = 1; uint32_t registers_size = 1; cx_blake2b_t hash; - assert_int_equal( - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ), - ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER - ); + assert_int_equal(ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash), + ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -167,13 +145,9 @@ static void test_ergo_tx_serializer_box_add_tree(void **state) { ERGO_TX_SERIALIZER_BOX_INIT(context); uint8_t tree_chunk_array[2] = {0x01, 0x02}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); - assert_int_equal( - ergo_tx_serializer_box_add_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[6] = { - 0xb9, 0x60, 0x01, 0x02, 0x03, 0x02 - }; + assert_int_equal(ergo_tx_serializer_box_add_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_hash[6] = {0xb9, 0x60, 0x01, 0x02, 0x03, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_TREE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED); @@ -187,10 +161,8 @@ static void test_ergo_tx_serializer_box_add_tree_bad_state(void **state) { context.state = ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED; uint8_t tree_chunk_array[2] = {0x01, 0x02}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); - assert_int_equal( - ergo_tx_serializer_box_add_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE - ); + assert_int_equal(ergo_tx_serializer_box_add_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -207,19 +179,15 @@ static void test_ergo_tx_serializer_box_add_tree_too_much_data(void **state) { uint32_t registers_size = 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ); - assert_int_equal( - ergo_tx_serializer_box_add_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA - ); + ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash); + assert_int_equal(ergo_tx_serializer_box_add_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_BOX_RES_ERR_TOO_MUCH_DATA); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -236,20 +204,16 @@ static void test_ergo_tx_serializer_box_add_tree_bad_hash(void **state) { uint32_t registers_size = 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ); + ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash); memset(context.hash, 0, sizeof(*context.hash)); - assert_int_equal( - ergo_tx_serializer_box_add_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER - ); + assert_int_equal(ergo_tx_serializer_box_add_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -266,19 +230,15 @@ static void test_ergo_tx_serializer_box_add_tree_more_data(void **state) { uint32_t registers_size = 1; cx_blake2b_t hash; ergo_tx_serializer_box_id_hash_init(&hash); - ergo_tx_serializer_box_init( - &context, - value, - ergo_tree_size, - creation_height, - tokens_count, - registers_size, - &hash - ); - assert_int_equal( - ergo_tx_serializer_box_add_tree(&context, &tree_chunk), - ERGO_TX_SERIALIZER_BOX_RES_MORE_DATA - ); + ergo_tx_serializer_box_init(&context, + value, + ergo_tree_size, + creation_height, + tokens_count, + registers_size, + &hash); + assert_int_equal(ergo_tx_serializer_box_add_tree(&context, &tree_chunk), + ERGO_TX_SERIALIZER_BOX_RES_MORE_DATA); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_TREE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_INITIALIZED); } @@ -288,23 +248,17 @@ static void test_ergo_tx_serializer_box_add_miners_fee_tree_mainnet(void **state ERGO_TX_SERIALIZER_BOX_INIT(context); bool is_mainnet = true; - assert_int_equal( - ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[109] = { - 0xb9, 0x60, 0x10, 0x05, 0x04, 0x00, 0x04, 0x00, 0x0e, 0x36, - 0x10, 0x02, 0x04, 0xa0, 0x0b, 0x08, 0xcd, 0x02, 0x79, 0xbe, - 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, - 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, - 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, - 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, 0x8c, 0xc7, 0xa7, 0x01, - 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, - 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, - 0x73, 0x00, 0x00, 0x01, 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, - 0x00, 0x74, 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, - 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04, 0x03, 0x02 - }; + assert_int_equal(ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_hash[] = { + 0xb9, 0x60, 0x10, 0x05, 0x04, 0x00, 0x04, 0x00, 0x0e, 0x36, 0x10, 0x02, 0x04, 0xa0, + 0x0b, 0x08, 0xcd, 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, + 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, + 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, + 0x8c, 0xc7, 0xa7, 0x01, 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, + 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, 0x73, 0x00, 0x00, 0x01, + 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, 0x00, 0x74, 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, + 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04, 0x03, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_FEE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED); @@ -315,23 +269,17 @@ static void test_ergo_tx_serializer_box_add_miners_fee_tree_testnet(void **state ERGO_TX_SERIALIZER_BOX_INIT(context); bool is_mainnet = false; - assert_int_equal( - ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[109] = { - 0xb9, 0x60, 0x10, 0x05, 0x04, 0x00, 0x04, 0x00, 0x0e, 0x36, - 0x10, 0x02, 0x04, 0xa0, 0x0b, 0x08, 0xcd, 0x02, 0x79, 0xbe, - 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, - 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, - 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, - 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, 0x8c, 0xc7, 0xa7, 0x01, - 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, - 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, - 0x73, 0x00, 0x00, 0x01, 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, - 0x00, 0x74, 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, 0x08, 0xcd, - 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04, 0x03, 0x02 - }; + assert_int_equal(ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_hash[] = { + 0xb9, 0x60, 0x10, 0x05, 0x04, 0x00, 0x04, 0x00, 0x0e, 0x36, 0x10, 0x02, 0x04, 0xa0, + 0x0b, 0x08, 0xcd, 0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, + 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, + 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98, 0xea, 0x02, 0xd1, 0x92, 0xa3, 0x9a, + 0x8c, 0xc7, 0xa7, 0x01, 0x73, 0x00, 0x73, 0x01, 0x10, 0x01, 0x02, 0x04, 0x02, 0xd1, + 0x96, 0x83, 0x03, 0x01, 0x93, 0xa3, 0x8c, 0xc7, 0xb2, 0xa5, 0x73, 0x00, 0x00, 0x01, + 0x93, 0xc2, 0xb2, 0xa5, 0x73, 0x01, 0x00, 0x74, 0x73, 0x02, 0x73, 0x03, 0x83, 0x01, + 0x08, 0xcd, 0xee, 0xac, 0x93, 0xb1, 0xa5, 0x73, 0x04, 0x03, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_FEE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED); @@ -342,10 +290,8 @@ static void test_ergo_tx_serializer_box_add_miners_fee_tree_bad_state(void **sta ergo_tx_serializer_box_context_t context; bool is_mainnet = true; - assert_int_equal( - ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), - ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE - ); + assert_int_equal(ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), + ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -355,10 +301,8 @@ static void test_ergo_tx_serializer_box_add_miners_fee_tree_bad_hash(void **stat ERGO_TX_SERIALIZER_BOX_INIT(context); bool is_mainnet = true; memset(context.hash, 0, sizeof(*context.hash)); - assert_int_equal( - ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), - ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER - ); + assert_int_equal(ergo_tx_serializer_box_add_miners_fee_tree(&context, is_mainnet), + ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -366,25 +310,18 @@ static void test_ergo_tx_serializer_box_add_change_tree(void **state) { (void) state; ERGO_TX_SERIALIZER_BOX_INIT(context); - const uint8_t raw_public_key[PUBLIC_KEY_LEN] = { - 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, - 0xfc, 0x53, 0x9d, 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, - 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, 0x64, 0x18, 0xde, 0x5a, - 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, 0x59, - 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, - 0x1a, 0x60, 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, - 0xe5, 0xcf, 0xf1, 0x0a, 0xe7 - }; - assert_int_equal( - ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[40] = { - 0xb9, 0x60, 0x00, 0x08, 0xcd, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, - 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, - 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, - 0x99, 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, 0x03, 0x02 - }; + const uint8_t raw_public_key[] = { + 0x04, 0x8b, 0x9f, 0xf8, 0x5d, 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, + 0x39, 0xc7, 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, 0x99, + 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, 0xfa, 0x2d, 0x53, 0x17, 0x16, 0x0a, + 0x59, 0x50, 0x0f, 0x5d, 0x31, 0xfa, 0xe8, 0x6b, 0xce, 0xe9, 0xab, 0x1a, 0x60, + 0x53, 0xa1, 0x1d, 0x53, 0x5d, 0x2d, 0x04, 0x3c, 0xe5, 0xcf, 0xf1, 0x0a, 0xe7}; + assert_int_equal(ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_hash[] = {0xb9, 0x60, 0x00, 0x08, 0xcd, 0x03, 0x8b, 0x9f, 0xf8, 0x5d, + 0xdd, 0x9f, 0x1e, 0x22, 0x88, 0xfc, 0x53, 0x9d, 0x39, 0xc7, + 0xc4, 0xee, 0xb7, 0xa5, 0x56, 0xf4, 0xd8, 0x11, 0xcb, 0x73, + 0x99, 0x64, 0x18, 0xde, 0x5a, 0xbd, 0xcb, 0x2a, 0x03, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.type, ERGO_TX_SERIALIZER_BOX_TYPE_CHANGE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED); @@ -397,10 +334,8 @@ static void test_ergo_tx_serializer_box_add_change_tree_bad_state(void **state) memset(&context, 0, sizeof(ergo_tx_serializer_box_context_t)); context.state = ERGO_TX_SERIALIZER_BOX_STATE_TREE_ADDED; const uint8_t raw_public_key[PUBLIC_KEY_LEN] = {0}; - assert_int_equal( - ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), - ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE - ); + assert_int_equal(ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), + ERGO_TX_SERIALIZER_BOX_RES_ERR_BAD_STATE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -410,10 +345,8 @@ static void test_ergo_tx_serializer_box_add_change_tree_bad_hash(void **state) { ERGO_TX_SERIALIZER_BOX_INIT(context); const uint8_t raw_public_key[PUBLIC_KEY_LEN] = {0}; memset(context.hash, 0, sizeof(*context.hash)); - assert_int_equal( - ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), - ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER - ); + assert_int_equal(ergo_tx_serializer_box_add_change_tree(&context, raw_public_key), + ERGO_TX_SERIALIZER_BOX_RES_ERR_HASHER); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_ERROR); } @@ -421,42 +354,35 @@ static void test_ergo_tx_serializer_box_add_tokens(void **state) { (void) state; ERGO_TX_SERIALIZER_BOX_INIT(context); - uint8_t tree_chunk_array[2] = {0x01, 0x02}; + + uint8_t table_tokens_array[] = { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; + BUFFER_FROM_ARRAY(table_tokens, table_tokens_array, sizeof(table_tokens_array)); + token_table_t table = {0}; + ergo_tx_serializer_table_context_t table_ctx; + assert_int_equal( + ergo_tx_serializer_table_init(&table_ctx, sizeof(table_tokens_array) / ERGO_ID_LEN, &table), + ERGO_TX_SERIALIZER_TABLE_RES_OK); + assert_int_equal(ergo_tx_serializer_table_add(&table_ctx, &table_tokens), + ERGO_TX_SERIALIZER_TABLE_RES_OK); + + uint8_t tree_chunk_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); ergo_tx_serializer_box_add_tree(&context, &tree_chunk); - uint8_t tokens_array[24] = { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x00, 0x00, 0x00, 0x01, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - token_table_t table = { - 2, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }, - { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - } - } - }; - assert_int_equal( - ergo_tx_serializer_box_add_tokens(&context, &tokens, &table), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[26] = { - 0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, 0x84, - 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, 0x84, 0x88, - 0x90, 0xa0, 0xc0, 0x80, 0x81, 0x02 - }; + assert_int_equal(ergo_tx_serializer_box_add_tokens(&context, &tokens, &table_ctx), + ERGO_TX_SERIALIZER_BOX_RES_OK); + + uint8_t expected_hash[] = {0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, + 0x84, 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, + 0x84, 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x81, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_TOKENS_ADDED); } @@ -465,45 +391,35 @@ static void test_ergo_tx_serializer_box_add_registers(void **state) { (void) state; ERGO_TX_SERIALIZER_BOX_INIT(context); - uint8_t tree_chunk_array[2] = {0x01, 0x02}; + + token_table_t table = {0}; + ergo_tx_serializer_table_context_t table_ctx; + uint8_t distinct_tokens_array[] = { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; + BUFFER_FROM_ARRAY(distinct_tokens, distinct_tokens_array, sizeof(distinct_tokens_array)); + ergo_tx_serializer_table_init(&table_ctx, sizeof(distinct_tokens_array) / ERGO_ID_LEN, &table); + ergo_tx_serializer_table_add(&table_ctx, &distinct_tokens); + + uint8_t tree_chunk_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); ergo_tx_serializer_box_add_tree(&context, &tree_chunk); - uint8_t tokens_array[24] = { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x00, 0x00, 0x00, 0x01, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - token_table_t table = { - 2, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }, - { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - } - } - }; - ergo_tx_serializer_box_add_tokens(&context, &tokens, &table); - uint8_t rc_array[2] = {0x01, 0x02}; + ergo_tx_serializer_box_add_tokens(&context, &tokens, &table_ctx); + + uint8_t rc_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(registers_chunk, rc_array, sizeof(rc_array)); - assert_int_equal( - ergo_tx_serializer_box_add_registers(&context, ®isters_chunk), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_hash[28] = { - 0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, 0x84, - 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, 0x84, 0x88, - 0x90, 0xa0, 0xc0, 0x80, 0x81, 0x02, 0x01, 0x02 - }; + assert_int_equal(ergo_tx_serializer_box_add_registers(&context, ®isters_chunk), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_hash[] = {0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, 0x84, + 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, 0x84, 0x88, + 0x90, 0xa0, 0xc0, 0x80, 0x81, 0x02, 0x01, 0x02}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_FINISHED); } @@ -512,90 +428,74 @@ static void test_ergo_tx_serializer_box_id_hash(void **state) { (void) state; ERGO_TX_SERIALIZER_BOX_INIT(context); - uint8_t tree_chunk_array[2] = {0x01, 0x02}; + + token_table_t table = {0}; + ergo_tx_serializer_table_context_t table_ctx; + uint8_t distinct_tokens_array[] = { + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; + BUFFER_FROM_ARRAY(distinct_tokens, distinct_tokens_array, sizeof(distinct_tokens_array)); + ergo_tx_serializer_table_init(&table_ctx, sizeof(distinct_tokens_array) / ERGO_ID_LEN, &table); + ergo_tx_serializer_table_add(&table_ctx, &distinct_tokens); + + uint8_t tree_chunk_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(tree_chunk, tree_chunk_array, sizeof(tree_chunk_array)); ergo_tx_serializer_box_add_tree(&context, &tree_chunk); - uint8_t tokens_array[24] = { - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x00, 0x00, 0x00, 0x01, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - token_table_t table = { - 2, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }, - { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - } - } - }; - ergo_tx_serializer_box_add_tokens(&context, &tokens, &table); - uint8_t rc_array[2] = {0x01, 0x02}; + ergo_tx_serializer_box_add_tokens(&context, &tokens, &table_ctx); + + uint8_t rc_array[] = {0x01, 0x02}; BUFFER_FROM_ARRAY(registers_chunk, rc_array, sizeof(rc_array)); ergo_tx_serializer_box_add_registers(&context, ®isters_chunk); - const uint8_t tx_id[ERGO_ID_LEN] = { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }; + const uint8_t tx_id[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; uint16_t box_index = 1; uint8_t box_id[ERGO_ID_LEN]; - assert_int_equal( - ergo_tx_serializer_box_id_hash(&context, tx_id, box_index, box_id), - ERGO_TX_SERIALIZER_BOX_RES_OK - ); - uint8_t expected_box_id[ERGO_ID_LEN] = { - 0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, - 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, - 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, - 0x13, 0x73 - }; + assert_int_equal(ergo_tx_serializer_box_id_hash(&context, tx_id, box_index, box_id), + ERGO_TX_SERIALIZER_BOX_RES_OK); + uint8_t expected_box_id[] = {0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, 0x70, + 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, 0xbe, 0x5b, + 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, 0x13, 0x73}; assert_memory_equal(box_id, expected_box_id, ERGO_ID_LEN); - uint8_t expected_hash[61] = { - 0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, 0x84, - 0x88, 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, 0x84, 0x88, - 0x90, 0xa0, 0xc0, 0x80, 0x81, 0x02, 0x01, 0x02, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01 - }; + uint8_t expected_hash[] = {0xb9, 0x60, 0x01, 0x02, 0x03, 0x02, 0x00, 0x81, 0x82, 0x84, 0x88, + 0x90, 0xa0, 0xc0, 0x80, 0x01, 0x01, 0x82, 0x84, 0x88, 0x90, 0xa0, + 0xc0, 0x80, 0x81, 0x02, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_BOX_STATE_HASH_FINALIZED); } int main() { - const struct CMUnitTest tests[] = {cmocka_unit_test(test_ergo_tx_serializer_box_init), - cmocka_unit_test(test_ergo_tx_serializer_box_init_too_many_tokens), - cmocka_unit_test(test_ergo_tx_serializer_box_init_too_much_data_ergo_tree_size), - cmocka_unit_test(test_ergo_tx_serializer_box_init_too_much_data_registers_size), - cmocka_unit_test(test_ergo_tx_serializer_box_init_bad_hash), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tree), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_bad_state), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_too_much_data), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_bad_hash), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_more_data), - cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_mainnet), - cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_testnet), - cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_bad_state), - cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_bad_hash), - cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree), - cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree_bad_state), - cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree_bad_hash), - cmocka_unit_test(test_ergo_tx_serializer_box_add_tokens), - cmocka_unit_test(test_ergo_tx_serializer_box_add_registers), - cmocka_unit_test(test_ergo_tx_serializer_box_id_hash)}; + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_ergo_tx_serializer_box_init), + cmocka_unit_test(test_ergo_tx_serializer_box_init_too_many_tokens), + cmocka_unit_test(test_ergo_tx_serializer_box_init_too_much_data_ergo_tree_size), + cmocka_unit_test(test_ergo_tx_serializer_box_init_too_much_data_registers_size), + cmocka_unit_test(test_ergo_tx_serializer_box_init_bad_hash), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tree), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_bad_state), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_too_much_data), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_bad_hash), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tree_more_data), + cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_mainnet), + cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_testnet), + cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_bad_state), + cmocka_unit_test(test_ergo_tx_serializer_box_add_miners_fee_tree_bad_hash), + cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree), + cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree_bad_state), + cmocka_unit_test(test_ergo_tx_serializer_box_add_change_tree_bad_hash), + cmocka_unit_test(test_ergo_tx_serializer_box_add_tokens), + cmocka_unit_test(test_ergo_tx_serializer_box_add_registers), + cmocka_unit_test(test_ergo_tx_serializer_box_id_hash)}; return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/unit-tests/test_tx_ser_input.c b/unit-tests/test_tx_ser_input.c index b4c86d90..da55966b 100644 --- a/unit-tests/test_tx_ser_input.c +++ b/unit-tests/test_tx_ser_input.c @@ -11,56 +11,39 @@ #include "common/rwbuffer.h" #include "macro_helpers.h" -const uint8_t test_box_id[32] = { \ - 0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, \ - 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, \ - 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, \ - 0x13, 0x73 \ -}; - -uint8_t test_tokens_array[40] = { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 -}; - -token_table_t test_tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } -}; - -#define ERGO_TX_SERIALIZER_INPUT_INIT(name) \ - ergo_tx_serializer_input_context_t name; \ - uint8_t token_frames_count = 1; \ - uint32_t proof_data_size = 3; \ - cx_blake2b_t hash; \ - blake2b_256_init(&hash); \ - assert_int_equal( \ - ergo_tx_serializer_input_init( \ - &context, \ - test_box_id, \ - token_frames_count, \ - proof_data_size, \ - &test_tokens_table, \ - &hash \ - ), \ - ERGO_TX_SERIALIZER_INPUT_RES_OK \ - ); - -#define VERIFY_HASH(hash, expected) \ - uint8_t *data; \ - size_t data_len; \ - _cx_blake2b_get_data(hash, &data, &data_len); \ - assert_int_equal(data_len, sizeof(expected)); \ +const uint8_t test_box_id[] = {0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, 0x70, + 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, 0xbe, 0x5b, + 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, 0x13, 0x73}; + +uint8_t test_tokens_array[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + +token_table_t test_tokens_table = {1, {{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}}}; + +#define ERGO_TX_SERIALIZER_INPUT_INIT(name) \ + ergo_tx_serializer_input_context_t name; \ + uint8_t token_frames_count = 1; \ + uint32_t proof_data_size = 3; \ + cx_blake2b_t hash; \ + blake2b_256_init(&hash); \ + assert_int_equal(ergo_tx_serializer_input_init(&context, \ + test_box_id, \ + token_frames_count, \ + proof_data_size, \ + &test_tokens_table, \ + &hash), \ + ERGO_TX_SERIALIZER_INPUT_RES_OK); + +#define VERIFY_HASH(hash, expected) \ + uint8_t *data; \ + size_t data_len; \ + _cx_blake2b_get_data(hash, &data, &data_len); \ + assert_int_equal(data_len, sizeof(expected)); \ assert_memory_equal(data, expected, sizeof(expected)); \ _cx_blake2b_free_data(hash); @@ -85,17 +68,13 @@ static void test_ergo_tx_serializer_input_init_bad_extension_size(void **state) uint32_t proof_data_size = 1; cx_blake2b_t hash; blake2b_256_init(&hash); - assert_int_equal( - ergo_tx_serializer_input_init( - &context, - test_box_id, - token_frames_count, - proof_data_size, - &test_tokens_table, - &hash - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_CONTEXT_EXTENSION_SIZE - ); + assert_int_equal(ergo_tx_serializer_input_init(&context, + test_box_id, + token_frames_count, + proof_data_size, + &test_tokens_table, + &hash), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_CONTEXT_EXTENSION_SIZE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -106,20 +85,11 @@ static void test_ergo_tx_serializer_input_add_tokens(void **state) { uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_OK - ); - uint8_t expected_hash[33] = { - 0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, - 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, - 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, - 0x13, 0x73, 0x00 - }; + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_OK); + uint8_t expected_hash[33] = {0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, 0x70, + 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, 0xbe, 0x5b, + 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, 0x13, 0x73, 0x00}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_EXTENSION_STARTED); } @@ -132,31 +102,21 @@ static void test_ergo_tx_serializer_input_add_tokens_empty_extension(void **stat uint32_t proof_data_size = 0; cx_blake2b_t hash; blake2b_256_init(&hash); - ergo_tx_serializer_input_init( - &context, - test_box_id, - token_frames_count, - proof_data_size, - &test_tokens_table, - &hash - ); + ergo_tx_serializer_input_init(&context, + test_box_id, + token_frames_count, + proof_data_size, + &test_tokens_table, + &hash); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_OK - ); - uint8_t expected_hash[34] = { - 0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, - 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, - 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, - 0x13, 0x73, 0x00, 0x00 - }; + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_OK); + uint8_t expected_hash[34] = {0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, + 0x3d, 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, + 0x23, 0x89, 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, + 0x32, 0x6f, 0x86, 0x13, 0x73, 0x00, 0x00}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_FINISHED); } @@ -169,14 +129,8 @@ static void test_ergo_tx_serializer_input_add_tokens_bad_state(void **state) { uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_STATE - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_STATE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -186,21 +140,12 @@ static void test_ergo_tx_serializer_input_add_tokens_bad_input(void **state) { ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); - const uint8_t box_id[32] = { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }; + const uint8_t box_id[32] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_INPUT_ID - ); + ergo_tx_serializer_input_add_tokens(&context, box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_INPUT_ID); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -211,14 +156,8 @@ static void test_ergo_tx_serializer_input_add_tokens_too_many_input_frames(void uint8_t token_frame_index = 1; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_TOO_MANY_INPUT_FRAMES - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_TOO_MANY_INPUT_FRAMES); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -230,25 +169,17 @@ static void test_ergo_tx_serializer_input_add_tokens_bad_frame_index(void **stat uint32_t proof_data_size = 3; cx_blake2b_t hash; blake2b_256_init(&hash); - ergo_tx_serializer_input_init( - &context, - test_box_id, - token_frames_count, - proof_data_size, - &test_tokens_table, - &hash - ); + ergo_tx_serializer_input_init(&context, + test_box_id, + token_frames_count, + proof_data_size, + &test_tokens_table, + &hash); uint8_t token_frame_index = 1; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_FRAME_INDEX - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_FRAME_INDEX); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -257,22 +188,13 @@ static void test_ergo_tx_serializer_input_add_tokens_bad_token_id(void **state) ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; - uint8_t tokens_array[31] = { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01 - }; + uint8_t tokens_array[31] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_TOKEN_ID - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_TOKEN_ID); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -281,23 +203,14 @@ static void test_ergo_tx_serializer_input_add_tokens_bad_token_value(void **stat ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; - uint8_t tokens_array[39] = { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 - }; + uint8_t tokens_array[39] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_TOKEN_VALUE - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_TOKEN_VALUE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -309,25 +222,17 @@ static void test_ergo_tx_serializer_input_add_tokens_more_data(void **state) { uint32_t proof_data_size = 3; cx_blake2b_t hash; blake2b_256_init(&hash); - ergo_tx_serializer_input_init( - &context, - test_box_id, - token_frames_count, - proof_data_size, - &test_tokens_table, - &hash - ); + ergo_tx_serializer_input_init(&context, + test_box_id, + token_frames_count, + proof_data_size, + &test_tokens_table, + &hash); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); assert_int_equal( - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ), - ERGO_TX_SERIALIZER_INPUT_RES_MORE_DATA - ); + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens), + ERGO_TX_SERIALIZER_INPUT_RES_MORE_DATA); } static void test_ergo_tx_serializer_input_add_context_extension(void **state) { @@ -336,27 +241,16 @@ static void test_ergo_tx_serializer_input_add_context_extension(void **state) { ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ); - uint8_t chunk_array[3] = { - 0x01, 0x02, 0x03 - }; + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens); + uint8_t chunk_array[3] = {0x01, 0x02, 0x03}; BUFFER_FROM_ARRAY(chunk, chunk_array, sizeof(chunk_array)); - assert_int_equal( - ergo_tx_serializer_input_add_context_extension(&context, &chunk), - ERGO_TX_SERIALIZER_INPUT_RES_OK - ); + assert_int_equal(ergo_tx_serializer_input_add_context_extension(&context, &chunk), + ERGO_TX_SERIALIZER_INPUT_RES_OK); assert_int_equal(context.context_extension_data_size, 0); - uint8_t expected_hash[36] = { - 0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, 0x3d, - 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, 0x23, 0x89, - 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, 0x32, 0x6f, 0x86, - 0x13, 0x73, 0x00, 0x01, 0x02, 0x03 - }; + uint8_t expected_hash[36] = {0xf1, 0xca, 0x1e, 0x06, 0x0a, 0xa1, 0x1f, 0x98, 0x9b, + 0x3d, 0x70, 0xec, 0x0e, 0x0c, 0x98, 0x7c, 0x95, 0x2e, + 0x23, 0x89, 0xbe, 0x5b, 0x82, 0x0b, 0xc7, 0xdb, 0xfc, + 0x32, 0x6f, 0x86, 0x13, 0x73, 0x00, 0x01, 0x02, 0x03}; VERIFY_HASH(context.hash, expected_hash); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_FINISHED); } @@ -365,14 +259,10 @@ static void test_ergo_tx_serializer_input_add_context_extension_bad_state(void * (void) state; ERGO_TX_SERIALIZER_INPUT_INIT(context); - uint8_t chunk_array[3] = { - 0x01, 0x02, 0x03 - }; + uint8_t chunk_array[3] = {0x01, 0x02, 0x03}; BUFFER_FROM_ARRAY(chunk, chunk_array, sizeof(chunk_array)); - assert_int_equal( - ergo_tx_serializer_input_add_context_extension(&context, &chunk), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_STATE - ); + assert_int_equal(ergo_tx_serializer_input_add_context_extension(&context, &chunk), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_BAD_STATE); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -382,20 +272,11 @@ static void test_ergo_tx_serializer_input_add_context_extension_too_much_data(vo ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ); - uint8_t chunk_array[4] = { - 0x01, 0x02, 0x03, 0x04 - }; + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens); + uint8_t chunk_array[4] = {0x01, 0x02, 0x03, 0x04}; BUFFER_FROM_ARRAY(chunk, chunk_array, sizeof(chunk_array)); - assert_int_equal( - ergo_tx_serializer_input_add_context_extension(&context, &chunk), - ERGO_TX_SERIALIZER_INPUT_RES_ERR_TOO_MUCH_PROOF_DATA - ); + assert_int_equal(ergo_tx_serializer_input_add_context_extension(&context, &chunk), + ERGO_TX_SERIALIZER_INPUT_RES_ERR_TOO_MUCH_PROOF_DATA); assert_int_equal(context.state, ERGO_TX_SERIALIZER_INPUT_STATE_ERROR); } @@ -405,38 +286,30 @@ static void test_ergo_tx_serializer_input_add_context_extension_more_data(void * ERGO_TX_SERIALIZER_INPUT_INIT(context); uint8_t token_frame_index = 0; BUFFER_FROM_ARRAY(tokens, test_tokens_array, sizeof(test_tokens_array)); - ergo_tx_serializer_input_add_tokens( - &context, - test_box_id, - token_frame_index, - &tokens - ); - uint8_t chunk_array[2] = { - 0x01, 0x02 - }; + ergo_tx_serializer_input_add_tokens(&context, test_box_id, token_frame_index, &tokens); + uint8_t chunk_array[2] = {0x01, 0x02}; BUFFER_FROM_ARRAY(chunk, chunk_array, sizeof(chunk_array)); - assert_int_equal( - ergo_tx_serializer_input_add_context_extension(&context, &chunk), - ERGO_TX_SERIALIZER_INPUT_RES_MORE_DATA - ); + assert_int_equal(ergo_tx_serializer_input_add_context_extension(&context, &chunk), + ERGO_TX_SERIALIZER_INPUT_RES_MORE_DATA); } int main() { - const struct CMUnitTest tests[] = {cmocka_unit_test(test_ergo_tx_serializer_input_init), - cmocka_unit_test(test_ergo_tx_serializer_input_init_bad_extension_size), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_empty_extension), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_state), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_input), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_too_many_input_frames), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_frame_index), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_token_id), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_token_value), - cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_more_data), - cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension), - cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_bad_state), - cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_too_much_data), - cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_more_data)}; + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_ergo_tx_serializer_input_init), + cmocka_unit_test(test_ergo_tx_serializer_input_init_bad_extension_size), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_empty_extension), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_state), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_input), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_too_many_input_frames), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_frame_index), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_token_id), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_bad_token_value), + cmocka_unit_test(test_ergo_tx_serializer_input_add_tokens_more_data), + cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension), + cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_bad_state), + cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_too_much_data), + cmocka_unit_test(test_ergo_tx_serializer_input_add_context_extension_more_data)}; return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/unit-tests/test_tx_ser_table.c b/unit-tests/test_tx_ser_table.c index 028e0fa7..7b55e085 100644 --- a/unit-tests/test_tx_ser_table.c +++ b/unit-tests/test_tx_ser_table.c @@ -17,42 +17,28 @@ static void test_ergo_tx_serializer_table_init(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 1; token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - assert_int_equal( - ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table), - ERGO_TX_SERIALIZER_TABLE_RES_OK - ); + 0, + {{ + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + }}}; + assert_int_equal(ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table), + ERGO_TX_SERIALIZER_TABLE_RES_OK); + assert_int_equal(context.distinct_tokens_count, tokens_count); + assert_ptr_equal(context.tokens_table, &tokens_table); + token_table_t empty = {0}; + assert_memory_equal(context.tokens_table, &empty, sizeof(empty)); } static void test_ergo_tx_serializer_table_init_too_many_tokens(void **state) { (void) state; ergo_tx_serializer_table_context_t context; - uint8_t tokens_count = TOKEN_MAX_COUNT; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; - assert_int_equal( - ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table), - ERGO_TX_SERIALIZER_TABLE_RES_ERR_TOO_MANY_TOKENS - ); + uint8_t tokens_count = TOKEN_MAX_COUNT + 1; + token_table_t tokens_table = {0}; + assert_int_equal(ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table), + ERGO_TX_SERIALIZER_TABLE_RES_ERR_TOO_MANY_TOKENS); } static void test_ergo_tx_serializer_table_add(void **state) { @@ -60,47 +46,28 @@ static void test_ergo_tx_serializer_table_add(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 2; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - assert_int_equal( - ergo_tx_serializer_table_add(&context, &tokens), - ERGO_TX_SERIALIZER_TABLE_RES_OK - ); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_OK); const token_table_t expected_tokens_table = { 2, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }, - { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - } - } - }; - assert_memory_equal(context.tokens_table, &expected_tokens_table, sizeof(expected_tokens_table)); + {{0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, + {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}}}; + assert_memory_equal(context.tokens_table, + &expected_tokens_table, + sizeof(expected_tokens_table)); } static void test_ergo_tx_serializer_table_add_too_many_tokens(void **state) { @@ -108,29 +75,17 @@ static void test_ergo_tx_serializer_table_add_too_many_tokens(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 1; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - assert_int_equal( - ergo_tx_serializer_table_add(&context, &tokens), - ERGO_TX_SERIALIZER_TABLE_RES_ERR_TOO_MANY_TOKENS - ); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_ERR_TOO_MANY_TOKENS); } static void test_ergo_tx_serializer_table_add_bad_token_id(void **state) { @@ -138,59 +93,32 @@ static void test_ergo_tx_serializer_table_add_bad_token_id(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 2; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); - uint8_t tokens_array[31] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02 - }; + uint8_t tokens_array[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - assert_int_equal( - ergo_tx_serializer_table_add(&context, &tokens), - ERGO_TX_SERIALIZER_TABLE_RES_ERR_BAD_TOKEN_ID - ); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_ERR_BAD_TOKEN_ID); } static void test_ergo_tx_serializer_table_add_more_data(void **state) { (void) state; ergo_tx_serializer_table_context_t context; - uint8_t tokens_count = 3; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + uint8_t tokens_count = 2; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); - uint8_t tokens_array[32] = { - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02 - }; + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); - assert_int_equal( - ergo_tx_serializer_table_add(&context, &tokens), - ERGO_TX_SERIALIZER_TABLE_RES_MORE_DATA - ); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_MORE_DATA); } static void test_ergo_tx_serializer_table_hash(void **state) { @@ -198,34 +126,24 @@ static void test_ergo_tx_serializer_table_hash(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 1; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); + uint8_t tokens_array[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; + BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_OK); cx_blake2b_t hash; blake2b_256_init(&hash); - assert_int_equal( - ergo_tx_serializer_table_hash(&context, &hash), - ERGO_TX_SERIALIZER_TABLE_RES_OK - ); + assert_int_equal(ergo_tx_serializer_table_hash(&context, &hash), + ERGO_TX_SERIALIZER_TABLE_RES_OK); uint8_t *data; size_t data_len; _cx_blake2b_get_data(&hash, &data, &data_len); - uint8_t expected[] = { - 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - }; + uint8_t expected[] = {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; assert_int_equal(data_len, sizeof(expected)); assert_memory_equal(data, expected, sizeof(expected)); _cx_blake2b_free_data(&hash); @@ -236,34 +154,29 @@ static void test_ergo_tx_serializer_table_hash_bad_hash(void **state) { ergo_tx_serializer_table_context_t context; uint8_t tokens_count = 1; - token_table_t tokens_table = { - 1, - { - { - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, - 0x01, 0x01 - } - } - }; + token_table_t tokens_table = {0}; ergo_tx_serializer_table_init(&context, tokens_count, &tokens_table); + uint8_t tokens_array[] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02}; + BUFFER_FROM_ARRAY(tokens, tokens_array, sizeof(tokens_array)); + assert_int_equal(ergo_tx_serializer_table_add(&context, &tokens), + ERGO_TX_SERIALIZER_TABLE_RES_OK); cx_blake2b_t hash = {0}; - assert_int_equal( - ergo_tx_serializer_table_hash(&context, &hash), - ERGO_TX_SERIALIZER_TABLE_RES_ERR_HASHER - ); + assert_int_equal(ergo_tx_serializer_table_hash(&context, &hash), + ERGO_TX_SERIALIZER_TABLE_RES_ERR_HASHER); } int main() { - const struct CMUnitTest tests[] = {cmocka_unit_test(test_ergo_tx_serializer_table_init), - cmocka_unit_test(test_ergo_tx_serializer_table_init_too_many_tokens), - cmocka_unit_test(test_ergo_tx_serializer_table_add), - cmocka_unit_test(test_ergo_tx_serializer_table_add_too_many_tokens), - cmocka_unit_test(test_ergo_tx_serializer_table_add_bad_token_id), - cmocka_unit_test(test_ergo_tx_serializer_table_add_more_data), - cmocka_unit_test(test_ergo_tx_serializer_table_hash), - cmocka_unit_test(test_ergo_tx_serializer_table_hash_bad_hash)}; + const struct CMUnitTest tests[] = { + cmocka_unit_test(test_ergo_tx_serializer_table_init), + cmocka_unit_test(test_ergo_tx_serializer_table_init_too_many_tokens), + cmocka_unit_test(test_ergo_tx_serializer_table_add), + cmocka_unit_test(test_ergo_tx_serializer_table_add_too_many_tokens), + cmocka_unit_test(test_ergo_tx_serializer_table_add_bad_token_id), + cmocka_unit_test(test_ergo_tx_serializer_table_add_more_data), + cmocka_unit_test(test_ergo_tx_serializer_table_hash), + cmocka_unit_test(test_ergo_tx_serializer_table_hash_bad_hash)}; return cmocka_run_group_tests(tests, NULL, NULL); }