RapidCheck property-based testing for Bitcoin Cash Node
Property-based testing is experimentally being added to Bitcoin Cash Node with RapidCheck, a C++ framework for property-based testing inspired by the Haskell library QuickCheck.
RapidCheck performs random testing of program properties. A specification of the program is given in the form of properties which functions should satisfy, and RapidCheck tests that the properties hold in a large number of randomly generated cases.
If an exception is found, RapidCheck tries to find the smallest case, for some definition of smallest, for which the property is still false and displays it as a counter-example. For example, if the input is an integer, RapidCheck tries to find the smallest integer for which the property is false.
The following instructions have been tested with Linux Debian and macOS.
Clone the RapidCheck source code and cd into the repository.
git clone https://github.com/emil-e/rapidcheck.git cd rapidcheck
mkdir build cd build cmake -GNinja .. -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DRC_ENABLE_BOOST_TEST=ON ninja sudo ninja install/strip
Configure Bitcoin Cash Node with RapidCheck.
cdto the directory of your local Bitcoin Cash Node repository, create a build directory and run cmake:
mkdir build cd build cmake -GNinja .. -DENABLE_PROPERTY_BASED_TESTS=ON
In the output you should see something similar to:
[...] -- Found Rapidcheck: /usr/local/include -- Found Rapidcheck: /usr/local/lib/librapidcheck.a [...]
Build Bitcoin Cash Node with RapidCheck.
Now you can run
ninja checkto build and run the unit tests, including the property-based tests. You can also build and run a single test by using
That's it! You are now running property-based tests in Bitcoin Cash Node.