bitcoin-test 0.1.16-alpha.0

test framework for the bitcoin system
Documentation
crate::ix!();



//-------------------------------------------[.cpp/bitcoin/src/test/validation_tests.cpp]

#[cfg(test)]
#[fixture(TestingSetup)]
pub mod validation_tests {

    pub fn test_block_subsidy_halvings(consensus_params: &ChainConsensusParams)  {
        
        todo!();
            /*
                int maxHalvings = 64;
            CAmount nInitialSubsidy = 50 * COIN;

            CAmount nPreviousSubsidy = nInitialSubsidy * 2; // for height == 0
            BOOST_CHECK_EQUAL(nPreviousSubsidy, nInitialSubsidy * 2);
            for (int nHalvings = 0; nHalvings < maxHalvings; nHalvings++) {
                int nHeight = nHalvings * consensusParams.nSubsidyHalvingInterval;
                CAmount nSubsidy = GetBlockSubsidy(nHeight, consensusParams);
                BOOST_CHECK(nSubsidy <= nInitialSubsidy);
                BOOST_CHECK_EQUAL(nSubsidy, nPreviousSubsidy / 2);
                nPreviousSubsidy = nSubsidy;
            }
            BOOST_CHECK_EQUAL(GetBlockSubsidy(maxHalvings * consensusParams.nSubsidyHalvingInterval, consensusParams), 0);
            */
    }

    pub fn test_block_subsidy_halvings(n_subsidy_halving_interval: i32)  {
        
        todo!();
            /*
                ChainConsensusParams consensusParams;
            consensusParams.nSubsidyHalvingInterval = nSubsidyHalvingInterval;
            TestBlockSubsidyHalvings(consensusParams);
            */
    }

    #[test] fn block_subsidy_test() {
        todo!();
        /*
        
            const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
            TestBlockSubsidyHalvings(chainParams->GetConsensus()); // As in main
            TestBlockSubsidyHalvings(150); // As in regtest
            TestBlockSubsidyHalvings(1000); // Just another interval

        */
    }

    #[test] fn subsidy_limit_test() {
        todo!();
        /*
        
            const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
            CAmount nSum = 0;
            for (int nHeight = 0; nHeight < 14000000; nHeight += 1000) {
                CAmount nSubsidy = GetBlockSubsidy(nHeight, chainParams->GetConsensus());
                BOOST_CHECK(nSubsidy <= 50 * COIN);
                nSum += nSubsidy * 1000;
                BOOST_CHECK(MoneyRange(nSum));
            }
            BOOST_CHECK_EQUAL(nSum, CAmount{2099999997690000});

        */
    }

    #[test] fn signet_parse_tests() {
        todo!();
        /*
        
            ArgsManager signet_argsman;
            signet_argsman.ForceSetArg("-signetchallenge", "51"); // set challenge to OP_TRUE
            const auto signet_params = CreateChainParams(signet_argsman, CBaseChainParams::SIGNET);
            CBlock block;
            BOOST_CHECK(signet_params->GetConsensus().signet_challenge == std::vector<uint8_t>{OP_TRUE});
            CScript challenge{OP_TRUE};

            // empty block is invalid
            BOOST_CHECK(!SignetTxs::Create(block, challenge));
            BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // no witness commitment
            CMutableTransaction cb;
            cb.vout.emplace_back(0, CScript{});
            block.vtx.push_back(MakeTransactionRef(cb));
            block.vtx.push_back(MakeTransactionRef(cb)); // Add dummy tx to exercise merkle root code
            BOOST_CHECK(!SignetTxs::Create(block, challenge));
            BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // no header is treated valid
            std::vector<uint8_t> witness_commitment_section_141{0xaa, 0x21, 0xa9, 0xed};
            for (int i = 0; i < 32; ++i) {
                witness_commitment_section_141.push_back(0xff);
            }
            cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141;
            block.vtx.at(0) = MakeTransactionRef(cb);
            BOOST_CHECK(SignetTxs::Create(block, challenge));
            BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // no data after header, valid
            std::vector<uint8_t> witness_commitment_section_325{0xec, 0xc7, 0xda, 0xa2};
            cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
            block.vtx.at(0) = MakeTransactionRef(cb);
            BOOST_CHECK(SignetTxs::Create(block, challenge));
            BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // Premature end of data, invalid
            witness_commitment_section_325.push_back(0x01);
            witness_commitment_section_325.push_back(0x51);
            cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
            block.vtx.at(0) = MakeTransactionRef(cb);
            BOOST_CHECK(!SignetTxs::Create(block, challenge));
            BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // has data, valid
            witness_commitment_section_325.push_back(0x00);
            cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
            block.vtx.at(0) = MakeTransactionRef(cb);
            BOOST_CHECK(SignetTxs::Create(block, challenge));
            BOOST_CHECK(CheckSignetBlockSolution(block, signet_params->GetConsensus()));

            // Extraneous data, invalid
            witness_commitment_section_325.push_back(0x00);
            cb.vout.at(0).scriptPubKey = CScript{} << OP_RETURN << witness_commitment_section_141 << witness_commitment_section_325;
            block.vtx.at(0) = MakeTransactionRef(cb);
            BOOST_CHECK(!SignetTxs::Create(block, challenge));
            BOOST_CHECK(!CheckSignetBlockSolution(block, signet_params->GetConsensus()));

        */
    }

    /**
      | Test retrieval of valid assumeutxo
      | values.
      |
      */
    #[test] fn test_assumeutxo() {
        todo!();
        /*
        
            const auto params = CreateChainParams(*m_node.args, CBaseChainParams::REGTEST);

            // These heights don't have assumeutxo configurations associated, per the contents
            // of chainparams.cpp.
            std::vector<int> bad_heights{0, 100, 111, 115, 209, 211};

            for (auto empty : bad_heights) {
                const auto out = ExpectedAssumeutxo(empty, *params);
                BOOST_CHECK(!out);
            }

            const auto out110 = *ExpectedAssumeutxo(110, *params);
            BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618");
            BOOST_CHECK_EQUAL(out110.nChainTx, 110U);

            const auto out210 = *ExpectedAssumeutxo(200, *params);
            BOOST_CHECK_EQUAL(out210.hash_serialized.ToString(), "51c8d11d8b5c1de51543c579736e786aa2736206d1e11e627568029ce092cf62");
            BOOST_CHECK_EQUAL(out210.nChainTx, 200U);

        */
    }
}