Skip to content
Prev Previous commit
Next Next commit
add test checks if channel upgrade should be failed with non-upgradab…
…le module

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jul 13, 2024
commit d69d2fa4264770d59b94551e11adaaa2df8f5d1e
35 changes: 18 additions & 17 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3259769)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3279145)
TestICS04Packet:testSendPacket() (gas: 6411842)
TestICS04Packet:testTimeoutOnClose() (gas: 3553375)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46748229)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3458747)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5265544)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5236422)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4434725)
TestICS04Upgrade:testUpgradeFull() (gas: 57839435)
TestICS04Upgrade:testUpgradeInit() (gas: 3071641)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2473015)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3905160)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5237309)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5610518)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4071379)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17708504)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21339547)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 71049506)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56508434)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45112783)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46749129)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3458822)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5265619)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5236497)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4434800)
TestICS04Upgrade:testUpgradeFull() (gas: 57839510)
TestICS04Upgrade:testUpgradeInit() (gas: 3071716)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2473090)
TestICS04Upgrade:testUpgradeNotUpgradableModule() (gas: 3646785)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3905235)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5237384)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5610593)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4071454)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17708579)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21339622)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 71050773)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56509184)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45113383)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61690)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565379)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2473938)
Expand Down
33 changes: 28 additions & 5 deletions tests/foundry/src/ICS04Upgrade.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import {LocalhostClientLib} from "../../../contracts/clients/09-localhost/Localh
import {LocalhostHelper} from "../../../contracts/clients/09-localhost/LocalhostHelper.sol";
import {IIBCChannelRecvPacket, IIBCChannelAcknowledgePacket} from "../../../contracts/core/04-channel/IIBCChannel.sol";
import {IIBCChannelUpgradeBase} from "../../../contracts/core/04-channel/IIBCChannelUpgrade.sol";
import {IIBCHostErrors} from "../../../contracts/core/24-host/IIBCHostErrors.sol";
import {TestIBCChannelUpgradableMockApp} from "./helpers/TestIBCChannelUpgradableMockApp.t.sol";
import {ICS04UpgradeTestHelper} from "./helpers/ICS04UpgradeTestHelper.t.sol";
import {ICS04PacketEventTestHelper} from "./helpers/ICS04PacketTestHelper.t.sol";
import {IBCMockLib} from "../../../contracts/apps/mock/IBCMockLib.sol";
import {IBCMockApp} from "../../../contracts/apps/mock/IBCMockApp.sol";

contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper {
using LocalhostHelper for TestableIBCHandler;
Expand Down Expand Up @@ -110,6 +112,20 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
}
}

function testUpgradeNotUpgradableModule() public {
string memory portId = "not-upgradable";
IIBCModule notUpgradableApp = new IBCMockApp(ibcHandler);
ibcHandler.bindPort(portId, notUpgradableApp);
(ChannelInfo memory channel0,) = createMockAppLocalhostChannel(Channel.Order.ORDER_UNORDERED, portId, MOCK_APP_VERSION_1);
IIBCChannelUpgradeBase.MsgChannelUpgradeInit memory msg_ = IIBCChannelUpgradeBase.MsgChannelUpgradeInit({
portId: channel0.portId,
channelId: channel0.channelId,
proposedUpgradeFields: mockApp.getUpgradeProposal(channel0.portId, channel0.channelId).fields
});
vm.expectRevert(abi.encodeWithSelector(IIBCHostErrors.IBCHostModuleDoesNotSupportIIBCModuleUpgrade.selector, address(notUpgradableApp)));
ibcHandler.channelUpgradeInit(msg_);
}

function testUpgradeOutOfSync() public {
(ChannelInfo memory channel0, ChannelInfo memory channel1) =
createMockAppLocalhostChannel(Channel.Order.ORDER_ORDERED);
Expand Down Expand Up @@ -1556,21 +1572,28 @@ contract TestICS04Upgrade is ICS04UpgradeTestHelper, ICS04PacketEventTestHelper
function createMockAppLocalhostChannel(Channel.Order ordering)
internal
returns (ChannelInfo memory, ChannelInfo memory)
{
return createMockAppLocalhostChannel(ordering, MOCK_APP_PORT, MOCK_APP_VERSION_1);
}

function createMockAppLocalhostChannel(Channel.Order ordering, string memory port, string memory version)
internal
returns (ChannelInfo memory, ChannelInfo memory)
{
(string memory connectionId0, string memory connectionId1) = ibcHandler.createLocalhostConnection();
(string memory channelId0, string memory channelId1) = ibcHandler.createLocalhostChannel(
LocalhostHelper.MsgCreateChannel({
connectionId0: connectionId0,
connectionId1: connectionId1,
portId0: MOCK_APP_PORT,
portId1: MOCK_APP_PORT,
portId0: port,
portId1: port,
ordering: ordering,
version: MOCK_APP_VERSION_1
version: version
})
);
return (
ChannelInfo({connectionId: connectionId0, portId: MOCK_APP_PORT, channelId: channelId0}),
ChannelInfo({connectionId: connectionId1, portId: MOCK_APP_PORT, channelId: channelId1})
ChannelInfo({connectionId: connectionId0, portId: port, channelId: channelId0}),
ChannelInfo({connectionId: connectionId1, portId: port, channelId: channelId1})
);
}

Expand Down