This commit is contained in:
John Freeman
2024-11-13 15:19:30 -06:00
committed by Bronek Kozicki
parent 6046fa239c
commit 12552162c9
2 changed files with 22 additions and 4 deletions

View File

@@ -362,8 +362,27 @@ class Vault_test : public beast::unit_test::suite
env.close();
}
}
{
// Withdraw non-zero assets.
auto tx = vault.withdraw(
{.depositor = depositor,
.id = keylet.key,
.amount = asset(100)});
env(tx);
env.close();
}
{
// TODO: get asset of share.
// Redeem non-zero shares.
auto tx = vault.withdraw(
{.depositor = depositor,
.id = keylet.key,
.amount = asset(1000)});
env(tx, ter(tecINSUFFICIENT_FUNDS));
env.close();
}
}
}
public:

View File

@@ -96,13 +96,12 @@ VaultWithdraw::doApply()
// The vault must have enough assets on hand.
// The vault may hold assets that it has already pledged.
// That is why we look at AssetAvailable instead of the account balance.
// TODO: Invariant: vault.AssetAvailable <= vault.Account.balance(vault.Asset)
// TODO: Invariant: vault.AssetAvailable <=
// vault.Account.balance(vault.Asset)
if (*vault->at(sfAssetAvailable) < assets)
return tecINSUFFICIENT_FUNDS;
std::cerr << "total before: " << *vault->at(sfAssetTotal) << std::endl;
vault->at(sfAssetTotal) -= assets;
std::cerr << "total after: " << *vault->at(sfAssetTotal) << std::endl;
vault->at(sfAssetAvailable) -= assets;
auto const& vaultAccount = vault->at(sfAccount);