From 42a21ef0045a04f01b35c9c8714c5a1645bee20c Mon Sep 17 00:00:00 2001 From: Eirik Ogilvie-Wigley Date: Mon, 5 Aug 2019 14:52:34 -0600 Subject: [PATCH] Test clean up and fixes --- qa/rpc-tests/shorter_block_times.py | 16 +++++++++------- src/gtest/test_foundersreward.cpp | 10 +++------- src/test/main_tests.cpp | 7 +++++-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/qa/rpc-tests/shorter_block_times.py b/qa/rpc-tests/shorter_block_times.py index b34882e26..8e807e466 100755 --- a/qa/rpc-tests/shorter_block_times.py +++ b/qa/rpc-tests/shorter_block_times.py @@ -21,7 +21,7 @@ class ShorterBlockTimes(BitcoinTestFramework): return start_nodes(4, self.options.tmpdir, [[ '-nuparams=5ba81b19:0', # Overwinter '-nuparams=76b809bb:0', # Sapling - '-nuparams=2bb40e60:103', # Blossom + '-nuparams=2bb40e60:106', # Blossom ]] * 4) def setup_chain(self): @@ -36,21 +36,23 @@ class ShorterBlockTimes(BitcoinTestFramework): # Sanity-check the block height 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_zaddr = self.nodes[0].z_getnewaddress('sapling') recipients = [{'address': node0_zaddr, 'amount': Decimal('10')}] myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0')) 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.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 self.nodes[1].generate(1) 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 assert_equal(10, Decimal(self.nodes[1].getwalletinfo()['immature_balance'])) @@ -64,7 +66,7 @@ class ShorterBlockTimes(BitcoinTestFramework): # Send and mine a transaction after activation myopid = self.nodes[0].z_sendmany(node0_taddr, recipients, 1, Decimal('0')) 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.sync_all() assert_equal(20, Decimal(self.nodes[0].z_gettotalbalance()['private'])) diff --git a/src/gtest/test_foundersreward.cpp b/src/gtest/test_foundersreward.cpp index d4b45a157..7eeb7fa0d 100644 --- a/src/gtest/test_foundersreward.cpp +++ b/src/gtest/test_foundersreward.cpp @@ -84,7 +84,7 @@ TEST(founders_reward_test, create_testnet_2of3multisig) { #endif -static int GetLastFoundersRewardHeight(const Consensus::Params& params){ +static int GetLastFoundersRewardHeight(const Consensus::Params& params) { int blossomActivationHeight = Params().GetConsensus().vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight; bool blossom = blossomActivationHeight != Consensus::NetworkUpgrade::NO_ACTIVATION_HEIGHT; return params.GetLastFoundersRewardBlockHeight(blossom ? blossomActivationHeight : 0); @@ -116,7 +116,7 @@ TEST(founders_reward_test, general) { EXPECT_EQ(HexStr(params.GetFoundersRewardScriptAtHeight(53127)), "a91455d64928e69829d9376c776550b6cc710d42715387"); 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. EXPECT_DEATH(params.GetFoundersRewardScriptAtHeight(0), "nHeight"); @@ -173,12 +173,8 @@ TEST(founders_reward_test, slow_start_subsidy) { SelectParams(CBaseChainParams::MAIN); 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; - for (int nHeight = 1; nHeight <= maxHeight; nHeight++) { + for (int nHeight = 1; nHeight <= GetLastFoundersRewardHeight(Params().GetConsensus()); nHeight++) { CAmount nSubsidy = GetBlockSubsidy(nHeight, params.GetConsensus()) / 5; totalSubsidy += nSubsidy; } diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp index b3930e550..5e2cb8a86 100644 --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -16,6 +16,8 @@ BOOST_FIXTURE_TEST_SUITE(main_tests, TestingSetup) const CAmount INITIAL_SUBSIDY = 12.5 * COIN; 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; } @@ -55,7 +57,7 @@ static void TestBlockSubsidyHalvings(int nSubsidySlowStartInterval, int nPreBlos Consensus::Params consensusParams; consensusParams.nSubsidySlowStartInterval = nSubsidySlowStartInterval; consensusParams.nPreBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval; - consensusParams.nPostBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval * 2; + consensusParams.nPostBlossomSubsidyHalvingInterval = nPreBlossomSubsidyHalvingInterval * Consensus::BLOSSOM_POW_TARGET_SPACING_RATIO; consensusParams.vUpgrades[Consensus::UPGRADE_BLOSSOM].nActivationHeight = blossomActivationHeight; TestBlockSubsidyHalvings(consensusParams); } @@ -78,7 +80,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) // Mining slow start for (; nHeight < consensusParams.nSubsidySlowStartInterval; nHeight++) { CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams); - BOOST_CHECK(nSubsidy <= 12.5 * COIN); + BOOST_CHECK(nSubsidy <= INITIAL_SUBSIDY); nSum += nSubsidy; BOOST_CHECK(MoneyRange(nSum)); } @@ -88,6 +90,7 @@ BOOST_AUTO_TEST_CASE(subsidy_limit_test) CAmount nSubsidy; do { nSubsidy = GetBlockSubsidy(nHeight, consensusParams); + BOOST_CHECK(nSubsidy <= INITIAL_SUBSIDY); nSum += nSubsidy; BOOST_ASSERT(MoneyRange(nSum)); ++nHeight;