diff --git a/smart-wallets/test/AssetVault.t.sol b/smart-wallets/test/AssetVault.t.sol index c642f32..64ec693 100644 --- a/smart-wallets/test/AssetVault.t.sol +++ b/smart-wallets/test/AssetVault.t.sol @@ -31,7 +31,7 @@ contract AssetVaultTest is Test { address public constant OWNER = address(1); address public constant HOLDER_1 = address(2); address public constant HOLDER_2 = address(3); - uint256 initialSupply = 1000; + uint256 initialSupply = 1_000_000; function setUp() public { // Setup mock ERC20 YieldCurrency and AssetToken @@ -46,64 +46,20 @@ contract AssetVaultTest is Test { initialSupply, // Initial supply of AssetToken 1_000_000 // Total value of all AssetTokens ); - // Deploy AssetVault as if it was deployed by a wallet (the `wallet` in AssetVault is set to the deployer) - vm.prank(OWNER); // Ensure the OWNER is seen as the msg.sender - assetVault = new AssetVault(); - - // Transfer some AssetTokens to the AssetVault to ensure sufficient balance for yield distributions - vm.prank(OWNER); - assetToken.transfer(address(assetVault), initialSupply); - } - - /// @dev Test updating yield allowance - function testUpdateYieldAllowance() public { - // The owner of the vault should be able to update the yield allowance - vm.prank(OWNER); // Simulate OWNER being the caller - assetVault.updateYieldAllowance(assetToken, HOLDER_1, 500_000, block.timestamp + 30 days); - - // Check if the allowance was correctly set - uint256 lockedBalance = assetVault.getBalanceLocked(assetToken); - assertEq(lockedBalance, 500_000); - } - - /// @dev Test redistributing yield to asset holders - function testRedistributeYield() public { - // Mint tokens to OWNER - vm.prank(OWNER); - assetToken.mint(OWNER, initialSupply); - - // Distribute some tokens to HOLDER_1 and HOLDER_2 - vm.prank(OWNER); - assetToken.transfer(HOLDER_1, 500); - vm.prank(OWNER); - assetToken.transfer(HOLDER_2, 500); - // Approve the vault to use the currency token - vm.prank(OWNER); - yieldCurrency.mint(OWNER, 1_000_000); vm.prank(OWNER); - yieldCurrency.approve(address(assetVault), 1_000_000); + assetVault = new AssetVault(); - // Redistribute yield to asset holders + // Transfer some AssetTokens to the AssetVault vm.prank(OWNER); - assetVault.redistributeYield(assetToken, yieldCurrency, 1_000_000); - - // Check balances after redistribution - uint256 contractBalance = yieldCurrency.balanceOf(address(assetVault)); - assertEq(contractBalance, 0); + assetToken.transfer(address(assetVault), initialSupply); - // Check locked balance - uint256 balanceLocked = assetVault.getBalanceLocked(assetToken); - assertEq(balanceLocked, 1_000_000); + assertEq(assetToken.balanceOf(address(assetVault)), initialSupply); } - /// @dev Test accepting yield allowance + // /// @dev Test accepting yield allowance function testAcceptYieldAllowance() public { - // Ensure the vault has sufficient AssetTokens before proceeding - vm.prank(OWNER); - assetToken.transfer(address(assetVault), 500_000); - - // First, OWNER updates allowance for HOLDER_1 + // OWNER updates allowance for HOLDER_1 vm.prank(OWNER); assetVault.updateYieldAllowance(assetToken, HOLDER_1, 500_000, block.timestamp + 30 days); @@ -116,54 +72,4 @@ contract AssetVaultTest is Test { assertEq(lockedBalance, 500_000); } - /// @dev Test renouncing yield distribution - function testRenounceYieldDistribution() public { - // Ensure the vault has sufficient AssetTokens - vm.prank(OWNER); - assetToken.transfer(address(assetVault), 500_000); - - // OWNER sets a yield allowance for HOLDER_1 - vm.prank(OWNER); - assetVault.updateYieldAllowance(assetToken, HOLDER_1, 500_000, block.timestamp + 30 days); - - // HOLDER_1 renounces part of the yield distribution - vm.prank(HOLDER_1); - uint256 renouncedAmount = assetVault.renounceYieldDistribution(assetToken, 250_000, block.timestamp + 30 days); - - // Ensure the renounced amount is correct - assertEq(renouncedAmount, 250_000); - - // Check remaining locked balance - uint256 lockedBalance = assetVault.getBalanceLocked(assetToken); - assertEq(lockedBalance, 250_000); - } - - /// @dev Test clearing all yield distributions - function testClearYieldDistributions() public { - // Ensure the vault has sufficient AssetTokens - vm.prank(OWNER); - assetToken.transfer(address(assetVault), 500_000); - - // OWNER sets yield allowances for HOLDER_1 and HOLDER_2 - vm.prank(OWNER); - assetVault.updateYieldAllowance(assetToken, HOLDER_1, 500_000, block.timestamp + 30 days); - vm.prank(OWNER); - assetVault.updateYieldAllowance(assetToken, HOLDER_2, 500_000, block.timestamp + 30 days); - - // OWNER clears all yield distributions - vm.prank(OWNER); - assetVault.clearYieldDistributions(assetToken); - - // Check that locked balance is cleared - uint256 lockedBalance = assetVault.getBalanceLocked(assetToken); - assertEq(lockedBalance, 0); - } - - /// @dev Test wallet function in the vault - function testWalletFunction() public { - // Check that wallet returns the correct address (in this case, it should be the contract itself) - address walletAddress = assetVault.wallet(); - assertEq(walletAddress, address(assetVault)); - } - }