mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-09 03:36:49 +00:00
Fix broken unit tests: EscrowToken
- Some EscrowToken tests used a hard-coded list of amendments to determine whether to expect large mantissa logic. That ignored the effects of fixCleanup3_2_0, especially as applied to the previous fix affecting preflight, preclaim, etc. - Add a helper function, useRulesGuards, which will return the same decision as createGuards and setCurrentRulesImpl. Use that helper function in the relevant tests. - Also remove an #include that clang-tidy was complaining about.
This commit is contained in:
@@ -124,6 +124,9 @@ private:
|
||||
|
||||
class NumberSO;
|
||||
|
||||
bool
|
||||
useRulesGuards(Rules const& rules);
|
||||
|
||||
void
|
||||
createGuards(
|
||||
Rules const& rules,
|
||||
|
||||
@@ -53,6 +53,9 @@ setCurrentTransactionRules(std::optional<Rules> r)
|
||||
bool const enableCuspRoundingFix = !r || r->enabled(fixCleanup3_2_0);
|
||||
bool const enableVaultNumbers = enableCuspRoundingFix ||
|
||||
(r->enabled(featureSingleAssetVault) || r->enabled(featureLendingProtocol));
|
||||
XRPL_ASSERT(
|
||||
!r || useRulesGuards(*r) == (enableCuspRoundingFix || enableVaultNumbers),
|
||||
"setCurrentTransactionRules : rule decisions match");
|
||||
Number::setMantissaScale(
|
||||
enableCuspRoundingFix ? MantissaRange::MantissaScale::Large
|
||||
: (enableVaultNumbers ? MantissaRange::MantissaScale::LargeLegacy
|
||||
@@ -61,6 +64,20 @@ setCurrentTransactionRules(std::optional<Rules> r)
|
||||
*getCurrentTransactionRulesRef() = std::move(r);
|
||||
}
|
||||
|
||||
bool
|
||||
useRulesGuards(Rules const& rules)
|
||||
{
|
||||
// The list of amendments used here - to decide whether to create a RulesGuard - must be a
|
||||
// superset of the list used to figure out which mantissa scale to use in
|
||||
// setCurrentTransactionRules. Additional amendments can be added if desired.
|
||||
//
|
||||
// As soon as any one of these amendments is retired, this whole function can be removed, along
|
||||
// with createGuards, and any other callers, and the first set of guards can be created directly
|
||||
// at the call site, without using optional.
|
||||
return rules.enabled(fixCleanup3_2_0) || rules.enabled(featureSingleAssetVault) ||
|
||||
rules.enabled(featureLendingProtocol);
|
||||
}
|
||||
|
||||
void
|
||||
createGuards(
|
||||
Rules const& rules,
|
||||
@@ -68,14 +85,7 @@ createGuards(
|
||||
std::optional<CurrentTransactionRulesGuard>& rulesGuard,
|
||||
std::optional<NumberMantissaScaleGuard>& mantissaScaleGuard)
|
||||
{
|
||||
// The list amendments used to decide which guard(s) to create must be a superset of the list
|
||||
// used to figure out which mantissa scale to use in setCurrentTransactionRules. Additional
|
||||
// amendments can be added if desired.
|
||||
//
|
||||
// As soon as any one of these amendments is retired, this whole function can be removed, and
|
||||
// the first set of guards can be created directly at the call site, without using optional.
|
||||
if (rules.enabled(fixCleanup3_2_0) || rules.enabled(featureSingleAssetVault) ||
|
||||
rules.enabled(featureLendingProtocol))
|
||||
if (useRulesGuards(rules))
|
||||
{
|
||||
// raii classes for the current ledger rules.
|
||||
// fixUniversalNumber predates the rulesGuard and should be replaced.
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <xrpl/beast/utility/instrumentation.h>
|
||||
#include <xrpl/ledger/ApplyView.h>
|
||||
#include <xrpl/ledger/OpenView.h>
|
||||
#include <xrpl/protocol/Feature.h>
|
||||
#include <xrpl/protocol/IOUAmount.h>
|
||||
#include <xrpl/protocol/Rules.h>
|
||||
#include <xrpl/protocol/SField.h>
|
||||
|
||||
@@ -572,8 +572,7 @@ struct EscrowToken_test : public beast::unit_test::Suite
|
||||
env(pay(gw, bob, usd(1)));
|
||||
env.close();
|
||||
|
||||
bool const largeMantissa =
|
||||
features[featureSingleAssetVault] || features[featureLendingProtocol];
|
||||
bool const largeMantissa = useRulesGuards(env.current()->rules());
|
||||
|
||||
// alice cannot create escrow for 1/10 iou - precision loss
|
||||
env(escrow::create(alice, bob, usd(1)),
|
||||
@@ -2136,8 +2135,7 @@ struct EscrowToken_test : public beast::unit_test::Suite
|
||||
env(pay(gw, bob, usd(1)));
|
||||
env.close();
|
||||
|
||||
bool const largeMantissa =
|
||||
features[featureSingleAssetVault] || features[featureLendingProtocol];
|
||||
bool const largeMantissa = useRulesGuards(env.current()->rules());
|
||||
|
||||
// alice cannot create escrow for 1/10 iou - precision loss
|
||||
env(escrow::create(alice, bob, usd(1)),
|
||||
|
||||
Reference in New Issue
Block a user