lbrycrd/src
Wladimir J. van der Laan 2971fd030f
Merge #11220: Check specific validation error in miner tests
12781db [Tests] check specific validation error in miner tests (Sjors Provoost)

Pull request description:

  ## Problem

  `BOOST_CHECK_THROW` merely checks that some `std::runtime_error` is
  thrown, but not which one.

  Here's an example of how this can cause a test to pass when a developer
  introduces a consensus bug. The test for the sigops limit assumes
  that `CreateNewBlock` fails with `bad-blk-sigops`. However it can
  also fail with bad-txns-vout-negative, if a naive developer lowers
  `BLOCKSUBSIDY` to `1*COIN`.

  ## Solution

  `BOOST_CHECK_EXCEPTION` allows an additional predicate function. This
  commit uses this for all exceptions that are checked for in
  `miner_tets.cpp`:
  * `bad-blk-sigops`
  * `bad-cb-multiple`
  * `bad-txns-inputs-missingorspent`
  * `block-validation-failed`

  If the function throws a different error, the test will fail. Although the message produced by Boost is a bit [confusing](http://boost.2283326.n4.nabble.com/Test-BOOST-CHECK-EXCEPTION-error-message-still-vague-tt4683257.html#a4683554), it does show which error was actually thrown. Here's what the above `1*COIN` bug would result in:

  <img width="1134" alt="schermafbeelding 2017-09-02 om 23 42 29" src="https://user-images.githubusercontent.com/10217/29998976-815cabce-9038-11e7-9c46-f5f6cfb0ca7d.png">

  ## Other considerations

  A more elegant solution in my opinion would be to subclass `std::runtime_error` for each `INVALID_TRANSACTION` type, but this would involve touching consensus code.

  I put the predicates in `test_bitcoin.h` because I assume they can be reused in other test files. However [serialize_tests.cpp](https://github.com/bitcoin/bitcoin/blob/v0.15.0rc3/src/test/serialize_tests.cpp#L245) also uses `BOOST_CHECK_EXCEPTION` and it defines the predicate in the test file itself.

  Instead of four `IsRejectInvalidReasonX(std::runtime_error const& e)` functions, I'd prefer something reusable like `bool IsRejectInvalidReason(String reason)(std::runtime_error const& e)`, which would be used like `BOOST_CHECK_EXCEPTION(functionThatThrows(), std::runtime_error, IsRejectInvalidReason("bad-blk-sigops")`. I couldn't figure out how to do that in C++.

Tree-SHA512: e364f19b4ac19f910f6e8d6533357f57ccddcbd9d53dcfaf923d424d2b9711446d6f36da193208b35788ca21863eadaa7becd9ad890334d334bccf8c2e63dee1
2017-12-19 13:06:01 +01:00
..
bench Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
compat Merge #11140: Trivial: Improve #endif comments 2017-11-17 15:34:51 +01:00
config
consensus scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
crypto scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
leveldb Update LevelDB with latest Bitcoin-specific patches 2017-08-01 12:40:42 -07:00
obj
obj-test
policy Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
primitives scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
qt Merge #10839: Don't use pass by reference to const for cheaply-copied types (bool, char, etc.) 2017-12-14 18:28:01 +01:00
rpc Merge #11178: Add iswitness parameter to decode- and fundrawtransaction RPCs 2017-12-19 09:55:11 +01:00
script Merge #10574: Remove includes in .cpp files for things the corresponding .h file already included 2017-12-12 14:56:25 +01:00
secp256k1 Bump secp256k1 subtree 2017-09-29 16:02:39 +02:00
support Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
test Merge #11220: Check specific validation error in miner tests 2017-12-19 13:06:01 +01:00
univalue Bump univalue and fix json formatting in tests 2017-09-29 14:35:46 +02:00
wallet Merge #11178: Add iswitness parameter to decode- and fundrawtransaction RPCs 2017-12-19 09:55:11 +01:00
zmq Merge #10493: Use range-based for loops (C++11) when looping over map elements 2017-11-30 17:10:05 -05:00
.clang-format Merge #10193: scripted-diff: Remove #include <boost/foreach.hpp> 2017-07-04 18:05:18 +02:00
addrdb.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
addrdb.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
addrman.cpp Merge #10493: Use range-based for loops (C++11) when looping over map elements 2017-11-30 17:10:05 -05:00
addrman.h Merge #10493: Use range-based for loops (C++11) when looping over map elements 2017-11-30 17:10:05 -05:00
amount.h Consensus: Policy: MOVEONLY: Move CFeeRate out of the consensus module 2017-05-03 18:00:13 +02:00
arith_uint256.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
arith_uint256.h Merge #10749: Use compile-time constants instead of unnamed enumerations (remove "enum hack") 2017-11-11 18:07:28 -05:00
base58.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
base58.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
bech32.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
bech32.h Import Bech32 C++ reference code & tests 2017-09-28 16:02:16 -07:00
bitcoin-cli-res.rc
bitcoin-cli.cpp cli: Reject arguments to -getinfo 2017-11-17 15:11:50 +01:00
bitcoin-tx-res.rc
bitcoin-tx.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
bitcoind-res.rc
bitcoind.cpp Create walletdir if datadir doesn't exist and fix tests 2017-11-18 00:50:59 +13:00
blockencodings.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
blockencodings.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
bloom.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
bloom.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
chain.cpp Merge #11337: Fix code constness in CBlockIndex::GetAncestor() overloads 2017-12-01 15:19:07 +01:00
chain.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
chainparams.cpp Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
chainparams.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
chainparamsbase.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
chainparamsbase.h Chainparams: Use a regular factory for creating chainparams 2017-05-03 18:15:47 +02:00
chainparamsseeds.h p2p: Hardcoded seeds update pre-0.15 branch 2017-07-30 14:04:51 +02:00
checkpoints.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
checkpoints.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
checkqueue.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
clientversion.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
clientversion.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
coins.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
coins.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
compat.h Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
compressor.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
compressor.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
core_io.h Merge #11178: Add iswitness parameter to decode- and fundrawtransaction RPCs 2017-12-19 09:55:11 +01:00
core_memusage.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
core_read.cpp Merge #11178: Add iswitness parameter to decode- and fundrawtransaction RPCs 2017-12-19 09:55:11 +01:00
core_write.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
cuckoocache.h Fix header guards using reserved identifiers 2017-08-26 02:56:53 +03:00
dbwrapper.cpp Merge #10574: Remove includes in .cpp files for things the corresponding .h file already included 2017-12-12 14:56:25 +01:00
dbwrapper.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
fs.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
fs.h [Trivial] Add BITCOIN_FS_H endif footer in fs.h 2017-05-19 02:01:28 -07:00
hash.cpp Remove unused include in hash.cpp 2017-12-13 20:08:49 +09:00
hash.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
httprpc.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
httprpc.h Remove unnecessary forward class declarations in header files 2017-06-12 20:37:43 +02:00
httpserver.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
httpserver.h Declare single-argument (non-converting) constructors "explicit" 2017-08-16 16:33:25 +02:00
indirectmap.h
init.cpp Merge #11831: Always return true if AppInitMain got to the end 2017-12-12 10:27:53 +01:00
init.h init: Factor out AppInitLockDataDirectory 2017-07-17 14:56:52 +02:00
key.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
key.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
keystore.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
keystore.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
limitedmap.h Declare single-argument (non-converting) constructors "explicit" 2017-08-16 16:33:25 +02:00
Makefile.am Add -walletdir parameter to specify custom wallet dir 2017-11-18 00:50:58 +13:00
Makefile.bench.include build: Make "make clean" remove all files created when running "make check" 2017-10-04 14:54:41 +02:00
Makefile.leveldb.include build: verify that the assembler can handle crc32 functions 2017-07-13 12:49:05 -04:00
Makefile.qt.include Merge #11621: [build] Add temp_bitcoin_locale_qrc to CLEAN_QT to fix make distcheck 2017-11-17 14:04:02 +01:00
Makefile.qttest.include Remove redundant testutil files 2017-09-05 15:02:17 +12:00
Makefile.test.include [tests] Test that mempool rejects coinbase transactions 2017-11-18 00:48:34 -08:00
memusage.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
merkleblock.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
merkleblock.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
miner.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
miner.h Make boost::multi_index comparators const 2017-12-07 10:06:38 -05:00
net.cpp Merge #11616: Update ban-state in case of dirty-state during periodic sweep 2017-12-15 10:43:34 +01:00
net.h Add Clang thread safety analysis annotations 2017-11-23 07:59:58 +01:00
net_processing.cpp Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
net_processing.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
netaddress.cpp Remove includes in .cpp files for things the corresponding .h file already included 2017-11-16 22:26:34 +01:00
netaddress.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
netbase.cpp Merge #11363: net: Split socket create/connect 2017-12-13 05:42:32 +01:00
netbase.h Merge #11363: net: Split socket create/connect 2017-12-13 05:42:32 +01:00
netmessagemaker.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
noui.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
noui.h
pow.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
pow.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
prevector.h Fix header guards using reserved identifiers 2017-08-26 02:56:53 +03:00
protocol.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
protocol.h Add NODE_NETWORK_LIMITED flags and min block amount constants 2017-12-05 11:03:59 -10:00
pubkey.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
pubkey.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
random.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
random.h Merge #11558: Minimal code changes to allow msvc compilation 2017-12-13 14:05:25 +01:00
rest.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
reverse_iterator.h Declare single-argument (non-converting) constructors "explicit" 2017-08-16 16:33:25 +02:00
reverselock.h
scheduler.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
scheduler.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
serialize.h Merge #10493: Use range-based for loops (C++11) when looping over map elements 2017-11-30 17:10:05 -05:00
streams.h Merge #10839: Don't use pass by reference to const for cheaply-copied types (bool, char, etc.) 2017-12-14 18:28:01 +01:00
sync.cpp threads: add a thread_local autoconf check 2017-11-27 15:01:47 -08:00
sync.h Switched sync.{cpp,h} to std threading primitives. 2017-11-18 11:35:14 -08:00
threadinterrupt.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
threadinterrupt.h
threadsafety.h
timedata.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
timedata.h
tinyformat.h [Util] Update tinyformat.h 2017-10-29 21:12:12 +08:00
torcontrol.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
torcontrol.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
txdb.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
txdb.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
txmempool.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
txmempool.h Make boost::multi_index comparators const 2017-12-07 10:06:38 -05:00
ui_interface.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
ui_interface.h Drop upgrade-cancel callback registration for a generic "resumeable" 2017-08-20 20:04:15 -04:00
uint256.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
uint256.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
undo.h Remove trailing whitespace causing travis failure 2017-11-16 08:23:03 +13:00
util.cpp Merge #10574: Remove includes in .cpp files for things the corresponding .h file already included 2017-12-12 14:56:25 +01:00
util.h Merge #11583: Do not make it trivial for inbound peers to generate log entries 2017-12-11 17:06:22 +01:00
utilmoneystr.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
utilmoneystr.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
utilstrencodings.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
utilstrencodings.h Implement BIP173 addresses and tests 2017-09-28 16:24:30 -07:00
utiltime.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
utiltime.h [logging] log system time and mock time 2017-05-10 15:49:00 -04:00
validation.cpp Merge #10574: Remove includes in .cpp files for things the corresponding .h file already included 2017-12-12 14:56:25 +01:00
validation.h Merge #10279: Add a CChainState class to validation.cpp to take another step towards clarifying internal interfaces 2017-12-12 14:36:57 +01:00
validationinterface.cpp Fix shutdown in case of errors during initialization 2017-11-28 12:12:05 +01:00
validationinterface.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
version.h Remove unused constant MEMPOOL_GD_VERSION 2017-06-09 01:45:36 +02:00
versionbits.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
versionbits.h scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
warnings.cpp scripted-diff: Replace #include "" with #include <> (ryanofsky) 2017-11-16 08:23:01 +13:00
warnings.h remove some unused functions 2017-07-22 09:55:57 +02:00