Electroneum
Loading...
Searching...
No Matches
json_serialization.cpp File Reference
#include <boost/optional/optional.hpp>
#include <boost/range/adaptor/indexed.hpp>
#include <gtest/gtest.h>
#include <rapidjson/document.h>
#include <vector>
#include "crypto/hash.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_core/cryptonote_tx_utils.h"
#include "serialization/json_object.h"
Include dependency graph for json_serialization.cpp:

Go to the source code of this file.

Functions

 TEST (JsonSerialization, MinerTransaction)
 TEST (JsonSerialization, RegularTransaction)
 TEST (JsonSerialization, RingctTransaction)
 TEST (JsonSerialization, BulletproofTransaction)

Function Documentation

◆ TEST() [1/4]

TEST ( JsonSerialization ,
BulletproofTransaction  )

Definition at line 183 of file json_serialization.cpp.

184{
186 acct1.generate();
187
189 acct2.generate();
190
191 const auto miner_tx = make_miner_transaction(acct1.get_keys().m_account_address);
192 const auto tx = make_transaction(
193 acct1.get_keys(), {miner_tx}, {acct2.get_keys().m_account_address}, true, true
194 );
195
196 crypto::hash tx_hash{};
198
199 rapidjson::Document doc;
200 cryptonote::json::toJsonValue(doc, tx, doc);
201
204
205 crypto::hash tx_copy_hash{};
206 ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
207 EXPECT_EQ(tx_hash, tx_copy_hash);
208
209 cryptonote::blobdata tx_bytes{};
210 cryptonote::blobdata tx_copy_bytes{};
211
214
215 EXPECT_EQ(tx_bytes, tx_copy_bytes);
216}
crypto::secret_key generate(const crypto::secret_key &recovery_key=crypto::secret_key(), bool recover=false, bool two_random=false)
Definition account.cpp:158
const account_keys & get_keys() const
Definition account.cpp:264
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1922
#define ASSERT_TRUE(condition)
Definition gtest.h:1865
POD_CLASS hash
Definition hash.h:50
void toJsonValue(rapidjson::Document &doc, const std::string &i, rapidjson::Value &val)
void fromJsonValue(const rapidjson::Value &val, std::string &str)
crypto::hash get_transaction_hash(const transaction &t)
std::string blobdata
bool t_serializable_object_to_blob(const t_object &to, blobdata &b_blob)
account_public_address m_account_address
Definition account.h:43
Here is the call graph for this function:

◆ TEST() [2/4]

TEST ( JsonSerialization ,
MinerTransaction  )

Definition at line 85 of file json_serialization.cpp.

86{
88 acct.generate();
89 const auto miner_tx = make_miner_transaction(acct.get_keys().m_account_address);
90
91 crypto::hash tx_hash{};
93
94 rapidjson::Document doc;
95 cryptonote::json::toJsonValue(doc, miner_tx, doc);
96
97 cryptonote::transaction miner_tx_copy;
98 cryptonote::json::fromJsonValue(doc, miner_tx_copy);
99
100 crypto::hash tx_copy_hash{};
101 ASSERT_TRUE(cryptonote::get_transaction_hash(miner_tx_copy, tx_copy_hash));
102 EXPECT_EQ(tx_hash, tx_copy_hash);
103
104 cryptonote::blobdata tx_bytes{};
105 cryptonote::blobdata tx_copy_bytes{};
106
108 ASSERT_TRUE(cryptonote::t_serializable_object_to_blob(miner_tx_copy, tx_copy_bytes));
109
110 EXPECT_EQ(tx_bytes, tx_copy_bytes);
111}
Here is the call graph for this function:

◆ TEST() [3/4]

TEST ( JsonSerialization ,
RegularTransaction  )

Definition at line 113 of file json_serialization.cpp.

114{
116 acct1.generate();
117
119 acct2.generate();
120
121 const auto miner_tx = make_miner_transaction(acct1.get_keys().m_account_address);
122 const auto tx = make_transaction(
123 acct1.get_keys(), {miner_tx}, {acct2.get_keys().m_account_address}, false, false
124 );
125
126 crypto::hash tx_hash{};
128
129 rapidjson::Document doc;
130 cryptonote::json::toJsonValue(doc, tx, doc);
131
134
135 crypto::hash tx_copy_hash{};
136 ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
137 EXPECT_EQ(tx_hash, tx_copy_hash);
138
139 cryptonote::blobdata tx_bytes{};
140 cryptonote::blobdata tx_copy_bytes{};
141
144
145 EXPECT_EQ(tx_bytes, tx_copy_bytes);
146}
Here is the call graph for this function:

◆ TEST() [4/4]

TEST ( JsonSerialization ,
RingctTransaction  )

Definition at line 148 of file json_serialization.cpp.

149{
151 acct1.generate();
152
154 acct2.generate();
155
156 const auto miner_tx = make_miner_transaction(acct1.get_keys().m_account_address);
157 const auto tx = make_transaction(
158 acct1.get_keys(), {miner_tx}, {acct2.get_keys().m_account_address}, true, false
159 );
160
161 crypto::hash tx_hash{};
163
164 rapidjson::Document doc;
165 cryptonote::json::toJsonValue(doc, tx, doc);
166
169
170 crypto::hash tx_copy_hash{};
171 ASSERT_TRUE(cryptonote::get_transaction_hash(tx_copy, tx_copy_hash));
172 EXPECT_EQ(tx_hash, tx_copy_hash);
173
174 cryptonote::blobdata tx_bytes{};
175 cryptonote::blobdata tx_copy_bytes{};
176
179
180 EXPECT_EQ(tx_bytes, tx_copy_bytes);
181}
Here is the call graph for this function: