Skip to content

Commit

Permalink
Add small APIv2 unit test for subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
Bronek committed Oct 26, 2023
1 parent 4d517e2 commit 2b397c9
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/test/rpc/Subscribe_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <ripple/core/ConfigSections.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/jss.h>
#include "ripple/json/json_value.h"
#include <test/jtx.h>
#include <test/jtx/WSClient.h>
#include <test/jtx/envconfig.h>
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -1223,6 +1298,7 @@ class Subscribe_test : public beast::unit_test::suite
testServer();
testLedger();
testTransactions();
testTransactions_APIv2();
testManifests();
testValidations(all - xrpFees);
testValidations(all);
Expand Down

0 comments on commit 2b397c9

Please sign in to comment.