Blackcoin Lore
This commit is contained in:
@@ -99,7 +99,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
{
|
||||
CBlock *pblock = &pblocktemplate->block; // pointer for convenience
|
||||
pblock->nVersion = 1;
|
||||
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+1;
|
||||
pblock->nTime = chainActive.Tip()->GetPastTimeLimit()+1;
|
||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||
txCoinbase.nVersion = 1;
|
||||
txCoinbase.vin[0].scriptSig = CScript();
|
||||
@@ -114,7 +114,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
pblock->hashMerkleRoot = BlockMerkleRoot(*pblock);
|
||||
pblock->nNonce = blockinfo[i].nonce;
|
||||
CValidationState state;
|
||||
BOOST_CHECK(ProcessNewBlock(state, chainparams, NULL, pblock, true, NULL));
|
||||
BOOST_CHECK(ProcessNewBlock(state, chainparams, NULL, pblock, true, NULL, pblock->GetHash()));
|
||||
BOOST_CHECK(state.IsValid());
|
||||
pblock->hashPrevBlock = pblock->GetHash();
|
||||
}
|
||||
@@ -283,8 +283,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
}
|
||||
|
||||
// non-final txs in mempool
|
||||
SetMockTime(chainActive.Tip()->GetMedianTimePast()+1);
|
||||
int flags = LOCKTIME_VERIFY_SEQUENCE|LOCKTIME_MEDIAN_TIME_PAST;
|
||||
SetMockTime(chainActive.Tip()->GetPastTimeLimit()+1);
|
||||
// height map
|
||||
std::vector<int> prevheights;
|
||||
|
||||
@@ -303,23 +302,22 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
tx.nLockTime = 0;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
|
||||
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
|
||||
BOOST_CHECK(SequenceLocks(tx, flags, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 2))); // Sequence locks pass on 2nd block
|
||||
BOOST_CHECK(CheckFinalTx(tx, 0)); // Locktime passes
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, 0)); // Sequence locks fail
|
||||
BOOST_CHECK(SequenceLocks(tx, 0, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 2))); // Sequence locks pass on 2nd block
|
||||
|
||||
// relative time locked
|
||||
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
|
||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | (((chainActive.Tip()->GetMedianTimePast()+1-chainActive[1]->GetMedianTimePast()) >> CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + 1); // txFirst[1] is the 3rd block
|
||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | (((chainActive.Tip()->GetPastTimeLimit()+1-chainActive[1]->GetPastTimeLimit()) >> CTxIn::SEQUENCE_LOCKTIME_GRANULARITY) + 1); // txFirst[1] is the 3rd block
|
||||
prevheights[0] = baseheight + 2;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
|
||||
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
|
||||
|
||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
|
||||
BOOST_CHECK(CheckFinalTx(tx, 0)); // Locktime passes
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, 0)); // Sequence locks fail
|
||||
for (int i = 0; i < 11; i++)
|
||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
|
||||
BOOST_CHECK(SequenceLocks(tx, flags, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 1))); // Sequence locks pass 512 seconds later
|
||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
|
||||
BOOST_CHECK(SequenceLocks(tx, 0, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 1))); // Sequence locks pass 512 seconds later
|
||||
for (int i = 0; i < 11; i++)
|
||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime -= 512; //undo tricked MTP
|
||||
|
||||
// absolute height locked
|
||||
@@ -329,34 +327,34 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
tx.nLockTime = chainActive.Tip()->nHeight + 1;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
|
||||
BOOST_CHECK(!CheckFinalTx(tx, flags)); // Locktime fails
|
||||
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
|
||||
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetMedianTimePast())); // Locktime passes on 2nd block
|
||||
BOOST_CHECK(!CheckFinalTx(tx, 0)); // Locktime fails
|
||||
BOOST_CHECK(TestSequenceLocks(tx, 0)); // Sequence locks pass
|
||||
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetPastTimeLimit())); // Locktime passes on 2nd block
|
||||
|
||||
// absolute time locked
|
||||
tx.vin[0].prevout.hash = txFirst[3]->GetHash();
|
||||
tx.nLockTime = chainActive.Tip()->GetMedianTimePast();
|
||||
tx.nLockTime = chainActive.Tip()->GetPastTimeLimit();
|
||||
prevheights.resize(1);
|
||||
prevheights[0] = baseheight + 4;
|
||||
hash = tx.GetHash();
|
||||
mempool.addUnchecked(hash, entry.Time(GetTime()).FromTx(tx));
|
||||
BOOST_CHECK(!CheckFinalTx(tx, flags)); // Locktime fails
|
||||
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
|
||||
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetMedianTimePast() + 1)); // Locktime passes 1 second later
|
||||
BOOST_CHECK(!CheckFinalTx(tx, 0)); // Locktime fails
|
||||
BOOST_CHECK(TestSequenceLocks(tx, 0)); // Sequence locks pass
|
||||
BOOST_CHECK(IsFinalTx(tx, chainActive.Tip()->nHeight + 2, chainActive.Tip()->GetPastTimeLimit() + 1)); // Locktime passes 1 second later
|
||||
|
||||
// mempool-dependent transactions (not added)
|
||||
tx.vin[0].prevout.hash = hash;
|
||||
prevheights[0] = chainActive.Tip()->nHeight + 1;
|
||||
tx.nLockTime = 0;
|
||||
tx.vin[0].nSequence = 0;
|
||||
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
|
||||
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
|
||||
BOOST_CHECK(CheckFinalTx(tx, 0)); // Locktime passes
|
||||
BOOST_CHECK(TestSequenceLocks(tx, 0)); // Sequence locks pass
|
||||
tx.vin[0].nSequence = 1;
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, 0)); // Sequence locks fail
|
||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG;
|
||||
BOOST_CHECK(TestSequenceLocks(tx, flags)); // Sequence locks pass
|
||||
BOOST_CHECK(TestSequenceLocks(tx, 0)); // Sequence locks pass
|
||||
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
|
||||
BOOST_CHECK(!TestSequenceLocks(tx, 0)); // Sequence locks fail
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
|
||||
|
||||
@@ -367,10 +365,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 3);
|
||||
delete pblocktemplate;
|
||||
// However if we advance height by 1 and time by 512, all of them should be mined
|
||||
for (int i = 0; i < CBlockIndex::nMedianTimeSpan; i++)
|
||||
for (int i = 0; i < 11; i++)
|
||||
chainActive.Tip()->GetAncestor(chainActive.Tip()->nHeight - i)->nTime += 512; //Trick the MedianTimePast
|
||||
chainActive.Tip()->nHeight++;
|
||||
SetMockTime(chainActive.Tip()->GetMedianTimePast() + 1);
|
||||
SetMockTime(chainActive.Tip()->GetPastTimeLimit() + 1);
|
||||
|
||||
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
|
||||
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5);
|
||||
|
||||
Reference in New Issue
Block a user