forked from lthn/blockchain
zarcanum core test - very basics
This commit is contained in:
parent
0d0ab5fe81
commit
10e93a47dc
5 changed files with 181 additions and 3 deletions
|
|
@ -170,12 +170,12 @@ namespace currency
|
|||
}
|
||||
|
||||
//, txin_htlc, txin_zc_input
|
||||
bool compare_variant_by_types(const txin_multisig& left, typename txin_multisig& right)
|
||||
inline bool compare_variant_by_types(const txin_multisig& left, typename txin_multisig& right)
|
||||
{
|
||||
return (left.multisig_out_id < right.multisig_out_id);
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
bool compare_variant_by_types(const txin_gen& left, typename txin_gen& right)
|
||||
inline bool compare_variant_by_types(const txin_gen& left, typename txin_gen& right)
|
||||
{
|
||||
//actually this should never happen, should we leave it in case it happen in unit tests? @sowle
|
||||
return (left.height < right.height);
|
||||
|
|
@ -226,7 +226,7 @@ namespace currency
|
|||
}
|
||||
};
|
||||
//---------------------------------------------------------------
|
||||
bool less_txin_v(const txin_v& left, const txin_v& right)
|
||||
inline bool less_txin_v(const txin_v& left, const txin_v& right)
|
||||
{
|
||||
//predefined type hierarchy based on it's tags defined in currency_basic.h, call compare_variant_by_types via 2-level visitor
|
||||
return boost::apply_visitor(left_visitor(right), left);
|
||||
|
|
|
|||
|
|
@ -1040,6 +1040,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
GENERATE_AND_PLAY(isolate_auditable_and_proof);
|
||||
|
||||
GENERATE_AND_PLAY(zarcanum_basic_test);
|
||||
|
||||
|
||||
// GENERATE_AND_PLAY(gen_block_reward);
|
||||
|
|
|
|||
|
|
@ -40,3 +40,4 @@
|
|||
#include "hard_fork_2.h"
|
||||
#include "atomic_tests.h"
|
||||
#include "isolate_auditable_and_proof.h"
|
||||
#include "zarcanum_test.h"
|
||||
|
|
|
|||
159
tests/core_tests/zarcanum_test.cpp
Normal file
159
tests/core_tests/zarcanum_test.cpp
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor 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 "zarcanum_test.h"
|
||||
#include "wallet_test_core_proxy.h"
|
||||
|
||||
#include "random_helper.h"
|
||||
|
||||
#define AMOUNT_TO_TRANSFER_ZARCANUM_BASIC (TESTS_DEFAULT_FEE*10)
|
||||
|
||||
|
||||
using namespace currency;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
zarcanum_basic_test::zarcanum_basic_test()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(zarcanum_basic_test, configure_core);
|
||||
REGISTER_CALLBACK_METHOD(zarcanum_basic_test, c1);
|
||||
}
|
||||
|
||||
bool zarcanum_basic_test::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
m_accounts.resize(MINER_ACC_IDX+1);
|
||||
account_base& miner_acc = m_accounts[MINER_ACC_IDX];
|
||||
miner_acc.generate();
|
||||
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time());
|
||||
DO_CALLBACK(events, "configure_core");
|
||||
set_hard_fork_heights_to_generator(generator);
|
||||
//TODO: Need to make sure REWIND_BLOCKS_N and other coretests codebase are capable of following hardfork4 rules
|
||||
//in this test hardfork4 moment moved to runtime section
|
||||
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 3);
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zarcanum_basic_test::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
currency::core_runtime_config pc = c.get_blockchain_storage().get_core_runtime_config();
|
||||
pc.hard_forks.set_hardfork_height(1, 1);
|
||||
pc.hard_forks.set_hardfork_height(2, 1);
|
||||
pc.hard_forks.set_hardfork_height(3, 1);
|
||||
pc.hard_forks.set_hardfork_height(4, 14);
|
||||
c.get_blockchain_storage().set_core_runtime_config(pc);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool zarcanum_basic_test::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
bool r = false;
|
||||
std::shared_ptr<tools::wallet2> miner_wlt = init_playtime_test_wallet(events, c, MINER_ACC_IDX);
|
||||
|
||||
account_base alice_acc;
|
||||
alice_acc.generate();
|
||||
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, alice_acc);
|
||||
|
||||
//pass over hardfork
|
||||
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, 2);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
|
||||
miner_wlt->refresh();
|
||||
alice_wlt->refresh();
|
||||
|
||||
|
||||
|
||||
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool");
|
||||
|
||||
//create transfer from pre-zarcanum inputs to post-zarcanum inputs
|
||||
uint64_t transfer_amount = AMOUNT_TO_TRANSFER_ZARCANUM_BASIC + TESTS_DEFAULT_FEE;
|
||||
miner_wlt->transfer(transfer_amount, alice_wlt->get_account().get_public_address());
|
||||
LOG_PRINT_MAGENTA("Legacy-2-zarcanum transaction sent to Alice: " << transfer_amount, LOG_LEVEL_0);
|
||||
|
||||
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
|
||||
|
||||
|
||||
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
//miner_wlt->refresh();
|
||||
alice_wlt->refresh();
|
||||
|
||||
uint64_t unlocked = 0;
|
||||
uint64_t balance = alice_wlt->balance(unlocked);
|
||||
CHECK_AND_ASSERT_MES(unlocked == transfer_amount, false, "wrong amount");
|
||||
|
||||
account_base bob_acc;
|
||||
bob_acc.generate();
|
||||
std::shared_ptr<tools::wallet2> bob_wlt = init_playtime_test_wallet(events, c, bob_acc);
|
||||
|
||||
|
||||
//create transfer from post-zarcanum inputs to post-zarcanum inputs
|
||||
uint64_t transfer_amount2 = AMOUNT_TO_TRANSFER_ZARCANUM_BASIC;
|
||||
alice_wlt->transfer(transfer_amount2, bob_acc.get_public_address());
|
||||
LOG_PRINT_MAGENTA("Zarcanum-2-zarcanum transaction sent from Alice to Bob " << transfer_amount2, LOG_LEVEL_0);
|
||||
|
||||
|
||||
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
|
||||
|
||||
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
bob_wlt->refresh();
|
||||
balance = bob_wlt->balance(unlocked);
|
||||
CHECK_AND_ASSERT_MES(unlocked == transfer_amount2, false, "wrong amount");
|
||||
|
||||
account_base staker_benefeciary_acc;
|
||||
staker_benefeciary_acc.generate();
|
||||
std::shared_ptr<tools::wallet2> staker_benefeciary_acc_wlt = init_playtime_test_wallet(events, c, staker_benefeciary_acc);
|
||||
|
||||
account_base miner_benefeciary_acc;
|
||||
miner_benefeciary_acc.generate();
|
||||
std::shared_ptr<tools::wallet2> miner_benefeciary_acc_wlt = init_playtime_test_wallet(events, c, miner_benefeciary_acc);
|
||||
|
||||
|
||||
//do staking
|
||||
for(size_t i = 0; i!= CURRENCY_MINED_MONEY_UNLOCK_WINDOW+4; i++)
|
||||
{
|
||||
size_t pos_entries_count = 0;
|
||||
if (!mine_next_pos_block_in_playtime_with_wallet(*miner_wlt.get(), staker_benefeciary_acc_wlt->get_account().get_public_address(), pos_entries_count))
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(false, false, "Couldn't generate staking");
|
||||
return false;
|
||||
}
|
||||
if (!mine_next_pow_block_in_playtime(miner_benefeciary_acc.get_public_address(), c))
|
||||
{
|
||||
CHECK_AND_ASSERT_MES(false, false, "Couldn't generate pow");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//attempt to spend staked and mined coinbase outs
|
||||
staker_benefeciary_acc_wlt->refresh();
|
||||
miner_benefeciary_acc_wlt->refresh();
|
||||
|
||||
staker_benefeciary_acc_wlt->transfer(transfer_amount2, bob_acc.get_public_address());
|
||||
LOG_PRINT_MAGENTA("Zarcanum(pos-coinbase)-2-zarcanum transaction sent from Staker to Bob " << transfer_amount2, LOG_LEVEL_0);
|
||||
|
||||
miner_benefeciary_acc_wlt->transfer(transfer_amount2, bob_acc.get_public_address());
|
||||
LOG_PRINT_MAGENTA("Zarcanum(pow-coinbase)-2-zarcanum transaction sent from Staker to Bob " << transfer_amount2, LOG_LEVEL_0);
|
||||
|
||||
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 2, false, "Incorrect txs count in the pool");
|
||||
|
||||
r = mine_next_pow_blocks_in_playtime(miner_wlt->get_account().get_public_address(), c, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
CHECK_AND_FORCE_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool");
|
||||
|
||||
|
||||
bob_wlt->refresh();
|
||||
balance = bob_wlt->balance(unlocked);
|
||||
CHECK_AND_ASSERT_MES(unlocked == transfer_amount2*3, false, "wrong amount");
|
||||
return true;
|
||||
}
|
||||
17
tests/core_tests/zarcanum_test.h
Normal file
17
tests/core_tests/zarcanum_test.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright (c) 2014-2018 Zano Project
|
||||
// Copyright (c) 2014-2018 The Louisdor 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 zarcanum_basic_test : public wallet_test
|
||||
{
|
||||
zarcanum_basic_test();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue