-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest_ergo_tree.c
73 lines (63 loc) · 3.6 KB
/
test_ergo_tree.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <stdint.h>
#include <stdbool.h>
#include <cmocka.h>
#include "ergo/ergo_tree.h"
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};
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};
assert_memory_equal(tree, expected, sizeof(expected));
}
static void test_ergo_tree_miners_fee_tree_mainnet(void **state) {
(void) state;
bool is_mainnet = true;
const uint8_t *tree;
size_t size;
ergo_tree_miners_fee_tree(is_mainnet, &tree, &size);
uint8_t expected[105] = {
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};
assert_int_equal(size, sizeof(expected));
assert_memory_equal(tree, expected, sizeof(expected));
}
static void test_ergo_tree_miners_fee_tree_testnet(void **state) {
(void) state;
bool is_mainnet = false;
const uint8_t *tree;
size_t size;
ergo_tree_miners_fee_tree(is_mainnet, &tree, &size);
uint8_t expected[105] = {
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};
assert_int_equal(size, sizeof(expected));
assert_memory_equal(tree, expected, sizeof(expected));
}
int main() {
const struct CMUnitTest tests[] = {cmocka_unit_test(test_ergo_tree_generate_p2pk),
cmocka_unit_test(test_ergo_tree_miners_fee_tree_mainnet),
cmocka_unit_test(test_ergo_tree_miners_fee_tree_testnet)};
return cmocka_run_group_tests(tests, NULL, NULL);
}