-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIv2(AccountTx): Added error messages on AccountTx #4571
Changes from all commits
4dadab6
2f3c7e3
f123188
42ca45f
7c838eb
ac88045
86a9b31
2e1e1a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ class AccountTx_test : public beast::unit_test::suite | |
}; | ||
|
||
void | ||
testParameters() | ||
testParameters(unsigned int apiVersion) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but wondering why the test cases in this file do not have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess is that we don't have any written, enforced guidelines for tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be useful to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our test framework and tests are long overdue for a redesign with firm and written guidelines, but I won't worry about the inconsistency in this PR. |
||
{ | ||
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)))); | ||
BEAST_EXPECT(isErr( | ||
env.rpc("json", "account_tx", to_string(jParms)), | ||
rpcINVALID_PARAMS)); | ||
|
||
p[jss::ledger_index_min] = 1; | ||
p[jss::ledger_index_max] = 2; | ||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
jParms[jss::account] = "0xDEADBEEF"; | ||
|
||
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)), | ||
rpcACT_MALFORMED)); | ||
|
||
// 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] = A1.human(); | ||
BEAST_EXPECT( | ||
hasTxs(env.rpc("json", "account_tx", to_string(jParms)))); | ||
|
||
p[jss::ledger_index_min] = 1; | ||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
// 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))); | ||
} | ||
|
||
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 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)))); | ||
// 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)))); | ||
} | ||
|
||
p[jss::ledger_index_max] = env.current()->info().seq; | ||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
// Ledger Sequence | ||
{ | ||
Json::Value p{jParms}; | ||
|
||
p[jss::ledger_index_max] = env.closed()->info().seq; | ||
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_max] = env.closed()->info().seq - 1; | ||
BEAST_EXPECT(noTxs(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)))); | ||
|
||
// Ledger Sequence | ||
{ | ||
Json::Value p{jParms}; | ||
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.closed()->info().seq; | ||
BEAST_EXPECT(hasTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
p[jss::ledger_index] = env.current()->info().seq + 1; | ||
BEAST_EXPECT(isErr( | ||
env.rpc("json", "account_tx", to_string(p)), | ||
rpcLGR_NOT_FOUND)); | ||
} | ||
|
||
p[jss::ledger_index] = env.closed()->info().seq - 1; | ||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
// Ledger Hash | ||
{ | ||
Json::Value p{jParms}; | ||
|
||
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_hash] = to_string(env.closed()->info().hash); | ||
BEAST_EXPECT( | ||
hasTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
|
||
p[jss::ledger_index] = env.current()->info().seq + 1; | ||
BEAST_EXPECT(isErr( | ||
env.rpc("json", "account_tx", to_string(p)), rpcLGR_NOT_FOUND)); | ||
p[jss::ledger_hash] = | ||
to_string(env.closed()->info().parentHash); | ||
BEAST_EXPECT( | ||
noTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
} | ||
} | ||
|
||
// Ledger Hash | ||
else | ||
{ | ||
Json::Value p{jParms}; | ||
// 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_hash] = to_string(env.closed()->info().hash); | ||
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_hash] = to_string(env.closed()->info().parentHash); | ||
BEAST_EXPECT(noTxs(env.rpc("json", "account_tx", to_string(p)))); | ||
BEAST_EXPECT(isErr( | ||
env.rpc("json", "account_tx", to_string(p)), | ||
rpcINVALID_PARAMS)); | ||
} | ||
|
||
// 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)); | ||
|
||
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_min] = 2; | ||
p[jss::ledger_index_max] = 1; | ||
BEAST_EXPECT(isErr( | ||
env.rpc("json", "account_tx", to_string(p)), | ||
rpcINVALID_LGR_RANGE)); | ||
} | ||
|
||
// 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 @@ class AccountTx_test : public beast::unit_test::suite | |
void | ||
run() override | ||
{ | ||
testParameters(); | ||
for (auto testVersion = RPC::apiMinimumSupportedVersion; | ||
testVersion <= RPC::apiBetaVersion; | ||
++testVersion) | ||
{ | ||
testParameters(testVersion); | ||
} | ||
testContents(); | ||
testAccountDelete(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not so important, but I'm wondering if it'll be nice to make constants like API_VERSION_1 and API_VERSION_2 instead of using raw numbers 1 and 2 since we are using it in a lot of places ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth it when we're just using consecutive integers to name the versions.