vault: fix transfer to self

This commit is contained in:
Mark Spanbroek 2025-02-05 14:04:46 +01:00
parent 523544a4e8
commit f6fb441dec
2 changed files with 9 additions and 5 deletions

View File

@ -126,15 +126,13 @@ abstract contract VaultBase {
require(lock.isLocked(), LockRequired());
Account memory sender = _getAccount(controller, fund, from);
Account memory receiver = _getAccount(controller, fund, to);
require(amount <= sender.balance.available, InsufficientBalance());
sender.balance.available -= amount;
receiver.balance.available += amount;
_checkAccountInvariant(sender, lock);
_accounts[controller][fund][from] = sender;
Account memory receiver = _getAccount(controller, fund, to);
receiver.balance.available += amount;
_accounts[controller][fund][to] = receiver;
}

View File

@ -292,6 +292,12 @@ describe("Vault", function () {
expect(await vault.getBalance(fund, address3)).to.equal(amount)
})
it("can transfer to self", async function () {
await setAutomine(true)
await vault.transfer(fund, address1, address1, amount)
expect(await vault.getBalance(fund, address1)).to.equal(amount);
})
it("does not transfer more than the balance", async function () {
await setAutomine(true)
await expect(