2#include <boost/optional/optional.hpp>
3#include <boost/range/adaptor/indexed.hpp>
4#include <gtest/gtest.h>
23 throw std::runtime_error{
"transaction construction error"};
27 throw std::runtime_error{
"could not get transaction hash"};
35 std::vector<cryptonote::transaction>
const& sources,
36 std::vector<cryptonote::account_public_address>
const& destinations,
40 std::uint64_t source_amount = 0;
41 std::vector<cryptonote::tx_source_entry> actual_sources;
42 for (
auto const&
source : sources)
44 std::vector<cryptonote::tx_extra_field> extra_fields;
46 throw std::runtime_error{
"invalid transaction"};
50 throw std::runtime_error{
"invalid transaction"};
52 for (
auto const& input : boost::adaptors::index(
source.vout))
54 source_amount += input.value().amount;
55 auto const&
key = boost::get<cryptonote::txout_to_key>(input.value().target);
57 actual_sources.push_back(
61 for (
unsigned ring = 0; ring < 10; ++ring)
62 actual_sources.back().push_output(input.index(),
key.key, input.value().amount);
66 std::vector<cryptonote::tx_destination_entry> to;
67 for (
auto const& destination : destinations)
68 to.push_back({(source_amount / destinations.size()), destination,
false});
73 std::vector<crypto::secret_key> extra_keys{};
75 std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
78 if (!
cryptonote::construct_tx_and_get_tx_key(from, subaddresses, actual_sources, to, boost::none, {}, tx, 0, tx_key, extra_keys,
rct, { bulletproof ?
rct::RangeProofBulletproof :
rct::RangeProofBorromean, bulletproof ? 2 : 0 }))
79 throw std::runtime_error{
"transaction construction error"};
85TEST(JsonSerialization, MinerTransaction)
94 rapidjson::Document doc;
95 cryptonote::json::toJsonValue(doc, miner_tx, doc);
98 cryptonote::json::fromJsonValue(doc, miner_tx_copy);
113TEST(JsonSerialization, RegularTransaction)
122 const auto tx = make_transaction(
123 acct1.
get_keys(), {miner_tx}, {acct2.get_keys().m_account_address},
false,
false
129 rapidjson::Document doc;
130 cryptonote::json::toJsonValue(doc, tx, doc);
133 cryptonote::json::fromJsonValue(doc, tx_copy);
148TEST(JsonSerialization, RingctTransaction)
157 const auto tx = make_transaction(
158 acct1.
get_keys(), {miner_tx}, {acct2.get_keys().m_account_address},
true,
false
164 rapidjson::Document doc;
165 cryptonote::json::toJsonValue(doc, tx, doc);
168 cryptonote::json::fromJsonValue(doc, tx_copy);
183TEST(JsonSerialization, BulletproofTransaction)
192 const auto tx = make_transaction(
193 acct1.
get_keys(), {miner_tx}, {acct2.get_keys().m_account_address},
true,
true
199 rapidjson::Document doc;
200 cryptonote::json::toJsonValue(doc, tx, doc);
203 cryptonote::json::fromJsonValue(doc, tx_copy);
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
const account_keys & get_keys() const
#define EXPECT_EQ(val1, val2)
#define TEST(test_case_name, test_name)
#define ASSERT_TRUE(condition)
epee::mlocked< tools::scrubbed< ec_scalar > > secret_key
bool construct_tx_and_get_tx_key(const account_keys &sender_account_keys, const std::unordered_map< crypto::public_key, subaddress_index > &subaddresses, std::vector< tx_source_entry > &sources, std::vector< tx_destination_entry > &destinations, const boost::optional< cryptonote::account_public_address > &change_addr, const std::vector< uint8_t > &extra, transaction &tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector< crypto::secret_key > &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, rct::multisig_out *msout, const uint32_t account_major_offset, const cryptonote::network_type nettype)
crypto::hash get_transaction_hash(const transaction &t)
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
bool construct_miner_tx(size_t height, size_t median_weight, uint64_t already_generated_coins, size_t current_block_weight, uint64_t fee, const account_public_address &miner_address, transaction &tx, const blobdata &extra_nonce, size_t max_outs, uint8_t hard_fork_version, network_type nettype)
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
const CharType(& source)[N]
account_public_address m_account_address
crypto::public_key m_spend_public_key