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