diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-03-22 18:01:09 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2017-03-23 09:25:17 +0000 |
commit | f065234b71f2e3d374d44435d47db4cd75ab1294 (patch) | |
tree | 9cd0f1fae6e0eaef9cfd677f085df88a9aa5250b /tests | |
parent | Merge pull request #1901 (diff) | |
download | monero-f065234b71f2e3d374d44435d47db4cd75ab1294.tar.xz |
core: cache tx and block hashes in the respective classes
An idea from smooth
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/serialization.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 86e20266b..7afc0d60c 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -331,6 +331,7 @@ TEST(Serialization, serializes_transacion_signatures_correctly) // Miner tx with empty signatures 2nd vector tx.signatures.resize(1); + tx.invalidate_hashes(); ASSERT_TRUE(serialization::dump_binary(tx, blob)); ASSERT_EQ(7, blob.size()); // 5 bytes + 2 bytes vin[0] + 0 bytes extra + 0 bytes signatures ASSERT_TRUE(serialization::parse_binary(blob, tx1)); @@ -345,16 +346,19 @@ TEST(Serialization, serializes_transacion_signatures_correctly) tx.signatures.resize(2); tx.signatures[0].resize(0); tx.signatures[1].resize(0); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // Miner tx with 2 signatures tx.signatures[0].resize(1); tx.signatures[1].resize(1); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // Two txin_gen, no signatures tx.vin.push_back(txin_gen1); tx.signatures.resize(0); + tx.invalidate_hashes(); ASSERT_TRUE(serialization::dump_binary(tx, blob)); ASSERT_EQ(9, blob.size()); // 5 bytes + 2 * 2 bytes vins + 0 bytes extra + 0 bytes signatures ASSERT_TRUE(serialization::parse_binary(blob, tx1)); @@ -363,10 +367,12 @@ TEST(Serialization, serializes_transacion_signatures_correctly) // Two txin_gen, signatures vector contains only one empty element tx.signatures.resize(1); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // Two txin_gen, signatures vector contains two empty elements tx.signatures.resize(2); + tx.invalidate_hashes(); ASSERT_TRUE(serialization::dump_binary(tx, blob)); ASSERT_EQ(9, blob.size()); // 5 bytes + 2 * 2 bytes vins + 0 bytes extra + 0 bytes signatures ASSERT_TRUE(serialization::parse_binary(blob, tx1)); @@ -375,18 +381,21 @@ TEST(Serialization, serializes_transacion_signatures_correctly) // Two txin_gen, signatures vector contains three empty elements tx.signatures.resize(3); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // Two txin_gen, signatures vector contains two non empty elements tx.signatures.resize(2); tx.signatures[0].resize(1); tx.signatures[1].resize(1); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // A few bytes instead of signature tx.vin.clear(); tx.vin.push_back(txin_gen1); tx.signatures.clear(); + tx.invalidate_hashes(); ASSERT_TRUE(serialization::dump_binary(tx, blob)); blob.append(std::string(sizeof(crypto::signature) / 2, 'x')); ASSERT_FALSE(serialization::parse_binary(blob, tx1)); @@ -406,6 +415,7 @@ TEST(Serialization, serializes_transacion_signatures_correctly) tx.vin.push_back(txin_to_key1); tx.signatures.resize(1); tx.signatures[0].resize(2); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // Too much signatures for two inputs @@ -413,24 +423,28 @@ TEST(Serialization, serializes_transacion_signatures_correctly) tx.signatures[0].resize(2); tx.signatures[1].resize(2); tx.signatures[2].resize(2); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // First signatures vector contains too little elements tx.signatures.resize(2); tx.signatures[0].resize(1); tx.signatures[1].resize(2); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // First signatures vector contains too much elements tx.signatures.resize(2); tx.signatures[0].resize(3); tx.signatures[1].resize(2); + tx.invalidate_hashes(); ASSERT_FALSE(serialization::dump_binary(tx, blob)); // There are signatures for each input tx.signatures.resize(2); tx.signatures[0].resize(2); tx.signatures[1].resize(2); + tx.invalidate_hashes(); ASSERT_TRUE(serialization::dump_binary(tx, blob)); ASSERT_TRUE(serialization::parse_binary(blob, tx1)); ASSERT_EQ(tx, tx1); |