mirror of
https://github.com/monero-project/monero.git
synced 2025-05-04 09:14:55 -04:00
Improve cryptonote (block and tx) binary read performance
This commit is contained in:
parent
0a1ddc2eff
commit
08e4497c6e
29 changed files with 229 additions and 230 deletions
|
@ -287,3 +287,73 @@ TEST(sort_tx_extra, invalid_suffix_partial)
|
|||
std::vector<uint8_t> expected(&expected_arr[0], &expected_arr[0] + sizeof(expected_arr));
|
||||
ASSERT_EQ(sorted, expected);
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_first)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_pub_key)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(1, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_last)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(1, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, remove_middle)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 1, 42, 1, 30, 208, 98, 162, 133, 64, 85, 83, 112,
|
||||
91, 188, 89, 211, 24, 131, 39, 154, 22, 228, 80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(3, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[1].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[2].type());
|
||||
|
||||
tx_extra_fields.clear();
|
||||
ASSERT_TRUE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
|
||||
ASSERT_EQ(2, tx_extra_fields.size());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
|
||||
}
|
||||
|
||||
TEST(remove_field_from_tx_extra, invalid_varint)
|
||||
{
|
||||
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
|
||||
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 2, 0x80, 0};
|
||||
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
|
||||
|
||||
ASSERT_FALSE(cryptonote::remove_field_from_tx_extra(extra, typeid(cryptonote::tx_extra_nonce)));
|
||||
ASSERT_EQ(sizeof(extra_arr), extra.size());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue