mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
APIv2: add error messages for account_tx (#4571)
Certain inputs for the AccountTx method should return an error. In other words, an invalid request from a user or client now results in an error message. Since this can change the response from the API, it is an API breaking change. This commit maintains backward compatibility by keeping the existing behavior for existing requests. When clients specify "api_version": 2, they will be able to get the updated error messages. Update unit tests to check the error based on the API version. * Fix #4288 * Fix #4545
This commit is contained in:
@@ -108,7 +108,7 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
};
|
||||
|
||||
void
|
||||
testParameters()
|
||||
testParameters(unsigned int apiVersion)
|
||||
{
|
||||
using namespace test::jtx;
|
||||
|
||||
@@ -143,104 +143,178 @@ class AccountTx_test : public beast::unit_test::suite
|
||||
};
|
||||
|
||||
Json::Value jParms;
|
||||
jParms[jss::api_version] = apiVersion;
|
||||
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(jParms)),
|
||||
rpcINVALID_PARAMS));
|
||||
|
||||
jParms[jss::account] = "0xDEADBEEF";
|
||||
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(jParms)),
|
||||
rpcACT_MALFORMED));
|
||||
|
||||
jParms[jss::account] = A1.human();
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(jParms))));
|
||||
|
||||
// Ledger min/max index
|
||||
if (apiVersion < 2)
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_min] = -1;
|
||||
p[jss::ledger_index_max] = -1;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 0;
|
||||
p[jss::ledger_index_max] = 100;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 1;
|
||||
p[jss::ledger_index_max] = 2;
|
||||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 2;
|
||||
p[jss::ledger_index_max] = 1;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
(RPC::apiMaximumSupportedVersion == 1 ? rpcLGR_IDXS_INVALID
|
||||
: rpcINVALID_LGR_RANGE)));
|
||||
}
|
||||
env.rpc("json", "account_tx", to_string(jParms)),
|
||||
rpcINVALID_PARAMS));
|
||||
|
||||
// Ledger index min only
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_min] = -1;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
jParms[jss::account] = "0xDEADBEEF";
|
||||
|
||||
p[jss::ledger_index_min] = 1;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = env.current()->info().seq;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
(RPC::apiMaximumSupportedVersion == 1 ? rpcLGR_IDXS_INVALID
|
||||
: rpcINVALID_LGR_RANGE)));
|
||||
env.rpc("json", "account_tx", to_string(jParms)),
|
||||
rpcACT_MALFORMED));
|
||||
|
||||
jParms[jss::account] = A1.human();
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(jParms))));
|
||||
|
||||
// Ledger min/max index
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_min] = -1;
|
||||
p[jss::ledger_index_max] = -1;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 0;
|
||||
p[jss::ledger_index_max] = 100;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 1;
|
||||
p[jss::ledger_index_max] = 2;
|
||||
BEAST_EXPECT(
|
||||
noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 2;
|
||||
p[jss::ledger_index_max] = 1;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
(RPC::apiMaximumSupportedVersion == 1
|
||||
? rpcLGR_IDXS_INVALID
|
||||
: rpcINVALID_LGR_RANGE)));
|
||||
}
|
||||
|
||||
// Ledger index min only
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_min] = -1;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = 1;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_min] = env.current()->info().seq;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
(RPC::apiMaximumSupportedVersion == 1
|
||||
? rpcLGR_IDXS_INVALID
|
||||
: rpcINVALID_LGR_RANGE)));
|
||||
}
|
||||
|
||||
// Ledger index max only
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_max] = -1;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_max] = env.current()->info().seq;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_max] = 3;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_max] = env.closed()->info().seq;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index_max] = env.closed()->info().seq - 1;
|
||||
BEAST_EXPECT(
|
||||
noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
}
|
||||
|
||||
// Ledger Sequence
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
|
||||
p[jss::ledger_index] = env.closed()->info().seq;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index] = env.closed()->info().seq - 1;
|
||||
BEAST_EXPECT(
|
||||
noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index] = env.current()->info().seq;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_NOT_VALIDATED));
|
||||
|
||||
p[jss::ledger_index] = env.current()->info().seq + 1;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_NOT_FOUND));
|
||||
}
|
||||
|
||||
// Ledger Hash
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
|
||||
p[jss::ledger_hash] = to_string(env.closed()->info().hash);
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_hash] =
|
||||
to_string(env.closed()->info().parentHash);
|
||||
BEAST_EXPECT(
|
||||
noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
}
|
||||
}
|
||||
|
||||
// Ledger index max only
|
||||
else
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_max] = -1;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
// Ledger index max/min/index all specified
|
||||
// ERRORS out with invalid Parenthesis
|
||||
{
|
||||
jParms[jss::account] = "0xDEADBEEF";
|
||||
jParms[jss::account] = A1.human();
|
||||
Json::Value p{jParms};
|
||||
|
||||
p[jss::ledger_index_max] = env.current()->info().seq;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
p[jss::ledger_index_max] = -1;
|
||||
p[jss::ledger_index_min] = -1;
|
||||
p[jss::ledger_index] = -1;
|
||||
|
||||
p[jss::ledger_index_max] = env.closed()->info().seq;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcINVALID_PARAMS));
|
||||
}
|
||||
|
||||
p[jss::ledger_index_max] = env.closed()->info().seq - 1;
|
||||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
}
|
||||
// Ledger index min/max only
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_max] = 100;
|
||||
p[jss::ledger_index_min] = 0;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_IDX_MALFORMED));
|
||||
|
||||
// Ledger Sequence
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_max] = -1;
|
||||
p[jss::ledger_index_min] = -1;
|
||||
BEAST_EXPECT(
|
||||
hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index] = env.closed()->info().seq;
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
p[jss::ledger_index_min] = 2;
|
||||
p[jss::ledger_index_max] = 1;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcINVALID_LGR_RANGE));
|
||||
}
|
||||
|
||||
p[jss::ledger_index] = env.closed()->info().seq - 1;
|
||||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_index] = env.current()->info().seq;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_NOT_VALIDATED));
|
||||
|
||||
p[jss::ledger_index] = env.current()->info().seq + 1;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)), rpcLGR_NOT_FOUND));
|
||||
}
|
||||
|
||||
// Ledger Hash
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
|
||||
p[jss::ledger_hash] = to_string(env.closed()->info().hash);
|
||||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
|
||||
p[jss::ledger_hash] = to_string(env.closed()->info().parentHash);
|
||||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p))));
|
||||
// Ledger index max only
|
||||
{
|
||||
Json::Value p{jParms};
|
||||
p[jss::ledger_index_max] = env.current()->info().seq;
|
||||
BEAST_EXPECT(isErr(
|
||||
env.rpc("json", "account_tx", to_string(p)),
|
||||
rpcLGR_IDX_MALFORMED));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,7 +667,12 @@ public:
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testParameters();
|
||||
for (auto testVersion = RPC::apiMinimumSupportedVersion;
|
||||
testVersion <= RPC::apiBetaVersion;
|
||||
++testVersion)
|
||||
{
|
||||
testParameters(testVersion);
|
||||
}
|
||||
testContents();
|
||||
testAccountDelete();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user