1
0
Fork 0
forked from lthn/blockchain

coretests: pos_mining_with_decoys improved to reveal a bug with staking using auditable wallets

This commit is contained in:
sowle 2023-11-09 18:47:13 +01:00
parent a151cab066
commit 1f0faf2c8e

View file

@ -152,10 +152,11 @@ bool pos_mining_with_decoys::generate(std::vector<test_event_entry>& events) con
{
uint64_t ts = test_core_time::get_time();
m_accounts.resize(TOTAL_ACCS_COUNT);
currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts);
currency::account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts);
currency::account_base& miner_acc = m_accounts[MINER_ACC_IDX]; miner_acc.generate(); miner_acc.set_createtime(ts);
currency::account_base& alice_acc = m_accounts[ALICE_ACC_IDX]; alice_acc.generate(); alice_acc.set_createtime(ts);
currency::account_base& bob_acc = m_accounts[BOB_ACC_IDX]; bob_acc.generate(); bob_acc.set_createtime(ts);
currency::account_base& carol_acc = m_accounts[CAROL_ACC_IDX]; carol_acc.generate(); carol_acc.set_createtime(ts);
currency::account_base& dan_acc = m_accounts[DAN_ACC_IDX]; dan_acc.generate(true); dan_acc.set_createtime(ts); // Dan has an auditable wallet
MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, ts);
DO_CALLBACK(events, "configure_core"); // default configure_core callback will initialize core runtime config with m_hardforks
@ -167,7 +168,8 @@ bool pos_mining_with_decoys::generate(std::vector<test_event_entry>& events) con
CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources failed");
std::vector<tx_destination_entry> destinations;
destinations.emplace_back(47 * TESTS_DEFAULT_FEE, alice_acc.get_public_address());
destinations.emplace_back(47 * TESTS_DEFAULT_FEE, miner_acc.get_public_address()); // as a decoy for Alice
destinations.emplace_back(47 * TESTS_DEFAULT_FEE, miner_acc.get_public_address()); // as a decoy for Alice and Dan
destinations.emplace_back(47 * TESTS_DEFAULT_FEE, dan_acc.get_public_address());
destinations.emplace_back(5 * TESTS_DEFAULT_FEE, bob_acc.get_public_address());
destinations.emplace_back(COIN, carol_acc.get_public_address());
@ -204,6 +206,10 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v
carol_wlt->refresh();
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*carol_wlt, "Carol", COIN, INVALID_BALANCE_VAL, COIN), false, "");
std::shared_ptr<tools::wallet2> dan_wlt = init_playtime_test_wallet(events, c, m_accounts[DAN_ACC_IDX]);
dan_wlt->refresh();
CHECK_AND_ASSERT_MES(check_balance_via_wallet(*dan_wlt, "Dan", 47 * TESTS_DEFAULT_FEE, INVALID_BALANCE_VAL, 47 * TESTS_DEFAULT_FEE), false, "");
// 1. Alice should be able to mine a PoS block with 1 decoys (ring size == 2)
size_t top_block_height = c.get_top_block_height();
@ -225,6 +231,7 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v
// 2. Bob should only be able to mine a PoS block with zero decoys (ring size == 1)
top_block_height = c.get_top_block_height();
bob_wlt->refresh();
r = bob_wlt->try_mint_pos(m_accounts[BOB_ACC_IDX].get_public_address());
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
@ -242,6 +249,7 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v
// 3. Carol should only be able to mine a PoS block with CURRENCY_DEFAULT_DECOY_SET_SIZE decoys (ring size == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1)
top_block_height = c.get_top_block_height();
carol_wlt->refresh();
r = carol_wlt->try_mint_pos(m_accounts[CAROL_ACC_IDX].get_public_address());
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
@ -255,5 +263,25 @@ bool pos_mining_with_decoys::c1(currency::core& c, size_t ev_index, const std::v
CHECK_AND_ASSERT_MES(intk.key_offsets.size() == CURRENCY_DEFAULT_DECOY_SET_SIZE + 1, false, "unexpected ring size: " << intk.key_offsets.size());
}
// 4. Dan has an auditable wallet that couldn't use mixins, but still he should be able to successfully mine a PoS block (ring size = 1, zero decoys)
top_block_height = c.get_top_block_height();
CHECK_AND_ASSERT_MES(dan_wlt->is_auditable(), false, "Dan's wallet is not auditable, which is unexpected");
dan_wlt->refresh();
r = dan_wlt->try_mint_pos(m_accounts[DAN_ACC_IDX].get_public_address());
CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed");
{
block b{};
CHECK_AND_ASSERT_MES(c.get_blockchain_storage().get_top_block(b), false, "");
CHECK_AND_ASSERT_MES(get_block_height(b) == top_block_height + 1, false, "unexpected top block height");
txin_to_key& intk = boost::get<txin_to_key>(b.miner_tx.vin[1]);
CHECK_AND_ASSERT_MES(intk.amount == 47 * TESTS_DEFAULT_FEE, false, "incorrect amount: " << intk.amount);
CHECK_AND_ASSERT_MES(intk.key_offsets.size() == 1, false, "unexpected ring size: " << intk.key_offsets.size());
}
return true;
}