Skip to content

Commit 2e16b38

Browse files
committed
scripted-diff: Wrap checks with ||
`||` is also `delete` when decomposing an expression. See previous commit message. ref: https://fekir.info/post/decomposing-an-expression/ -BEGIN VERIFY SCRIPT- set -eu MACRO_RE='BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW' FILES=$(git grep -lE "\b(${MACRO_RE})[[:space:]]*\(" -- \ ':(glob)src/test/**/*.cpp' ':(glob)src/test/**/*.h' \ ':(glob)src/test/*.cpp' ':(glob)src/test/*.h' \ ':(glob)src/ipc/test/**/*.cpp' ':(glob)src/ipc/test/**/*.h' \ ':(glob)src/ipc/test/*.cpp' ':(glob)src/ipc/test/*.h' 2>/dev/null || true) if [ -z "$FILES" ]; then echo "no matching files" exit 0 fi perl -i -0777 -pe ' use strict; use warnings; my $names = "BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW"; my $re = qr/\b($names)\s*\(/; my @DIGIT_SEP_PREV = (0) x 256; $DIGIT_SEP_PREV[ord($_)] = 1 for split //, "0123456789abcdefABCDEF" . chr(39); sub is_char_open { my ($s, $i) = @_; return 1 if $i == 0; return $DIGIT_SEP_PREV[ord(substr($$s, $i-1, 1))] ? 0 : 1; } sub close_paren { my ($s, $open) = @_; my ($depth, $i, $in_str, $in_char) = (0, $open, 0, 0); my $n = length($$s); while ($i < $n) { my $c = substr($$s, $i, 1); if ($in_str) { if ($c eq "\\") { $i += 2; next; } $in_str = 0 if $c eq q{"}; } elsif ($in_char) { if ($c eq "\\") { $i += 2; next; } $in_char = 0 if $c eq chr(39); } elsif ($c eq q{"}) { $in_str = 1; } elsif ($c eq chr(39) && is_char_open($s, $i)) { $in_char = 1; } elsif ($c =~ /[(\[{]/) { $depth++; } elsif ($c =~ /[)\]}]/) { $depth--; return $i if $depth == 0; } $i++; } return -1; } sub split_first_comma { my ($s) = @_; my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0); my $n = length($s); while ($i < $n) { my $c = substr($s, $i, 1); if ($in_str) { if ($c eq "\\") { $i += 2; next; } $in_str = 0 if $c eq q{"}; } elsif ($in_char) { if ($c eq "\\") { $i += 2; next; } $in_char = 0 if $c eq chr(39); } elsif ($c eq q{"}) { $in_str = 1; } elsif ($c eq chr(39) && is_char_open(\$s, $i)) { $in_char = 1; } elsif ($c =~ /[(\[{]/) { $depth++; } elsif ($c =~ /[)\]}]/) { $depth--; } elsif ($c eq "," && $depth == 0) { return (substr($s, 0, $i), substr($s, $i)); } $i++; } return ($s, ""); } sub has_top_level_or { my ($e) = @_; my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0); my $n = length($e); while ($i < $n) { my $c = substr($e, $i, 1); if ($in_str) { if ($c eq "\\") { $i += 2; next; } $in_str = 0 if $c eq q{"}; $i++; next; } elsif ($in_char) { if ($c eq "\\") { $i += 2; next; } $in_char = 0 if $c eq chr(39); $i++; next; } if ($c eq q{"}) { $in_str = 1; $i++; next; } if ($c eq chr(39) && is_char_open(\$e, $i)) { $in_char = 1; $i++; next; } if ($c =~ /[(\[{]/) { $depth++; $i++; next; } if ($c =~ /[)\]}]/) { $depth--; $i++; next; } if ($depth == 0 && $i + 1 < $n && substr($e, $i, 2) eq "||") { return 1; } $i++; } return 0; } my $text = $_; my $out = ""; my $cur = 0; while ($text =~ /$re/g) { my $macro = $1; my $m_start = $-[0]; my $p_open = $+[0] - 1; my $p_close = close_paren(\$text, $p_open); next if $p_close < 0; my $args = substr($text, $p_open + 1, $p_close - $p_open - 1); my ($expr_raw, $message) = split_first_comma($args); my $expr = $expr_raw; $expr =~ s/^\s+//; $expr =~ s/\s+$//; next unless has_top_level_or($expr); $out .= substr($text, $cur, $m_start - $cur); $out .= "$macro(($expr)$message)"; $cur = $p_close + 1; pos($text) = $cur; } $out .= substr($text, $cur); $_ = $out; ' -- $FILES -END VERIFY SCRIPT-
1 parent 4cdcaf2 commit 2e16b38

13 files changed

Lines changed: 25 additions & 25 deletions

src/test/addrman_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(addrman_ports)
185185
BOOST_CHECK(addrman->Add({CAddress(addr1_port, NODE_NONE)}, source));
186186
BOOST_CHECK_EQUAL(addrman->Size(), 2U);
187187
auto addr_ret2 = addrman->Select().first;
188-
BOOST_CHECK(addr_ret2.ToStringAddrPort() == "250.1.1.1:8333" || addr_ret2.ToStringAddrPort() == "250.1.1.1:8334");
188+
BOOST_CHECK((addr_ret2.ToStringAddrPort() == "250.1.1.1:8333" || addr_ret2.ToStringAddrPort() == "250.1.1.1:8334"));
189189

190190
// Test: Add same IP but diff port to tried table; this converts the entry with
191191
// the specified port to tried, but not the other.
@@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network)
311311

312312
while (--counter > 0 && (!new_selected || !tried_selected)) {
313313
const CAddress selected{addrman->Select(/*new_only=*/false, {NET_I2P}).first};
314-
BOOST_REQUIRE(selected == i2p_addr || selected == i2p_addr2);
314+
BOOST_REQUIRE((selected == i2p_addr || selected == i2p_addr2));
315315
if (selected == i2p_addr) {
316316
tried_selected = true;
317317
} else {

src/test/argsman_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ BOOST_AUTO_TEST_CASE(util_GetBoolArg)
334334

335335
// Each letter should be set.
336336
for (const char opt : "abcdef")
337-
BOOST_CHECK(testArgs.IsArgSet({'-', opt}) || !opt);
337+
BOOST_CHECK((testArgs.IsArgSet({'-', opt}) || !opt));
338338

339339
// Nothing else should be in the map
340340
testArgs.LockSettings([&](const common::Settings& s) {

src/test/arith_uint256_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ BOOST_AUTO_TEST_CASE( comparison ) // <= >= < >
276276
BOOST_CHECK(0 < TmpL);
277277
BOOST_CHECK(0 <= TmpL);
278278
TmpL |= R1L;
279-
BOOST_CHECK( TmpL >= R1L ); BOOST_CHECK( (TmpL == R1L) != (TmpL > R1L)); BOOST_CHECK( (TmpL == R1L) || !( TmpL <= R1L));
280-
BOOST_CHECK( R1L <= TmpL ); BOOST_CHECK( (R1L == TmpL) != (R1L < TmpL)); BOOST_CHECK( (TmpL == R1L) || !( R1L >= TmpL));
279+
BOOST_CHECK( TmpL >= R1L ); BOOST_CHECK( (TmpL == R1L) != (TmpL > R1L)); BOOST_CHECK(((TmpL == R1L) || !( TmpL <= R1L)));
280+
BOOST_CHECK( R1L <= TmpL ); BOOST_CHECK( (R1L == TmpL) != (R1L < TmpL)); BOOST_CHECK(((TmpL == R1L) || !( R1L >= TmpL)));
281281
BOOST_CHECK(! (TmpL < R1L)); BOOST_CHECK(! (R1L > TmpL));
282282
}
283283

src/test/descriptor_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
203203
BOOST_CHECK(max_sat_nonmaxsig <= max_sat_maxsig);
204204
const auto max_elems{parse_priv->MaxSatisfactionElems()};
205205
const bool is_input_size_info_set{max_sat_maxsig && max_sat_nonmaxsig && max_elems};
206-
BOOST_CHECK_MESSAGE(is_input_size_info_set || is_nontop_or_nonsolvable, prv);
206+
BOOST_CHECK_MESSAGE((is_input_size_info_set || is_nontop_or_nonsolvable), prv);
207207

208208
// The ScriptSize() must match the size of the Script string. (ScriptSize() is set for all descs but 'combo()'.)
209209
const bool is_combo{!parse_priv->IsSingleType()};
210-
BOOST_CHECK_MESSAGE(is_combo || parse_priv->ScriptSize() == scripts[0][0].size() / 2, "Invalid ScriptSize() for " + prv);
210+
BOOST_CHECK_MESSAGE((is_combo || parse_priv->ScriptSize() == scripts[0][0].size() / 2), "Invalid ScriptSize() for " + prv);
211211

212212
// Check that the correct OutputType is inferred
213213
BOOST_CHECK(parse_priv->GetOutputType() == type);

src/test/miniscript_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,9 @@ void TestSatisfy(const KeyConverter& converter, const Node& node)
392392
if (node.ValidSatisfactions()) BOOST_CHECK(res);
393393
// More detailed: non-malleable satisfactions must be valid, or could fail with ops count error (if CheckOpsLimit failed),
394394
// or with a stack size error (if CheckStackSize check fails).
395-
BOOST_CHECK(res ||
395+
BOOST_CHECK((res ||
396396
(!node.CheckOpsLimit() && serror == ScriptError::SCRIPT_ERR_OP_COUNT) ||
397-
(!node.CheckStackSize() && serror == ScriptError::SCRIPT_ERR_STACK_SIZE));
397+
(!node.CheckStackSize() && serror == ScriptError::SCRIPT_ERR_STACK_SIZE)));
398398
}
399399

400400
if (mal_success && (!nonmal_success || witness_mal.stack != witness_nonmal.stack)) {
@@ -403,7 +403,7 @@ void TestSatisfy(const KeyConverter& converter, const Node& node)
403403
bool res = VerifyScript(CScript(), script_pubkey, &witness_mal, STANDARD_SCRIPT_VERIFY_FLAGS, checker, &serror);
404404
// Malleable satisfactions are not guaranteed to be valid under any conditions, but they can only
405405
// fail due to stack or ops limits.
406-
BOOST_CHECK(res || serror == ScriptError::SCRIPT_ERR_OP_COUNT || serror == ScriptError::SCRIPT_ERR_STACK_SIZE);
406+
BOOST_CHECK((res || serror == ScriptError::SCRIPT_ERR_OP_COUNT || serror == ScriptError::SCRIPT_ERR_STACK_SIZE));
407407
}
408408

409409
if (node.IsSane()) {
@@ -453,7 +453,7 @@ void Test(const std::string& ms, const std::string& hexscript, int mode, const K
453453
auto node = miniscript::FromString(ms, converter);
454454
const bool is_tapscript{miniscript::IsTapscript(converter.MsContext())};
455455
if (mode == TESTMODE_INVALID || ((mode & TESTMODE_P2WSH_INVALID) && !is_tapscript) || ((mode & TESTMODE_TAPSCRIPT_INVALID) && is_tapscript)) {
456-
BOOST_CHECK_MESSAGE(!node || !node->IsValid(), "Unexpectedly valid: " + ms);
456+
BOOST_CHECK_MESSAGE((!node || !node->IsValid()), "Unexpectedly valid: " + ms);
457457
} else {
458458
BOOST_CHECK_MESSAGE(node, "Unparseable: " + ms);
459459
BOOST_CHECK_MESSAGE(node->IsValid(), "Invalid: " + ms);

src/test/policyestimator_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
190190
m_node.validation_signals->SyncWithValidationInterfaceQueue();
191191

192192
for (int i = 1; i < 10;i++) {
193-
BOOST_CHECK(feeEst.estimateFee(i) == CFeeRate(0) || feeEst.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
193+
BOOST_CHECK((feeEst.estimateFee(i) == CFeeRate(0) || feeEst.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee));
194194
}
195195

196196
// Mine all those transactions
@@ -215,7 +215,7 @@ BOOST_AUTO_TEST_CASE(BlockPolicyEstimates)
215215

216216
BOOST_CHECK(feeEst.estimateFee(1) == CFeeRate(0));
217217
for (int i = 2; i < 10;i++) {
218-
BOOST_CHECK(feeEst.estimateFee(i) == CFeeRate(0) || feeEst.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee);
218+
BOOST_CHECK((feeEst.estimateFee(i) == CFeeRate(0) || feeEst.estimateFee(i).GetFeePerK() > origFeeEst[i-1] - deltaFee));
219219
}
220220

221221
// Mine 400 more blocks where everything is mined every block

src/test/private_broadcast_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ BOOST_AUTO_TEST_CASE(basic)
6868
check_peer_counts(/*tx1_peer_count=*/0, /*tx2_peer_count=*/0);
6969

7070
const auto tx_for_recipient1{pb.PickTxForSend(/*will_send_to_nodeid=*/recipient1, /*will_send_to_address=*/addr1).value()};
71-
BOOST_CHECK(tx_for_recipient1 == tx1 || tx_for_recipient1 == tx2);
71+
BOOST_CHECK((tx_for_recipient1 == tx1 || tx_for_recipient1 == tx2));
7272

7373
// A second pick must return the other transaction.
7474
const NodeId recipient2{2};
7575
const CService addr2{ipv4Addr, 2222};
7676
const auto tx_for_recipient2{pb.PickTxForSend(/*will_send_to_nodeid=*/recipient2, /*will_send_to_address=*/addr2).value()};
77-
BOOST_CHECK(tx_for_recipient2 == tx1 || tx_for_recipient2 == tx2);
77+
BOOST_CHECK((tx_for_recipient2 == tx1 || tx_for_recipient2 == tx2));
7878
BOOST_CHECK_NE(tx_for_recipient1, tx_for_recipient2);
7979

8080
check_peer_counts(/*tx1_peer_count=*/1, /*tx2_peer_count=*/1);

src/test/script_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
13051305
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy_b));
13061306
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
13071307
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSigCopy, scriptSig);
1308-
BOOST_CHECK(combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig);
1308+
BOOST_CHECK((combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig));
13091309

13101310
// P2SH, single-signature case:
13111311
CScript pkSingle; pkSingle << ToByteVector(keys[0].GetPubKey()) << OP_CHECKSIG;
@@ -1323,7 +1323,7 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
13231323
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy_d));
13241324
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
13251325
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSigCopy, scriptSig);
1326-
BOOST_CHECK(combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig);
1326+
BOOST_CHECK((combined.scriptSig == scriptSigCopy.scriptSig || combined.scriptSig == scriptSig.scriptSig));
13271327

13281328
// Hardest case: Multisig 2-of-3
13291329
scriptPubKey = GetScriptForMultisig(2, pubkeys);

src/test/sighash_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ BOOST_AUTO_TEST_CASE(sighash_caching)
292292
HashWriter dummy{};
293293
cache.Store(hash_type, diff_scriptcode, dummy);
294294
(void)SignatureHash(scriptcode, tx, in_index, hash_type, amount, sigversion, nullptr, &cache);
295-
BOOST_CHECK(cache.Load(hash_type, scriptcode, dummy) || expect_one);
295+
BOOST_CHECK((cache.Load(hash_type, scriptcode, dummy) || expect_one));
296296
}
297297
}
298298
}

src/test/skiplist_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
5757
vBlocksMain[i].phashBlock = &vHashMain[i];
5858
vBlocksMain[i].BuildSkip();
5959
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksMain[i].GetBlockHash()).GetLow64(), vBlocksMain[i].nHeight);
60-
BOOST_CHECK(vBlocksMain[i].pprev == nullptr || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1);
60+
BOOST_CHECK((vBlocksMain[i].pprev == nullptr || vBlocksMain[i].nHeight == vBlocksMain[i].pprev->nHeight + 1));
6161
}
6262

6363
// Build a branch that splits off at block 49999, 50000 blocks long.
@@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE(getlocator_test)
7070
vBlocksSide[i].phashBlock = &vHashSide[i];
7171
vBlocksSide[i].BuildSkip();
7272
BOOST_CHECK_EQUAL((int)UintToArith256(vBlocksSide[i].GetBlockHash()).GetLow64(), vBlocksSide[i].nHeight);
73-
BOOST_CHECK(vBlocksSide[i].pprev == nullptr || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1);
73+
BOOST_CHECK((vBlocksSide[i].pprev == nullptr || vBlocksSide[i].nHeight == vBlocksSide[i].pprev->nHeight + 1));
7474
}
7575

7676
// Build a CChain for the main branch.
@@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE(findearliestatleast_test)
140140
int64_t test_time = vBlocksMain[r].nTime;
141141
CBlockIndex* ret = chain.FindEarliestAtLeast(test_time, 0);
142142
BOOST_CHECK(ret->nTimeMax >= test_time);
143-
BOOST_CHECK((ret->pprev==nullptr) || ret->pprev->nTimeMax < test_time);
143+
BOOST_CHECK(((ret->pprev==nullptr) || ret->pprev->nTimeMax < test_time));
144144
BOOST_CHECK(vBlocksMain[r].GetAncestor(ret->nHeight) == ret);
145145
}
146146
}
@@ -272,7 +272,7 @@ BOOST_AUTO_TEST_CASE(build_skip_height_test)
272272
block_index[i].pprev = i == 0 ? nullptr : &block_index[i - 1];
273273
block_index[i].nHeight = i;
274274
block_index[i].BuildSkip();
275-
BOOST_CHECK(block_index[i].pskip || i == 0);
275+
BOOST_CHECK((block_index[i].pskip || i == 0));
276276
}
277277

278278
for (auto& [input, expected] : TEST_DATA) {

0 commit comments

Comments
 (0)