You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

checkblock_tests.cpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2013-2014 The Bitcoin Core developers
  2. // Distributed under the MIT software license, see the accompanying
  3. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  4. //
  5. // Unit tests for block.CheckBlock()
  6. //
  7. #include "clientversion.h"
  8. #include "main.h"
  9. #include "utiltime.h"
  10. #include "test/test_bitcoin.h"
  11. #include <cstdio>
  12. #include <boost/filesystem/operations.hpp>
  13. #include <boost/filesystem/path.hpp>
  14. #include <boost/test/unit_test.hpp>
  15. BOOST_FIXTURE_TEST_SUITE(CheckBlock_tests, BasicTestingSetup)
  16. bool read_block(const std::string& filename, CBlock& block)
  17. {
  18. namespace fs = boost::filesystem;
  19. fs::path testFile = fs::current_path() / "data" / filename;
  20. #ifdef TEST_DATA_DIR
  21. if (!fs::exists(testFile))
  22. {
  23. testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename;
  24. }
  25. #endif
  26. FILE* fp = fopen(testFile.string().c_str(), "rb");
  27. if (!fp) return false;
  28. fseek(fp, 8, SEEK_SET); // skip msgheader/size
  29. CAutoFile filein(fp, SER_DISK, CLIENT_VERSION);
  30. if (filein.IsNull()) return false;
  31. filein >> block;
  32. return true;
  33. }
  34. BOOST_AUTO_TEST_CASE(May15)
  35. {
  36. // Putting a 1MB binary file in the git repository is not a great
  37. // idea, so this test is only run if you manually download
  38. // test/data/Mar12Fork.dat from
  39. // http://sourceforge.net/projects/bitcoin/files/Bitcoin/blockchain/Mar12Fork.dat/download
  40. unsigned int tMay15 = 1368576000;
  41. SetMockTime(tMay15); // Test as if it was right at May 15
  42. CBlock forkingBlock;
  43. if (read_block("Mar12Fork.dat", forkingBlock))
  44. {
  45. CValidationState state;
  46. // After May 15'th, big blocks are OK:
  47. forkingBlock.nTime = tMay15; // Invalidates PoW
  48. BOOST_CHECK(CheckBlock(forkingBlock, state, false, false));
  49. }
  50. SetMockTime(0);
  51. }
  52. BOOST_AUTO_TEST_SUITE_END()