From 91d32e449e4bec49fba2356547b1c53b6e3cbc35 Mon Sep 17 00:00:00 2001 From: RnkSngh Date: Fri, 3 May 2024 14:19:20 -0400 Subject: [PATCH] use dummy client instead of mocking proofs --- .../upgradeableProxy/Dispatcher.upgrade.t.sol | 27 ------------------ .../DispatcherRC4.upgrade.t.sol | 28 ++++++++----------- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/test/upgradeableProxy/Dispatcher.upgrade.t.sol b/test/upgradeableProxy/Dispatcher.upgrade.t.sol index 74085e55..8b65133b 100644 --- a/test/upgradeableProxy/Dispatcher.upgrade.t.sol +++ b/test/upgradeableProxy/Dispatcher.upgrade.t.sol @@ -83,7 +83,6 @@ contract ChannelHandShakeUpgradeUtil is ChannelHandshakeUtils { string[2] memory versions = ["1.0", "2.0"]; for (uint256 i = 0; i < settings.length; i++) { for (uint256 j = 0; j < versions.length; j++) { - // mockHandShakeProofs(le, re, settings[i], versions[j]); le.versionCall = versions[j]; le.versionExpected = versions[j]; re.version = versions[j]; @@ -166,32 +165,6 @@ contract ChannelHandShakeUpgradeUtil is ChannelHandshakeUtils { bytes32 slot1 = keccak256(abi.encode(portAddress, nextSequenceRecvSlot)); slot = keccak256(abi.encode(channelId, slot1)); } - - function mockHandShakeProofs(LocalEnd memory _local, ChannelEnd memory _remote) public { - // Mock the proofs required to initialize a channel - mockProofs(ChannelState.TRY_PENDING, _remote.portId, _local.portId, _remote.channelId, _local.channelId); - mockProofs(ChannelState.ACK_PENDING, _local.portId, _remote.portId, _local.channelId, _remote.channelId); - mockProofs(ChannelState.CONFIRM_PENDING, _remote.portId, _local.portId, _remote.channelId, _local.channelId); - } - - function mockProofs( - ChannelState state, - string memory localPortId, - string memory cpPortId, - bytes32 localChannelId, - bytes32 cpChannelId - ) internal { - vm.mockCall( - address(opLightClient), - abi.encodeWithSelector( - OptimisticLightClient.verifyMembership.selector, - validProof, - Ibc.channelProofKey(localPortId, localChannelId), - Ibc.channelProofValue(state, ChannelOrder.ORDERED, "1.0", connectionHops, cpPortId, cpChannelId) - ), - "" - ); - } } contract DispatcherUpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeTestUtils { diff --git a/test/upgradeableProxy/DispatcherRC4.upgrade.t.sol b/test/upgradeableProxy/DispatcherRC4.upgrade.t.sol index 13cb14a8..656309a9 100644 --- a/test/upgradeableProxy/DispatcherRC4.upgrade.t.sol +++ b/test/upgradeableProxy/DispatcherRC4.upgrade.t.sol @@ -43,8 +43,10 @@ contract DispatcherRC4UpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeTestUti oldDummyDispatcherProxy = deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient); // Deploy op old dispatcher - opLightClient = new OptimisticLightClient(1, opProofVerifier, l1BlockProvider); - dispatcherProxy = deployDispatcherRC4ProxyAndImpl(portPrefix, opLightClient); + DummyLightClient dummyLightClient2 = new DummyLightClient(); // dummyLightClient2 models the op light client in + // prod - it will be the light client that is chosen for the upgrade (and the oldDummyDispatcherProxy will + // be deprecated) + dispatcherProxy = deployDispatcherRC4ProxyAndImpl(portPrefix, dummyLightClient2); // Set up dispatcher with non-trivial state mars = new Mars(dispatcherProxy); @@ -59,14 +61,13 @@ contract DispatcherRC4UpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeTestUti _remoteDummy = ChannelEnd(receivingPortId, "dummy-channel-2", "1.0"); // Add state to test if impacted by upgrade - mockHandShakeProofs(_local, _remote); doProofChannelHandshake(_local, _remote, receivingMars); sendPacket(_local.channelId); // Upgrade dispatcherProxy for tests upgradeDispatcher(portPrefix, address(dispatcherProxy)); - dispatcherProxy.setClientForConnection(connectionHops0[0], dummyLightClient); - dispatcherProxy.setClientForConnection(connectionHops1[0], opLightClient); + dispatcherProxy.setClientForConnection(connectionHops0[0], dummyLightClient2); + dispatcherProxy.setClientForConnection(connectionHops1[0], dummyLightClient2); } function test_SentPacketState_Conserved_RC4_Upgrade() public { @@ -117,12 +118,9 @@ contract DispatcherRC4UpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeTestUti LocalEnd memory _local2 = LocalEnd(mars2, portId2, "channel-1", connectionHops1, "1.0", "1.0"); ChannelHandshakeSetting memory setting = ChannelHandshakeSetting(ChannelOrder.ORDERED, false, false, validProof); - // should revert without loading proof, since we're using the proof client - vm.expectRevert(abi.encodeWithSelector(OptimisticLightClient.AppHashHasNotPassedFraudProofWindow.selector)); channelOpenTry(_local2, _remote, setting, false); // Another dapp should be able to initialize another channel and send a packet from the new channel - mockHandShakeProofs(_local2, _remote); doProofChannelHandshake(_local2, _remote, receivingMars); sendOnePacket(_local2.channelId, 1, mars2); assert( @@ -142,14 +140,17 @@ contract DispatcherRC4MidwayUpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeT ChannelEnd _le; string sendingPortId; string receivingPortId; + DummyLightClient dummyLightClient2; function setUp() public override { ChannelHandshakeSetting memory setting = ChannelHandshakeSetting(ChannelOrder.ORDERED, false, true, validProof); DispatcherRc4 oldOpDispatcherImplementation = new DispatcherRc4(); - bytes memory initData = abi.encodeWithSelector(DispatcherRc4.initialize.selector, portPrefix, opLightClient); + bytes memory initData = abi.encodeWithSelector(DispatcherRc4.initialize.selector, portPrefix, dummyLightClient); dispatcherProxy = IDispatcher(address(new ERC1967Proxy(address(oldOpDispatcherImplementation), initData))); + dummyLightClient2 = new DummyLightClient(); + mars = new Mars(dispatcherProxy); receivingMars = new Mars(dispatcherProxy); @@ -165,18 +166,15 @@ contract DispatcherRC4MidwayUpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeT // Do only half a handshake to test upgrading between handshakes channelOpenInit(_local, _remote, setting, true); - mockProofs(ChannelState.TRY_PENDING, _re.portId, _le.portId, _re.channelId, _le.channelId); channelOpenTry(_re, _le, setting, true); } // Test that channel handshake can be finished even if done during an upgrade function test_UpgradeBetween_ChannelOpen() public { upgradeDispatcher(portPrefix, address(dispatcherProxy)); - dispatcherProxy.setClientForConnection(connectionHops1[0], opLightClient); + dispatcherProxy.setClientForConnection(connectionHops1[0], dummyLightClient2); ChannelHandshakeSetting memory setting = ChannelHandshakeSetting(ChannelOrder.ORDERED, false, true, validProof); - mockProofs(ChannelState.ACK_PENDING, _le.portId, _re.portId, _le.channelId, _re.channelId); channelOpenAck(_local, _remote, setting, true); - mockProofs(ChannelState.CONFIRM_PENDING, _re.portId, _le.portId, _re.channelId, _le.channelId); channelOpenConfirm(_re, _le, setting, true); } @@ -184,9 +182,7 @@ contract DispatcherRC4MidwayUpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeT function test_UpgradeBetween_SentPacketState() public { // Finish up channel handshake so that we can send packet ChannelHandshakeSetting memory setting = ChannelHandshakeSetting(ChannelOrder.ORDERED, false, true, validProof); - mockProofs(ChannelState.ACK_PENDING, _le.portId, _re.portId, _le.channelId, _re.channelId); channelOpenAck(_local, _remote, setting, true); - mockProofs(ChannelState.CONFIRM_PENDING, _re.portId, _le.portId, _re.channelId, _le.channelId); channelOpenConfirm(_re, _le, setting, true); // Send packet before upgrade @@ -197,7 +193,7 @@ contract DispatcherRC4MidwayUpgradeTest is ChannelHandShakeUpgradeUtil, UpgradeT // Do upgrade before finishing packet handshake upgradeDispatcher(portPrefix, address(dispatcherProxy)); - dispatcherProxy.setClientForConnection(connectionHops1[0], dummyLightClient); + dispatcherProxy.setClientForConnection(connectionHops1[0], dummyLightClient2); // Now recv and ack packet IbcEndpoint memory src = IbcEndpoint(sendingPortId, _local.channelId);