Catch up the consequences of Number changes

- Change the Number::maxIntValue to all 9's.
- Add integral() to Asset (copied from Lending)
- Add toNumber() functions to STAmount, MPTAmount, XRPAmount to allow
  explicit conversions with enforcement options.
- Add optional Number::EnforceInteger options to STAmount and STNumber
  ctors, conversions, etc. IOUs are never checked.
- Update Vault transactors, and helper functions, to check restrictions.
- Fix and add Vault tests.
This commit is contained in:
Ed Hennis
2025-11-05 18:15:49 -05:00
parent 82f68496b8
commit bd196c7609
15 changed files with 274 additions and 24 deletions

View File

@@ -3597,7 +3597,32 @@ class Vault_test : public beast::unit_test::suite
});
testCase(18, [&, this](Env& env, Data d) {
testcase("Scale deposit overflow on second deposit");
testcase("MPT scale deposit overflow");
// The computed number of shares can not be represented as an MPT
// without truncation
{
auto tx = d.vault.deposit(
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = d.asset(5)});
env(tx, ter{tecPRECISION_LOSS});
env.close();
}
});
testCase(14, [&, this](Env& env, Data d) {
testcase("MPT scale deposit overflow on first deposit");
auto tx = d.vault.deposit(
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = d.asset(10)});
env(tx, ter{tecPRECISION_LOSS});
env.close();
});
testCase(14, [&, this](Env& env, Data d) {
testcase("MPT scale deposit overflow on second deposit");
{
auto tx = d.vault.deposit(
@@ -3618,8 +3643,8 @@ class Vault_test : public beast::unit_test::suite
}
});
testCase(18, [&, this](Env& env, Data d) {
testcase("Scale deposit overflow on total shares");
testCase(14, [&, this](Env& env, Data d) {
testcase("No MPT scale deposit overflow on total shares");
{
auto tx = d.vault.deposit(
@@ -3635,7 +3660,7 @@ class Vault_test : public beast::unit_test::suite
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = d.asset(5)});
env(tx, ter{tecPATH_DRY});
env(tx);
env.close();
}
});
@@ -3919,6 +3944,28 @@ class Vault_test : public beast::unit_test::suite
testCase(18, [&, this](Env& env, Data d) {
testcase("Scale withdraw overflow");
{
auto tx = d.vault.deposit(
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = d.asset(5)});
env(tx, ter{tecPRECISION_LOSS});
env.close();
}
{
auto tx = d.vault.withdraw(
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = STAmount(d.asset, Number(10, 0))});
env(tx, ter{tecPRECISION_LOSS});
env.close();
}
});
testCase(14, [&, this](Env& env, Data d) {
testcase("MPT scale withdraw overflow");
{
auto tx = d.vault.deposit(
{.depositor = d.depositor,
@@ -4137,6 +4184,29 @@ class Vault_test : public beast::unit_test::suite
testCase(18, [&, this](Env& env, Data d) {
testcase("Scale clawback overflow");
{
auto tx = d.vault.deposit(
{.depositor = d.depositor,
.id = d.keylet.key,
.amount = d.asset(5)});
env(tx, ter(tecPRECISION_LOSS));
env.close();
}
{
auto tx = d.vault.clawback(
{.issuer = d.issuer,
.id = d.keylet.key,
.holder = d.depositor,
.amount = STAmount(d.asset, Number(10, 0))});
env(tx, ter{tecPRECISION_LOSS});
env.close();
}
});
testCase(14, [&, this](Env& env, Data d) {
testcase("MPT Scale clawback overflow");
{
auto tx = d.vault.deposit(
{.depositor = d.depositor,