Test clean up and fixes
This commit is contained in:
parent
5a93638981
commit
42a21ef004
|
@ -21,7 +21,7 @@ class ShorterBlockTimes(BitcoinTestFramework):
|
||||||
return start_nodes(4, self.options.tmpdir, [[
|
return start_nodes(4, self.options.tmpdir, [[
|
||||||
'-nuparams=5ba81b19:0', # Overwinter
|
'-nuparams=5ba81b19:0', # Overwinter
|
||||||
'-nuparams=76b809bb:0', # Sapling
|
'-nuparams=76b809bb:0', # Sapling
|
||||||
'-nuparams=2bb40e60:103', # Blossom
|
'-nuparams=2bb40e60:106', # Blossom
|
||||||
]] * 4)
|
]] * 4)
|
||||||
|
|
||||||
def setup_chain(self):
|
def setup_chain(self):
|
||||||
|
@ -36,21 +36,23 @@ class ShorterBlockTimes(BitcoinTestFramework):
|
||||||
# Sanity-check the block height
|
# Sanity-check the block height
|
||||||
assert_equal(self.nodes[0].getblockcount(), 101)
|
assert_equal(self.nodes[0].getblockcount(), 101)
|
||||||
|
|
||||||
# Make sure we can send a transaction on the last pre-Blossom block
|
|
||||||
node0_taddr = get_coinbase_address(self.nodes[0])
|
node0_taddr = get_coinbase_address(self.nodes[0])
|
||||||
node0_zaddr = self.nodes[0].z_getnewaddress('sapling')
|
node0_zaddr = self.nodes[0].z_getnewaddress('sapling')
|
||||||
recipients = [{'address': node0_zaddr, 'amount': Decimal('10')}]
|
recipients = [{'address': node0_zaddr, 'amount': Decimal('10')}]
|
||||||
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0'))
|
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0'))
|
||||||
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
||||||
assert_equal(105, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # Blossom activation - 1 + 3
|
assert_equal(105, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # Blossom activation - 1
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
|
self.nodes[0].generate(1)
|
||||||
|
self.sync_all()
|
||||||
|
assert_equal(10, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
||||||
|
|
||||||
print "Mining last pre-Blossom block"
|
self.nodes[0].generate(2)
|
||||||
|
self.sync_all()
|
||||||
|
print "Mining last pre-Blossom blocks"
|
||||||
# Activate blossom
|
# Activate blossom
|
||||||
self.nodes[1].generate(1)
|
self.nodes[1].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
# Check that the last pre-Blossom transaction was mined
|
|
||||||
assert_equal(10, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
|
||||||
# Check that we received a pre-Blossom mining reward
|
# Check that we received a pre-Blossom mining reward
|
||||||
assert_equal(10, Decimal(self.nodes[1].getwalletinfo()['immature_balance']))
|
assert_equal(10, Decimal(self.nodes[1].getwalletinfo()['immature_balance']))
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ class ShorterBlockTimes(BitcoinTestFramework):
|
||||||
# Send and mine a transaction after activation
|
# Send and mine a transaction after activation
|
||||||
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0'))
|
myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0'))
|
||||||
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
txid = wait_and_assert_operationid_status(self.nodes[0], myopid)
|
||||||
assert_equal(144, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # height + 1 + 40
|
assert_equal(147, self.nodes[0].getrawtransaction(txid, 1)['expiryheight']) # height + 1 + 40
|
||||||
self.nodes[1].generate(1)
|
self.nodes[1].generate(1)
|
||||||
self.sync_all()
|
self.sync_all()
|
||||||
assert_equal(20, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
assert_equal(20, Decimal(self.nodes[0].z_gettotalbalance()['private']))
|
||||||
|
|
|
@ -116,7 +116,7 @@ TEST(founders_reward_test, general) {
|
||||||
EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(53127)), "a91455d64928e69829d9376c776550b6cc710d42715387");
|
EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(53127)), "a91455d64928e69829d9376c776550b6cc710d42715387");
|
||||||
EXPECT_EQ(params.GetFoundersRewardAddressAtHeight(53127), "t2ENg7hHVqqs9JwU5cgjvSbxnT2a9USNfhy");
|
EXPECT_EQ(params.GetFoundersRewardAddressAtHeight(53127), "t2ENg7hHVqqs9JwU5cgjvSbxnT2a9USNfhy");
|
||||||
|
|
||||||
int maxHeight = params.GetConsensus().GetLastFoundersRewardBlockHeight(0);
|
int maxHeight = GetLastFoundersRewardHeight(params.GetConsensus());
|
||||||
|
|
||||||
// If the block height parameter is out of bounds, there is an assert.
|
// If the block height parameter is out of bounds, there is an assert.
|
||||||
EXPECT_DEATH(params.GetFoundersRewardScriptAtHeight(0), "nHeight");
|
EXPECT_DEATH(params.GetFoundersRewardScriptAtHeight(0), "nHeight");
|
||||||
|
@ -173,12 +173,8 @@ TEST(founders_reward_test, slow_start_subsidy) {
|
||||||
SelectParams(CBaseChainParams::MAIN);
|
SelectParams(CBaseChainParams::MAIN);
|
||||||
CChainParams params = Params();
|
CChainParams params = Params();
|
||||||
|
|
||||||
int blossomActivationHeight = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight;
|
|
||||||
bool blossom = blossomActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT;
|
|
||||||
int maxHeight = Params().GetConsensus().GetLastFoundersRewardBlockHeight(blossom ? blossomActivationHeight : 0);
|
|
||||||
|
|
||||||
CAmount totalSubsidy = 0;
|
CAmount totalSubsidy = 0;
|
||||||
for (int nHeight = 1; nHeight <= maxHeight; nHeight++) {
|
for (int nHeight = 1; nHeight <= GetLastFoundersRewardHeight(Params().GetConsensus()); nHeight++) {
|
||||||
CAmount nSubsidy = GetBlockSubsidy(nHeight, params.GetConsensus()) / 5;
|
CAmount nSubsidy = GetBlockSubsidy(nHeight, params.GetConsensus()) / 5;
|
||||||
totalSubsidy += nSubsidy;
|
totalSubsidy += nSubsidy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup)
|
||||||
const CAmount INITIAL_SUBSIDY = 12.5 * COIN;
|
const CAmount INITIAL_SUBSIDY = 12.5 * COIN;
|
||||||
|
|
||||||
static int GetTotalHalvings(const Consensus::Params& consensusParams) {
|
static int GetTotalHalvings(const Consensus::Params& consensusParams) {
|
||||||
|
// This assumes that BLOSSOM_POW_TARGET_SPACING_RATIO == 2
|
||||||
|
// and treats blossom activation as a halving event
|
||||||
return consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT ? 64 : 65;
|
return consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight == Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT ? 64 : 65;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +57,7 @@ static void TestBlockSubsidyHalvings(int nSubsidySlowStartInterval, int nPreBlos
|
||||||
Consensus::Params consensusParams;
|
Consensus::Params consensusParams;
|
||||||
consensusParams.nSubsidySlowStartInterval = nSubsidySlowStartInterval;
|
consensusParams.nSubsidySlowStartInterval = nSubsidySlowStartInterval;
|
||||||
consensusParams.nPreBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval;
|
consensusParams.nPreBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval;
|
||||||
consensusParams.nPostBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval * 2;
|
consensusParams.nPostBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO;
|
||||||
consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight = blossomActivationHeight;
|
consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight = blossomActivationHeight;
|
||||||
TestBlockSubsidyHalvings(consensusParams);
|
TestBlockSubsidyHalvings(consensusParams);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +80,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
|
||||||
// Mining slow start
|
// Mining slow start
|
||||||
for (; nHeight < consensusParams.nSubsidySlowStartInterval; nHeight++) {
|
for (; nHeight < consensusParams.nSubsidySlowStartInterval; nHeight++) {
|
||||||
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
||||||
BOOST_CHECK(nSubsidy <= 12.5 * COIN);
|
BOOST_CHECK(nSubsidy <= INITIAL_SUBSIDY);
|
||||||
nSum += nSubsidy;
|
nSum += nSubsidy;
|
||||||
BOOST_CHECK(MoneyRange(nSum));
|
BOOST_CHECK(MoneyRange(nSum));
|
||||||
}
|
}
|
||||||
|
@ -88,6 +90,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test)
|
||||||
CAmount nSubsidy;
|
CAmount nSubsidy;
|
||||||
do {
|
do {
|
||||||
nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
|
||||||
|
BOOST_CHECK(nSubsidy <= INITIAL_SUBSIDY);
|
||||||
nSum += nSubsidy;
|
nSum += nSubsidy;
|
||||||
BOOST_ASSERT(MoneyRange(nSum));
|
BOOST_ASSERT(MoneyRange(nSum));
|
||||||
++nHeight;
|
++nHeight;
|
||||||
|
|
Loading…
Reference in New Issue