forked from lthn/blockchain
added test for getblocktemplate
This commit is contained in:
parent
69e68807bf
commit
320816fd99
4 changed files with 109 additions and 3 deletions
|
|
@ -6414,11 +6414,16 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
tx.signatures.clear();
|
||||
tx.proofs.clear();
|
||||
}
|
||||
|
||||
currency::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
||||
//std::vector<crypto::point_t&> tx_outs_commitments;
|
||||
if (!m_is_in_checkpoint_zone)
|
||||
{
|
||||
auto cleanup = [&](){ purge_block_data_from_blockchain(bl, tx_processed_count); bvc.m_verification_failed = true; };
|
||||
auto cleanup = [&](){
|
||||
bool add_res = m_tx_pool.add_tx(tx, tvc, true, true);
|
||||
m_tx_pool.add_transaction_to_black_list(tx);
|
||||
purge_block_data_from_blockchain(bl, tx_processed_count);
|
||||
bvc.m_verification_failed = true;
|
||||
};
|
||||
|
||||
CHECK_AND_ASSERT_MES_CUSTOM(collect_rangeproofs_data_from_tx(tx, tx_id, range_proofs_agregated), false, cleanup(),
|
||||
"block " << id << ", tx " << tx_id << ": collect_rangeproofs_data_from_tx failed");
|
||||
|
|
@ -6435,7 +6440,6 @@ bool blockchain_storage::handle_block_to_main_chain(const block& bl, const crypt
|
|||
if(!check_tx_inputs(tx, tx_id))
|
||||
{
|
||||
LOG_PRINT_L0("Block with id: " << id << " has at least one transaction (id: " << tx_id << ") with wrong inputs.");
|
||||
currency::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
|
||||
if (taken_from_pool)
|
||||
{
|
||||
bool add_res = m_tx_pool.add_tx(tx, tvc, true, true);
|
||||
|
|
|
|||
|
|
@ -1089,6 +1089,8 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY_HF(wallet_rpc_exchange_suite, "3,4");
|
||||
GENERATE_AND_PLAY(wallet_chain_switch_with_spending_the_same_ki);
|
||||
GENERATE_AND_PLAY(wallet_sending_to_integrated_address);
|
||||
GENERATE_AND_PLAY_HF(block_template_blacklist_test, "4-*");
|
||||
|
||||
|
||||
// GENERATE_AND_PLAY(emission_test); // simulate 1 year of blockchain, too long run (1 y ~= 1 hr), by demand only
|
||||
// LOG_ERROR2("print_reward_change_first_blocks.log", currency::print_reward_change_first_blocks(525601).str()); // outputs first 1 year of blocks' rewards (simplier)
|
||||
|
|
|
|||
|
|
@ -3809,3 +3809,95 @@ bool wallet_and_sweep_below::c1(currency::core& c, size_t ev_index, const std::v
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
block_template_blacklist_test::block_template_blacklist_test()
|
||||
{
|
||||
REGISTER_CALLBACK_METHOD(block_template_blacklist_test, c1);
|
||||
}
|
||||
|
||||
bool block_template_blacklist_test::generate(std::vector<test_event_entry>& events) const
|
||||
{
|
||||
// Test idea: basic check for wallet2::sweep_below() functionality
|
||||
|
||||
uint64_t ts = test_core_time::get_time();
|
||||
m_accounts.resize(TOTAL_ACCS_COUNT);
|
||||
account_base preminer_acc;
|
||||
preminer_acc.generate();
|
||||
preminer_acc.set_createtime(ts);
|
||||
account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
|
||||
account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
|
||||
MAKE_GENESIS_BLOCK(events, blk_0, preminer_acc, ts);
|
||||
DO_CALLBACK(events, "configure_core");
|
||||
|
||||
MAKE_NEXT_BLOCK(events, blk_1, blk_0, preminer_acc);
|
||||
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, 3 * CURRENCY_MINED_MONEY_UNLOCK_WINDOW - 1);
|
||||
|
||||
DO_CALLBACK(events, "c1");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool block_template_blacklist_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);
|
||||
std::shared_ptr<tools::wallet2> alice_wlt = init_playtime_test_wallet(events, c, ALICE_ACC_IDX);
|
||||
|
||||
miner_wlt->refresh();
|
||||
miner_wlt->transfer(COIN / 10, alice_wlt->get_account().get_public_address());
|
||||
miner_wlt->transfer(COIN / 10, alice_wlt->get_account().get_public_address());
|
||||
|
||||
//take first transaction and corrupt it intentionalyy
|
||||
std::list<transaction> txs;
|
||||
c.get_tx_pool().get_transactions(txs);
|
||||
CHECK_AND_ASSERT_MES(txs.size() == 2, false, "wrong tx count");
|
||||
|
||||
|
||||
txs.resize(1);
|
||||
currency::transaction broken_tx;
|
||||
uint64_t blob_size = 0;
|
||||
uint64_t fee = 0;
|
||||
r = c.get_tx_pool().take_tx(currency::get_transaction_hash(*txs.begin()), broken_tx, blob_size, fee);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to take from pool");
|
||||
|
||||
|
||||
broken_tx.signatures.resize(broken_tx.signatures.size() - 1);
|
||||
//manually add completely broken tx to pool
|
||||
c.get_tx_pool().do_insert_transaction(broken_tx, get_transaction_hash(broken_tx), currency::get_object_blobsize(broken_tx), false, get_tx_fee(broken_tx), c.get_block_id_by_height(0), 0);
|
||||
|
||||
CHECK_AND_ASSERT_MES(c.get_tx_pool().get_transactions_count() == 2, false, "wrong tx count");
|
||||
|
||||
|
||||
currency::create_block_template_params cbtp = AUTO_VAL_INIT(cbtp);
|
||||
cbtp.miner_address = miner_wlt->get_account().get_public_address();
|
||||
|
||||
{
|
||||
currency::create_block_template_response cbtr = AUTO_VAL_INIT(cbtr);
|
||||
r = c.get_block_template(cbtp, cbtr);
|
||||
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to create block template");
|
||||
CHECK_AND_ASSERT_MES(cbtr.b.tx_hashes.size() == 2, false, "failed to create block template");
|
||||
}
|
||||
|
||||
r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c);
|
||||
CHECK_AND_ASSERT_MES(!r, false, "Unexpectedly created block");
|
||||
|
||||
//now let's check if broken tx actually added to next blocktemplate
|
||||
|
||||
{
|
||||
currency::create_block_template_response cbtr = AUTO_VAL_INIT(cbtr);
|
||||
r = c.get_block_template(cbtp, cbtr);
|
||||
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to create block template");
|
||||
CHECK_AND_ASSERT_MES(cbtr.b.tx_hashes.size() == 1, false, "failed to create block template");
|
||||
|
||||
}
|
||||
|
||||
r = mine_next_pow_block_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Unexpectedly failed to create block");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,3 +294,11 @@ struct wallet_and_sweep_below : public wallet_test
|
|||
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);
|
||||
};
|
||||
|
||||
|
||||
struct block_template_blacklist_test : public wallet_test
|
||||
{
|
||||
block_template_blacklist_test();
|
||||
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);
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue