Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed May 31, 2024
1 parent 1635643 commit 45e5a20
Show file tree
Hide file tree
Showing 8 changed files with 744 additions and 1,315 deletions.
23 changes: 9 additions & 14 deletions unit-tests/test_address.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
16 changes: 4 additions & 12 deletions unit-tests/test_bip32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 11 additions & 18 deletions unit-tests/test_ergo_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
Loading

0 comments on commit 45e5a20

Please sign in to comment.