lbrycrd/src/test/gen/crypto_gen.h
Chris Stewart b2f49bd732 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
2018-08-27 08:51:51 -05:00

63 lines
1.5 KiB
C++

// 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