get tests passing for new block rewards, change initial reward to 400M

This commit is contained in:
Jimmy Kiselak 2016-04-16 18:42:11 -04:00
parent 76b40a0ab4
commit a78dfae04f
5 changed files with 74 additions and 49 deletions

View file

@ -129,17 +129,17 @@ public:
nMaxTipAge = 24 * 60 * 60;
nPruneAfterHeight = 100000;
genesis = CreateGenesisBlock(1446058291, 92744, 0x1f00ffff, 1, 350000000 * COIN, consensus);
genesis = CreateGenesisBlock(1446058291, 71748, 0x1f00ffff, 1, 400000000 * COIN, consensus);
consensus.hashGenesisBlock = genesis.GetHash();
//std::cout << "hex: " << consensus.hashGenesisBlock.GetHex() << std::endl;
assert(consensus.hashGenesisBlock == uint256S("0x00005fa7f9e8fece6b2dfbeb0001b5b20f42f7fe49197fbbd170370f58d4c7d7"));
assert(consensus.hashGenesisBlock == uint256S("0x0000678ddce6b9b57e58fab6b89a1cf63519ffb4bc097debb1836577ead9a3be"));
//std::cout << "merkle root: " << genesis.hashMerkleRoot.GetHex() << std::endl;
assert(genesis.hashMerkleRoot == uint256S("0xba64cd17d1a1d03b1e5db2dc477822ba8f858443a38b0640d918b211ab22c51d"));
assert(genesis.hashMerkleRoot == uint256S("0xb8211c82c3d15bcd78bba57005b86fed515149a53a425eb592c07af99fe559cc"));
vSeeds.clear();
vFixedSeeds.clear();
vSeeds.push_back(CDNSSeedData("lbrycrd.lbry.io", "testseed.lbrycrd.lbry.io")); // lbry.io
vSeeds.push_back(CDNSSeedData("lbrycrd.lbry.io", "seed.lbrycrd.lbry.io")); // lbry.io
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,0x55);
base58Prefixes[SCRIPT_ADDRESS] = std::vector<unsigned char>(1,0x7a);
@ -194,12 +194,12 @@ public:
nMaxTipAge = 0x7fffffff;
nPruneAfterHeight = 1000;
genesis = CreateGenesisBlock(1446058291, 92744, 0x1f00ffff, 1, 350000000 * COIN, consensus);
genesis = CreateGenesisBlock(1446058291, 71748, 0x1f00ffff, 1, 400000000 * COIN, consensus);
consensus.hashGenesisBlock = genesis.GetHash();
//std::cout << "testnet genesis hash: " << genesis.GetHash().GetHex() << std::endl;
//std::cout << "testnet merkle hash: " << genesis.hashMerkleRoot.GetHex() << std::endl;
assert(consensus.hashGenesisBlock == uint256S("0x00005fa7f9e8fece6b2dfbeb0001b5b20f42f7fe49197fbbd170370f58d4c7d7"));
assert(genesis.hashMerkleRoot == uint256S("0xba64cd17d1a1d03b1e5db2dc477822ba8f858443a38b0640d918b211ab22c51d"));
assert(consensus.hashGenesisBlock == uint256S("0x0000678ddce6b9b57e58fab6b89a1cf63519ffb4bc097debb1836577ead9a3be"));
assert(genesis.hashMerkleRoot == uint256S("0xb8211c82c3d15bcd78bba57005b86fed515149a53a425eb592c07af99fe559cc"));
vFixedSeeds.clear();
vSeeds.clear();
@ -259,12 +259,12 @@ public:
nDefaultPort = 29246;
nPruneAfterHeight = 1000;
genesis = CreateGenesisBlock(1446058291, 3, 0x207fffff, 1, 350000000 * COIN, consensus);
genesis = CreateGenesisBlock(1446058291, 1, 0x207fffff, 1, 400000000 * COIN, consensus);
consensus.hashGenesisBlock = genesis.GetHash();
//std::cout << "regtest genensis hash: " << genesis.GetHash().GetHex() << std::endl;
//std::cout << "regtest hashmerkleroot: " << genesis.hashMerkleRoot.GetHex() << std::endl;
assert(consensus.hashGenesisBlock == uint256S("0x27cc4fec37b39831971deadcee7cf4725db7d693a0421fc1d9ca19b7420f5f27"));
assert(genesis.hashMerkleRoot == uint256S("0xba64cd17d1a1d03b1e5db2dc477822ba8f858443a38b0640d918b211ab22c51d"));
assert(consensus.hashGenesisBlock == uint256S("0x6e3fcf1299d4ec5d79c3a4c91d624a4acf9e2e173d95a1a0504f677669687556"));
assert(genesis.hashMerkleRoot == uint256S("0xb8211c82c3d15bcd78bba57005b86fed515149a53a425eb592c07af99fe559cc"));
vFixedSeeds.clear(); //! Regtest mode doesn't have any fixed seeds.
vSeeds.clear(); //! Regtest mode doesn't have any DNS seeds.

View file

@ -1108,13 +1108,19 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
{
return 400000000 * COIN;
}
else if (nHeight <= 5000)
else if (nHeight <= 5100)
{
return 1;
return 1 * COIN;
}
else if (nHeight <= 55000)
{
return ceil((nHeight - 5000) / 100);
int l = nHeight - 5000;
int nLevel = 0;
for (int i = 0; i < l; i+=100)
{
nLevel++;
}
return nLevel * COIN;
}
CAmount nStartingSubsidy = 500 * COIN;
int nLevel = (nHeight - 55001) / consensusParams.nSubsidyLevelInterval;

View file

@ -306,6 +306,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
CMutableTransaction tx3 = BuildTransaction(tx1);
tx3.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx1ClaimId << vchValue1 << OP_2DROP << OP_2DROP << OP_TRUE;
tx3.vout[0].nValue -= 10000;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx2);
@ -322,7 +323,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
CMutableTransaction tx7 = BuildTransaction(coinbases[3]);
tx7.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName1 << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx7.vout[0].nValue = tx1.vout[0].nValue - 1;
tx7.vout[0].nValue = tx1.vout[0].nValue - 10001;
uint160 tx7ClaimId = ClaimIdHash(tx7.GetHash(), 0);
std::vector<unsigned char> vchTx7ClaimId(tx7ClaimId.begin(), tx7ClaimId.end());
COutPoint tx7OutPoint(tx7.GetHash(), 0);
@ -336,6 +337,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_insert_update_claim)
CMutableTransaction tx9 = BuildTransaction(tx7);
tx9.vout[0].scriptPubKey = CScript() << OP_UPDATE_CLAIM << vchName1 << vchTx7ClaimId << vchValue2 << OP_2DROP << OP_2DROP << OP_TRUE;
tx9.vout[0].nValue -= 10000;
COutPoint tx9OutPoint(tx9.GetHash(), 0);
CMutableTransaction tx10 = BuildTransaction(coinbases[4]);
@ -1282,19 +1284,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 100000000;
tx1.vout[0].nValue = 1;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = 500000000;
tx2.vout[0].nValue = 5;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1ClaimId << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
tx3.vout[0].nValue = 5;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx1);
@ -1633,19 +1635,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_supporting_claims2)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 100000000;
tx1.vout[0].nValue = 1;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = 500000000;
tx2.vout[0].nValue = 5;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1ClaimId << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
tx3.vout[0].nValue = 5;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx1);
@ -2109,19 +2111,19 @@ BOOST_AUTO_TEST_CASE(claimtrie_expiring_supports)
CMutableTransaction tx1 = BuildTransaction(coinbases[0]);
tx1.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue1 << OP_2DROP << OP_DROP << OP_TRUE;
tx1.vout[0].nValue = 100000000;
tx1.vout[0].nValue = 1;
COutPoint tx1OutPoint(tx1.GetHash(), 0);
CMutableTransaction tx2 = BuildTransaction(coinbases[1]);
tx2.vout[0].scriptPubKey = CScript() << OP_CLAIM_NAME << vchName << vchValue2 << OP_2DROP << OP_DROP << OP_TRUE;
tx2.vout[0].nValue = 500000000;
tx2.vout[0].nValue = 5;
COutPoint tx2OutPoint(tx2.GetHash(), 0);
CMutableTransaction tx3 = BuildTransaction(coinbases[2]);
uint160 tx1ClaimId = ClaimIdHash(tx1.GetHash(), 0);
std::vector<unsigned char> vchTx1ClaimId(tx1ClaimId.begin(), tx1ClaimId.end());
tx3.vout[0].scriptPubKey = CScript() << OP_SUPPORT_CLAIM << vchName << vchTx1ClaimId << OP_2DROP << OP_DROP << OP_TRUE;
tx3.vout[0].nValue = 500000000;
tx3.vout[0].nValue = 5;
COutPoint tx3OutPoint(tx3.GetHash(), 0);
CMutableTransaction tx4 = BuildTransaction(tx1);

View file

@ -14,17 +14,34 @@ BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
static void TestBlockSubsidyReductions(const Consensus::Params& consensusParams)
{
int nHeight = 0;
BOOST_CHECK_EQUAL(GetBlockSubsidy(nHeight, consensusParams), 400000000*COIN);
// Verify that block reward is 1 until block 5100
nHeight += 25;
for (; nHeight < 5100; nHeight += 80)
{
BOOST_CHECK_EQUAL(GetBlockSubsidy(nHeight, consensusParams), 1*COIN);
}
nHeight = 5100;
// Verify it increases by 1 coin every 100 blocks
for (int i = 1; nHeight < 55000; nHeight += 100, i++)
{
BOOST_CHECK_EQUAL(GetBlockSubsidy(nHeight, consensusParams), i*COIN);
}
int maxReductions = 500;
CAmount nInitialSubsidy = 500 * COIN;
int nHeight;
int nReductions;
for (nReductions = 0; nReductions < maxReductions; nReductions++)
{
nHeight = (((nReductions * nReductions + nReductions) >> 1) * consensusParams.nSubsidyLevelInterval) + 1;
nHeight = (((nReductions * nReductions + nReductions) >> 1) * consensusParams.nSubsidyLevelInterval) + 55001;
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
BOOST_CHECK_EQUAL(nSubsidy, nInitialSubsidy - nReductions * COIN);
}
nHeight = (((nReductions * nReductions + nReductions) >> 1) * consensusParams.nSubsidyLevelInterval) + 1;
nHeight = (((nReductions * nReductions + nReductions) >> 1) * consensusParams.nSubsidyLevelInterval) + 55001;
BOOST_CHECK_EQUAL(GetBlockSubsidy(nHeight, consensusParams), 0);
}
@ -53,7 +70,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
nSum += nSubsidy * 1000;
BOOST_CHECK(MoneyRange(nSum));
}
BOOST_CHECK_EQUAL(nSum, 102091600000000000LL);
BOOST_CHECK_EQUAL(nSum, 108322100000000000LL);
}
bool ReturnFalse() { return false; }

View file

@ -91,17 +91,17 @@ struct {
};*/
const unsigned int nonces[] = {
1702, 4426, 44803, 21, 88869, 40139, 16382, 13525, 114648, 1190,
194459, 110761, 23732, 7293, 171766, 61663, 11548, 120419, 55377, 16735,
22878, 134905, 212010, 386284, 64559, 40003, 74327, 94247, 285391, 23496,
15196, 72827, 7657, 54628, 128507, 85977, 110355, 7423, 2783, 10412,
101705, 371190, 48999, 107613, 277276, 64945, 5153, 84763, 15821, 26367,
218930, 24372, 149133, 319882, 546029, 276981, 234459, 42544, 25492, 271478,
211922, 337435, 316666, 76817, 478054, 34093, 11356, 67492, 316269, 150493,
472164, 126274, 185348, 55992, 17084, 13907, 120452, 17353, 33428, 843,
4592, 242491, 55161, 22142, 120981, 318025, 70127, 41879, 138513, 98839,
55840, 475261, 176074, 114618, 195011, 890468, 760697, 46632, 740918, 481503,
259751, 282723, 1912906, 2630280, 1418854, 1477557, 1250567, 2533285, 2699754, 545072,
79715, 115775, 224572, 12063, 35799, 81128, 7459, 3704, 74161, 174952,
179883, 1883, 24971, 12115, 7908, 24791, 78905, 135694, 24855, 6108,
45125, 6200, 326764, 105132, 1706, 243717, 3782, 90681, 130062, 7707,
77604, 62455, 49605, 21726, 119057, 27524, 73984, 1331, 51531, 38874,
52443, 99097, 36007, 27173, 88714, 287757, 235289, 353070, 239689, 1365413,
196645, 94742, 76681, 73463, 267621, 233818, 398669, 606185, 68966, 784609,
486234, 139093, 81707, 173497, 46683, 359339, 110459, 376803, 186202, 113121,
22549, 185881, 237077, 68777, 37739, 18754, 74470, 59347, 68344, 387196,
288599, 63477, 50646, 72807, 1276757, 311156, 350217, 824070, 268004, 203189,
11127, 512344, 101745, 161626, 7476, 92476, 807780, 183217, 1406078, 4693874,
1143704, 89400, 277776, 1555386, 2463291, 1965076, 2377228, 170135, 112842, 118000,
};
// NOTE: These tests rely on CreateNewBlock doing its own self-validation!
@ -172,10 +172,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].prevout.n = 0;
tx.vout.resize(1);
tx.vout[0].nValue = 5000000000LL;
tx.vout[0].nValue = 50000000LL;
for (unsigned int i = 0; i < 1001; ++i)
{
tx.vout[0].nValue -= 1000000;
tx.vout[0].nValue -= 10000;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
@ -192,10 +192,10 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].scriptSig << vchData << OP_DROP;
tx.vin[0].scriptSig << OP_1;
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vout[0].nValue = 5000000000LL;
tx.vout[0].nValue = 50000000LL;
for (unsigned int i = 0; i < 128; ++i)
{
tx.vout[0].nValue -= 10000000;
tx.vout[0].nValue -= 10000;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// child with higher priority than parent
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
tx.vout[0].nValue = 4900000000LL;
tx.vout[0].nValue = 49000000LL;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[1].scriptSig = CScript() << OP_1;
tx.vin[1].prevout.hash = txFirst[0]->GetHash();
tx.vin[1].prevout.n = 0;
tx.vout[0].nValue = 5900000000LL;
tx.vout[0].nValue = 59000000LL;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
@ -244,14 +244,14 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].prevout.n = 0;
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vout[0].nValue = 4900000000LL;
tx.vout[0].nValue = 49000000LL;
script = CScript() << OP_0;
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
tx.vin[0].prevout.hash = hash;
tx.vin[0].scriptSig = CScript() << (std::vector<unsigned char>)script;
tx.vout[0].nValue -= 1000000;
tx.vout[0].nValue -= 10000;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
BOOST_CHECK(pblocktemplate = CreateNewBlock(scriptPubKey));
@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
// double spend txn pair in mempool
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vout[0].nValue = 4900000000LL;
tx.vout[0].nValue = 49000000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
hash = tx.GetHash();
mempool.addUnchecked(hash, CTxMemPoolEntry(tx, 11, GetTime(), 111.0, 11));
@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
tx.vin[0].scriptSig = CScript() << OP_1;
tx.vin[0].nSequence = 0;
tx.vout[0].nValue = 4900000000LL;
tx.vout[0].nValue = 49000000LL;
tx.vout[0].scriptPubKey = CScript() << OP_1;
tx.nLockTime = chainActive.Tip()->nHeight+1;
hash = tx.GetHash();
@ -293,7 +293,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx2.vin[0].scriptSig = CScript() << OP_1;
tx2.vin[0].nSequence = 0;
tx2.vout.resize(1);
tx2.vout[0].nValue = 4900000000LL;
tx2.vout[0].nValue = 49000000LL;
tx2.vout[0].scriptPubKey = CScript() << OP_1;
tx2.nLockTime = chainActive.Tip()->GetMedianTimePast()+1;
hash = tx2.GetHash();