19 #include <boost/test/unit_test.hpp>
25 static CKey GetRandomKey()
32 static CKeyID GetRandomKeyID()
44 static CScript GetRandomScript()
49 static ProRegPL GetRandomProRegPayload()
62 pl.
vchSig = InsecureRandBytes(63);
85 pl.
vchSig = InsecureRandBytes(63);
105 int vecsize = InsecureRandRange(500);
106 for (
int i = 0; i < vecsize; i++) {
107 fc.
signers.emplace_back((
bool)InsecureRandBits(1));
108 fc.
validMembers.emplace_back((
bool)InsecureRandBits(1));
137 template <
typename T>
138 static void TrivialCheckSpecialTx(
const CMutableTransaction& mtx,
const bool shouldFail,
const std::string& rejectReason)
143 BOOST_CHECK(pl.IsTriviallyValid(state) == !shouldFail);
149 static void SpecialTxTrivialValidator(
const UniValue& tests)
151 for (
size_t i = 1; i < tests.
size(); i++) {
152 const auto& test = tests[i];
157 std::string rejectReason =
"";
159 txHash =
uint256S(test[0].get_str());
161 txType = test[1].get_str();
165 bool shouldFail = test.size() > 3;
167 rejectReason = test[3].get_str();
172 case CTransaction::TxType::PROREG:
174 TrivialCheckSpecialTx<ProRegPL>(mtx, shouldFail, rejectReason);
176 case CTransaction::TxType::PROUPSERV:
178 TrivialCheckSpecialTx<ProUpServPL>(mtx, shouldFail, rejectReason);
180 case CTransaction::TxType::PROUPREG:
182 TrivialCheckSpecialTx<ProUpRegPL>(mtx, shouldFail, rejectReason);
184 case CTransaction::TxType::PROUPREV:
186 TrivialCheckSpecialTx<ProUpRevPL>(mtx, shouldFail, rejectReason);
192 std::string strTest = test.write();
193 BOOST_ERROR(
"Bad test, couldn't deserialize data: " << strTest);
207 mtx.
nType = CTransaction::TxType::PROREG;
208 mtx.
nVersion = CTransaction::TxVersion::LEGACY;
213 mtx.
nType = CTransaction::TxType::NORMAL;
224 mtx.
nType = CTransaction::TxType::PROREG;
230 mtx.
extraPayload = std::vector<uint8_t>(MAX_SPECIALTX_EXTRAPAYLOAD + 1, 1);
241 ProRegPL pl = GetRandomProRegPayload();
256 const ProRegPL& pl = GetRandomProRegPayload();
276 const ProUpServPL& pl = GetRandomProUpServPayload();
291 const ProUpRegPL& pl = GetRandomProUpRegPayload();
307 const ProUpRevPL& pl = GetRandomProUpRevPayload();
321 ProRegPL pl = GetRandomProRegPayload();
323 const CKey& key = GetRandomKey();
326 std::string strError;
350 UniValue tests =
read_json(std::string(json_tests::specialtx_valid, json_tests::specialtx_valid +
sizeof(json_tests::specialtx_valid)));
351 SpecialTxTrivialValidator(tests);
356 UniValue tests =
read_json(std::string(json_tests::specialtx_invalid, json_tests::specialtx_invalid +
sizeof(json_tests::specialtx_invalid)));
357 SpecialTxTrivialValidator(tests);
#define BLS_CURVE_SIG_SIZE
#define BLS_CURVE_PUBKEY_SIZE
const CChainParams & Params()
Return the currently selected parameters.
CBLSPublicKey GetPublicKey() const
void SetByteVector(const std::vector< uint8_t > &vecBytes)
An encapsulated private key.
void MakeNewKey(bool fCompressed)
Generate a new private key using a cryptographic PRNG.
CPubKey GetPubKey() const
Compute the public key from a private key.
A reference to a CKey: the Hash160 of its serialized public key.
static bool SignMessage(const std::string &strMessage, std::vector< unsigned char > &vchSigRet, const CKey &key)
Sign the message, returns true if successful.
static bool VerifyMessage(const CPubKey &pubkey, const std::vector< unsigned char > &vchSig, const std::string &strMessage, std::string &strErrorRet)
Verify the message signature, returns true if successful.
CKeyID GetID() const
Get the KeyID of this public key (hash of its serialization)
Serialized script, used inside transaction inputs and outputs.
The basic transaction that is broadcasted on the network and contained in blocks.
Capture information about block/transaction validation.
std::string GetRejectReason() const
CScript scriptOperatorPayout
COutPoint collateralOutpoint
CBLSPublicKey pubKeyOperator
std::vector< unsigned char > vchSig
std::string MakeSignString() const
std::vector< unsigned char > vchSig
CBLSPublicKey pubKeyOperator
CScript scriptOperatorPayout
CBLSPublicKey quorumPublicKey
std::vector< bool > validMembers
std::vector< bool > signers
CFinalCommitment commitment
BOOST_AUTO_TEST_SUITE_END()
UniValue read_json(const std::string &jsondata)
llmq::CFinalCommitment GetRandomLLMQCommitment()
BOOST_AUTO_TEST_CASE(protx_validation_test)
#define T(expected, seed, data)
RecursiveMutex cs_main
Global state.
bool Lookup(const std::string &name, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
#define BOOST_FIXTURE_TEST_SUITE(a, b)
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
uint256 GetRandHash() noexcept
uint256 CalcTxInputsHash(const CTransaction &tx)
bool CheckSpecialTxNoContext(const CTransaction &tx, CValidationState &state)
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a PIVX scriptPubKey for the given CTxDestination.
A mutable version of CTransaction.
Optional< std::vector< uint8_t > > extraPayload
void SetTxPayload(CMutableTransaction &tx, const T &payload)
bool GetTxPayload(const std::vector< unsigned char > &payload, T &obj)
uint256 uint256S(const char *str)
std::vector< unsigned char > ParseHex(const char *psz)