text: // Copyright (c) 2015 The Bitcoin Core developers
  // Distributed under the MIT/X11 software license, see the accompanying
  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  
  #include "chain.h"
  #include "chainparams.h"
  #include "pow.h"
  #include "random.h"
  #include "util.h"
  #include "test/test_bitcoin.h"
  
  #include <boost/test/unit_test.hpp>
  
  using namespace std;
  
  BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
  
  BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
  {
      SelectParams(CBaseChainParams::MAIN);
      const Consensus::Params& params = Params().GetConsensus();
  
      std::vector<CBlockIndex> blocks(10000);
      for (int i = 0; i < 10000; i++) {
          blocks[i].pprev = i ? &blocks[i - 1] : NULL;
          blocks[i].nHeight = i;
          blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
          blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
          blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
      }
  
      for (int j = 0; j < 1000; j++) {
          CBlockIndex *p1 = &blocks[GetRand(10000)];
          CBlockIndex *p2 = &blocks[GetRand(10000)];
          CBlockIndex *p3 = &blocks[GetRand(10000)];
  
          int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params);
          BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());
      }
  }
  
  BOOST_AUTO_TEST_SUITE_END()
  