Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
checkblock_tests.cpp
Go to the documentation of this file.
1 //
2 // Unit tests for block.CheckBlock()
3 //
4 #include <algorithm>
5 
6 #include <boost/assign/list_of.hpp> // for 'map_list_of()'
7 #include <boost/date_time/posix_time/posix_time_types.hpp>
8 #include <boost/test/unit_test.hpp>
9 #include <boost/foreach.hpp>
10 
11 #include "main.h"
12 #include "wallet.h"
13 #include "net.h"
14 #include "util.h"
15 
16 BOOST_AUTO_TEST_SUITE(CheckBlock_tests)
17 
18 bool
19 read_block(const std::string& filename, CBlock& block)
20 {
21  namespace fs = boost::filesystem;
22  fs::path testFile = fs::current_path() / "test" / "data" / filename;
23 #ifdef TEST_DATA_DIR
24  if (!fs::exists(testFile))
25  {
26  testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename;
27  }
28 #endif
29  FILE* fp = fopen(testFile.string().c_str(), "rb");
30  if (!fp) return false;
31 
32  fseek(fp, 8, SEEK_SET); // skip msgheader/size
33 
34  CAutoFile filein = CAutoFile(fp, SER_DISK, CLIENT_VERSION);
35  if (!filein) return false;
36 
37  filein >> block;
38 
39  return true;
40 }
41 
43 {
44  // Putting a 1MB binary file in the git repository is not a great
45  // idea, so this test is only run if you manually download
46  // test/data/Mar12Fork.dat from
47  // http://sourceforge.net/projects/bitcoin/files/Bitcoin/blockchain/Mar12Fork.dat/download
48  unsigned int tMay15 = 1368576000;
49  SetMockTime(tMay15); // Test as if it was right at May 15
50 
51  CBlock forkingBlock;
52  if (read_block("Mar12Fork.dat", forkingBlock))
53  {
55  forkingBlock.nTime = tMay15-1; // Invalidates PoW
56  BOOST_CHECK(!forkingBlock.CheckBlock(state, false, false));
57 
58  // After May 15'th, big blocks are OK:
59  forkingBlock.nTime = tMay15; // Invalidates PoW
60  BOOST_CHECK(forkingBlock.CheckBlock(state, false, false));
61  }
62 
63  SetMockTime(0);
64 }
65 
66 BOOST_AUTO_TEST_SUITE_END()
bool read_block(const std::string &filename, CBlock &block)
BOOST_AUTO_TEST_CASE(May15)
Definition: main.h:1334
void SetMockTime(int64 nMockTimeIn)
Definition: util.cpp:1305
MTState * state
Definition: db_test.cc:1708
Capture information about block/transaction validation.
Definition: main.h:1907
unsigned int nTime
Definition: main.h:1286
bool CheckBlock(CValidationState &state, bool fCheckPOW=true, bool fCheckMerkleRoot=true) const
Definition: main.cpp:2165
RAII wrapper for FILE*.
Definition: serialize.h:1108