parent
08c4994969
commit
9e071b0089
@ -1 +1 @@
|
||||
berkeleydb boost-filesystem boost-multi-index boost-signals2 boost-test boost-thread libevent[thread] rapidcheck zeromq double-conversion
|
||||
berkeleydb boost-filesystem boost-multi-index boost-signals2 boost-test boost-thread libevent[thread] zeromq double-conversion
|
@ -1,21 +0,0 @@
|
||||
package=rapidcheck
|
||||
$(package)_version=d9482c683429fe79122e3dcab14c9655874aeb8e
|
||||
$(package)_download_path=https://github.com/emil-e/rapidcheck/archive
|
||||
$(package)_file_name=$($(package)_version).tar.gz
|
||||
$(package)_sha256_hash=b9ee8955b175fd3c0757ebd887bb075541761af08b0c28391b7c6c0685351f6b
|
||||
|
||||
define $(package)_config_cmds
|
||||
cmake -DCMAKE_INSTALL_PREFIX=$($(package)_staging_dir)$(host_prefix) -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DRC_ENABLE_BOOST_TEST=ON -B .
|
||||
endef
|
||||
|
||||
define $(package)_preprocess_cmds
|
||||
sed -i.old 's/ -Wall//' CMakeLists.txt
|
||||
endef
|
||||
|
||||
define $(package)_build_cmds
|
||||
$(MAKE) rapidcheck
|
||||
endef
|
||||
|
||||
define $(package)_stage_cmds
|
||||
$(MAKE) rapidcheck install
|
||||
endef
|
@ -1,84 +0,0 @@
|
||||
# RapidCheck property-based testing for Bitcoin Core
|
||||
|
||||
## Concept
|
||||
|
||||
Property-based testing is experimentally being added to Bitcoin Core with
|
||||
[RapidCheck](https://github.com/emil-e/rapidcheck), a C++ framework for
|
||||
property-based testing inspired by the Haskell library
|
||||
[QuickCheck](https://hackage.haskell.org/package/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.
|
||||
|
||||
## Running
|
||||
|
||||
If RapidCheck is installed, Bitcoin Core will automatically run the
|
||||
property-based tests with the unit tests during `make check`, unless the
|
||||
`--without-rapidcheck` flag is passed when configuring.
|
||||
|
||||
For more information, run `./configure --help` and see `--with-rapidcheck` under
|
||||
Optional Packages.
|
||||
|
||||
## Setup
|
||||
|
||||
The following instructions have been tested with Linux Debian and macOS.
|
||||
|
||||
1. Clone the RapidCheck source code and cd into the repository.
|
||||
|
||||
```shell
|
||||
git clone https://github.com/emil-e/rapidcheck.git
|
||||
cd rapidcheck
|
||||
```
|
||||
|
||||
2. Build RapidCheck (requires CMake to be installed).
|
||||
|
||||
```shell
|
||||
cmake -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true -DRC_ENABLE_BOOST_TEST=ON $(pwd)
|
||||
make && make install
|
||||
```
|
||||
|
||||
3. Configure Bitcoin Core with RapidCheck.
|
||||
|
||||
`cd` to the directory of your local bitcoin repository and run
|
||||
`./configure`. In the output you should see:
|
||||
|
||||
```shell
|
||||
checking rapidcheck.h usability... yes
|
||||
checking rapidcheck.h presence... yes
|
||||
checking for rapidcheck.h... yes
|
||||
[...]
|
||||
Options used to compile and link:
|
||||
[...]
|
||||
with test = yes
|
||||
with prop = yes
|
||||
```
|
||||
|
||||
4. Build Bitcoin Core with RapidCheck.
|
||||
|
||||
Now you can run `make` and should see the property-based tests compiled with
|
||||
the unit tests:
|
||||
|
||||
```shell
|
||||
Making all in src
|
||||
[...]
|
||||
CXX test/gen/test_bitcoin-crypto_gen.o
|
||||
CXX test/test_bitcoin-key_properties.o
|
||||
```
|
||||
|
||||
5. Run the unit tests with `make check`. The property-based tests will be run
|
||||
with the unit tests.
|
||||
|
||||
```shell
|
||||
Running tests: crypto_tests from test/crypto_tests.cpp
|
||||
[...]
|
||||
Running tests: key_properties from test/key_properties.cpp
|
||||
```
|
||||
|
||||
That's it! You are now running property-based tests in Bitcoin Core.
|
@ -1,19 +0,0 @@
|
||||
// Copyright (c) 2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#include <test/gen/crypto_gen.h>
|
||||
|
||||
#include <key.h>
|
||||
|
||||
#include <rapidcheck/gen/Arbitrary.h>
|
||||
#include <rapidcheck/Gen.h>
|
||||
#include <rapidcheck/gen/Predicate.h>
|
||||
#include <rapidcheck/gen/Container.h>
|
||||
|
||||
/** Generates 1 to 20 keys for OP_CHECKMULTISIG */
|
||||
rc::Gen<std::vector<CKey>> MultisigKeys()
|
||||
{
|
||||
return rc::gen::suchThat(rc::gen::arbitrary<std::vector<CKey>>(), [](const std::vector<CKey>& keys) {
|
||||
return keys.size() >= 1 && keys.size() <= 15;
|
||||
});
|
||||
};
|
@ -1,63 +0,0 @@
|
||||
// Copyright (c) 2018 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#ifndef BITCOIN_TEST_GEN_CRYPTO_GEN_H
|
||||
#define BITCOIN_TEST_GEN_CRYPTO_GEN_H
|
||||
|
||||
#include <key.h>
|
||||
#include <random.h>
|
||||
#include <uint256.h>
|
||||
#include <rapidcheck/gen/Arbitrary.h>
|
||||
#include <rapidcheck/Gen.h>
|
||||
#include <rapidcheck/gen/Create.h>
|
||||
#include <rapidcheck/gen/Numeric.h>
|
||||
|
||||
/** Generates 1 to 15 keys for OP_CHECKMULTISIG */
|
||||
rc::Gen<std::vector<CKey>> MultisigKeys();
|
||||
|
||||
namespace rc
|
||||
{
|
||||
/** Generator for a new CKey */
|
||||
template <>
|
||||
struct Arbitrary<CKey> {
|
||||
static Gen<CKey> arbitrary()
|
||||
{
|
||||
return rc::gen::map<int>([](int x) {
|
||||
CKey key;
|
||||
key.MakeNewKey(true);
|
||||
return key;
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/** Generator for a CPrivKey */
|
||||
template <>
|
||||
struct Arbitrary<CPrivKey> {
|
||||
static Gen<CPrivKey> arbitrary()
|
||||
{
|
||||
return gen::map(gen::arbitrary<CKey>(), [](const CKey& key) {
|
||||
return key.GetPrivKey();
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
/** Generator for a new CPubKey */
|
||||
template <>
|
||||
struct Arbitrary<CPubKey> {
|
||||
static Gen<CPubKey> arbitrary()
|
||||
{
|
||||
return gen::map(gen::arbitrary<CKey>(), [](const CKey& key) {
|
||||
return key.GetPubKey();
|
||||
});
|
||||
};
|
||||
};
|
||||
/** Generates a arbitrary uint256 */
|
||||
template <>
|
||||
struct Arbitrary<uint256> {
|
||||
static Gen<uint256> arbitrary()
|
||||
{
|
||||
return rc::gen::just(GetRandHash());
|
||||
};
|
||||
};
|
||||
} //namespace rc
|
||||
#endif
|
@ -1,48 +0,0 @@
|
||||
// Copyright (c) 2018-2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#include <key.h>
|
||||
|
||||
#include <uint256.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <rapidcheck/boost_test.h>
|
||||
#include <rapidcheck/gen/Arbitrary.h>
|
||||
#include <rapidcheck/Gen.h>
|
||||
|
||||
#include <test/gen/crypto_gen.h>
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(key_properties, BasicTestingSetup)
|
||||
|
||||
/** Check CKey uniqueness */
|
||||
RC_BOOST_PROP(key_uniqueness, (const CKey& key1, const CKey& key2))
|
||||
{
|
||||
RC_ASSERT(!(key1 == key2));
|
||||
}
|
||||
|
||||
/** Verify that a private key generates the correct public key */
|
||||
RC_BOOST_PROP(key_generates_correct_pubkey, (const CKey& key))
|
||||
{
|
||||
CPubKey pubKey = key.GetPubKey();
|
||||
RC_ASSERT(key.VerifyPubKey(pubKey));
|
||||
}
|
||||
|
||||
/** Create a CKey using the 'Set' function must give us the same key */
|
||||
RC_BOOST_PROP(key_set_symmetry, (const CKey& key))
|
||||
{
|
||||
CKey key1;
|
||||
key1.Set(key.begin(), key.end(), key.IsCompressed());
|
||||
RC_ASSERT(key1 == key);
|
||||
}
|
||||
|
||||
/** Create a CKey, sign a piece of data, then verify it with the public key */
|
||||
RC_BOOST_PROP(key_sign_symmetry, (const CKey& key, const uint256& hash))
|
||||
{
|
||||
std::vector<unsigned char> vchSig;
|
||||
key.Sign(hash, vchSig, 0);
|
||||
const CPubKey& pubKey = key.GetPubKey();
|
||||
RC_ASSERT(pubKey.Verify(hash, vchSig));
|
||||
}
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in new issue