From b2f49bd7325989267017260a9e7c843588a8c237 Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Sat, 24 Mar 2018 18:37:10 -0500 Subject: Integration of property based testing into Bitcoin Core update copyright headers attempt to fix linting errors Fixing issue with make check classifying generator files as actual unit tests Wrapping gen files in ENABLE_PROPERTY_TESTS macro Make macro better --- src/test/gen/crypto_gen.cpp | 19 ++++++++++++++ src/test/gen/crypto_gen.h | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/test/key_properties.cpp | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 src/test/gen/crypto_gen.cpp create mode 100644 src/test/gen/crypto_gen.h create mode 100644 src/test/key_properties.cpp (limited to 'src/test') diff --git a/src/test/gen/crypto_gen.cpp b/src/test/gen/crypto_gen.cpp new file mode 100644 index 0000000000..ca8c65806f --- /dev/null +++ b/src/test/gen/crypto_gen.cpp @@ -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 + +#include + +#include +#include +#include +#include + +/** Generates 1 to 20 keys for OP_CHECKMULTISIG */ +rc::Gen> MultisigKeys() +{ + return rc::gen::suchThat(rc::gen::arbitrary>(), [](const std::vector& keys) { + return keys.size() >= 1 && keys.size() <= 15; + }); +}; diff --git a/src/test/gen/crypto_gen.h b/src/test/gen/crypto_gen.h new file mode 100644 index 0000000000..7c2fb0350f --- /dev/null +++ b/src/test/gen/crypto_gen.h @@ -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 +#include +#include +#include +#include +#include +#include + +/** Generates 1 to 15 keys for OP_CHECKMULTISIG */ +rc::Gen> MultisigKeys(); + +namespace rc +{ +/** Generator for a new CKey */ +template <> +struct Arbitrary { + static Gen arbitrary() + { + return rc::gen::map([](int x) { + CKey key; + key.MakeNewKey(true); + return key; + }); + }; +}; + +/** Generator for a CPrivKey */ +template <> +struct Arbitrary { + static Gen arbitrary() + { + return gen::map(gen::arbitrary(), [](const CKey& key) { + return key.GetPrivKey(); + }); + }; +}; + +/** Generator for a new CPubKey */ +template <> +struct Arbitrary { + static Gen arbitrary() + { + return gen::map(gen::arbitrary(), [](const CKey& key) { + return key.GetPubKey(); + }); + }; +}; +/** Generates a arbitrary uint256 */ +template <> +struct Arbitrary { + static Gen arbitrary() + { + return rc::gen::just(GetRandHash()); + }; +}; +} //namespace rc +#endif diff --git a/src/test/key_properties.cpp b/src/test/key_properties.cpp new file mode 100644 index 0000000000..14e3c85359 --- /dev/null +++ b/src/test/key_properties.cpp @@ -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 + +#include +#include