Skip to content

Commit

Permalink
fix: check for valid ammID field in amm_info RPC (#5188)
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip authored Nov 18, 2024
1 parent 838978b commit 0ec17b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/test/rpc/AMMInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,32 @@ class AMMInfo_test : public jtx::AMMTestBase
});
}

void
testInvalidAmmField()
{
using namespace jtx;
testcase("Invalid amm field");

testAMM([&](AMM& amm, Env&) {
auto const resp = amm.ammRpcInfo(
std::nullopt,
jss::validated.c_str(),
std::nullopt,
std::nullopt,
gw);
BEAST_EXPECT(
resp.isMember("error") && resp["error"] == "actNotFound");
});
}

void
run() override
{
testErrors();
testSimpleRpc();
testVoteAndBid();
testFreeze();
testInvalidAmmField();
}
};

Expand Down
2 changes: 2 additions & 0 deletions src/xrpld/rpc/handlers/AMMInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ doAMMInfo(RPC::JsonContext& context)
if (!sle)
return Unexpected(rpcACT_MALFORMED);
ammID = sle->getFieldH256(sfAMMID);
if (ammID->isZero())
return Unexpected(rpcACT_NOT_FOUND);
}

if (params.isMember(jss::account))
Expand Down

0 comments on commit 0ec17b6

Please sign in to comment.