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.

64 lines
1.5 KiB

// Unit tests for block.CheckBlock()
#include "main.h"
#include <cstdio>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/test/unit_test.hpp>
read_block(const std::string& filename, CBlock& block)
namespace fs = boost::filesystem;
fs::path testFile = fs::current_path() / "data" / filename;
if (!fs::exists(testFile))
testFile = fs::path(BOOST_PP_STRINGIZE(TEST_DATA_DIR)) / filename;
FILE* fp = fopen(testFile.string().c_str(), "rb");
if (!fp) return false;
fseek(fp, 8, SEEK_SET); // skip msgheader/size
CAutoFile filein = CAutoFile(fp, SER_DISK, CLIENT_VERSION);
if (!filein) return false;
filein >> block;
return true;
// Putting a 1MB binary file in the git repository is not a great
// idea, so this test is only run if you manually download
// test/data/Mar12Fork.dat from
unsigned int tMay15 = 1368576000;
SetMockTime(tMay15); // Test as if it was right at May 15
CBlock forkingBlock;
if (read_block("Mar12Fork.dat", forkingBlock))
CValidationState state;
// After May 15'th, big blocks are OK:
forkingBlock.nTime = tMay15; // Invalidates PoW
BOOST_CHECK(CheckBlock(forkingBlock, state, false, false));