diff --git a/src/avalanche/proof.h b/src/avalanche/proof.h --- a/src/avalanche/proof.h +++ b/src/avalanche/proof.h @@ -118,9 +118,7 @@ IMPLEMENT_RCU_REFCOUNT(uint64_t); public: - Proof() - : sequence(0), expirationTime(0), master(), stakes(), - payoutScriptPubKey(CScript()), limitedProofId(), proofid() {} + Proof() : Proof(0, 0, CPubKey(), {}, CScript(), SchnorrSig()) {} Proof(uint64_t sequence_, int64_t expirationTime_, CPubKey master_, std::vector stakes_, const CScript &payoutScriptPubKey_, diff --git a/src/avalanche/test/proof_tests.cpp b/src/avalanche/test/proof_tests.cpp --- a/src/avalanche/test/proof_tests.cpp +++ b/src/avalanche/test/proof_tests.cpp @@ -886,6 +886,30 @@ gArgs.ClearForcedArg("-legacyavaproof"); } +BOOST_AUTO_TEST_CASE(serialization_roundtrip) { + auto checkSerializationRoundTrip = [&](const ProofRef &proof) { + Proof unserProof; + bilingual_str error; + BOOST_CHECK(Proof::FromHex(unserProof, proof->ToHex(), error)); + BOOST_CHECK(error.empty()); + BOOST_CHECK_EQUAL(proof->getId(), unserProof.getId()); + BOOST_CHECK(proof->getSignature() == unserProof.getSignature()); + }; + + for (const std::string &legacy : {"0", "1"}) { + gArgs.ForceSetArg("-legacyavaproof", legacy); + + checkSerializationRoundTrip(ProofRef::make()); + + for (size_t i = 0; i < 100; i++) { + checkSerializationRoundTrip(buildRandomProof( + GetRand(std::numeric_limits::max()))); + } + } + + gArgs.ClearForcedArg("-legacyavaproof"); +} + BOOST_AUTO_TEST_CASE(verify) { CCoinsView coinsDummy; CCoinsViewCache coins(&coinsDummy);