Skip to content

Commit

Permalink
Add unit test for tx
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 25, 2023
1 parent 117d00d commit aa7d8ca
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions src/test/rpc/Transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand All @@ -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 + "\": " //
Expand All @@ -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);
}
};

Expand Down

0 comments on commit aa7d8ca

Please sign in to comment.