|
5 | 5 | #include <test/util/setup_common.h> |
6 | 6 |
|
7 | 7 | #include <evo/assetlocktx.h> |
| 8 | +#include <evo/creditpool.h> // to test CSkipSet |
8 | 9 | #include <policy/settings.h> |
9 | 10 | #include <script/signingprovider.h> |
10 | 11 | #include <consensus/tx_check.h> |
|
14 | 15 |
|
15 | 16 | #include <boost/test/unit_test.hpp> |
16 | 17 |
|
| 18 | +#include <random> |
| 19 | +#include <unordered_set> |
17 | 20 |
|
18 | 21 | // |
19 | 22 | // Helper: create two dummy transactions, each with |
@@ -357,4 +360,30 @@ BOOST_FIXTURE_TEST_CASE(evo_assetunlock, TestChain100Setup) |
357 | 360 |
|
358 | 361 | } |
359 | 362 |
|
| 363 | +BOOST_FIXTURE_TEST_CASE(evo_skipset, TestChain100Setup) |
| 364 | +{ |
| 365 | + std::mt19937 gen; |
| 366 | + for (size_t test = 0; test < 17; ++test) { |
| 367 | + std::uniform_int_distribution<uint64_t> dist_value(0, (1 << test)); |
| 368 | + size_t skip_size = test ? (1 << (test - 1)) : 1; |
| 369 | + CSkipSet set_1{skip_size}; |
| 370 | + std::unordered_set<uint64_t> set_2; |
| 371 | + for (size_t iter = 0; iter < (1 << test) * 2; ++iter) { |
| 372 | + uint64_t value = dist_value(gen); |
| 373 | + BOOST_CHECK(set_1.contains(value) == !!set_2.count(value)); |
| 374 | + if (!set_1.contains(value) && set_1.canBeAdded(value)) { |
| 375 | + BOOST_CHECK(!set_1.contains(value)); |
| 376 | + BOOST_CHECK(set_1.add(value)); |
| 377 | + set_2.insert(value); |
| 378 | + } |
| 379 | + BOOST_CHECK(set_1.contains(value) == !!set_2.count(value)); |
| 380 | + BOOST_CHECK(set_1.size() == set_2.size()); |
| 381 | + } |
| 382 | + if (test > 4) { |
| 383 | + BOOST_CHECK(set_1.size() > ((1 << test) / 4)); |
| 384 | + } |
| 385 | + } |
| 386 | +} |
| 387 | + |
| 388 | + |
360 | 389 | BOOST_AUTO_TEST_SUITE_END() |
0 commit comments