Skip to content

Commit 97acfe9

Browse files
authored
Fix: URIToken Test (XRPLF#247)
1 parent 475b6f7 commit 97acfe9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/test/app/URIToken_test.cpp

+19-10
Original file line numberDiff line numberDiff line change
@@ -1964,14 +1964,27 @@ struct URIToken_test : public beast::unit_test::suite
19641964
auto const gw = Account{"gateway"};
19651965
auto const USD = gw["USD"];
19661966

1967-
// Rate between 1.0 & 2.0
1968-
std::array<double, 5> testCases = {{1, 1.1, 1.0005, 1.25, 2}};
1967+
struct TestRateData
1968+
{
1969+
double rate;
1970+
STAmount delta;
1971+
std::string multiply;
1972+
std::string divide;
1973+
};
1974+
std::array<TestRateData, 6> testCases = {{
1975+
{1, USD(100), "1100", "1100"},
1976+
{1.1, USD(100), "1110", "1090.909090909091"},
1977+
{1.0005, USD(100), "1100.05", "1099.950024987506"},
1978+
{1.005, USD(100), "1100.4999999", "1099.502487661197"},
1979+
{1.25, USD(100), "1125", "1080"},
1980+
{2, USD(100), "1200", "1050"},
1981+
}};
19691982

19701983
for (auto const& tc : testCases)
19711984
{
19721985
Env env{*this, features};
19731986
env.fund(XRP(10000), alice, bob, gw);
1974-
env(rate(gw, tc));
1987+
env(rate(gw, tc.rate));
19751988
env.close();
19761989
env.trust(USD(100000), alice, bob);
19771990
env.close();
@@ -1993,18 +2006,14 @@ struct URIToken_test : public beast::unit_test::suite
19932006
env(uritoken::buy(bob, id), uritoken::amt(delta));
19942007
env.close();
19952008
auto xferRate = transferRate(*env.current(), gw);
2009+
auto const postAlice = env.balance(alice, USD.issue());
19962010
if (!env.current()->rules().enabled(fixXahauV1))
19972011
{
1998-
BEAST_EXPECT(
1999-
env.balance(alice, USD.issue()) ==
2000-
preAlice +
2001-
multiplyRound(delta, xferRate, USD.issue(), true));
2012+
BEAST_EXPECT(to_string(postAlice.value()) == tc.multiply);
20022013
}
20032014
else
20042015
{
2005-
BEAST_EXPECT(
2006-
env.balance(alice, USD.issue()) ==
2007-
preAlice + divideRound(delta, xferRate, USD.issue(), true));
2016+
BEAST_EXPECT(to_string(postAlice.value()) == tc.divide);
20082017
}
20092018
BEAST_EXPECT(env.balance(bob, USD.issue()) == preBob - delta);
20102019
}

0 commit comments

Comments
 (0)