From 8012b65fd1448c6258a9bda20ce3202fe6c743fc Mon Sep 17 00:00:00 2001 From: Schlagonia Date: Mon, 17 Jun 2024 14:42:04 -0600 Subject: [PATCH] test: deposited --- src/L1YearnEscrow.sol | 2 +- test/L1Escrow.t.sol | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/L1YearnEscrow.sol b/src/L1YearnEscrow.sol index 884ce7a..d72a21b 100644 --- a/src/L1YearnEscrow.sol +++ b/src/L1YearnEscrow.sol @@ -192,7 +192,7 @@ contract L1YearnEscrow is L1Escrow { // Send an equivalent amount of shares for the difference. uint256 shares; unchecked { - _vault.convertToShares(amount - maxWithdraw); + shares = _vault.convertToShares(amount - maxWithdraw); } _vault.transfer(destinationAddress, shares); diff --git a/test/L1Escrow.t.sol b/test/L1Escrow.t.sol index e302e1b..2aad7c4 100644 --- a/test/L1Escrow.t.sol +++ b/test/L1Escrow.t.sol @@ -106,6 +106,7 @@ contract EscrowTest is Setup { mockEscrow.bridgeToken(user, _amount, true); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -136,6 +137,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(vault.totalAssets(), _amount - toWithdraw); + assertEq(mockEscrow.deposited(), _amount - toWithdraw); assertEq(asset.balanceOf(user), toWithdraw); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount - toWithdraw); @@ -146,6 +148,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(vault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), 0); @@ -185,6 +188,7 @@ contract EscrowTest is Setup { mockEscrow.bridgeToken(user, _amount, true); assertEq(vault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), _amount); assertEq(vault.balanceOf(address(mockEscrow)), 0); @@ -201,6 +205,7 @@ contract EscrowTest is Setup { mockEscrow.bridgeToken(user, _amount, true); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount * 2); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), _amount); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -214,6 +219,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(vault.totalAssets(), _amount - 10); + assertEq(mockEscrow.deposited(), _amount * 2 - toWithdraw); assertEq(asset.balanceOf(user), toWithdraw); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount - 10); @@ -247,6 +253,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), toDeposit); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), _amount - toDeposit); assertEq(vault.balanceOf(address(mockEscrow)), toDeposit); @@ -257,6 +264,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(vault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), 0); @@ -276,6 +284,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -288,6 +297,7 @@ contract EscrowTest is Setup { mockEscrow.rebalance(); assertEq(vault.totalAssets(), left); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), _amount - left); assertEq(vault.balanceOf(address(mockEscrow)), left); @@ -298,6 +308,7 @@ contract EscrowTest is Setup { mockEscrow.rebalance(); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -316,6 +327,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -330,6 +342,7 @@ contract EscrowTest is Setup { mockEscrow.updateVault(address(newVault)); assertEq(vault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), _amount); assertEq(vault.balanceOf(address(mockEscrow)), 0); assertEq(asset.allowance(address(mockEscrow), address(vault)), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); @@ -345,6 +358,7 @@ contract EscrowTest is Setup { assertEq(vault.totalAssets(), 0); assertEq(newVault.totalAssets(), _amount * 2); + assertEq(mockEscrow.deposited(), _amount * 2); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), 0); @@ -356,6 +370,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(newVault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount * 2); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(newVault.balanceOf(address(mockEscrow)), 0); @@ -374,6 +389,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -390,6 +406,7 @@ contract EscrowTest is Setup { mockEscrow.withdraw(czar, _amount); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(vault.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(czar), _amount); assertEq(asset.balanceOf(address(mockEscrow)), 0); @@ -404,6 +421,7 @@ contract EscrowTest is Setup { mockEscrow.onMessageReceived(counterPart, l2RollupID, data); assertEq(vault.totalAssets(), 0); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), 0); @@ -422,6 +440,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), _amount); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), 0); assertEq(vault.balanceOf(address(mockEscrow)), _amount); @@ -443,6 +462,7 @@ contract EscrowTest is Setup { // Should have sent the liquid balance and the rest in shares assertEq(vault.totalAssets(), toLock); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount - toLock); assertEq(vault.balanceOf(user), toLock); assertEq(asset.balanceOf(address(mockEscrow)), 0); @@ -469,6 +489,7 @@ contract EscrowTest is Setup { mintAndBridge(mockEscrow, user, _amount); assertEq(vault.totalAssets(), _amount - _minimumBuffer); + assertEq(mockEscrow.deposited(), _amount); assertEq(asset.balanceOf(user), 0); assertEq(asset.balanceOf(address(mockEscrow)), _minimumBuffer); assertEq( @@ -496,6 +517,7 @@ contract EscrowTest is Setup { // Should have sent the liquid balance and the rest in shares assertEq(vault.totalAssets(), toLock); + assertEq(mockEscrow.deposited(), 0); assertEq(asset.balanceOf(user), _amount - toLock); assertEq(vault.balanceOf(user), toLock); assertEq(asset.balanceOf(address(mockEscrow)), 0);