-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge #12775: Integration of property based testing into Bitcoin Core
b2f49bd Integration of property based testing into Bitcoin Core (Chris Stewart) Pull request description: This PR is a subset of the changes in #8469. It's meant to be easier to review. This PR contains all of the build instructions needed for travis to pass. It includes one property call `key_properties.cpp` along with a generator file called `crypto_gen.{h,cpp}`. Tree-SHA512: 895c9d9273dcd29f696b1de8dfe1ee843095831bf1f68472844181278850bec36b20f0ba7e51e796112c5cc75cd24759f9f1771906503bbf3af16f627e18c6c9
- Loading branch information
Showing
9 changed files
with
196 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package=rapidcheck | ||
$(package)_version=10fc0cb | ||
$(package)_download_path=https://github.com/MarcoFalke/rapidcheck/archive | ||
$(package)_file_name=$(package)-$($(package)_version).tar.gz | ||
$(package)_sha256_hash=9640926223c00af45bce4c7df8b756b5458a89b2ba74cfe3e404467f13ce26df | ||
|
||
define $(package)_config_cmds | ||
cmake -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true . | ||
endef | ||
|
||
define $(package)_build_cmds | ||
$(MAKE) && \ | ||
mkdir -p $($(package)_staging_dir)$(host_prefix)/include && \ | ||
cp -a include/* $($(package)_staging_dir)$(host_prefix)/include/ && \ | ||
cp -a extras/boost_test/include/rapidcheck/* $($(package)_staging_dir)$(host_prefix)/include/rapidcheck/ && \ | ||
mkdir -p $($(package)_staging_dir)$(host_prefix)/lib && \ | ||
cp -a librapidcheck.a $($(package)_staging_dir)$(host_prefix)/lib/ | ||
endef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// 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 <key.h> | ||
|
||
#include <base58.h> | ||
#include <script/script.h> | ||
#include <uint256.h> | ||
#include <util.h> | ||
#include <utilstrencodings.h> | ||
#include <test/test_bitcoin.h> | ||
#include <string> | ||
#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() |