forked from lthn/blockchain
coretests: random_outs_and_burnt_coins test added
This commit is contained in:
parent
f900fa7e15
commit
1e3c0cd396
3 changed files with 139 additions and 0 deletions
|
|
@ -914,6 +914,7 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(get_random_outs_test);
|
||||
GENERATE_AND_PLAY(mix_attr_tests);
|
||||
GENERATE_AND_PLAY(mix_in_spent_outs);
|
||||
GENERATE_AND_PLAY(random_outs_and_burnt_coins);
|
||||
|
||||
// Block verification tests
|
||||
GENERATE_AND_PLAY(gen_block_big_major_version);
|
||||
|
|
|
|||
|
|
@ -58,5 +58,132 @@ bool get_random_outs_test::check_get_rand_outs(currency::core& c, size_t ev_inde
|
|||
c.get_blockchain_storage().get_random_outs_for_amounts(req, res);
|
||||
CHECK_AND_ASSERT_MES(res.outs[0].outs.size() == 3, false, "Incorrect number of random outs returned.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
random_outs_and_burnt_coins::random_outs_and_burnt_coins()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(random_outs_and_burnt_coins, c1);
|
||||
}
|
||||
|
||||
bool random_outs_and_burnt_coins::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test idead: make sure burned coins (that are technically will NEVER EVER been spent)
|
||||
// cannot be used for mixing in, as it reduces anonimity.
|
||||
|
||||
bool r = false;
|
||||
|
||||
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();
|
||||
account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_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 + 4);
|
||||
|
||||
// find unique amount and store it to m_amount
|
||||
uint64_t stub;
|
||||
r = calculate_amounts_many_outs_have_and_no_outs_have(get_outs_money_amount(blk_0r.miner_tx), stub, m_amount);
|
||||
CHECK_AND_ASSERT_MES(r, false, "calculate_amounts_many_outs_have_and_no_outs_have failed");
|
||||
|
||||
// prepare fake outputs and burn it
|
||||
// make m_fake_amounts_count outputs each of amount amount_no_outs_have
|
||||
std::vector<tx_destination_entry> destinations;
|
||||
for(size_t i = 0; i < m_fake_amounts_count; ++i)
|
||||
destinations.push_back(tx_destination_entry(m_amount, null_pub_addr));
|
||||
std::vector<tx_source_entry> sources;
|
||||
|
||||
r = fill_tx_sources(sources, events, blk_0r, miner_acc.get_keys(), m_amount * m_fake_amounts_count + TESTS_DEFAULT_FEE, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
|
||||
|
||||
transaction tx_0 = AUTO_VAL_INIT(tx_0);
|
||||
r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0);
|
||||
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
|
||||
|
||||
uint64_t burned_tx_amount_total = get_burned_amount(tx_0);
|
||||
CHECK_AND_ASSERT_MES(burned_tx_amount_total == m_fake_amounts_count * m_amount, false, "incorrect value of burned amount: " << burned_tx_amount_total << ", expected: " << m_fake_amounts_count * m_amount);
|
||||
|
||||
events.push_back(tx_0);
|
||||
|
||||
// send to Alice amount_no_outs_have coins
|
||||
MAKE_TX(events, tx_1, miner_acc, alice_acc, m_amount, blk_0r);
|
||||
|
||||
MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, std::list<transaction>({tx_0, tx_1}));
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc);
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool random_outs_and_burnt_coins::c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
|
||||
{
|
||||
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<tools::wallet2> miner_wlt = init_playtime_test_wallet(events, c, m_accounts[MINER_ACC_IDX]);
|
||||
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, m_accounts[ALICE_ACC_IDX]);
|
||||
std::shared_ptr<tools::wallet2> bob_wlt = init_playtime_test_wallet(events, c, m_accounts[BOB_ACC_IDX]);
|
||||
|
||||
bool r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt,
|
||||
m_amount, // expected total
|
||||
false,
|
||||
CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6 + WALLET_DEFAULT_TX_SPENDABLE_AGE,
|
||||
m_amount // expected unlocked
|
||||
), false, "");
|
||||
|
||||
std::vector<tx_destination_entry> destinations({tx_destination_entry(m_amount - TESTS_DEFAULT_FEE, m_accounts[BOB_ACC_IDX].get_public_address())});
|
||||
|
||||
// make sure it's impossible to mixin an output with m_amount amount (because each one is burned)
|
||||
for (uint64_t fake_outs = m_fake_amounts_count + 1; fake_outs > 0; --fake_outs)
|
||||
{
|
||||
LOG_PRINT_L0("trying transfer with fake_outs = " << fake_outs);
|
||||
r = false;
|
||||
try
|
||||
{
|
||||
alice_wlt->transfer(destinations, fake_outs, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment);
|
||||
}
|
||||
catch (tools::error::not_enough_outs_to_mix&)
|
||||
{
|
||||
r = true;
|
||||
}
|
||||
CHECK_AND_ASSERT_MES(r, false, "exception was not cought as expected for fake_outs = " << fake_outs);
|
||||
}
|
||||
|
||||
|
||||
// make normal output with m_amount amount and try to use it as mixin
|
||||
miner_wlt->refresh();
|
||||
miner_wlt->transfer(m_amount, m_accounts[BOB_ACC_IDX].get_public_address());
|
||||
|
||||
// miner few blocks to make it mixable
|
||||
r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, WALLET_DEFAULT_TX_SPENDABLE_AGE);
|
||||
CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_blocks_in_playtime failed");
|
||||
|
||||
alice_wlt->refresh();
|
||||
|
||||
// try with 2 fake outputs -- should not work, as we've just added to the blockchain only one
|
||||
r = false;
|
||||
try
|
||||
{
|
||||
alice_wlt->transfer(destinations, 2 /* fake outs count */, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment);
|
||||
}
|
||||
catch (tools::error::not_enough_outs_to_mix&)
|
||||
{
|
||||
r = true;
|
||||
}
|
||||
CHECK_AND_ASSERT_MES(r, false, "exception was not cought as expected");
|
||||
|
||||
// one mixin should perfectly work
|
||||
alice_wlt->transfer(destinations, 1 /* fake outs count */, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment);
|
||||
|
||||
// check Bob's balance
|
||||
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, m_amount * 2 - TESTS_DEFAULT_FEE, false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6 + WALLET_DEFAULT_TX_SPENDABLE_AGE * 2), false, "");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
#include "chaingen.h"
|
||||
#include "wallet_tests_basic.h"
|
||||
|
||||
struct get_random_outs_test : public test_chain_unit_enchanced
|
||||
{
|
||||
|
|
@ -16,3 +17,13 @@ struct get_random_outs_test : public test_chain_unit_enchanced
|
|||
private:
|
||||
mutable uint64_t m_amount;
|
||||
};
|
||||
|
||||
struct random_outs_and_burnt_coins : public wallet_test
|
||||
{
|
||||
random_outs_and_burnt_coins();
|
||||
bool generate(std::vector<test_event_entry>& events) const;
|
||||
bool c1(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
|
||||
|
||||
mutable uint64_t m_amount;
|
||||
static constexpr uint64_t m_fake_amounts_count = 3;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue