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.5KB

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