Skip to content

Commit 04738d8

Browse files
committed
test: Enforce comparison of signed types at compile time
1 parent 56506a6 commit 04738d8

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
@@ -388,7 +388,7 @@ FIXTURE_TEST_CASE(addrman_new_multiplicity, BasicTestingSetup)
388388
addrman->Add({addr}, source);
389389
}
390390
AddressPosition addr_pos = addrman->FindAddressEntry(addr).value();
391-
CHECK(addr_pos.multiplicity == 1U);
391+
CHECK(addr_pos.multiplicity == 1);
392392
CHECK(addrman->Size() == 1U);
393393

394394
// if nTime increases, an addr can occur in up to 8 buckets
@@ -401,7 +401,7 @@ FIXTURE_TEST_CASE(addrman_new_multiplicity, BasicTestingSetup)
401401
addrman->Add({addr}, source);
402402
}
403403
AddressPosition addr_pos_multi = addrman->FindAddressEntry(addr).value();
404-
CHECK(addr_pos_multi.multiplicity == 8U);
404+
CHECK(addr_pos_multi.multiplicity == 8);
405405
// multiplicity doesn't affect size
406406
CHECK(addrman->Size() == 1U);
407407
}
@@ -643,7 +643,7 @@ FIXTURE_TEST_CASE(caddrinfo_get_new_bucket_legacy, BasicTestingSetup)
643643
}
644644
// Test: IP addresses in the different source groups should map to MORE
645645
// than 64 buckets.
646-
CHECK(buckets.size() > 64);
646+
CHECK(buckets.size() > 64U);
647647
}
648648

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

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

777777
buckets.clear();
778778
for (int p = 0; p < 255; p++) {
@@ -866,7 +866,7 @@ FIXTURE_TEST_CASE(remove_invalid, BasicTestingSetup)
866866
addrman->Add({new1, tried1, new2, tried2}, CNetAddr{});
867867
addrman->Good(tried1);
868868
addrman->Good(tried2);
869-
REQUIRE(addrman->Size() == 4);
869+
REQUIRE(addrman->Size() == 4U);
870870

871871
stream << *addrman;
872872

@@ -889,7 +889,7 @@ FIXTURE_TEST_CASE(remove_invalid, BasicTestingSetup)
889889

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

895895
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
@@ -164,7 +164,7 @@ FIXTURE_TEST_CASE(blockmanager_block_data_part, TestChain100Setup)
164164

165165
auto block{blockman.ReadRawBlock(tip_block_pos)};
166166
REQUIRE(block);
167-
REQUIRE(block->size() >= 200);
167+
REQUIRE(block->size() >= 200U);
168168

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

193193
auto block{blockman.ReadRawBlock(tip_block_pos)};
194194
REQUIRE(block);
195-
REQUIRE(block->size() >= 200);
195+
REQUIRE(block->size() >= 200U);
196196

197197
const auto expect_part_error{[&](size_t offset, size_t size) {
198198
auto res{blockman.ReadRawBlock(tip_block_pos, std::pair{offset, size})};
@@ -259,7 +259,7 @@ FIXTURE_TEST_CASE(blockmanager_flush_block_file, BasicTestingSetup)
259259

260260
// Blockstore is empty
261261
LOCK(::cs_main);
262-
CHECK(blockman.CalculateCurrentUsage() == 0);
262+
CHECK(blockman.CalculateCurrentUsage() == 0U);
263263

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

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)