From df8c4b6594c20a83c6b665877e6257a74b36a9ed Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 19 May 2020 20:18:23 +0300 Subject: [PATCH] coretests: hard_fork_2_no_new_structures_before_hf fixed and greatly improved with positive cases --- tests/core_tests/hard_fork_2.cpp | 74 +++++++++++++++++++++++++------- tests/core_tests/hard_fork_2.h | 2 + 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/tests/core_tests/hard_fork_2.cpp b/tests/core_tests/hard_fork_2.cpp index ebcf0e4f..8e293353 100644 --- a/tests/core_tests/hard_fork_2.cpp +++ b/tests/core_tests/hard_fork_2.cpp @@ -518,12 +518,14 @@ bool hard_fork_2_auditable_addresses_basics::c1(currency::core& c, size_t ev_ind //------------------------------------------------------------------------------ hard_fork_2_no_new_structures_before_hf::hard_fork_2_no_new_structures_before_hf() - : hard_fork_2_base_test(13) + : hard_fork_2_base_test(16) { + REGISTER_CALLBACK_METHOD(hard_fork_2_no_new_structures_before_hf, c1); } bool hard_fork_2_no_new_structures_before_hf::generate(std::vector& events) const { + 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(); @@ -535,6 +537,7 @@ bool hard_fork_2_no_new_structures_before_hf::generate(std::vector extra; + // extra with tx_payer -- not allowed before HF2 tx_payer payer = AUTO_VAL_INIT(payer); payer.acc_addr = miner_acc.get_public_address(); @@ -543,7 +546,16 @@ bool hard_fork_2_no_new_structures_before_hf::generate(std::vector tx_set; - bool r = put_alias_via_tx_to_list(events, tx_set, blk_0r, miner_acc, alias_entry, generator); + r = put_alias_via_tx_to_list(events, tx_set, blk_2, miner_acc, alias_entry, generator); CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); transaction tx_2 = tx_set.front(); // blk_1b_3 is invalid as containing tx_2 DO_CALLBACK(events, "mark_invalid_block"); - MAKE_NEXT_BLOCK_TX1(events, blk_1b_3, blk_1b_2, miner_acc, tx_2); + MAKE_NEXT_BLOCK_TX1(events, blk_3b, blk_2, miner_acc, tx_2); + + + // extra with extra_alias_entry_old -- okay + extra_alias_entry_old alias_entry_old = AUTO_VAL_INIT(alias_entry_old); + alias_entry_old.m_address = alice_acc.get_public_address().to_old(); + alias_entry_old.m_alias = "alicealice"; + + tx_set.clear(); + r = put_alias_via_tx_to_list(events, tx_set, blk_2, miner_acc, alias_entry_old, generator); + CHECK_AND_ASSERT_MES(r, false, "put_alias_via_tx_to_list failed"); + transaction tx_2_old = tx_set.front(); + MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_2_old); + // activate HF2 - MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc); - MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); - MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc); + MAKE_NEXT_BLOCK(events, blk_5, blk_4, miner_acc); + MAKE_NEXT_BLOCK(events, blk_6, blk_5, miner_acc); + MAKE_NEXT_BLOCK(events, blk_7, blk_6, miner_acc); // tx_0 with tx_payer should be accepted after HF2 - MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4, miner_acc, tx_0); + MAKE_NEXT_BLOCK_TX1(events, blk_8, blk_7, miner_acc, tx_0); // tx_1 with tx_receiver should be accepted after HF2 - MAKE_NEXT_BLOCK_TX1(events, blk_6, blk_5, miner_acc, tx_1); + MAKE_NEXT_BLOCK_TX1(events, blk_9, blk_8, miner_acc, tx_1); // tx_2 with extra_alias_entry should be accepted after HF2 - MAKE_NEXT_BLOCK_TX1(events, blk_7, blk_6, miner_acc, tx_2); + MAKE_NEXT_BLOCK_TX1(events, blk_10, blk_9, miner_acc, tx_2); + + // check aliases + DO_CALLBACK(events, "c1"); return true; } bool hard_fork_2_no_new_structures_before_hf::c1(currency::core& c, size_t ev_index, const std::vector& events) { + extra_alias_entry_base ai = AUTO_VAL_INIT(ai); + bool r = c.get_blockchain_storage().get_alias_info("alicealice", ai); + CHECK_AND_ASSERT_MES(r, false, "failed to get alias"); + CHECK_AND_ASSERT_MES(ai.m_address == m_accounts[ALICE_ACC_IDX].get_public_address(), false, "invalid address for alicealice alias"); + + ai = AUTO_VAL_INIT(ai); + r = c.get_blockchain_storage().get_alias_info("minerminer", ai); + CHECK_AND_ASSERT_MES(r, false, "failed to get alias minerminer"); + CHECK_AND_ASSERT_MES(ai.m_address == m_accounts[MINER_ACC_IDX].get_public_address(), false, "invalid address for minerminer alias"); + return true; } diff --git a/tests/core_tests/hard_fork_2.h b/tests/core_tests/hard_fork_2.h index ca11dc17..230a72d0 100644 --- a/tests/core_tests/hard_fork_2.h +++ b/tests/core_tests/hard_fork_2.h @@ -50,6 +50,8 @@ struct hard_fork_2_auditable_addresses_basics : public wallet_test, public hard_ struct hard_fork_2_no_new_structures_before_hf : public wallet_test, public hard_fork_2_base_test { + using hard_fork_2_base_test::check_block_verification_context; // this is necessary for correct work of do_check_block_verification_context, consider rafactoring + hard_fork_2_no_new_structures_before_hf(); bool generate(std::vector& events) const; bool c1(currency::core& c, size_t ev_index, const std::vector& events);