mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Fix underflow rounding issue:
Very small payment could fail when STAmount::mulRound underflowed and returned zero, when it should have rounded up to the smallest representable value.
This commit is contained in:
@@ -121,10 +121,49 @@ public:
|
||||
expect (isOffer (env, "alice", XRP (300), USD (100)) &&
|
||||
isOffer (env, "alice", XRP (400), USD (200)));
|
||||
}
|
||||
void testTinyPayment ()
|
||||
{
|
||||
// Regression test for tiny payments
|
||||
using namespace jtx;
|
||||
auto const alice = Account ("alice");
|
||||
auto const bob = Account ("bob");
|
||||
auto const carol = Account ("carol");
|
||||
auto const gw = Account ("gw");
|
||||
|
||||
auto const USD = gw["USD"];
|
||||
auto const EUR = gw["EUR"];
|
||||
|
||||
Env env (*this);
|
||||
|
||||
|
||||
env.fund (XRP (10000), alice, bob, carol, gw);
|
||||
env.trust (USD (1000), alice, bob, carol);
|
||||
env.trust (EUR (1000), alice, bob, carol);
|
||||
env (pay (gw, alice, USD (100)));
|
||||
env (pay (gw, carol, EUR (100)));
|
||||
|
||||
// Create more offers than the loop max count in DeliverNodeReverse
|
||||
for (int i=0;i<101;++i)
|
||||
env (offer (carol, USD (1), EUR (2)));
|
||||
|
||||
auto const switchoverTime = STAmountCalcSwitchovers::enableUnderflowFixCloseTime ();
|
||||
|
||||
for (auto timeDelta : {-10, 10}){
|
||||
auto const closeTime = switchoverTime + timeDelta;
|
||||
STAmountCalcSwitchovers switchover (closeTime);
|
||||
env.close (NetClock::time_point (std::chrono::seconds (closeTime)));
|
||||
// Will fail without the underflow fix
|
||||
auto expectedResult = switchover.enableUnderflowFix () ?
|
||||
tesSUCCESS : tecPATH_PARTIAL;
|
||||
env (pay ("alice", "bob", EUR (epsilon)), path (~EUR),
|
||||
sendmax (USD (100)), ter (expectedResult));
|
||||
}
|
||||
}
|
||||
void run ()
|
||||
{
|
||||
testCanceledOffer ();
|
||||
testRmFundedOffer ();
|
||||
testTinyPayment ();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user