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

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