From 3a2fb378a497c572136f3d058efe090be18035c0 Mon Sep 17 00:00:00 2001 From: sowle Date: Mon, 27 Apr 2020 16:09:02 +0300 Subject: [PATCH] initial coretests for auditability, work in progress --- tests/core_tests/chaingen_tests_list.h | 1 + tests/core_tests/hard_fork_2.cpp | 72 ++++++++++++++++++++++++++ tests/core_tests/hard_fork_2.h | 22 ++++++++ tests/core_tests/wallet_tests.cpp | 2 +- 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tests/core_tests/hard_fork_2.cpp create mode 100644 tests/core_tests/hard_fork_2.h diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h index 635e1cd7..bccf06ee 100644 --- a/tests/core_tests/chaingen_tests_list.h +++ b/tests/core_tests/chaingen_tests_list.h @@ -37,3 +37,4 @@ #include "hard_fork_1_consensus_test.h" #include "hard_fork_1_bad_pos_source.h" #include "hard_fork_1.h" +#include "hard_fork_2.h" diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp new file mode 100644 index 00000000..a0c76fa9 --- /dev/null +++ b/tests/core_tests/hard_fork_2.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2020 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "chaingen.h" +#include "hard_fork_2.h" +//#include "pos_block_builder.h" +//#include "tx_builder.h" +//#include "random_helper.h" + +using namespace currency; + +//------------------------------------------------------------------------------ + +hard_fork_2_base_test::hard_fork_2_base_test(size_t hardfork_height) + : m_hardfork_height(hardfork_height) +{ + REGISTER_CALLBACK_METHOD(hard_fork_2_base_test, configure_core); +} + +bool hard_fork_2_base_test::configure_core(currency::core& c, size_t ev_index, const std::vector& events) +{ + currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config(); + pc.min_coinstake_age = TESTS_POS_CONFIG_MIN_COINSTAKE_AGE; + pc.pos_minimum_heigh = TESTS_POS_CONFIG_POS_MINIMUM_HEIGH; + pc.hard_fork_01_starts_after_height = m_hardfork_height; + pc.hard_fork_02_starts_after_height = m_hardfork_height; + c.get_blockchain_storage().set_core_runtime_config(pc); + return true; +} + +//------------------------------------------------------------------------------ + +hard_fork_2_tx_payer_in_wallet::hard_fork_2_tx_payer_in_wallet() + : hard_fork_2_base_test(16) +{ + REGISTER_CALLBACK_METHOD(hard_fork_2_tx_payer_in_wallet, c1); } + +bool hard_fork_2_tx_payer_in_wallet::generate(std::vector& events) const +{ + // Test idea: make sure that wallet uses tx_payer_old only before HF2 and tx_payer after + + m_accounts.resize(TOTAL_ACCS_COUNT); + account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); + account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); + + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3); + + DO_CALLBACK(events, "c1"); + + // REWIND_BLOCKS_N(events, blk_1r, blk_1, miner_acc, WALLET_DEFAULT_TX_SPENDABLE_AGE); + + + return true; +} + +bool hard_fork_2_tx_payer_in_wallet::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + bool r = false, stub_bool = false; + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + std::shared_ptr miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]); + + CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Miner", miner_wlt, COIN * (CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3), true), false, ""); + + /*r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); + CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool: " << c.get_pool_transactions_count()); + */ + + return true; +} diff --git a/tests/core_tests/hard_fork_2.h b/tests/core_tests/hard_fork_2.h new file mode 100644 index 00000000..8e981f4b --- /dev/null +++ b/tests/core_tests/hard_fork_2.h @@ -0,0 +1,22 @@ +// Copyright (c) 2020 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#pragma once + +#include "chaingen.h" +#include "wallet_tests_basic.h" + +struct hard_fork_2_base_test : virtual public test_chain_unit_enchanced +{ + hard_fork_2_base_test(size_t hardfork_height); + bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); + + size_t m_hardfork_height; +}; + +struct hard_fork_2_tx_payer_in_wallet : public hard_fork_2_base_test, public wallet_test +{ + hard_fork_2_tx_payer_in_wallet(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); +}; diff --git a/tests/core_tests/wallet_tests.cpp b/tests/core_tests/wallet_tests.cpp index 1900c59e..74c9f24e 100644 --- a/tests/core_tests/wallet_tests.cpp +++ b/tests/core_tests/wallet_tests.cpp @@ -1434,7 +1434,7 @@ bool gen_wallet_decrypted_attachments::generate(std::vector& e CREATE_TEST_WALLET(alice_wlt, alice_acc, blk_0); REFRESH_TEST_WALLET_AT_GEN_TIME(events, alice_wlt, blk_0r, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); - // these attachments will be use across all the transactions in this test + // these attachments will be used across all the transactions in this test currency::tx_payer a_tx_payer = AUTO_VAL_INIT(a_tx_payer); a_tx_payer.acc_addr = miner_acc.get_keys().account_address; currency::tx_comment a_tx_comment = AUTO_VAL_INIT(a_tx_comment);