initial [broken] update

This commit is contained in:
mydesktop 2014-05-03 12:19:43 -04:00
parent 0f42b2eba6
commit 333f975760
38 changed files with 849 additions and 232 deletions

View file

@ -323,7 +323,7 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events
destinations.push_back(de);
transaction tmp_tx;
if (!construct_tx(miner_account.get_keys(), sources, destinations, tmp_tx, 0))
if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
@ -365,7 +365,7 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>
destinations.push_back(de);
transaction tmp_tx;
if (!construct_tx(miner_account.get_keys(), sources, destinations, tmp_tx, 0))
if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tmp_tx, 0))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_1);

View file

@ -425,9 +425,12 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te
ts.amount = oi.amount;
ts.real_output_in_tx_index = oi.out_no;
ts.real_out_tx_key = get_tx_pub_key_from_extra(*oi.p_tx); // incoming tx public key
if (!fill_output_entries(outs[o.first], sender_out, nmix, ts.real_output, ts.outputs))
size_t realOutput;
if (!fill_output_entries(outs[o.first], sender_out, nmix, realOutput, ts.outputs))
continue;
ts.real_output = realOutput;
sources.push_back(ts);
sources_amount += ts.amount;
@ -528,7 +531,7 @@ bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote
vector<tx_destination_entry> destinations;
fill_tx_sources_and_destinations(events, blk_head, from, to, amount, fee, nmix, sources, destinations);
return construct_tx(from.get_keys(), sources, destinations, tx, 0);
return construct_tx(from.get_keys(), sources, destinations, std::vector<uint8_t>(), tx, 0);
}
transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const block& blk_head,

View file

@ -1,4 +1,4 @@
#pragma once
#pragma once
//======================================================================================================================
@ -113,7 +113,7 @@ bool gen_double_spend_in_tx<txs_keeped_by_block>::generate(std::vector<test_even
destinations.push_back(de);
cryptonote::transaction tx_1;
if (!construct_tx(bob_account.get_keys(), sources, destinations, tx_1, 0))
if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0))
return false;
SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_keeped_by_block, txs_keeped_by_block);

View file

@ -72,7 +72,7 @@ bool gen_uint_overflow_base::mark_last_valid_block(cryptonote::core& c, size_t e
bool gen_uint_overflow_1::generate(std::vector<test_event_entry>& events) const
{
uint64_t ts_start = 1338224400;
uint64_t ts_start = 1338224400;
GENERATE_ACCOUNT(miner_account);
MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
@ -116,7 +116,7 @@ bool gen_uint_overflow_1::generate(std::vector<test_event_entry>& events) const
bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
{
uint64_t ts_start = 1338224400;
uint64_t ts_start = 1338224400;
GENERATE_ACCOUNT(miner_account);
MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
@ -148,7 +148,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(tx_destination_entry(sources.front().amount - MONEY_SUPPLY - MONEY_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr));
cryptonote::transaction tx_1;
if (!construct_tx(miner_account.get_keys(), sources, destinations, tx_1, 0))
if (!construct_tx(miner_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_1, 0))
return false;
events.push_back(tx_1);
@ -174,7 +174,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(de);
cryptonote::transaction tx_2;
if (!construct_tx(bob_account.get_keys(), sources, destinations, tx_2, 0))
if (!construct_tx(bob_account.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_2, 0))
return false;
events.push_back(tx_2);

View file

@ -81,9 +81,7 @@ bool test_transaction_generation_and_ring_signature()
oe.second = boost::get<txout_to_key>(tx_mine_6.vout[0].target).key;
src.outputs.push_back(oe);
crypto::public_key tx_pub_key = null_pkey;
cryptonote::parse_and_validate_tx_extra(tx_mine_2, tx_pub_key);
src.real_out_tx_key = tx_pub_key;
src.real_out_tx_key = cryptonote::get_tx_pub_key_from_extra(tx_mine_2);
src.real_output = 1;
src.real_output_in_tx_index = 0;
}
@ -95,7 +93,7 @@ bool test_transaction_generation_and_ring_signature()
destinations.push_back(td);
transaction tx_rc1;
bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, tx_rc1, 0);
bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, std::vector<uint8_t>(), tx_rc1, 0);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1);

View file

@ -52,7 +52,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor,
try
{
w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx);
w1.transfer(dsts, mix_in_factor, 0, DEFAULT_FEE, std::vector<uint8_t>(), tools::detail::null_split_strategy, tools::tx_dust_policy(DEFAULT_FEE), tx);
return true;
}
catch (const std::exception&)
@ -144,7 +144,7 @@ bool transactions_flow_test(std::string& working_folder,
}
//lets make a lot of small outs to ourselves
//since it is not possible to start from transaction that bigger than 20Kb, we gonna make transactions
//since it is not possible to start from transaction that bigger than 20Kb, we gonna make transactions
//with 500 outs (about 18kb), and we have to wait appropriate count blocks, mined for test wallet
while(true)
{

View file

@ -204,8 +204,6 @@
#define GTEST_NAME_ "Google Test"
#define GTEST_PROJECT_URL_ "http://code.google.com/p/googletest/"
#define GTEST_HAS_TR1_TUPLE 0
// Determines the version of gcc that is used to compile this.
#ifdef __GNUC__
// 40302 means version 4.3.2.

View file

@ -36,7 +36,7 @@ public:
std::vector<tx_destination_entry> destinations;
destinations.push_back(tx_destination_entry(this->m_source_amount, m_alice.get_keys().m_account_address));
if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, m_tx, 0))
if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, std::vector<uint8_t>(), m_tx, 0))
return false;
get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);

View file

@ -42,7 +42,7 @@ public:
bool test()
{
return cryptonote::construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, m_destinations, m_tx, 0);
return cryptonote::construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, m_destinations, std::vector<uint8_t>(), m_tx, 0);
}
private:

View file

@ -14,7 +14,7 @@
void set_process_affinity(int core)
{
#if defined(__APPLE__)
#if defined (__APPLE__)
return;
#elif defined(BOOST_WINDOWS)
DWORD_PTR mask = 1;

View file

@ -4,52 +4,132 @@
#include "gtest/gtest.h"
#include <vector>
#include "common/util.h"
#include "cryptonote_core/cryptonote_format_utils.h"
TEST(parse_and_validate_tx_extra, is_correct_parse_and_validate_tx_extra)
TEST(parse_tx_extra, handles_empty_extra)
{
std::vector<uint8_t> extra;;
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_TRUE(tx_extra_fields.empty());
}
TEST(parse_tx_extra, handles_padding_only_size_1)
{
const uint8_t extra_arr[] = {0};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(1, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type());
ASSERT_EQ(1, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size);
}
TEST(parse_tx_extra, handles_padding_only_size_2)
{
const uint8_t extra_arr[] = {0, 0};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(1, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type());
ASSERT_EQ(2, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size);
}
TEST(parse_tx_extra, handles_padding_only_max_size)
{
std::vector<uint8_t> extra(TX_EXTRA_NONCE_MAX_COUNT, 0);
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(1, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[0].type());
ASSERT_EQ(TX_EXTRA_NONCE_MAX_COUNT, boost::get<cryptonote::tx_extra_padding>(tx_extra_fields[0]).size);
}
TEST(parse_tx_extra, handles_padding_only_exceed_max_size)
{
std::vector<uint8_t> extra(TX_EXTRA_NONCE_MAX_COUNT + 1, 0);
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
}
TEST(parse_tx_extra, handles_invalid_padding_only)
{
std::vector<uint8_t> extra(2, 0);
extra[1] = 42;
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_FALSE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
}
TEST(parse_tx_extra, handles_pub_key_only)
{
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(1, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
}
TEST(parse_tx_extra, handles_extra_nonce_only)
{
const uint8_t extra_arr[] = {2, 1, 42};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(1, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_nonce), tx_extra_fields[0].type());
cryptonote::tx_extra_nonce extra_nonce = boost::get<cryptonote::tx_extra_nonce>(tx_extra_fields[0]);
ASSERT_EQ(1, extra_nonce.nonce.size());
ASSERT_EQ(42, extra_nonce.nonce[0]);
}
TEST(parse_tx_extra, handles_pub_key_and_padding)
{
const uint8_t extra_arr[] = {1, 30, 208, 98, 162, 133, 64, 85, 83, 112, 91, 188, 89, 211, 24, 131, 39, 154, 22, 228,
80, 63, 198, 141, 173, 111, 244, 183, 4, 149, 186, 140, 230, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<uint8_t> extra(&extra_arr[0], &extra_arr[0] + sizeof(extra_arr));
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_TRUE(cryptonote::parse_tx_extra(extra, tx_extra_fields));
ASSERT_EQ(2, tx_extra_fields.size());
ASSERT_EQ(typeid(cryptonote::tx_extra_pub_key), tx_extra_fields[0].type());
ASSERT_EQ(typeid(cryptonote::tx_extra_padding), tx_extra_fields[1].type());
}
TEST(parse_and_validate_tx_extra, is_valid_tx_extra_parsed)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
cryptonote::account_base acc;
acc.generate();
cryptonote::blobdata b = "dsdsdfsdfsf";
bool r = cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1);
ASSERT_TRUE(r);
crypto::public_key tx_pub_key;
r = cryptonote::parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_TRUE(r);
ASSERT_TRUE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_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, cryptonote::null_pkey);
}
TEST(parse_and_validate_tx_extra, is_correct_extranonce_too_big)
TEST(parse_and_validate_tx_extra, fails_on_big_extra_nonce)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
cryptonote::account_base acc;
acc.generate();
cryptonote::blobdata b(260, 0);
bool r = cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1);
ASSERT_FALSE(r);
cryptonote::blobdata b(TX_EXTRA_NONCE_MAX_COUNT + 1, 0);
ASSERT_FALSE(cryptonote::construct_miner_tx(0, 0, 10000000000000, 1000, DEFAULT_FEE, acc.get_keys().m_account_address, tx, b, 1));
}
TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_couner_too_big)
TEST(parse_and_validate_tx_extra, fails_on_wrong_size_in_extra_nonce)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
tx.extra.resize(20, 0);
tx.extra[0] = TX_EXTRA_NONCE;
tx.extra[1] = 255;
crypto::public_key tx_pub_key;
bool r = parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_FALSE(r);
std::vector<cryptonote::tx_extra_field> tx_extra_fields;
ASSERT_FALSE(cryptonote::parse_tx_extra(tx.extra, tx_extra_fields));
}
TEST(parse_and_validate_tx_extra, is_correct_wrong_extra_nonce_double_entry)
{
cryptonote::transaction tx = AUTO_VAL_INIT(tx);
tx.extra.resize(20, 0);
cryptonote::blobdata v = "asasdasd";
cryptonote::add_tx_extra_nonce(tx, v);
cryptonote::add_tx_extra_nonce(tx, v);
crypto::public_key tx_pub_key;
bool r = parse_and_validate_tx_extra(tx, tx_pub_key);
ASSERT_FALSE(r);
}
TEST(validate_parse_amount_case, validate_parse_amount)
{
uint64_t res = 0;