From 8fc7bab618a78fbd10522c9be41d017de2b734b2 Mon Sep 17 00:00:00 2001 From: "A.L." Date: Wed, 11 Dec 2024 12:30:50 +0800 Subject: [PATCH] test: add case for clearing out second slot when replacing by a shorter route --- test/unit/ReservoirPriceOracle.t.sol | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/test/unit/ReservoirPriceOracle.t.sol b/test/unit/ReservoirPriceOracle.t.sol index 2ebd095..121ebf9 100644 --- a/test/unit/ReservoirPriceOracle.t.sol +++ b/test/unit/ReservoirPriceOracle.t.sol @@ -861,6 +861,36 @@ contract ReservoirPriceOracleTest is BaseTest { assertEq(_oracle.route(address(_tokenA), address(_tokenB)).length, 3); } + function testSetRoute_2ndSlotClearedWhenReplacing3HopByShorterRoute() external { + // arrange - set A-D-B-C + address[] memory lRoute = new address[](4); + address lStart = address(_tokenA); + address lIntermediate1 = address(_tokenD); + address lIntermediate2 = address(_tokenB); + address lEnd = address(_tokenC); + lRoute[0] = lStart; + lRoute[1] = lIntermediate1; + lRoute[2] = lIntermediate2; + lRoute[3] = lEnd; + uint64[] memory lRewardThreshold = new uint64[](3); + lRewardThreshold[0] = lRewardThreshold[1] = lRewardThreshold[2] = Constants.WAD; + + _oracle.setRoute(lStart, lEnd, lRoute, lRewardThreshold); + + // act - replace it by A-C + address[] memory lNewRoute = new address[](2); + lNewRoute[0] = address(_tokenA); + lNewRoute[1] = address(_tokenC); + uint64[] memory lNewRewardThreshold = new uint64[](1); + lNewRewardThreshold[0] = Constants.WAD; + _oracle.setRoute(address(_tokenA), address(_tokenC), lNewRoute, lNewRewardThreshold); + + // assert + bytes32 lSecondSlot = bytes32(uint256(Utils.calculateSlot(address(_tokenA), address(_tokenC))) + 1); + bytes32 secondSlotValue = vm.load(address(_oracle), lSecondSlot); + assertEq(secondSlotValue, 0); + } + function testClearRoute() external { // arrange address lToken0 = address(_tokenB);