mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
feat: actually test something EHF unit tests
This commit is contained in:
parent
762a808b8c
commit
64cedb30bd
@ -116,6 +116,10 @@ bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager&
|
|||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-version");
|
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Params().IsValidMNActivation(mnhfTx.signal.versionBit, pindexPrev->GetMedianTimePast())) {
|
||||||
|
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-non-ehf");
|
||||||
|
}
|
||||||
|
|
||||||
const CBlockIndex* pindexQuorum = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(mnhfTx.signal.quorumHash));
|
const CBlockIndex* pindexQuorum = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(mnhfTx.signal.quorumHash));
|
||||||
if (!pindexQuorum) {
|
if (!pindexQuorum) {
|
||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-quorum-hash");
|
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-quorum-hash");
|
||||||
@ -139,10 +143,6 @@ bool CheckMNHFTx(const ChainstateManager& chainman, const llmq::CQuorumManager&
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Params().IsValidMNActivation(mnhfTx.signal.versionBit, pindexPrev->GetMedianTimePast())) {
|
|
||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-non-ehf");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
#include <consensus/validation.h>
|
#include <consensus/validation.h>
|
||||||
#include <evo/mnhftx.h>
|
#include <evo/mnhftx.h>
|
||||||
#include <evo/specialtx.h>
|
#include <evo/specialtx.h>
|
||||||
|
#include <llmq/context.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
#include <validation.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
@ -18,24 +20,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
bool VerifyMNHFTx(const CTransaction& tx, TxValidationState& state)
|
static CMutableTransaction CreateMNHFTx(const uint256& quorumHash, const CBLSSignature& cblSig, const uint16_t& versionBit)
|
||||||
{
|
|
||||||
if (const auto opt_mnhfTx_payload = GetTxPayload<MNHFTxPayload>(tx); !opt_mnhfTx_payload) {
|
|
||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-payload");
|
|
||||||
} else if (opt_mnhfTx_payload->nVersion == 0 ||
|
|
||||||
opt_mnhfTx_payload->nVersion > MNHFTxPayload::CURRENT_VERSION) {
|
|
||||||
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-mnhf-version");
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static CMutableTransaction CreateMNHFTx(const uint256& mnhfTxHash, const CBLSSignature& cblSig, const uint16_t& versionBit)
|
|
||||||
{
|
{
|
||||||
MNHFTxPayload extraPayload;
|
MNHFTxPayload extraPayload;
|
||||||
extraPayload.nVersion = 1;
|
extraPayload.nVersion = 1;
|
||||||
extraPayload.signal.versionBit = versionBit;
|
extraPayload.signal.versionBit = versionBit;
|
||||||
extraPayload.signal.quorumHash = mnhfTxHash;
|
extraPayload.signal.quorumHash = quorumHash;
|
||||||
extraPayload.signal.sig = cblSig;
|
extraPayload.signal.sig = cblSig;
|
||||||
|
|
||||||
CMutableTransaction tx;
|
CMutableTransaction tx;
|
||||||
@ -46,19 +36,18 @@ static CMutableTransaction CreateMNHFTx(const uint256& mnhfTxHash, const CBLSSig
|
|||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_FIXTURE_TEST_SUITE(evo_mnhf_tests, BasicTestingSetup)
|
BOOST_FIXTURE_TEST_SUITE(evo_mnhf_tests, TestChain100Setup)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(verify_mnhf_specialtx_tests)
|
BOOST_AUTO_TEST_CASE(verify_mnhf_specialtx_tests)
|
||||||
{
|
{
|
||||||
int count = 10;
|
int count = 10;
|
||||||
uint16_t ver = 2;
|
uint16_t bit = 1;
|
||||||
|
|
||||||
std::vector<CBLSSignature> vec_sigs;
|
std::vector<CBLSSignature> vec_sigs;
|
||||||
std::vector<CBLSPublicKey> vec_pks;
|
std::vector<CBLSPublicKey> vec_pks;
|
||||||
std::vector<CBLSSecretKey> vec_sks;
|
std::vector<CBLSSecretKey> vec_sks;
|
||||||
|
|
||||||
CBLSSecretKey sk;
|
CBLSSecretKey sk;
|
||||||
uint256 hash = GetRandHash();
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
sk.MakeNewKey();
|
sk.MakeNewKey();
|
||||||
vec_pks.push_back(sk.GetPublicKey());
|
vec_pks.push_back(sk.GetPublicKey());
|
||||||
@ -71,13 +60,27 @@ BOOST_AUTO_TEST_CASE(verify_mnhf_specialtx_tests)
|
|||||||
BOOST_CHECK(ag_sk.IsValid());
|
BOOST_CHECK(ag_sk.IsValid());
|
||||||
BOOST_CHECK(ag_pk.IsValid());
|
BOOST_CHECK(ag_pk.IsValid());
|
||||||
|
|
||||||
uint256 verHash = uint256S(ToString(ver));
|
uint256 verHash = uint256S(ToString(bit));
|
||||||
auto sig = ag_sk.Sign(verHash);
|
auto sig = ag_sk.Sign(verHash);
|
||||||
BOOST_CHECK(sig.VerifyInsecure(ag_pk, verHash));
|
BOOST_CHECK(sig.VerifyInsecure(ag_pk, verHash));
|
||||||
|
|
||||||
const CMutableTransaction tx = CreateMNHFTx(hash, sig, ver);
|
auto& chainman = Assert(m_node.chainman);
|
||||||
|
auto& qman = *Assert(m_node.llmq_ctx)->qman;
|
||||||
|
const CBlockIndex* pindex = chainman->ActiveChain().Tip();
|
||||||
|
uint256 hash = GetRandHash();
|
||||||
TxValidationState state;
|
TxValidationState state;
|
||||||
BOOST_CHECK(VerifyMNHFTx(CTransaction(tx), state));
|
|
||||||
|
{ // wrong quorum (we don't have any indeed)
|
||||||
|
const CTransaction tx{CTransaction(CreateMNHFTx(hash, sig, bit))};
|
||||||
|
CheckMNHFTx(*chainman, qman, CTransaction(tx), pindex, state);
|
||||||
|
BOOST_CHECK_EQUAL(state.ToString(), "bad-mnhf-quorum-hash");
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // non EHF fork
|
||||||
|
const CTransaction tx{CTransaction(CreateMNHFTx(hash, sig, 28))};
|
||||||
|
CheckMNHFTx(*chainman, qman, CTransaction(tx), pindex, state);
|
||||||
|
BOOST_CHECK_EQUAL(state.ToString(), "bad-mnhf-non-ehf");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -145,7 +145,6 @@ class MnehfTest(DashTestFramework):
|
|||||||
pubkey = key.get_pubkey().get_bytes()
|
pubkey = key.get_pubkey().get_bytes()
|
||||||
ehf_tx = self.create_mnehf(28, pubkey)
|
ehf_tx = self.create_mnehf(28, pubkey)
|
||||||
ehf_unknown_tx = self.create_mnehf(27, pubkey)
|
ehf_unknown_tx = self.create_mnehf(27, pubkey)
|
||||||
ehf_invalid_tx = self.create_mnehf(9, pubkey) # deployment that is known as non-EHF
|
|
||||||
|
|
||||||
self.log.info("Checking deserialization of CMnEhf by python's code")
|
self.log.info("Checking deserialization of CMnEhf by python's code")
|
||||||
mnehf_payload = CMnEhf()
|
mnehf_payload = CMnEhf()
|
||||||
@ -166,7 +165,6 @@ class MnehfTest(DashTestFramework):
|
|||||||
self.log.info(f"ehf tx: {ehf_tx_sent}")
|
self.log.info(f"ehf tx: {ehf_tx_sent}")
|
||||||
ehf_unknown_tx_sent = self.send_tx(ehf_unknown_tx)
|
ehf_unknown_tx_sent = self.send_tx(ehf_unknown_tx)
|
||||||
self.log.info(f"unknown ehf tx: {ehf_unknown_tx_sent}")
|
self.log.info(f"unknown ehf tx: {ehf_unknown_tx_sent}")
|
||||||
self.send_tx(ehf_invalid_tx, expected_error='bad-mnhf-non-ehf')
|
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
ehf_blockhash = self.nodes[1].generate(1)[0]
|
ehf_blockhash = self.nodes[1].generate(1)[0]
|
||||||
self.sync_blocks()
|
self.sync_blocks()
|
||||||
|
Loading…
Reference in New Issue
Block a user