Skip to content

Commit

Permalink
Fix amm_info
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Nov 12, 2024
1 parent 9d58f11 commit dddf2b3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/test/rpc/AMMInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,45 @@ class AMMInfo_test : public jtx::AMMTestBase
});
}

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

Env env{*this};

Account const gw("gw");
env.fund(XRP(10000), gw);

Json::Value jv;
jv[jss::TransactionType] = jss::AMMCreate;
jv[jss::Account] = gw.human();
jv[jss::TradingFee] = "0";
jv[jss::Amount] = "10000000";
jv[jss::Amount2] =
AnyAmount(gw["USD"](10)).value.getJson(JsonOptions::none);

env(jv, fee(drops(env.current()->fees().increment)));
env.close();

Json::Value jvParams;
jvParams[jss::ledger_index] = jss::validated;
jvParams[jss::amm_account] = gw.human();
auto const resp = env.rpc("json", "amm_info", to_string(jvParams));
BEAST_EXPECT(
resp.isMember("result") && resp["result"].isMember("error") &&
resp["result"]["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 dddf2b3

Please sign in to comment.