Changeset View
Changeset View
Standalone View
Standalone View
src/test/bloom_tests.cpp
Show First 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(spendingTx), | ||||
"Simple Bloom filter didn't add output"); | "Simple Bloom filter didn't add output"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(ParseHex("a266436d2965547608b9e15d9032a7b9d64fa431")); | filter.insert(ParseHex("a266436d2965547608b9e15d9032a7b9d64fa431")); | ||||
BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter didn't match output address"); | "Simple Bloom filter didn't match output address"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(COutPoint(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb" | filter.insert(COutPoint( | ||||
"6ba58f3bdaab65e73b7e9260b"), | unspentid_t(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb" | ||||
"6ba58f3bdaab65e73b7e9260b")), | |||||
0)); | 0)); | ||||
BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter didn't match COutPoint"); | "Simple Bloom filter didn't match COutPoint"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
COutPoint prevOutPoint(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb6" | COutPoint prevOutPoint( | ||||
"ba58f3bdaab65e73b7e9260b"), | unspentid_t(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb6" | ||||
"ba58f3bdaab65e73b7e9260b")), | |||||
0); | 0); | ||||
{ | { | ||||
std::vector<uint8_t> data(32 + sizeof(unsigned int)); | std::vector<uint8_t> data(32 + sizeof(unsigned int)); | ||||
memcpy(&data[0], prevOutPoint.hash.begin(), 32); | memcpy(&data[0], prevOutPoint.unspentid.begin(), 32); | ||||
memcpy(&data[32], &prevOutPoint.n, sizeof(unsigned int)); | memcpy(&data[32], &prevOutPoint.n, sizeof(unsigned int)); | ||||
filter.insert(data); | filter.insert(data); | ||||
} | } | ||||
BOOST_CHECK_MESSAGE( | BOOST_CHECK_MESSAGE( | ||||
filter.IsRelevantAndUpdate(tx), | filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter didn't match manually serialized COutPoint"); | "Simple Bloom filter didn't match manually serialized COutPoint"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(uint256S( | filter.insert(uint256S( | ||||
"00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436")); | "00000009e784f32f62ef849763d4f45b98e07ba658647343b915ff832b110436")); | ||||
BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter matched random tx hash"); | "Simple Bloom filter matched random tx hash"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(ParseHex("0000006d2965547608b9e15d9032a7b9d64fa431")); | filter.insert(ParseHex("0000006d2965547608b9e15d9032a7b9d64fa431")); | ||||
BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter matched random address"); | "Simple Bloom filter matched random address"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(COutPoint(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb" | filter.insert(COutPoint( | ||||
"6ba58f3bdaab65e73b7e9260b"), | unspentid_t(uint256S("0x90c122d70786e899529d71dbeba91ba216982fb" | ||||
"6ba58f3bdaab65e73b7e9260b")), | |||||
1)); | 1)); | ||||
BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter matched COutPoint for an output " | "Simple Bloom filter matched COutPoint for an output " | ||||
"we didn't care about"); | "we didn't care about"); | ||||
filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | filter = CBloomFilter(10, 0.000001, 0, BLOOM_UPDATE_ALL); | ||||
filter.insert(COutPoint(uint256S("0x000000d70786e899529d71dbeba91ba216982fb" | filter.insert(COutPoint( | ||||
"6ba58f3bdaab65e73b7e9260b"), | unspentid_t(uint256S("0x000000d70786e899529d71dbeba91ba216982fb" | ||||
"6ba58f3bdaab65e73b7e9260b")), | |||||
0)); | 0)); | ||||
BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | BOOST_CHECK_MESSAGE(!filter.IsRelevantAndUpdate(tx), | ||||
"Simple Bloom filter matched COutPoint for an output " | "Simple Bloom filter matched COutPoint for an output " | ||||
"we didn't care about"); | "we didn't care about"); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(merkle_block_1) { | BOOST_AUTO_TEST_CASE(merkle_block_1) { | ||||
// Random real block | // Random real block | ||||
// (0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af) | // (0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af) | ||||
▲ Show 20 Lines • Show All 653 Lines • ▼ Show 20 Lines | filter.insert(ParseHex("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f" | ||||
"13ad1357231a2252247d97a46a91")); | "13ad1357231a2252247d97a46a91")); | ||||
// ...and the output address of the 4th transaction | // ...and the output address of the 4th transaction | ||||
filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); | filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); | ||||
CMerkleBlock merkleBlock(block, filter); | CMerkleBlock merkleBlock(block, filter); | ||||
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); | BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); | ||||
// We should match the generation outpoint | // We should match the generation outpoint | ||||
BOOST_CHECK( | BOOST_CHECK(filter.contains( | ||||
filter.contains(COutPoint(uint256S("0x147caa76786596590baa4e98f5d9f48b8" | COutPoint(unspentid_t(uint256S("0x147caa76786596590baa4e98f5d9f48b8" | ||||
"6c7765e489f7a6ff3360fe5c674360b"), | "6c7765e489f7a6ff3360fe5c674360b")), | ||||
0))); | 0))); | ||||
// ... but not the 4th transaction's output (its not pay-2-pubkey) | // ... but not the 4th transaction's output (its not pay-2-pubkey) | ||||
BOOST_CHECK( | BOOST_CHECK(!filter.contains( | ||||
!filter.contains(COutPoint(uint256S("0x02981fa052f0481dbc5868f4fc216603" | COutPoint(unspentid_t(uint256S("0x02981fa052f0481dbc5868f4fc216603" | ||||
"5a10f27a03cfd2de67326471df5bc041"), | "5a10f27a03cfd2de67326471df5bc041")), | ||||
0))); | 0))); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) { | BOOST_AUTO_TEST_CASE(merkle_block_4_test_update_none) { | ||||
// Random real block | // Random real block | ||||
// (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4) | // (000000000000b731f2eef9e8c63173adfb07e41bd53eb0ef0a6b720d6cb6dea4) | ||||
// With 7 txes | // With 7 txes | ||||
CBlock block; | CBlock block; | ||||
CDataStream stream( | CDataStream stream( | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | filter.insert(ParseHex("04eaafc2314def4ca98ac970241bcab022b9c1e1f4ea423a20f" | ||||
"13ad1357231a2252247d97a46a91")); | "13ad1357231a2252247d97a46a91")); | ||||
// ...and the output address of the 4th transaction | // ...and the output address of the 4th transaction | ||||
filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); | filter.insert(ParseHex("b6efd80d99179f4f4ff6f4dd0a007d018c385d21")); | ||||
CMerkleBlock merkleBlock(block, filter); | CMerkleBlock merkleBlock(block, filter); | ||||
BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); | BOOST_CHECK(merkleBlock.header.GetHash() == block.GetHash()); | ||||
// We shouldn't match any outpoints (UPDATE_NONE) | // We shouldn't match any outpoints (UPDATE_NONE) | ||||
BOOST_CHECK( | BOOST_CHECK(!filter.contains( | ||||
!filter.contains(COutPoint(uint256S("0x147caa76786596590baa4e98f5d9f48b" | COutPoint(unspentid_t(uint256S("0x147caa76786596590baa4e98f5d9f48b" | ||||
"86c7765e489f7a6ff3360fe5c674360b"), | "86c7765e489f7a6ff3360fe5c674360b")), | ||||
0))); | 0))); | ||||
BOOST_CHECK( | BOOST_CHECK(!filter.contains( | ||||
!filter.contains(COutPoint(uint256S("0x02981fa052f0481dbc5868f4fc216603" | COutPoint(unspentid_t(uint256S("0x02981fa052f0481dbc5868f4fc216603" | ||||
"5a10f27a03cfd2de67326471df5bc041"), | "5a10f27a03cfd2de67326471df5bc041")), | ||||
0))); | 0))); | ||||
} | } | ||||
static std::vector<uint8_t> RandomData() { | static std::vector<uint8_t> RandomData() { | ||||
uint256 r = GetRandHash(); | uint256 r = GetRandHash(); | ||||
return std::vector<uint8_t>(r.begin(), r.end()); | return std::vector<uint8_t>(r.begin(), r.end()); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(rolling_bloom) { | BOOST_AUTO_TEST_CASE(rolling_bloom) { | ||||
▲ Show 20 Lines • Show All 72 Lines • Show Last 20 Lines |