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,
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(
58 {{}, 0, key_field.pub_key, {}, std::size_t(input.index()), input.value().amount,
rct,
rct::identity()}
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"};
85 TEST(JsonSerialization, MinerTransaction)
113 TEST(JsonSerialization, RegularTransaction)
122 const auto tx = make_transaction(
148 TEST(JsonSerialization, RingctTransaction)
157 const auto tx = make_transaction(
183 TEST(JsonSerialization, BulletproofTransaction)
192 const auto tx = make_transaction(
bool parse_tx_extra(const std::vector< uint8_t > &tx_extra, std::vector< tx_extra_field > &tx_extra_fields)
const CharType(& source)[N]
bool find_tx_extra_field_by_type(const std::vector< tx_extra_field > &tx_extra_fields, T &field, size_t index=0)
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
crypto::public_key m_spend_public_key
unsigned __int64 uint64_t
GenericDocument< UTF8<> > Document
GenericDocument with UTF8 encoding.
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
void toJsonValue(rapidjson::Document &doc, const std::string &i, rapidjson::Value &val)
account_public_address m_account_address
void fromJsonValue(const rapidjson::Value &val, std::string &str)
#define ASSERT_TRUE(condition)
crypto::hash get_transaction_hash(const transaction &t)
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)
TEST(JsonSerialization, MinerTransaction)
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)
#define EXPECT_EQ(val1, val2)