aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-02-08 18:47:56 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-02-08 18:52:00 +0000
commita333c42cdeab4675c22df25255313752d81a2d4e (patch)
tree97abd7cc6a0a06375979eebfdc72913b7940bef8 /src/cryptonote_core
parentcore_tests: allow setting miner tx max_outs when creating a block (diff)
downloadmonero-a333c42cdeab4675c22df25255313752d81a2d4e.tar.xz
core_tests: add tests for hard fork behaviors (MRL-0004)
We also replace the --fakechain option with an optional structure containing details about configuration for the core/blockchain, for test purposes. This seems more future friendly.
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp20
-rw-r--r--src/cryptonote_core/blockchain.h5
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp7
-rw-r--r--src/cryptonote_core/cryptonote_core.h6
4 files changed, 26 insertions, 12 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 70953f3e7..7dd0aca42 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -50,6 +50,7 @@
#include "warnings.h"
#include "crypto/hash.h"
#include "cryptonote_core/checkpoints_create.h"
+#include "cryptonote_core/cryptonote_core.h"
#if defined(PER_BLOCK_CHECKPOINT)
#include "blocks/blocks.h"
#endif
@@ -252,11 +253,13 @@ uint64_t Blockchain::get_current_blockchain_height() const
//------------------------------------------------------------------
//FIXME: possibly move this into the constructor, to avoid accidentally
// dereferencing a null BlockchainDB pointer
-bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain)
+bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::test_options *test_options)
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
+ bool fakechain = test_options != NULL;
+
if (db == nullptr)
{
LOG_ERROR("Attempted to init Blockchain with null DB");
@@ -273,12 +276,19 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain
m_testnet = testnet;
if (m_hardfork == nullptr)
{
- if (m_testnet)
+ if (fakechain)
+ m_hardfork = new HardFork(*db, 1, 0);
+ else if (m_testnet)
m_hardfork = new HardFork(*db, 1, testnet_hard_fork_version_1_till);
else
m_hardfork = new HardFork(*db, 1, mainnet_hard_fork_version_1_till);
}
- if (m_testnet)
+ if (fakechain)
+ {
+ for (size_t n = 0; test_options->hard_forks[n].first; ++n)
+ m_hardfork->add_fork(test_options->hard_forks[n].first, test_options->hard_forks[n].second, 0, n + 1);
+ }
+ else if (m_testnet)
{
for (size_t n = 0; n < sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]); ++n)
m_hardfork->add_fork(testnet_hard_forks[n].version, testnet_hard_forks[n].height, testnet_hard_forks[n].threshold, testnet_hard_forks[n].time);
@@ -348,11 +358,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain
return true;
}
//------------------------------------------------------------------
-bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet, const bool fakechain)
+bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet)
{
if (hf != nullptr)
m_hardfork = hf;
- bool res = init(db, testnet, fakechain);
+ bool res = init(db, testnet, NULL);
if (hf == nullptr)
hf = m_hardfork;
return res;
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 5299fed99..ab2c8f9e8 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -58,6 +58,7 @@
namespace cryptonote
{
class tx_memory_pool;
+ struct test_options;
enum blockchain_db_sync_mode
{
@@ -91,8 +92,8 @@ namespace cryptonote
Blockchain(tx_memory_pool& tx_pool);
- bool init(BlockchainDB* db, const bool testnet = false, const bool fakechain = false);
- bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = false, const bool fakechain = false);
+ bool init(BlockchainDB* db, const bool testnet = false, const cryptonote::test_options *test_options = NULL);
+ bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = false);
bool deinit();
void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; }
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 2479931be..2c485d791 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -145,13 +145,11 @@ namespace cryptonote
command_line::add_arg(desc, command_line::arg_db_sync_mode);
command_line::add_arg(desc, command_line::arg_show_time_stats);
command_line::add_arg(desc, command_line::arg_db_auto_remove_logs);
- command_line::add_arg(desc, command_line::arg_fakechain);
}
//-----------------------------------------------------------------------------------------------
bool core::handle_command_line(const boost::program_options::variables_map& vm)
{
m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on);
- m_fakechain = command_line::get_arg(vm, command_line::arg_fakechain);
auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir;
m_config_folder = command_line::get_arg(vm, data_dir_arg);
@@ -251,8 +249,9 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::init(const boost::program_options::variables_map& vm)
+ bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options)
{
+ m_fakechain = test_options != NULL;
bool r = handle_command_line(vm);
r = m_mempool.init(m_fakechain ? std::string() : m_config_folder);
@@ -398,7 +397,7 @@ namespace cryptonote
m_blockchain_storage.set_user_options(blocks_threads,
blocks_per_sync, sync_mode, fast_sync);
- r = m_blockchain_storage.init(db, m_testnet, m_fakechain);
+ r = m_blockchain_storage.init(db, m_testnet, test_options);
// now that we have a valid m_blockchain_storage, we can clean out any
// transactions in the pool that do not conform to the current fork
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 90fdfefca..3c6f56749 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -56,6 +56,10 @@ DISABLE_VS_WARNINGS(4355)
namespace cryptonote
{
+ struct test_options {
+ const std::pair<uint8_t, uint64_t> *hard_forks;
+ };
+
/************************************************************************/
/* */
/************************************************************************/
@@ -81,7 +85,7 @@ namespace cryptonote
miner& get_miner(){return m_miner;}
const miner& get_miner()const{return m_miner;}
static void init_options(boost::program_options::options_description& desc);
- bool init(const boost::program_options::variables_map& vm);
+ bool init(const boost::program_options::variables_map& vm, const test_options *test_options = NULL);
bool set_genesis_block(const block& b);
bool deinit();
static void set_fast_exit();