Compare commits

...

4 Commits

Author SHA1 Message Date
Bronek Kozicki
8a75beffc2 Is it a valid fix ???? 2025-11-04 14:14:22 +00:00
Bronek Kozicki
23e9ec5e4b Test rounding error 2025-11-04 14:12:31 +00:00
Bronek Kozicki
ec683f2743 Merge branch 'develop' into Bronek/VaultDeposit_invariant_violation 2025-11-04 09:39:25 +00:00
Bronek Kozicki
27dd73ca91 Repro VaultDeposit invariant violation 2025-11-04 09:38:53 +00:00
2 changed files with 86 additions and 28 deletions

View File

@@ -2446,6 +2446,47 @@ class Vault_test : public beast::unit_test::suite
} }
} }
void
testIOURounding()
{
using namespace test::jtx;
testcase("IOU rounding");
Account const issuer{"issuer"};
Account const owner{"owner"};
auto const IOU = issuer["IOU"];
Env env{*this};
Vault vault{env};
env.fund(XRP(1'000), issuer, owner);
env.close();
env(trust(owner, IOU(1'000)));
env(pay(issuer, owner, IOU(118.75)));
env.close();
auto [tx, vaultKeylet] =
vault.create({.owner = owner, .asset = IOU.asset()});
tx[sfScale] = 1;
env(tx);
env.close();
env(vault.deposit(
{.depositor = owner, .id = vaultKeylet.key, .amount = IOU(100)}));
env.close();
auto const tx1 = vault.deposit(
{.depositor = owner, .id = vaultKeylet.key, .amount = IOU(3.75)});
for (auto i = 0; i < 5; ++i)
{
if (i == 4)
std::cerr << tx1 << '\n';
env(tx1);
env.close();
}
}
void void
testWithIOU() testWithIOU()
{ {
@@ -4973,20 +5014,21 @@ public:
void void
run() override run() override
{ {
testSequences(); // testSequences();
testPreflight(); // testPreflight();
testCreateFailXRP(); // testCreateFailXRP();
testCreateFailIOU(); // testCreateFailIOU();
testCreateFailMPT(); // testCreateFailMPT();
testWithMPT(); // testWithMPT();
testWithIOU(); // testWithIOU();
testWithDomainCheck(); testIOURounding();
testWithDomainCheckXRP(); // testWithDomainCheck();
testNonTransferableShares(); // testWithDomainCheckXRP();
testFailedPseudoAccount(); // testNonTransferableShares();
testScaleIOU(); // testFailedPseudoAccount();
testRPC(); // testScaleIOU();
testDelegate(); // testRPC();
// testDelegate();
} }
}; };

View File

@@ -1011,25 +1011,41 @@ public:
} }
} }
void
testRoundingError()
{
testcase("rounding error");
STAmount assets{noIssue()};
STAmount const shares{noIssue(), 37, 0};
Number const shareTotal{1148};
Number assetTotal{1148, -1};
assets = (assetTotal * shares) / shareTotal;
std::cerr << assets << '\n'; // 3.699999999999999/1/1
BEAST_EXPECT(assets == Number(37l, -1)); // FAIL
}
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
void void
run() override run() override
{ {
testSetValue(); // testSetValue();
testNativeCurrency(); // testNativeCurrency();
testCustomCurrency(); // testCustomCurrency();
testArithmetic(); // testArithmetic();
testUnderflow(); // testUnderflow();
testRounding(); // testRounding();
testConvertXRP(); // testConvertXRP();
testConvertIOU(); // testConvertIOU();
testCanAddXRP(); // testCanAddXRP();
testCanAddIOU(); // testCanAddIOU();
testCanAddMPT(); // testCanAddMPT();
testCanSubtractXRP(); // testCanSubtractXRP();
testCanSubtractIOU(); // testCanSubtractIOU();
testCanSubtractMPT(); // testCanSubtractMPT();
testRoundingError();
} }
}; };