Skip to content

Commit

Permalink
fix: update deposit4626 tests to use arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaraRingas committed Oct 25, 2024
1 parent 92f87b1 commit 8d17fde
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions test/unit/router-plus/SuperformRouterPlus.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
Expand All @@ -445,24 +447,32 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args with an invalid deposit selector
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: abi.encodeWithSelector(bytes4(keccak256("invalidDepositSelector()")), superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Expect the function to revert with INVALID_DEPOSIT_SELECTOR error
vm.expectRevert(ISuperformRouterPlus.INVALID_DEPOSIT_SELECTOR.selector);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

vm.stopPrank();
}



function test_deposit4626_multipleVaults() public {
// TODO
}

function test_rebalanceSinglePosition_zeroAddressInterimAsset() public {
vm.startPrank(deployer);

Expand Down Expand Up @@ -529,6 +539,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
Expand All @@ -538,27 +550,30 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount * 10, // Assuming a large value for revert
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});

argsArray[0] = args;
// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Execute deposit4626
vm.expectRevert(ISuperformRouterPlus.ASSETS_RECEIVED_OUT_OF_SLIPPAGE.selector);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);
}

function test_deposit4626_toleranceExceeded() public {
vm.startPrank(deployer);

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
Expand All @@ -576,21 +591,23 @@ contract SuperformRouterPlusTest is ProtocolActions {
);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Execute deposit4626
vm.recordLogs();
vm.expectRevert(ISuperformRouterPlus.TOLERANCE_EXCEEDED.selector);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

vm.stopPrank();
}
Expand All @@ -600,6 +617,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
Expand All @@ -617,21 +636,23 @@ contract SuperformRouterPlusTest is ProtocolActions {
);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount,
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Execute deposit4626
vm.recordLogs();
vm.expectRevert(ISuperformRouterPlus.TOLERANCE_EXCEEDED.selector);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

vm.stopPrank();
}
Expand All @@ -641,6 +662,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18 - 2 wei;
Expand All @@ -650,20 +673,22 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount, // Assuming 1:1 ratio for simplicity
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Execute deposit4626
vm.recordLogs();
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

// Verify the results
assertGt(
Expand Down Expand Up @@ -2520,6 +2545,8 @@ contract SuperformRouterPlusTest is ProtocolActions {

// Deploy a mock ERC4626 vault
VaultMock mockVault = new VaultMock(IERC20(getContract(SOURCE_CHAIN, "DAI")), "Mock Vault", "mVLT");
address[] calldata vaults = new address[](1);
vaults[0] = address(mockVault);

// Mint some DAI to the deployer
uint256 daiAmount = 1e18;
Expand All @@ -2529,20 +2556,22 @@ contract SuperformRouterPlusTest is ProtocolActions {
uint256 vaultTokenAmount = mockVault.deposit(daiAmount, deployer);

// Prepare deposit4626 args
Deposit4626Args[] calldata argsArray = new Deposit4626Args[](1);
ISuperformRouterPlus.Deposit4626Args memory args = ISuperformRouterPlus.Deposit4626Args({
amount: vaultTokenAmount,
expectedOutputAmount: daiAmount, // Assuming 1:1 ratio for simplicity
maxSlippage: 100, // 1%
receiverAddressSP: deployer,
depositCallData: _buildDepositCallData(superformId1, daiAmount)
});
argsArray[0] = args;

// Approve RouterPlus to spend vault tokens
mockVault.approve(ROUTER_PLUS_SOURCE, vaultTokenAmount);

// Execute deposit4626
vm.recordLogs();
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(address(mockVault), args);
SuperformRouterPlus(ROUTER_PLUS_SOURCE).deposit4626{ value: 1 ether }(vaults, argsArray);

// Verify the results
assertGt(
Expand Down

0 comments on commit 8d17fde

Please sign in to comment.