Compare commits

...

4 Commits

Author SHA1 Message Date
Ed Hennis
e3ad106797 Merge branch 'develop' into ximinez/parse-guard 2026-06-30 16:28:16 -04:00
Ed Hennis
f6ab0b16bb fixup! Review feedback: ParseFailureGuard 2026-06-30 14:34:06 -04:00
Ed Hennis
a8ead867ba Review feedback: ParseFailureGuard
- Rename oldExpected to oldExpected_.
- Prevent copying, and moving.
- Make getParseFailureGuard [[nodiscard]].
2026-06-30 13:44:38 -04:00
Ed Hennis
84589262c1 test: Add an RAII class to manage the env.parseFailureExpected flag 2026-06-29 18:26:31 -04:00
4 changed files with 43 additions and 5 deletions

View File

@@ -463,7 +463,7 @@ class Batch_test : public beast::unit_test::Suite
auto const batchFee = batch::calcBatchFee(env, 0, 2);
auto tx1 = batch::Inner(pay(alice, bob, XRP(1)), seq + 1);
tx1[jss::Fee] = "1.5";
env.setParseFailureExpected(true);
auto const g = env.getParseFailureGuard(true);
try
{
env(batch::outer(alice, seq, batchFee, tfAllOrNothing),
@@ -475,7 +475,6 @@ class Batch_test : public beast::unit_test::Suite
{
BEAST_EXPECT(true);
}
env.setParseFailureExpected(false);
}
// temSEQ_AND_TICKET: Batch: inner txn cannot have both Sequence

View File

@@ -5458,9 +5458,9 @@ class Vault_test : public beast::unit_test::Suite
env.close();
// 2. Mantissa larger than uint64 max
env.setParseFailureExpected(true);
try
{
auto const g = env.getParseFailureGuard(true);
tx[sfAssetsMaximum] = "18446744073709551617e5"; // uint64 max + 1
env(tx);
BEAST_EXPECTS(false, "Expected parse_error for mantissa larger than uint64 max");
@@ -5471,7 +5471,6 @@ class Vault_test : public beast::unit_test::Suite
BEAST_EXPECT(
e.what() == "invalidParamsField 'tx_json.AssetsMaximum' has invalid data."s);
}
env.setParseFailureExpected(false);
}
}

View File

@@ -482,6 +482,46 @@ public:
parseFailureExpected_ = b;
}
/** RAII class to set and restore the parse failure flag (setParseFailureExpected).
*
* Can be created directly, or through the `getParseFailureGuard(bool)` function.
*/
class ParseFailureGuard final
{
Env& self_;
bool oldExpected_ = self_.parseFailureExpected_;
public:
ParseFailureGuard(Env& self, bool b) : self_(self)
{
self_.setParseFailureExpected(b);
}
~ParseFailureGuard()
{
self_.setParseFailureExpected(oldExpected_);
}
// No copy, no move
ParseFailureGuard(ParseFailureGuard const&) = delete;
ParseFailureGuard&
operator=(ParseFailureGuard const&) = delete;
ParseFailureGuard(ParseFailureGuard&& other) = delete;
ParseFailureGuard&
operator=(ParseFailureGuard&&) = delete;
};
/** Gets an RAII guard to set and restore the parse failure flag
*
* Usage:
* auto const guard = env.getParseFailureGuard(true/false);
*/
[[nodiscard]] ParseFailureGuard
getParseFailureGuard(bool b)
{
return ParseFailureGuard{*this, b};
}
/** Turn off signature checks. */
void
disableSigs()

View File

@@ -602,7 +602,7 @@ Env::autofill(JTx& jt)
catch (ParseError const&)
{
if (!parseFailureExpected_)
test.log << "parse failed:\n" << pretty(jv) << std::endl;
test.log << "parse failure:\n" << pretty(jv) << std::endl;
rethrow();
}
}