From c2a3b52548964e4bb91e4490b59da2ebe5931790 Mon Sep 17 00:00:00 2001 From: Bronek Kozicki Date: Tue, 24 Oct 2023 17:39:45 +0000 Subject: [PATCH] Add unit test for tx --- src/test/rpc/Transaction_test.cpp | 41 ++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/test/rpc/Transaction_test.cpp b/src/test/rpc/Transaction_test.cpp index c16d7bbd004..22d3ed2e29b 100644 --- a/src/test/rpc/Transaction_test.cpp +++ b/src/test/rpc/Transaction_test.cpp @@ -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,42 @@ 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); + } 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 +785,8 @@ class Transaction_test : public beast::unit_test::suite testRangeCTIDRequest(features); testCTIDValidation(features); testCTIDRPC(features); - testRequest(features); + testRequest(features, 1); + testRequest(features, 2); } };