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