aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/core_tests/CMakeLists.txt6
-rw-r--r--tests/core_tests/chaingen.cpp5
-rw-r--r--tests/core_tests/chaingen.h20
-rw-r--r--tests/core_tests/chaingen_main.cpp7
-rw-r--r--tests/core_tests/chaingen_tests_list.h1
-rw-r--r--tests/unit_tests/blockchain_db.cpp11
-rw-r--r--tests/unit_tests/hardfork.cpp4
7 files changed, 42 insertions, 12 deletions
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index 5f34bdc10..c34039c17 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -38,7 +38,8 @@ set(core_tests_sources
integer_overflow.cpp
ring_signature_1.cpp
transaction_tests.cpp
- tx_validation.cpp)
+ tx_validation.cpp
+ v2_tests.cpp)
set(core_tests_headers
block_reward.h
@@ -52,7 +53,8 @@ set(core_tests_headers
integer_overflow.h
ring_signature_1.h
transaction_tests.h
- tx_validation.h)
+ tx_validation.h
+ v2_tests.h)
add_executable(coretests
${core_tests_sources}
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 8f413c09c..4fdd0a600 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -215,13 +215,14 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
const crypto::hash& prev_id/* = crypto::hash()*/, const difficulty_type& diffic/* = 1*/,
const transaction& miner_tx/* = transaction()*/,
const std::vector<crypto::hash>& tx_hashes/* = std::vector<crypto::hash>()*/,
- size_t txs_sizes/* = 0*/)
+ size_t txs_sizes/* = 0*/, size_t max_outs/* = 0*/)
{
blk.major_version = actual_params & bf_major_ver ? major_ver : CURRENT_BLOCK_MAJOR_VERSION;
blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION;
blk.timestamp = actual_params & bf_timestamp ? timestamp : prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN; // Keep difficulty unchanged
blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block);
blk.tx_hashes = actual_params & bf_tx_hashes ? tx_hashes : std::vector<crypto::hash>();
+ max_outs = actual_params & bf_max_outs ? max_outs : 1;
size_t height = get_block_height(prev_block) + 1;
uint64_t already_generated_coins = get_already_generated_coins(prev_block);
@@ -235,7 +236,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
{
size_t current_block_size = txs_sizes + get_object_blobsize(blk.miner_tx);
// TODO: This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
- if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, current_block_size, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 1))
+ if (!construct_miner_tx(height, misc_utils::median(block_sizes), already_generated_coins, current_block_size, 0, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs))
return false;
}
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index fa12601a4..f2bbb7346 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -220,7 +220,8 @@ public:
bf_prev_id = 1 << 3,
bf_miner_tx = 1 << 4,
bf_tx_hashes = 1 << 5,
- bf_diffic = 1 << 6
+ bf_diffic = 1 << 6,
+ bf_max_outs = 1 << 7
};
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
@@ -240,7 +241,7 @@ public:
const cryptonote::account_base& miner_acc, int actual_params = bf_none, uint8_t major_ver = 0,
uint8_t minor_ver = 0, uint64_t timestamp = 0, const crypto::hash& prev_id = crypto::hash(),
const cryptonote::difficulty_type& diffic = 1, const cryptonote::transaction& miner_tx = cryptonote::transaction(),
- const std::vector<crypto::hash>& tx_hashes = std::vector<crypto::hash>(), size_t txs_sizes = 0);
+ const std::vector<crypto::hash>& tx_hashes = std::vector<crypto::hash>(), size_t txs_sizes = 0, size_t max_outs = 0);
bool construct_block_manually_tx(cryptonote::block& blk, const cryptonote::block& prev_block,
const cryptonote::account_base& miner_acc, const std::vector<crypto::hash>& tx_hashes, size_t txs_size);
@@ -470,6 +471,14 @@ inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<t
}
//--------------------------------------------------------------------------
template<class t_test_class>
+struct get_test_options {
+ const std::pair<uint8_t, uint64_t> hard_forks[1] = {std::make_pair(1, 0)};
+ const cryptonote::test_options test_options = {
+ hard_forks
+ };
+};
+//--------------------------------------------------------------------------
+template<class t_test_class>
inline bool do_replay_events(std::vector<test_event_entry>& events)
{
boost::program_options::options_description desc("Allowed options");
@@ -484,15 +493,12 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
if (!r)
return false;
- // hardcode a --fakechain option for tests
- static const char * const fakechain[] = {"", "--fakechain"};
- boost::program_options::store(boost::program_options::parse_command_line(2, fakechain, desc), vm);
-
cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
cryptonote::core c(&pr);
// FIXME: make sure that vm has arg_testnet_on set to true or false if
// this test needs for it to be so.
- if (!c.init(vm))
+ const get_test_options<t_test_class> gto;
+ if (!c.init(vm, &gto.test_options))
{
std::cout << concolor::magenta << "Failed to init core" << concolor::normal << std::endl;
return false;
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index 99ae496e3..40bce1e4e 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -168,6 +168,13 @@ int main(int argc, char* argv[])
GENERATE_AND_PLAY(gen_block_reward);
+ GENERATE_AND_PLAY(gen_v2_tx_mixable_0_mixin);
+ GENERATE_AND_PLAY(gen_v2_tx_mixable_low_mixin);
+ GENERATE_AND_PLAY(gen_v2_tx_unmixable_only);
+ GENERATE_AND_PLAY(gen_v2_tx_unmixable_one);
+ GENERATE_AND_PLAY(gen_v2_tx_unmixable_two);
+ GENERATE_AND_PLAY(gen_v2_tx_dust);
+
std::cout << (failed_tests.empty() ? concolor::green : concolor::magenta);
std::cout << "\nREPORT:\n";
std::cout << " Test run: " << tests_count << '\n';
diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h
index e18e00f74..4da87a973 100644
--- a/tests/core_tests/chaingen_tests_list.h
+++ b/tests/core_tests/chaingen_tests_list.h
@@ -39,6 +39,7 @@
#include "integer_overflow.h"
#include "ring_signature_1.h"
#include "tx_validation.h"
+#include "v2_tests.h"
/************************************************************************/
/* */
/************************************************************************/
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index bda8c167e..127a15b44 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -155,7 +155,7 @@ template <typename T>
class BlockchainDBTest : public testing::Test
{
protected:
- BlockchainDBTest() : m_db(new T())
+ BlockchainDBTest() : m_db(new T()), m_hardfork(*m_db, 1, 0)
{
for (auto& i : t_blocks)
{
@@ -184,11 +184,18 @@ protected:
}
BlockchainDB* m_db;
+ HardFork m_hardfork;
std::string m_prefix;
std::vector<block> m_blocks;
std::vector<std::vector<transaction> > m_txs;
std::vector<std::string> m_filenames;
+ void init_hard_fork()
+ {
+ m_hardfork.init();
+ m_db->set_hard_fork(&m_hardfork);
+ }
+
void get_filenames()
{
m_filenames = m_db->get_filenames();
@@ -257,6 +264,7 @@ TYPED_TEST(BlockchainDBTest, AddBlock)
// make sure open does not throw
ASSERT_NO_THROW(this->m_db->open(fname));
this->get_filenames();
+ this->init_hard_fork();
// adding a block with no parent in the blockchain should throw.
// note: this shouldn't be possible, but is a good (and cheap) failsafe.
@@ -300,6 +308,7 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
// make sure open does not throw
ASSERT_NO_THROW(this->m_db->open(fname));
this->get_filenames();
+ this->init_hard_fork();
ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index e20f58a5d..7432c03ec 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -57,6 +57,10 @@ public:
virtual void batch_start(uint64_t batch_num_blocks=0) {}
virtual void batch_stop() {}
virtual void set_batch_transactions(bool) {}
+ virtual void block_txn_start() {}
+ virtual void block_txn_stop() {}
+ virtual void block_txn_abort() {}
+ virtual void drop_hard_fork_info() {}
virtual bool block_exists(const crypto::hash& h) const { return false; }
virtual block get_block(const crypto::hash& h) const { return block(); }
virtual uint64_t get_block_height(const crypto::hash& h) const { return 0; }