diff --git a/src/test/rpc/Subscribe_test.cpp b/src/test/rpc/Subscribe_test.cpp index 7725390f6b6..bb419cbb4a1 100644 --- a/src/test/rpc/Subscribe_test.cpp +++ b/src/test/rpc/Subscribe_test.cpp @@ -22,6 +22,7 @@ #include #include #include +#include "ripple/json/json_value.h" #include #include #include @@ -307,6 +308,80 @@ class Subscribe_test : public beast::unit_test::suite BEAST_EXPECT(jv[jss::status] == "success"); } + void + testTransactions_APIv2() + { + testcase("transactions API version 2"); + + using namespace std::chrono_literals; + using namespace jtx; + Env env(*this); + auto wsc = makeWSClient(env.app().config()); + Json::Value stream{Json::objectValue}; + + { + // RPC subscribe to transactions stream + stream[jss::api_version] = 2; + stream[jss::streams] = Json::arrayValue; + stream[jss::streams].append("transactions"); + auto jv = wsc->invoke("subscribe", stream); + if (wsc->version() == 2) + { + BEAST_EXPECT( + jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] == "2.0"); + BEAST_EXPECT( + jv.isMember(jss::ripplerpc) && jv[jss::ripplerpc] == "2.0"); + BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5); + } + BEAST_EXPECT(jv[jss::status] == "success"); + } + + { + env.fund(XRP(10000), "alice"); + env.close(); + + // Check stream update for payment transaction + BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) { + return jv[jss::meta]["AffectedNodes"][1u]["CreatedNode"] + ["NewFields"][jss::Account] // + == Account("alice").human() && + jv[jss::close_time_iso] // + == "2000-01-01T00:00:10Z" && + jv[jss::validated] == true && // + jv[jss::tx_json][jss::TransactionType] // + == jss::Payment && + jv[jss::tx_json][jss::DeliverMax] // + == "10000000010" && + !jv[jss::tx_json].isMember(jss::Amount) && + jv[jss::tx_json][jss::Fee] // + == "10" && + jv[jss::tx_json][jss::Sequence] // + == 1; + })); + + // Check stream update for accountset transaction + BEAST_EXPECT(wsc->findMsg(5s, [&](auto const& jv) { + return jv[jss::meta]["AffectedNodes"][0u]["ModifiedNode"] + ["FinalFields"][jss::Account] == + Account("alice").human(); + })); + } + + { + // RPC unsubscribe + auto jv = wsc->invoke("unsubscribe", stream); + if (wsc->version() == 2) + { + BEAST_EXPECT( + jv.isMember(jss::jsonrpc) && jv[jss::jsonrpc] == "2.0"); + BEAST_EXPECT( + jv.isMember(jss::ripplerpc) && jv[jss::ripplerpc] == "2.0"); + BEAST_EXPECT(jv.isMember(jss::id) && jv[jss::id] == 5); + } + BEAST_EXPECT(jv[jss::status] == "success"); + } + } + void testManifests() { @@ -1223,6 +1298,7 @@ class Subscribe_test : public beast::unit_test::suite testServer(); testLedger(); testTransactions(); + testTransactions_APIv2(); testManifests(); testValidations(all - xrpFees); testValidations(all);