mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
Improve checks in VaultWithdraw, more tests
This commit is contained in:
@@ -899,9 +899,14 @@ class Vault_test : public beast::unit_test::suite
|
||||
Vault vault{env};
|
||||
|
||||
MPTTester mptt{env, issuer, mptInitNoFund};
|
||||
mptt.create({.flags = tfMPTCanTransfer | tfMPTCanLock});
|
||||
mptt.create(
|
||||
{.flags = tfMPTCanTransfer | tfMPTCanLock | lsfMPTCanClawback |
|
||||
tfMPTRequireAuth});
|
||||
PrettyAsset asset = mptt.issuanceID();
|
||||
mptt.authorize({.account = owner});
|
||||
mptt.authorize({.account = issuer, .holder = owner});
|
||||
mptt.authorize({.account = depositor});
|
||||
mptt.authorize({.account = issuer, .holder = depositor});
|
||||
env(pay(issuer, depositor, asset(1000)));
|
||||
env.close();
|
||||
|
||||
@@ -978,6 +983,54 @@ class Vault_test : public beast::unit_test::suite
|
||||
tx[sfDestination] = issuer.human();
|
||||
env(tx, ter(tecFROZEN));
|
||||
});
|
||||
|
||||
testCase([this](
|
||||
Env& env,
|
||||
Account const& issuer,
|
||||
Account const& owner,
|
||||
Account const& depositor,
|
||||
Asset const& asset,
|
||||
Vault& vault,
|
||||
MPTTester& mptt) {
|
||||
testcase("MPT un-authorization blocks withdrawal");
|
||||
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||
env(tx);
|
||||
env.close();
|
||||
tx = vault.deposit(
|
||||
{.depositor = depositor,
|
||||
.id = keylet.key,
|
||||
.amount = asset(1000)});
|
||||
env(tx);
|
||||
env.close();
|
||||
|
||||
mptt.authorize(
|
||||
{.account = issuer,
|
||||
.holder = depositor,
|
||||
.flags = tfMPTUnauthorize});
|
||||
tx = vault.withdraw(
|
||||
{.depositor = depositor,
|
||||
.id = keylet.key,
|
||||
.amount = asset(100)});
|
||||
env(tx, ter(tecNO_AUTH));
|
||||
|
||||
// Withdrawal to other (authorized) accounts works
|
||||
tx[sfDestination] = issuer.human();
|
||||
env(tx);
|
||||
tx[sfDestination] = owner.human();
|
||||
env(tx);
|
||||
|
||||
// Clawback works
|
||||
tx = vault.clawback(
|
||||
{.issuer = issuer,
|
||||
.id = keylet.key,
|
||||
.holder = depositor,
|
||||
.amount = asset(800)});
|
||||
env(tx);
|
||||
|
||||
// Can delete empty vault
|
||||
tx = vault.del({.owner = owner, .id = keylet.key});
|
||||
env(tx);
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1235,10 +1288,25 @@ class Vault_test : public beast::unit_test::suite
|
||||
}
|
||||
|
||||
{
|
||||
testcase("IOU freeze");
|
||||
testcase("IOU deleted trust line, withdraw to 3rd party");
|
||||
env(trust(issuer, asset(0), owner, tfSetFreeze));
|
||||
|
||||
auto tx = vault.withdraw(
|
||||
{.depositor = owner, .id = keylet.key, .amount = asset(10)});
|
||||
env(tx, ter{tecFROZEN});
|
||||
|
||||
tx[sfDestination] = charlie.human();
|
||||
env(tx);
|
||||
env.close();
|
||||
|
||||
BEAST_EXPECT(env.balance(charlie, issue) == asset(30));
|
||||
}
|
||||
|
||||
{
|
||||
testcase("IOU global freeze");
|
||||
env(fset(issuer, asfGlobalFreeze));
|
||||
auto tx = vault.withdraw(
|
||||
{.depositor = owner, .id = keylet.key, .amount = asset(20)});
|
||||
{.depositor = owner, .id = keylet.key, .amount = asset(10)});
|
||||
env(tx, ter{tecFROZEN});
|
||||
|
||||
tx[sfDestination] = issuer.human();
|
||||
|
||||
@@ -99,14 +99,6 @@ VaultWithdraw::preclaim(PreclaimContext const& ctx)
|
||||
return tecNO_PERMISSION;
|
||||
}
|
||||
|
||||
if (auto const ter = std::visit(
|
||||
[&]<ValidIssueType TIss>(TIss const& issue) -> TER {
|
||||
return requireAuth(ctx.view, issue, dstAcct);
|
||||
},
|
||||
asset.value());
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
|
||||
if (assets.holds<MPTIssue>())
|
||||
{
|
||||
if (auto const ter = canTransfer(
|
||||
@@ -116,6 +108,14 @@ VaultWithdraw::preclaim(PreclaimContext const& ctx)
|
||||
}
|
||||
}
|
||||
|
||||
if (auto const ter = std::visit(
|
||||
[&]<ValidIssueType TIss>(TIss const& issue) -> TER {
|
||||
return requireAuth(ctx.view, issue, dstAcct);
|
||||
},
|
||||
asset.value());
|
||||
!isTesSuccess(ter))
|
||||
return ter;
|
||||
|
||||
// Cannot withdraw from a Vault an Asset frozen for the destination account
|
||||
if (isFrozen(ctx.view, dstAcct, asset))
|
||||
return tecFROZEN;
|
||||
|
||||
Reference in New Issue
Block a user