forked from such-gitea/wownero
fix unit tests
This commit is contained in:
@@ -148,10 +148,10 @@ foreach(BENCH IN LISTS MONERO_WALLET_CRYPTO_BENCH)
|
||||
endforeach ()
|
||||
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/benchmark.h.in" "${MONERO_GENERATED_HEADERS_DIR}/tests/benchmark.h")
|
||||
monero_add_minimal_executable(monero-wallet-crypto-bench benchmark.cpp ${BENCH_OBJECTS})
|
||||
target_link_libraries(monero-wallet-crypto-bench cncrypto)
|
||||
monero_add_minimal_executable(wownero-wallet-crypto-bench benchmark.cpp ${BENCH_OBJECTS})
|
||||
target_link_libraries(wownero-wallet-crypto-bench cncrypto)
|
||||
|
||||
add_test(NAME wallet-crypto-bench COMMAND monero-wallet-crypto-bench)
|
||||
add_test(NAME wallet-crypto-bench COMMAND wownero-wallet-crypto-bench)
|
||||
|
||||
|
||||
set(enabled_tests
|
||||
|
||||
@@ -40,9 +40,8 @@ namespace
|
||||
const account_public_address& miner_address, std::vector<size_t>& block_weights, size_t target_tx_weight,
|
||||
size_t target_block_weight, uint64_t fee = 0)
|
||||
{
|
||||
if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, fee, miner_address, miner_tx))
|
||||
if (!construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, static_cast<size_t>(height), misc_utils::median(block_weights), already_generated_coins, target_block_weight, fee, miner_address, miner_tx))
|
||||
return false;
|
||||
|
||||
size_t current_weight = get_transaction_weight(miner_tx);
|
||||
size_t try_count = 0;
|
||||
while (target_tx_weight != current_weight)
|
||||
|
||||
@@ -45,7 +45,8 @@ namespace
|
||||
for (size_t i = 0; i < new_block_count; ++i)
|
||||
{
|
||||
block blk_next;
|
||||
difficulty_type diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1);
|
||||
const uint64_t height = get_block_height(blk_prev) + 1;
|
||||
difficulty_type diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1, height, cryptonote::network_type::MAINNET);
|
||||
if (!generator.construct_block_manually(blk_next, blk_prev, miner_account,
|
||||
test_generator::bf_timestamp | test_generator::bf_diffic, 0, 0, blk_prev.timestamp, crypto::hash(), diffic))
|
||||
return false;
|
||||
@@ -175,9 +176,10 @@ bool gen_block_invalid_nonce::generate(std::vector<test_event_entry>& events) co
|
||||
return false;
|
||||
|
||||
// Create invalid nonce
|
||||
difficulty_type diffic = next_difficulty(timestamps, commulative_difficulties,DIFFICULTY_TARGET_V1);
|
||||
assert(1 < diffic);
|
||||
const block& blk_last = boost::get<block>(events.back());
|
||||
const uint64_t height = get_block_height(blk_last) + 1;
|
||||
difficulty_type diffic = next_difficulty(timestamps, commulative_difficulties,DIFFICULTY_TARGET_V1, height, cryptonote::network_type::MAINNET);
|
||||
assert(1 < diffic);
|
||||
uint64_t timestamp = blk_last.timestamp;
|
||||
block blk_3;
|
||||
do
|
||||
@@ -572,7 +574,8 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
|
||||
do
|
||||
{
|
||||
blk_last = boost::get<block>(events.back());
|
||||
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1);
|
||||
const uint64_t height = get_block_height(blk_last) + 1;
|
||||
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1, height, cryptonote::network_type::MAINNET);
|
||||
if (!lift_up_difficulty(events, timestamps, cummulative_difficulties, generator, 1, blk_last, miner_account))
|
||||
return false;
|
||||
std::cout << "Block #" << events.size() << ", difficulty: " << diffic << std::endl;
|
||||
@@ -587,7 +590,8 @@ bool gen_block_invalid_binary_format::generate(std::vector<test_event_entry>& ev
|
||||
std::vector<crypto::hash> tx_hashes;
|
||||
tx_hashes.push_back(get_transaction_hash(tx_0));
|
||||
size_t txs_weight = get_transaction_weight(tx_0);
|
||||
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1);
|
||||
const uint64_t height = get_block_height(blk_last) + 1;
|
||||
diffic = next_difficulty(timestamps, cummulative_difficulties,DIFFICULTY_TARGET_V1, height, cryptonote::network_type::MAINNET);
|
||||
if (!generator.construct_block_manually(blk_test, blk_last, miner_account,
|
||||
test_generator::bf_diffic | test_generator::bf_timestamp | test_generator::bf_tx_hashes, 0, 0, blk_last.timestamp,
|
||||
crypto::hash(), diffic, transaction(), tx_hashes, txs_weight))
|
||||
|
||||
@@ -265,7 +265,7 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
|
||||
size_t target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
|
||||
while (true)
|
||||
{
|
||||
if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10, hf_ver ? hf_ver.get() : 1))
|
||||
if (!construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, static_cast<size_t>(height), misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10, hf_ver ? hf_ver.get() : 1))
|
||||
return false;
|
||||
|
||||
size_t actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
|
||||
@@ -368,7 +368,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
|
||||
{
|
||||
size_t current_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
|
||||
// TODO: This will work, until size of constructed block is less then CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE
|
||||
if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, current_block_weight, fees, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
|
||||
if (!construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, static_cast<size_t>(height), misc_utils::median(block_weights), already_generated_coins, current_block_weight, fees, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), max_outs, hf_version))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,17 @@ bool test_transaction_generation_and_ring_signature()
|
||||
account_base rv_acc2;
|
||||
rv_acc2.generate();
|
||||
transaction tx_mine_1;
|
||||
construct_miner_tx(0, 0, 0, 10, 0, miner_acc1.get_keys().m_account_address, tx_mine_1);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 10, 0, miner_acc1.get_keys().m_account_address, tx_mine_1);
|
||||
transaction tx_mine_2;
|
||||
construct_miner_tx(0, 0, 0, 0, 0, miner_acc2.get_keys().m_account_address, tx_mine_2);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 0, 0, miner_acc2.get_keys().m_account_address, tx_mine_2);
|
||||
transaction tx_mine_3;
|
||||
construct_miner_tx(0, 0, 0, 0, 0, miner_acc3.get_keys().m_account_address, tx_mine_3);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 0, 0, miner_acc3.get_keys().m_account_address, tx_mine_3);
|
||||
transaction tx_mine_4;
|
||||
construct_miner_tx(0, 0, 0, 0, 0, miner_acc4.get_keys().m_account_address, tx_mine_4);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 0, 0, miner_acc4.get_keys().m_account_address, tx_mine_4);
|
||||
transaction tx_mine_5;
|
||||
construct_miner_tx(0, 0, 0, 0, 0, miner_acc5.get_keys().m_account_address, tx_mine_5);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 0, 0, miner_acc5.get_keys().m_account_address, tx_mine_5);
|
||||
transaction tx_mine_6;
|
||||
construct_miner_tx(0, 0, 0, 0, 0, miner_acc6.get_keys().m_account_address, tx_mine_6);
|
||||
construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 0, 0, miner_acc6.get_keys().m_account_address, tx_mine_6);
|
||||
|
||||
//fill inputs entry
|
||||
std::vector<tx_source_entry> sources;
|
||||
@@ -137,7 +137,7 @@ bool test_block_creation()
|
||||
bool r = get_account_address_from_str(info, MAINNET, "0099be99c70ef10fd534c43c88e9d13d1c8853213df7e362afbec0e4ee6fec4948d0c190b58f4b356cd7feaf8d9d0a76e7c7e5a9a0a497a6b1faf7a765882dd08ac2");
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to import");
|
||||
block b;
|
||||
r = construct_miner_tx(90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, info.address, b.miner_tx, blobdata(), 11);
|
||||
r = construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 90, epee::misc_utils::median(szs), 3553616528562147, 33094, 10000000, info.address, b.miner_tx, blobdata(), 11);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ static int test_wide_difficulty(const char *filename)
|
||||
}
|
||||
cryptonote::difficulty_type res = cryptonote::next_difficulty(
|
||||
std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
|
||||
std::vector<cryptonote::difficulty_type>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
|
||||
std::vector<cryptonote::difficulty_type>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET, static_cast<uint64_t>(n), static_cast<cryptonote::network_type>(0));
|
||||
if (res != difficulty) {
|
||||
cerr << "Wrong wide difficulty for block " << n << endl
|
||||
<< "Expected: " << difficulty << endl
|
||||
@@ -123,7 +123,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
cryptonote::difficulty_type wide_res = cryptonote::next_difficulty(
|
||||
std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
|
||||
std::vector<cryptonote::difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
|
||||
std::vector<cryptonote::difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET, static_cast<uint64_t>(n), static_cast<cryptonote::network_type>(0));
|
||||
if ((wide_res & 0xffffffffffffffff).convert_to<uint64_t>() != res) {
|
||||
cerr << "Wrong wide difficulty for block " << n << endl
|
||||
<< "Expected: " << res << endl
|
||||
|
||||
@@ -55,7 +55,7 @@ public:
|
||||
{
|
||||
m_miners[i].generate();
|
||||
|
||||
if (!construct_miner_tx(0, 0, 0, 2, 0, m_miners[i].get_keys().m_account_address, m_miner_txs[i]))
|
||||
if (!construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 2, 0, m_miners[i].get_keys().m_account_address, m_miner_txs[i]))
|
||||
return false;
|
||||
|
||||
txout_to_key tx_out = boost::get<txout_to_key>(m_miner_txs[i].vout[0].target);
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
m_bob.generate();
|
||||
|
||||
if (!construct_miner_tx(0, 0, 0, 2, 0, m_bob.get_keys().m_account_address, m_tx))
|
||||
if (!construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 0, 2, 0, m_bob.get_keys().m_account_address, m_tx))
|
||||
return false;
|
||||
|
||||
m_tx_pub_key = get_tx_pub_key_from_extra(m_tx);
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace test
|
||||
make_miner_transaction(cryptonote::account_public_address const& to)
|
||||
{
|
||||
cryptonote::transaction tx{};
|
||||
if (!cryptonote::construct_miner_tx(0, 0, 5000, 500, 500, to, tx))
|
||||
if (!cryptonote::construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 5000, 500, 500, to, tx))
|
||||
throw std::runtime_error{"transaction construction error"};
|
||||
|
||||
crypto::hash id{0};
|
||||
|
||||
@@ -519,7 +519,7 @@ TEST(cryptonote_protocol_handler, race_condition)
|
||||
hardfork
|
||||
);
|
||||
block.miner_tx.vout.push_back(cryptonote::tx_out{reward, cryptonote::txout_to_key{}});
|
||||
diff = storage.get_difficulty_for_next_block();
|
||||
diff = storage.get_difficulty_for_next_block(cryptonote::network_type::MAINNET);
|
||||
};
|
||||
struct stat {
|
||||
struct chain {
|
||||
|
||||
@@ -141,7 +141,7 @@ TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed)
|
||||
cryptonote::account_base acc;
|
||||
acc.generate();
|
||||
cryptonote::blobdata b = "dsdsdfsdfsf";
|
||||
ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1));
|
||||
ASSERT_TRUE(cryptonote::construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1));
|
||||
crypto::public_key tx_pub_key = cryptonote::get_tx_pub_key_from_extra(tx);
|
||||
ASSERT_NE(tx_pub_key, crypto::null_pkey);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce)
|
||||
cryptonote::account_base acc;
|
||||
acc.generate();
|
||||
cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0);
|
||||
ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1));
|
||||
ASSERT_FALSE(cryptonote::construct_miner_tx(nullptr, cryptonote::network_type::MAINNET, 0, 0, 10000000000000, 1000, TEST_FEE, acc.get_keys().m_account_address, tx, b, 1));
|
||||
}
|
||||
TEST(parse_and_validate_tx_extra, fails_on_wrong_size_in_extra_nonce)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user