mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Merge pull request #7661
08e4497
Improve cryptonote (block and tx) binary read performance (Lee Clagett)
This commit is contained in:
commit
7499837a6f
29 changed files with 229 additions and 230 deletions
|
@ -132,11 +132,10 @@ TEST(Serialization, BinaryArchiveInts) {
|
|||
ASSERT_EQ(8, oss.str().size());
|
||||
ASSERT_EQ(string("\0\0\0\0\xff\0\0\0", 8), oss.str());
|
||||
|
||||
istringstream iss(oss.str());
|
||||
binary_archive<false> iar(iss);
|
||||
binary_archive<false> iar{epee::strspan<std::uint8_t>(oss.str())};
|
||||
iar.serialize_int(x1);
|
||||
ASSERT_EQ(8, iss.tellg());
|
||||
ASSERT_TRUE(iss.good());
|
||||
ASSERT_EQ(8, iar.getpos());
|
||||
ASSERT_TRUE(iar.good());
|
||||
|
||||
ASSERT_EQ(x, x1);
|
||||
}
|
||||
|
@ -151,10 +150,9 @@ TEST(Serialization, BinaryArchiveVarInts) {
|
|||
ASSERT_EQ(6, oss.str().size());
|
||||
ASSERT_EQ(string("\x80\x80\x80\x80\xF0\x1F", 6), oss.str());
|
||||
|
||||
istringstream iss(oss.str());
|
||||
binary_archive<false> iar(iss);
|
||||
binary_archive<false> iar{epee::strspan<std::uint8_t>(oss.str())};
|
||||
iar.serialize_varint(x1);
|
||||
ASSERT_TRUE(iss.good());
|
||||
ASSERT_TRUE(iar.good());
|
||||
ASSERT_EQ(x, x1);
|
||||
}
|
||||
|
||||
|
|
|
@ -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