From 2bccc942c070b4c9e39b784c3e23c660516a65eb Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Fri, 19 Jan 2024 09:48:24 +0000 Subject: [PATCH 1/3] test: csr --- src/crosschain-data/extensions/CoreStateRegistry.sol | 7 ++++--- .../crosschain-data/extensions/CoreStateRegistry.t.sol | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/crosschain-data/extensions/CoreStateRegistry.sol b/src/crosschain-data/extensions/CoreStateRegistry.sol index b8bb224ee..9ef74b201 100644 --- a/src/crosschain-data/extensions/CoreStateRegistry.sol +++ b/src/crosschain-data/extensions/CoreStateRegistry.sol @@ -789,9 +789,10 @@ contract CoreStateRegistry is BaseStateRegistry, ICoreStateRegistry { bool fulfilment; bool errors; for (uint256 i; i < numberOfVaults; ++i) { - /// @dev if updating the deposit payload fails because of slippage, multiVaultData.amounts[i] is set to 0 - /// @dev this means that this amount was already added to the failedDeposits state variable and should not - /// be re-added (or processed here) + /// @dev it is not possible in theory to have multiVaultData.amounts to be 0 at this point + /// @dev this is due to the fact that 0 values are moved in updateDeposit which must always run prior to + /// processing the payload + /// @dev this check is added here only for sanity purposes and full coverage of the line is not possible if (multiVaultData.amounts[i] != 0) { underlying = IERC20(_getVaultAsset(superforms[i])); diff --git a/test/unit/crosschain-data/extensions/CoreStateRegistry.t.sol b/test/unit/crosschain-data/extensions/CoreStateRegistry.t.sol index eb420e9b4..dca2961fd 100644 --- a/test/unit/crosschain-data/extensions/CoreStateRegistry.t.sol +++ b/test/unit/crosschain-data/extensions/CoreStateRegistry.t.sol @@ -99,6 +99,12 @@ contract CoreStateRegistryTest is ProtocolActions { vm.prank(deployer); vm.expectRevert(Error.BRIDGE_TOKENS_PENDING.selector); CoreStateRegistry(payable(getContract(AVAX, "CoreStateRegistry"))).processPayload{ value: nativeValue }(1); + + vm.prank(deployer); + MockERC20(getContract(AVAX, "DAI")).transfer(getContract(AVAX, "CoreStateRegistry"), 838); + + vm.prank(deployer); + CoreStateRegistry(payable(getContract(AVAX, "CoreStateRegistry"))).processPayload{ value: nativeValue }(1); } /// @dev this test ensures that if a superform update failed because of slippage in 2 of 4 vaults From 8c7b7bc6af33a19cb6b0cb7fbd58b29ff07ef700 Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:04:03 +0000 Subject: [PATCH 2/3] test: paymentHelper nits --- test/unit/payments/PaymentHelper.t.sol | 93 ++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/test/unit/payments/PaymentHelper.t.sol b/test/unit/payments/PaymentHelper.t.sol index f2180c03f..95c4ec8c6 100644 --- a/test/unit/payments/PaymentHelper.t.sol +++ b/test/unit/payments/PaymentHelper.t.sol @@ -303,6 +303,99 @@ contract PaymentHelperTest is ProtocolActions { assertGt(fees, 0); } + function test_estimateSingleXChainMultiVault_retain4626() public { + vm.prank(deployer); + SuperformFactory(getContract(ETH, "SuperformFactory")).changeFormImplementationPauseStatus( + 2, ISuperformFactory.PauseStatus(1), "" + ); + + uint8[] memory ambIds = new uint8[](1); + + ambIds[0] = 1; + ambIds[0] = 2; + + bytes memory emptyBytes; + uint256[] memory superFormIds = new uint256[](1); + superFormIds[0] = _generateTimelockSuperformPackWithShift(); + + uint256[] memory uint256MemoryArray = new uint256[](1); + uint256MemoryArray[0] = 420; + + LiqRequest[] memory liqRequestMemoryArray = new LiqRequest[](1); + liqRequestMemoryArray[0] = LiqRequest(emptyBytes, address(0), address(0), 1, ETH, 420); + bool[] memory retain4626 = new bool[](1); + + retain4626[0] = true; + + (,,, uint256 fees) = paymentHelper.estimateSingleXChainMultiVault( + SingleXChainMultiVaultStateReq( + ambIds, + ARBI, + MultiVaultSFData( + superFormIds, + /// timelock + uint256MemoryArray, + uint256MemoryArray, + uint256MemoryArray, + liqRequestMemoryArray, + emptyBytes, + new bool[](1), + retain4626, + receiverAddress, + receiverAddress, + emptyBytes + ) + ), + false + ); + assertGt(fees, 0); + } + + function test_estimateSingleXChainMultiVault_sameDst() public { + vm.prank(deployer); + SuperformFactory(getContract(ETH, "SuperformFactory")).changeFormImplementationPauseStatus( + 2, ISuperformFactory.PauseStatus(1), "" + ); + + uint8[] memory ambIds = new uint8[](1); + + ambIds[0] = 1; + ambIds[0] = 2; + + bytes memory emptyBytes; + uint256[] memory superFormIds = new uint256[](1); + superFormIds[0] = _generateTimelockSuperformPackWithShift(); + + uint256[] memory uint256MemoryArray = new uint256[](1); + uint256MemoryArray[0] = 420; + + LiqRequest[] memory liqRequestMemoryArray = new LiqRequest[](1); + liqRequestMemoryArray[0] = LiqRequest(emptyBytes, address(0), address(0), 1, ETH, 420); + + (,,, uint256 fees) = paymentHelper.estimateSingleXChainMultiVault( + SingleXChainMultiVaultStateReq( + ambIds, + ETH, + MultiVaultSFData( + superFormIds, + /// timelock + uint256MemoryArray, + uint256MemoryArray, + uint256MemoryArray, + liqRequestMemoryArray, + emptyBytes, + new bool[](1), + new bool[](1), + receiverAddress, + receiverAddress, + emptyBytes + ) + ), + false + ); + assertGt(fees, 0); + } + function test_estimateMultiDstSingleVault_formImplPaused() public { vm.prank(deployer); SuperformFactory(getContract(ETH, "SuperformFactory")).changeFormImplementationPauseStatus( From 0544685363687535f3706d6b494a9db4a652d37f Mon Sep 17 00:00:00 2001 From: Timepunk <45543880+0xTimepunk@users.noreply.github.com> Date: Fri, 19 Jan 2024 10:29:00 +0000 Subject: [PATCH 3/3] chore: cover 1 line --- test/unit/payments/PaymentHelper.t.sol | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/unit/payments/PaymentHelper.t.sol b/test/unit/payments/PaymentHelper.t.sol index 95c4ec8c6..1d28aea1c 100644 --- a/test/unit/payments/PaymentHelper.t.sol +++ b/test/unit/payments/PaymentHelper.t.sol @@ -304,11 +304,6 @@ contract PaymentHelperTest is ProtocolActions { } function test_estimateSingleXChainMultiVault_retain4626() public { - vm.prank(deployer); - SuperformFactory(getContract(ETH, "SuperformFactory")).changeFormImplementationPauseStatus( - 2, ISuperformFactory.PauseStatus(1), "" - ); - uint8[] memory ambIds = new uint8[](1); ambIds[0] = 1; @@ -351,12 +346,7 @@ contract PaymentHelperTest is ProtocolActions { assertGt(fees, 0); } - function test_estimateSingleXChainMultiVault_sameDst() public { - vm.prank(deployer); - SuperformFactory(getContract(ETH, "SuperformFactory")).changeFormImplementationPauseStatus( - 2, ISuperformFactory.PauseStatus(1), "" - ); - + function test_estimateSingleXChainMultiVault_sameDst_deposit() public { uint8[] memory ambIds = new uint8[](1); ambIds[0] = 1; @@ -391,7 +381,7 @@ contract PaymentHelperTest is ProtocolActions { emptyBytes ) ), - false + true ); assertGt(fees, 0); }