1
0
Fork 0
forked from lthn/blockchain

coretests: hard_fork_2_auditable_addresses_basics changed to reflect updated auditable address rule

This commit is contained in:
sowle 2020-05-14 20:11:21 +03:00
parent a2ac9c7640
commit ae5269d12c
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC

View file

@ -406,7 +406,7 @@ bool hard_fork_2_auditable_addresses_basics::generate(std::vector<test_event_ent
/*
Test idea: make sure that:
(1) before HF2 txs with mix_attr == 1 can be sent and then they are recognized by wallet;
(2) before HF2 txs to an auditable address can't be sent via wallet2::transfer()
(2) before HF2 txs to an auditable address CAN be sent via wallet2::transfer()
(3) after HF2 txs to an auditable address CAN be sent via wallet2::transfer()
*/
@ -421,8 +421,9 @@ bool hard_fork_2_auditable_addresses_basics::generate(std::vector<test_event_ent
DO_CALLBACK(events, "configure_core");
REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
MAKE_TX(events, tx_0, miner_acc, alice_acc, MK_TEST_COINS(11), blk_0r);
MAKE_TX(events, tx_0a, miner_acc, alice_acc, MK_TEST_COINS(11), blk_0r);
MAKE_TX(events, tx_0b, miner_acc, alice_acc, MK_TEST_COINS(11), blk_0r);
// tx_1 has outputs to an auditable address, it's allowed before HF2
MAKE_TX(events, tx_1, miner_acc, bob_acc, MK_TEST_COINS(5), blk_0r);
@ -435,7 +436,7 @@ bool hard_fork_2_auditable_addresses_basics::generate(std::vector<test_event_ent
CHECK_AND_ASSERT_MES(mix_attr == CURRENCY_TO_KEY_OUT_FORCED_NO_MIX, false, "Incorrect mix_attr in tx_1: " << mix_attr);
}
MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, std::list<transaction>({ tx_0, tx_1 }));
MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, std::list<transaction>({ tx_0a, tx_0b, tx_1 }));
REWIND_BLOCKS_N(events, blk_1r, blk_1, miner_acc, WALLET_DEFAULT_TX_SPENDABLE_AGE);
@ -451,31 +452,37 @@ bool hard_fork_2_auditable_addresses_basics::c1(currency::core& c, size_t ev_ind
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]);
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(11), false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(22), false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, MK_TEST_COINS(5), false, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1 + WALLET_DEFAULT_TX_SPENDABLE_AGE), false, "");
// sending coins to an auditable address should not be allowed until HF2
std::vector<tx_destination_entry> destination{tx_destination_entry(MK_TEST_COINS(1), bob_wlt->get_account().get_public_address())};
transaction tx = AUTO_VAL_INIT(tx);
bool exception_caught = false;
try
{
alice_wlt->transfer(destination, 0, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment, tx);
}
catch (tools::error::wallet_common_error& e)
{
exception_caught = true;
}
CHECK_AND_ASSERT_MES(exception_caught, false, "exception was not cought as expected");
alice_wlt->transfer(destination, 0, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment, tx);
// mine few block to activate HF2
r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 3);
// make sure all Bob's outputs has mix_attr = 1
for (auto& out : tx.vout)
{
if (out.amount != MK_TEST_COINS(1))
continue; // skip change
uint8_t mix_attr = boost::get<txout_to_key>(out.target).mix_attr;
CHECK_AND_ASSERT_MES(mix_attr == CURRENCY_TO_KEY_OUT_FORCED_NO_MIX, false, "Incorrect mix_attr in tx: " << mix_attr);
}
// mine a block to confirm the tx
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 1, false, "Incorrect txs count in the pool");
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");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(11), false, 3), false, "");
// mine few block to activate HF2
r = mine_next_pow_blocks_in_playtime(m_accounts[MINER_ACC_IDX].get_public_address(), c, 2);
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");
// now coins should be normally sent
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, MK_TEST_COINS(20), false, 3), false, "");
// repeat the transfer after HF2 (using the same destinations)
alice_wlt->transfer(destination, 0, 0, TESTS_DEFAULT_FEE, empty_extra, empty_attachment, tx);
// make sure all Bob's outputs has mix_attr = 1
@ -494,7 +501,7 @@ bool hard_fork_2_auditable_addresses_basics::c1(currency::core& c, size_t ev_ind
CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == 0, false, "Incorrect txs count in the pool");
// make sure the funds were received
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, MK_TEST_COINS(5 + 1), false, 3 + 1), false, "");
CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Bob", bob_wlt, MK_TEST_COINS(5 + 1 + 1), false, 3 + 1), false, "");
return true;
}