Skip to content

Commit

Permalink
fix CTID in tx command returns invalidParams on lowercase hex (XRPLF#…
Browse files Browse the repository at this point in the history
…5049)

* fix CTID in tx command returns invalidParams on lowercase hex

* test mixed case and change auto to explicit type

* add header cctype because std::tolower is called

* remove unused local variable

* change test case comment from 'lowercase' to 'mixed case'

---------

Co-authored-by: Zack Brunson <Zshooter@gmail.com>
  • Loading branch information
2 people authored and vlntb committed Aug 23, 2024
1 parent 69f8590 commit 4d230a8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/test/rpc/Transaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <xrpl/protocol/jss.h>
#include <xrpl/protocol/serialize.h>

#include <cctype>
#include <optional>
#include <tuple>

Expand Down Expand Up @@ -671,6 +672,47 @@ class Transaction_test : public beast::unit_test::suite
BEAST_EXPECT(jrr[jss::hash]);
}

// test querying with mixed case ctid
{
Env env{*this, makeNetworkConfig(11111)};
std::uint32_t const netID = env.app().config().NETWORK_ID;

Account const alice = Account("alice");
Account const bob = Account("bob");

std::uint32_t const startLegSeq = env.current()->info().seq;
env.fund(XRP(10000), alice, bob);
env(pay(alice, bob, XRP(10)));
env.close();

std::string const ctid = *RPC::encodeCTID(startLegSeq, 0, netID);
auto isUpper = [](char c) { return std::isupper(c) != 0; };

// Verify that there are at least two upper case letters in ctid and
// test a mixed case
if (BEAST_EXPECT(
std::count_if(ctid.begin(), ctid.end(), isUpper) > 1))
{
// Change the first upper case letter to lower case.
std::string mixedCase = ctid;
{
auto const iter = std::find_if(
mixedCase.begin(), mixedCase.end(), isUpper);
*iter = std::tolower(*iter);
}
BEAST_EXPECT(ctid != mixedCase);

Json::Value jsonTx;
jsonTx[jss::binary] = false;
jsonTx[jss::ctid] = mixedCase;
jsonTx[jss::id] = 1;
Json::Value const jrr =
env.rpc("json", "tx", to_string(jsonTx))[jss::result];
BEAST_EXPECT(jrr[jss::ctid] == ctid);
BEAST_EXPECT(jrr[jss::hash]);
}
}

// test that if the network is 65535 the ctid is not in the response
{
Env env{*this, makeNetworkConfig(65535)};
Expand Down
2 changes: 1 addition & 1 deletion src/xrpld/rpc/CTID.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ decodeCTID(const T ctid) noexcept
if (ctidString.length() != 16)
return {};

if (!boost::regex_match(ctidString, boost::regex("^[0-9A-F]+$")))
if (!boost::regex_match(ctidString, boost::regex("^[0-9A-Fa-f]+$")))
return {};

ctidValue = std::stoull(ctidString, nullptr, 16);
Expand Down

0 comments on commit 4d230a8

Please sign in to comment.