Skip to content

Commit

Permalink
use dummy client instead of mocking proofs
Browse files Browse the repository at this point in the history
  • Loading branch information
RnkSngh committed May 6, 2024
1 parent ece0684 commit 91d32e4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
27 changes: 0 additions & 27 deletions test/upgradeableProxy/Dispatcher.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 12 additions & 16 deletions test/upgradeableProxy/DispatcherRC4.upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -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(
Expand All @@ -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);

Expand All @@ -165,28 +166,23 @@ 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);
}

// Test that packet sending can be finished even if done during an upgade
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

Expand All @@ -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);
Expand Down

0 comments on commit 91d32e4

Please sign in to comment.