Skip to content

Commit 7a582b6

Browse files
committed
test: Enforce comparison of signed types at compile time
1 parent 8f22508 commit 7a582b6

35 files changed

Lines changed: 366 additions & 359 deletions

src/test/addrman_tests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ FIXTURE_TEST_CASE(addrman_new_multiplicity, BasicTestingSetup)
389389
addrman->Add({addr}, source);
390390
}
391391
AddressPosition addr_pos = addrman->FindAddressEntry(addr).value();
392-
CHECK(addr_pos.multiplicity == 1U);
392+
CHECK(addr_pos.multiplicity == 1);
393393
CHECK(addrman->Size() == 1U);
394394

395395
// if nTime increases, an addr can occur in up to 8 buckets
@@ -402,7 +402,7 @@ FIXTURE_TEST_CASE(addrman_new_multiplicity, BasicTestingSetup)
402402
addrman->Add({addr}, source);
403403
}
404404
AddressPosition addr_pos_multi = addrman->FindAddressEntry(addr).value();
405-
CHECK(addr_pos_multi.multiplicity == 8U);
405+
CHECK(addr_pos_multi.multiplicity == 8);
406406
// multiplicity doesn't affect size
407407
CHECK(addrman->Size() == 1U);
408408
}
@@ -644,7 +644,7 @@ FIXTURE_TEST_CASE(caddrinfo_get_new_bucket_legacy, BasicTestingSetup)
644644
}
645645
// Test: IP addresses in the different source groups should map to MORE
646646
// than 64 buckets.
647-
CHECK(buckets.size() > 64);
647+
CHECK(buckets.size() > 64U);
648648
}
649649

650650
// The following three test cases use asmap.raw
@@ -696,7 +696,7 @@ FIXTURE_TEST_CASE(caddrinfo_get_tried_bucket, BasicTestingSetup)
696696
}
697697
// Test: IP addresses in the different /16 prefix MAY map to more than
698698
// 8 buckets.
699-
CHECK(buckets.size() > 8);
699+
CHECK(buckets.size() > 8U);
700700

701701
buckets.clear();
702702
for (int j = 0; j < 255; j++) {
@@ -773,7 +773,7 @@ FIXTURE_TEST_CASE(caddrinfo_get_new_bucket, BasicTestingSetup)
773773
}
774774
// Test: IP addresses in the different source /16 prefixes usually map to MORE
775775
// than 1 bucket.
776-
CHECK(buckets.size() > 1);
776+
CHECK(buckets.size() > 1U);
777777

778778
buckets.clear();
779779
for (int p = 0; p < 255; p++) {
@@ -867,7 +867,7 @@ FIXTURE_TEST_CASE(remove_invalid, BasicTestingSetup)
867867
addrman->Add({new1, tried1, new2, tried2}, CNetAddr{});
868868
addrman->Good(tried1);
869869
addrman->Good(tried2);
870-
REQUIRE(addrman->Size() == 4);
870+
REQUIRE(addrman->Size() == 4U);
871871

872872
stream << *addrman;
873873

@@ -890,7 +890,7 @@ FIXTURE_TEST_CASE(remove_invalid, BasicTestingSetup)
890890

891891
addrman = std::make_unique<AddrMan>(EMPTY_NETGROUPMAN, DETERMINISTIC, GetCheckRatio(m_node));
892892
stream >> *addrman;
893-
CHECK(addrman->Size() == 2);
893+
CHECK(addrman->Size() == 2U);
894894
}
895895

896896
FIXTURE_TEST_CASE(addrman_selecttriedcollision, BasicTestingSetup)

src/test/banman_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ FIXTURE_TEST_CASE(file, BasicTestingSetup)
3434
BanMan banman{banlist_path, /*client_interface=*/nullptr, /*default_ban_time=*/0};
3535
banmap_t entries_read;
3636
banman.GetBanned(entries_read);
37-
CHECK(entries_read.size() == 1);
37+
CHECK(entries_read.size() == 1U);
3838
}
3939
}
4040
}

src/test/blockmanager_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ FIXTURE_TEST_CASE(blockmanager_block_data_part, TestChain100Setup)
163163

164164
auto block{blockman.ReadRawBlock(tip_block_pos)};
165165
REQUIRE(block);
166-
REQUIRE(block->size() >= 200);
166+
REQUIRE(block->size() >= 200U);
167167

168168
const auto expect_part{[&](size_t offset, size_t size) {
169169
auto res{blockman.ReadRawBlock(tip_block_pos, std::pair{offset, size})};
@@ -191,7 +191,7 @@ FIXTURE_TEST_CASE(blockmanager_block_data_part_error, TestChain100Setup)
191191

192192
auto block{blockman.ReadRawBlock(tip_block_pos)};
193193
REQUIRE(block);
194-
REQUIRE(block->size() >= 200);
194+
REQUIRE(block->size() >= 200U);
195195

196196
const auto expect_part_error{[&](size_t offset, size_t size) {
197197
auto res{blockman.ReadRawBlock(tip_block_pos, std::pair{offset, size})};
@@ -257,7 +257,7 @@ FIXTURE_TEST_CASE(blockmanager_flush_block_file, BasicTestingSetup)
257257
constexpr int TEST_BLOCK_SIZE{81};
258258

259259
// Blockstore is empty
260-
CHECK(blockman.CalculateCurrentUsage() == 0);
260+
CHECK(blockman.CalculateCurrentUsage() == 0U);
261261

262262
// Write the first block to a new location.
263263
FlatFilePos pos1{blockman.WriteBlock(block1, /*nHeight=*/1)};
@@ -288,10 +288,10 @@ FIXTURE_TEST_CASE(blockmanager_flush_block_file, BasicTestingSetup)
288288
// Verify this behavior by attempting (and failing) to write block 3 data
289289
// to block 2 location.
290290
CBlockFileInfo* block_data = blockman.GetBlockFileInfo(0);
291-
CHECK(block_data->nBlocks == 2);
291+
CHECK(block_data->nBlocks == 2U);
292292
blockman.UpdateBlockInfo(block3, /*nHeight=*/3, /*pos=*/pos2);
293293
// Metadata is updated...
294-
CHECK(block_data->nBlocks == 3);
294+
CHECK(block_data->nBlocks == 3U);
295295
// ...but there are still only two blocks in the file
296296
CHECK(blockman.CalculateCurrentUsage() == (TEST_BLOCK_SIZE + STORAGE_HEADER_BYTES) * 2);
297297

src/test/btcsignals_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ FIXTURE_TEST_CASE(thread_safety, BasicTestingSetup)
187187
// sig will have been called 2000 times, and at least 1000 of those will
188188
// have been executing multiple incrementing callbacks. So while val is
189189
// probably MUCH bigger, it's guaranteed to be at least 3000.
190-
CHECK(val.load() >= 3000);
190+
CHECK(val.load() >= 3000U);
191191
}
192192

193193
/* Test that connection and disconnection works from within signal

src/test/coins_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,15 +1139,15 @@ FIXTURE_TEST_CASE(ccoins_reset_guard, BasicTestingSetup)
11391139
const auto reset_guard{cache.CreateResetGuard()};
11401140
CHECK((cache.AccessCoin(outpoint) == coin));
11411141
CHECK(!cache.AccessCoin(outpoint).IsSpent());
1142-
CHECK(cache.GetCacheSize() == 1);
1143-
CHECK(cache.GetDirtyCount() == 1);
1142+
CHECK(cache.GetCacheSize() == 1U);
1143+
CHECK(cache.GetDirtyCount() == 1U);
11441144
CHECK(cache.GetBestBlock() == cache_best_block);
11451145
CHECK(!root_cache.HaveCoinInCache(outpoint));
11461146
}
11471147

11481148
CHECK(cache.AccessCoin(outpoint).IsSpent());
1149-
CHECK(cache.GetCacheSize() == 0);
1150-
CHECK(cache.GetDirtyCount() == 0);
1149+
CHECK(cache.GetCacheSize() == 0U);
1150+
CHECK(cache.GetDirtyCount() == 0U);
11511151
CHECK(cache.GetBestBlock() == base_best_block);
11521152
CHECK(!root_cache.HaveCoinInCache(outpoint));
11531153

@@ -1157,7 +1157,7 @@ FIXTURE_TEST_CASE(ccoins_reset_guard, BasicTestingSetup)
11571157
}
11581158

11591159
CHECK(cache.AccessCoin(outpoint).IsSpent());
1160-
CHECK(cache.GetCacheSize() == 0);
1160+
CHECK(cache.GetCacheSize() == 0U);
11611161
CHECK(cache.GetDirtyCount() == 0U);
11621162
CHECK(cache.GetBestBlock() == base_best_block);
11631163
CHECK(!root_cache.HaveCoinInCache(outpoint));

src/test/coinsviewoverlay_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ TEST_CASE(fetch_no_double_spend)
140140
}
141141
}
142142
// Coins are not added to the view, even though they exist unspent in the parent db
143-
CHECK(view.GetCacheSize() == 0);
143+
CHECK(view.GetCacheSize() == 0U);
144144
}
145145

146146
TEST_CASE(fetch_no_inputs)
@@ -157,7 +157,7 @@ TEST_CASE(fetch_no_inputs)
157157
CHECK(!view.GetCoin(in.prevout));
158158
}
159159
}
160-
CHECK(view.GetCacheSize() == 0);
160+
CHECK(view.GetCacheSize() == 0U);
161161
}
162162

163163
TEST_SUITE_END()

src/test/dbwrapper_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,18 +355,18 @@ FIXTURE_TEST_CASE(iterator_ordering, BasicTestingSetup)
355355
for (const int seek_start : {0x00, 0x80}) {
356356
it->Seek((uint8_t)seek_start);
357357
for (unsigned int x=seek_start; x<255; ++x) {
358-
uint8_t key;
359-
uint32_t value;
358+
uint8_t key{};
359+
uint32_t value{};
360360
CHECK(it->Valid());
361361
if (!it->Valid()) // Avoid spurious errors about invalid iterator's key and value in case of failure
362362
break;
363363
CHECK(it->GetKey(key));
364364
if (x & 1) {
365-
CHECK(key == x + 1);
365+
CHECK(static_cast<unsigned>(key) == x + 1);
366366
continue;
367367
}
368368
CHECK(it->GetValue(value));
369-
CHECK(key == x);
369+
CHECK(static_cast<unsigned>(key) == x);
370370
CHECK(value == x*x);
371371
it->Next();
372372
}

src/test/descriptor_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ std::set<CPubKey> GetKeyData(const FlatSigningProvider& provider, int flags) {
126126
for (const auto& [_, pubkey] : provider.pubkeys) {
127127
if (flags & XONLY_KEYS) {
128128
unsigned char bytes[33];
129-
CHECK(pubkey.size() == 33);
129+
CHECK(pubkey.size() == 33U);
130130
std::copy(pubkey.begin(), pubkey.end(), bytes);
131131
bytes[0] = 0x02;
132132
CPubKey norm_pubkey{bytes};
@@ -153,7 +153,7 @@ std::set<std::pair<CPubKey, KeyOriginInfo>> GetKeyOriginData(const FlatSigningPr
153153
if (ignored.contains(keyid)) continue;
154154
if (flags & XONLY_KEYS) {
155155
unsigned char bytes[33];
156-
CHECK(data.first.size() == 33);
156+
CHECK(data.first.size() == 33U);
157157
std::copy(data.first.begin(), data.first.end(), bytes);
158158
bytes[0] = 0x02;
159159
CPubKey norm_pubkey{bytes};
@@ -339,22 +339,22 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
339339
// For ranged, unhardened derivation, None of the keys in origins should appear in the cache but the cache should have parent keys
340340
// But we can derive one level from each of those parent keys and find them all
341341
CHECK(der_xpub_cache.empty());
342-
CHECK(parent_xpub_cache.size() > 0);
342+
CHECK(parent_xpub_cache.size() > 0U);
343343
std::set<CPubKey> pubkeys;
344344
for (const auto& xpub_pair : parent_xpub_cache) {
345345
const CExtPubKey& xpub = xpub_pair.second;
346346
CExtPubKey der;
347347
CHECK(xpub.Derive(der, i));
348348
pubkeys.insert(der.pubkey);
349349
}
350-
int count_pks = 0;
350+
size_t count_pks = 0;
351351
for (const auto& origin_pair : script_provider_cached.origins) {
352352
const CPubKey& pk = origin_pair.second.first;
353353
count_pks += pubkeys.count(pk);
354354
}
355355
if (flags & MUSIG_DERIVATION) {
356356
if (!(flags & MIXED_MUSIG)) {
357-
CHECK(count_pks == 1);
357+
CHECK(count_pks == 1U);
358358
}
359359
CHECK(num_xpubs == pubkeys.size());
360360
} else {
@@ -391,7 +391,7 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
391391
CHECK(xpub.Derive(der, i));
392392
pubkeys.insert(der.pubkey);
393393
}
394-
int count_pks = 0;
394+
size_t count_pks = 0;
395395
for (const auto& origin_pair : script_provider_cached.origins) {
396396
const CPubKey& pk = origin_pair.second.first;
397397
count_pks += pubkeys.count(pk);

src/test/disconnected_transactions.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup)
1616
// transactions would realistically be in a block together, they just need distinct txids and
1717
// uniform size for this test to work.
1818
std::vector<CTransactionRef> block_vtx(m_coinbase_txns);
19-
CHECK(block_vtx.size() == 100);
19+
CHECK(block_vtx.size() == 100U);
2020

2121
// Roughly estimate sizes to sanity check that DisconnectedBlockTransactions::DynamicMemoryUsage
2222
// is within an expected range.
@@ -52,7 +52,7 @@ FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup)
5252
CHECK((disconnectpool.DynamicMemoryUsage() <= MAP_1 + ENTRY_USAGE_ESTIMATE));
5353

5454
// Only 1 transaction can be kept
55-
CHECK(1 == evicted_txns.size());
55+
CHECK(1U == evicted_txns.size());
5656
// Transactions are added from back to front and eviction is FIFO.
5757
CHECK(block_vtx.at(1) == evicted_txns.front());
5858

@@ -66,7 +66,7 @@ FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup)
6666
const size_t USAGE_100_OVERESTIMATE{MAP_100 + ENTRY_USAGE_ESTIMATE * 100};
6767
DisconnectedBlockTransactions disconnectpool{USAGE_100_OVERESTIMATE};
6868
auto evicted_txns{disconnectpool.AddTransactionsFromBlock(block_vtx)};
69-
CHECK(evicted_txns.size() == 0);
69+
CHECK(evicted_txns.size() == 0U);
7070
CHECK((disconnectpool.DynamicMemoryUsage() <= USAGE_100_OVERESTIMATE));
7171

7272
usage_full = disconnectpool.DynamicMemoryUsage();
@@ -82,7 +82,7 @@ FIXTURE_TEST_CASE(disconnectpool_memory_limits, TestChain100Setup)
8282
CHECK((disconnectpool.DynamicMemoryUsage() <= MAX_MEMUSAGE_99));
8383

8484
// Only 1 transaction needed to be evicted
85-
CHECK(1 == evicted_txns.size());
85+
CHECK(1U == evicted_txns.size());
8686

8787
// Transactions are added from back to front and eviction is FIFO.
8888
// The last transaction of block_vtx should be the first to be evicted.

src/test/fs_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ FIXTURE_TEST_CASE(fsbridge_pathtostring, BasicTestingSetup)
3131
// and these functions do encoding and decoding, so the behavior of this
3232
// test would be undefined.
3333
std::string invalid_u8_str = "\xf0";
34-
CHECK(invalid_u8_str.size() == 1);
34+
CHECK(invalid_u8_str.size() == 1U);
3535
CHECK(fs::PathToString(fs::PathFromString(invalid_u8_str)) == invalid_u8_str);
3636
#endif
3737
}

0 commit comments

Comments
 (0)