mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-05 16:57:56 +00:00
Compare commits
3 Commits
ximinez/le
...
vlntb/RIPD
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a913a791aa | ||
|
|
933447ce48 | ||
|
|
5fe00e32a3 |
@@ -5243,6 +5243,46 @@ class Vault_test : public beast::unit_test::suite
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
testFrozenWithdrawToIssuer()
|
||||
{
|
||||
using namespace test::jtx;
|
||||
|
||||
testcase("frozen IOU can be withdrawn to issuer");
|
||||
|
||||
Env env{*this, testable_amendments() | featureSingleAssetVault};
|
||||
Account issuer{"issuer"};
|
||||
Account owner{"owner"};
|
||||
Account depositor{"depositor"};
|
||||
env.fund(XRP(1000), issuer, owner, depositor);
|
||||
env.close();
|
||||
|
||||
PrettyAsset asset = issuer["IOU"];
|
||||
env.trust(asset(1000), owner);
|
||||
env.trust(asset(1000), depositor);
|
||||
env(pay(issuer, owner, asset(100)));
|
||||
env(pay(issuer, depositor, asset(200)));
|
||||
env.close();
|
||||
|
||||
Vault vault{env};
|
||||
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||
env(tx);
|
||||
env.close();
|
||||
|
||||
env(vault.deposit(
|
||||
{.depositor = depositor, .id = keylet.key, .amount = asset(50)}));
|
||||
env.close();
|
||||
|
||||
env(fset(issuer, asfGlobalFreeze));
|
||||
env.close();
|
||||
|
||||
auto withdraw = vault.withdraw(
|
||||
{.depositor = depositor, .id = keylet.key, .amount = asset(10)});
|
||||
withdraw[sfDestination] = issuer.human();
|
||||
env(withdraw, ter{tesSUCCESS});
|
||||
env.close();
|
||||
}
|
||||
|
||||
public:
|
||||
void
|
||||
run() override
|
||||
@@ -5261,6 +5301,7 @@ public:
|
||||
testScaleIOU();
|
||||
testRPC();
|
||||
testDelegate();
|
||||
testFrozenWithdrawToIssuer();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -80,13 +80,23 @@ VaultWithdraw::preclaim(PreclaimContext const& ctx)
|
||||
return ter;
|
||||
|
||||
// Cannot withdraw from a Vault an Asset frozen for the destination account
|
||||
if (auto const ret = checkFrozen(ctx.view, dstAcct, vaultAsset))
|
||||
return ret;
|
||||
if (!vaultAsset.holds<Issue>() ||
|
||||
(dstAcct != vaultAsset.getIssuer() &&
|
||||
account != vaultAsset.getIssuer()))
|
||||
{
|
||||
if (auto const ret = checkFrozen(ctx.view, dstAcct, vaultAsset))
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Cannot return shares to the vault, if the underlying asset was frozen for
|
||||
// the submitter
|
||||
if (auto const ret = checkFrozen(ctx.view, account, vaultShare))
|
||||
return ret;
|
||||
if (!vaultAsset.holds<Issue>() ||
|
||||
(dstAcct != vaultAsset.getIssuer() &&
|
||||
account != vaultAsset.getIssuer()))
|
||||
{
|
||||
if (auto const ret = checkFrozen(ctx.view, account, vaultShare))
|
||||
return ret;
|
||||
}
|
||||
|
||||
return tesSUCCESS;
|
||||
}
|
||||
@@ -115,6 +125,7 @@ VaultWithdraw::doApply()
|
||||
|
||||
auto const amount = ctx_.tx[sfAmount];
|
||||
Asset const vaultAsset = vault->at(sfAsset);
|
||||
auto const dstAcct = ctx_.tx[~sfDestination].value_or(account_);
|
||||
MPTIssue const share{mptIssuanceID};
|
||||
STAmount sharesRedeemed = {share};
|
||||
STAmount assetsWithdrawn;
|
||||
@@ -165,11 +176,21 @@ VaultWithdraw::doApply()
|
||||
return tecPATH_DRY;
|
||||
}
|
||||
|
||||
// When withdrawing IOU to the issuer, ignore freeze since spec allows
|
||||
// returning frozen IOU assets to their issuer. MPTs don't have this
|
||||
// exemption - MPT locks function like "deep freeze" with no issuer
|
||||
// exception.
|
||||
FreezeHandling const freezeHandling = (vaultAsset.holds<Issue>() &&
|
||||
(dstAcct == vaultAsset.getIssuer() ||
|
||||
account_ == vaultAsset.getIssuer()))
|
||||
? FreezeHandling::fhIGNORE_FREEZE
|
||||
: FreezeHandling::fhZERO_IF_FROZEN;
|
||||
|
||||
if (accountHolds(
|
||||
view(),
|
||||
account_,
|
||||
share,
|
||||
FreezeHandling::fhZERO_IF_FROZEN,
|
||||
freezeHandling,
|
||||
AuthHandling::ahIGNORE_AUTH,
|
||||
j_) < sharesRedeemed)
|
||||
{
|
||||
@@ -237,8 +258,6 @@ VaultWithdraw::doApply()
|
||||
// else quietly ignore, account balance is not zero
|
||||
}
|
||||
|
||||
auto const dstAcct = ctx_.tx[~sfDestination].value_or(account_);
|
||||
|
||||
return doWithdraw(
|
||||
view(),
|
||||
ctx_.tx,
|
||||
|
||||
Reference in New Issue
Block a user