Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 802 Lines • ▼ Show 20 Lines | auto addCoin = [&]() { | ||||
coins.AddCoin(outpoint, | coins.AddCoin(outpoint, | ||||
Coin(CTxOut(amount, script), height, is_coinbase), false); | Coin(CTxOut(amount, script), height, is_coinbase), false); | ||||
return outpoint; | return outpoint; | ||||
}; | }; | ||||
const COutPoint conflictingOutpoint = addCoin(); | const COutPoint conflictingOutpoint = addCoin(); | ||||
const COutPoint outpointToSend = addCoin(); | const COutPoint outpointToSend = addCoin(); | ||||
const COutPoint outpointToAdd(TxId(GetRandHash()), 0); | |||||
ProofRef proofToInvalidate; | ProofRef proofToInvalidate; | ||||
{ | { | ||||
ProofBuilder pb(0, 0, key); | ProofBuilder pb(0, 0, key); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pb.addUTXO(conflictingOutpoint, amount, height, is_coinbase, key)); | pb.addUTXO(conflictingOutpoint, amount, height, is_coinbase, key)); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pb.addUTXO(outpointToSend, amount, height, is_coinbase, key)); | pb.addUTXO(outpointToSend, amount, height, is_coinbase, key)); | ||||
proofToInvalidate = std::make_shared<Proof>(pb.build()); | proofToInvalidate = std::make_shared<Proof>(pb.build()); | ||||
} | } | ||||
BOOST_CHECK(pm.registerProof(proofToInvalidate)); | BOOST_CHECK(pm.registerProof(proofToInvalidate)); | ||||
ProofRef conflictingProof; | ProofRef conflictingProof; | ||||
{ | { | ||||
ProofBuilder pb(0, 0, key); | ProofBuilder pb(0, 0, key); | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
pb.addUTXO(conflictingOutpoint, amount, height, is_coinbase, key)); | pb.addUTXO(conflictingOutpoint, amount, height, is_coinbase, key)); | ||||
BOOST_CHECK( | BOOST_CHECK(pb.addUTXO(addCoin(), amount, height, is_coinbase, key)); | ||||
pb.addUTXO(outpointToAdd, amount, height, is_coinbase, key)); | |||||
conflictingProof = std::make_shared<Proof>(pb.build()); | conflictingProof = std::make_shared<Proof>(pb.build()); | ||||
} | } | ||||
BOOST_CHECK(!pm.registerProof(conflictingProof)); | BOOST_CHECK(!pm.registerProof(conflictingProof)); | ||||
// The conflicting proof is orphaned due to the missing outpointToAdd | // The conflicting proof is orphaned | ||||
BOOST_CHECK(pm.isOrphan(conflictingProof->getId())); | BOOST_CHECK(pm.isOrphan(conflictingProof->getId())); | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | CCoinsViewCache &coins = ::ChainstateActive().CoinsTip(); | ||||
// Make proofToInvalidate invalid | // Make proofToInvalidate invalid | ||||
coins.SpendCoin(outpointToSend); | coins.SpendCoin(outpointToSend); | ||||
// Make conflictingProof valid | |||||
coins.AddCoin(outpointToAdd, | |||||
Coin(CTxOut(amount, script), height, is_coinbase), false); | |||||
} | } | ||||
pm.updatedBlockTip(); | pm.updatedBlockTip(); | ||||
BOOST_CHECK(pm.isOrphan(proofToInvalidate->getId())); | BOOST_CHECK(pm.isOrphan(proofToInvalidate->getId())); | ||||
BOOST_CHECK(!pm.isOrphan(conflictingProof->getId())); | BOOST_CHECK(!pm.isOrphan(conflictingProof->getId())); | ||||
BOOST_CHECK(pm.isValid(conflictingProof->getId())); | BOOST_CHECK(pm.isValid(conflictingProof->getId())); | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |