Unify JSON serialization format of transactions (#4775)

* Remove include <ranges>

* Formatting fix

* Output for subscriptions

* Output from sign, submit etc.

* Output from ledger

* Output from account_tx

* Output from transaction_entry

* Output from tx

* Store close_time_iso in API v2 output

* Add small APIv2 unit test for subscribe

* Add unit test for transaction_entry

* Add unit test for tx

* Remove inLedger from API version 2

* Set ledger_hash and ledger_index

* Move isValidated from RPCHelpers to LedgerMaster

* Store closeTime in LedgerFill

* Time formatting fix

* additional tests for Subscribe unit tests

* Improved comments

* Rename mInLedger to mLedgerIndex

* Minor fixes

* Set ledger_hash on closed ledger, even if not validated

* Update API-CHANGELOG.md

* Add ledger_hash, ledger_index to transaction_entry

* Fix validated and close_time_iso in account_tx

* Fix typos

* Improve getJson for Transaction and STTx

* Minor improvements

* Replace class enum JsonOptions with struct

We may consider turning this into a general-purpose template and using it elsewhere

* simplify the extraction of transactionID from Transaction object

* Remove obsolete comments

* Unconditionally set validated in account_tx output

* Minor improvements

* Minor fixes

---------

Co-authored-by: Chenna Keshava <ckeshavabs@gmail.com>
This commit is contained in:
Bronek Kozicki
2023-11-08 18:36:24 +00:00
committed by GitHub
parent 09e0f103f4
commit 32ced493de
33 changed files with 763 additions and 234 deletions

View File

@@ -694,15 +694,13 @@ class Transaction_test : public beast::unit_test::suite
}
void
testRequest(FeatureBitset features)
testRequest(FeatureBitset features, unsigned apiVersion)
{
testcase("Test Request");
testcase("Test Request API version " + std::to_string(apiVersion));
using namespace test::jtx;
using std::to_string;
const char* COMMAND = jss::tx.c_str();
Env env{*this};
Account const alice{"alice"};
Account const alie{"alie"};
@@ -725,18 +723,47 @@ class Transaction_test : public beast::unit_test::suite
Json::Value expected = txn->getJson(JsonOptions::none);
expected[jss::DeliverMax] = expected[jss::Amount];
if (apiVersion > 1)
{
expected.removeMember(jss::hash);
expected.removeMember(jss::Amount);
}
Json::Value const result = {[&env, txn, apiVersion]() {
Json::Value params{Json::objectValue};
params[jss::transaction] = to_string(txn->getTransactionID());
params[jss::binary] = false;
params[jss::api_version] = apiVersion;
return env.client().invoke("tx", params);
}()};
auto const result =
env.rpc(COMMAND, to_string(txn->getTransactionID()));
BEAST_EXPECT(result[jss::result][jss::status] == jss::success);
if (apiVersion > 1)
{
BEAST_EXPECT(
result[jss::result][jss::close_time_iso] ==
"2000-01-01T00:00:20Z");
BEAST_EXPECT(
result[jss::result][jss::hash] ==
to_string(txn->getTransactionID()));
BEAST_EXPECT(result[jss::result][jss::validated] == true);
BEAST_EXPECT(result[jss::result][jss::ledger_index] == 4);
BEAST_EXPECT(
result[jss::result][jss::ledger_hash] ==
"B41882E20F0EC6228417D28B9AE0F33833645D35F6799DFB782AC97FC4BB51"
"D2");
}
for (auto memberIt = expected.begin(); memberIt != expected.end();
memberIt++)
{
std::string const name = memberIt.memberName();
if (BEAST_EXPECT(result[jss::result].isMember(name)))
auto const& result_transaction =
(apiVersion > 1 ? result[jss::result][jss::tx_json]
: result[jss::result]);
if (BEAST_EXPECT(result_transaction.isMember(name)))
{
auto const received = result[jss::result][name];
auto const received = result_transaction[name];
BEAST_EXPECTS(
received == *memberIt,
"Transaction contains \n\"" + name + "\": " //
@@ -763,7 +790,8 @@ public:
testRangeCTIDRequest(features);
testCTIDValidation(features);
testCTIDRPC(features);
testRequest(features);
test::jtx::forAllApiVersions(
std::bind_front(&Transaction_test::testRequest, this, features));
}
};