Skip to content

Commit e70f0d5

Browse files
committed
move IBCChannelUpgradableModule into apps/commons
Signed-off-by: Jun Kimura <jun.kimura@datachain.jp>
1 parent 9b5036a commit e70f0d5

File tree

5 files changed

+101
-98
lines changed

5 files changed

+101
-98
lines changed

tests/foundry/src/helpers/IBCChannelUpgradableModule.sol renamed to contracts/apps/commons/IBCChannelUpgradableModule.sol

Lines changed: 7 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {Channel, UpgradeFields, Timeout} from "../../../../contracts/proto/Channel.sol";
5-
import {IIBCHandler} from "../../../../contracts/core/25-handler/IIBCHandler.sol";
6-
import {IIBCModuleUpgrade} from "../../../../contracts/core/26-router/IIBCModuleUpgrade.sol";
7-
import {AppBase} from "../../../../contracts/apps/commons/IBCAppBase.sol";
8-
9-
interface IIBCChannelUpgradableModuleErrors {
10-
// ------------------- Errors ------------------- //
11-
12-
error IBCChannelUpgradableModuleUnauthorizedUpgrader();
13-
error IBCChannelUpgradableModuleInvalidTimeout();
14-
error IBCChannelUpgradableModuleInvalidConnectionHops();
15-
error IBCChannelUpgradableModuleUpgradeAlreadyExists();
16-
error IBCChannelUpgradableModuleUpgradeNotFound();
17-
error IBCChannelUpgradableModuleInvalidUpgrade();
18-
19-
error IBCChannelUpgradableModuleCannotRemoveInProgressUpgrade();
20-
/// @param state The current state of the channel
21-
error IBCChannelUpgradableModuleChannelNotFlushingState(Channel.State state);
22-
/// @param actual The actual upgrade sequence
23-
error IBCChannelUpgradableModuleSequenceMismatch(uint64 actual);
24-
25-
error IBCChannelUpgradableModuleChannelNotFound();
26-
error IBCChannelUpgradableModuleCannotOverwriteUpgrade();
27-
}
28-
29-
interface IIBCChannelUpgradableModule {
30-
// ------------------- Data Structures ------------------- //
31-
32-
/**
33-
* @dev Proposed upgrade fields
34-
* @param fields Upgrade fields
35-
* @param timeout Absolute timeout for the upgrade
36-
*/
37-
struct UpgradeProposal {
38-
UpgradeFields.Data fields;
39-
Timeout.Data timeout;
40-
}
41-
42-
/**
43-
* @dev Allowed transition for the channel upgrade
44-
* @param flushComplete Whether the upgrade is allowed to transition to the flush complete state
45-
*/
46-
struct AllowedTransition {
47-
bool flushComplete;
48-
}
49-
50-
// ------------------- Functions ------------------- //
51-
52-
/**
53-
* @dev Returns the proposed upgrade for the given port, channel, and sequence
54-
*/
55-
function getUpgradeProposal(string calldata portId, string calldata channelId)
56-
external
57-
view
58-
returns (UpgradeProposal memory);
59-
60-
/**
61-
* @dev Propose an upgrade for the given port, channel, and sequence
62-
* @notice This function is only callable by an authorized upgrader
63-
* The upgrader must call this function before calling `channelUpgradeInit` or `channelUpgradeTry` of the IBC handler
64-
*/
65-
function proposeUpgrade(
66-
string calldata portId,
67-
string calldata channelId,
68-
UpgradeFields.Data calldata upgradeFields,
69-
Timeout.Data calldata timeout
70-
) external;
71-
72-
/**
73-
* @dev Removes the proposed upgrade for the given port and channel
74-
* @notice This function is only callable by an authorized upgrader
75-
* @param portId Port identifier
76-
* @param channelId Channel identifier
77-
*/
78-
function removeUpgradeProposal(string calldata portId, string calldata channelId) external;
79-
80-
/**
81-
* @dev Allow the upgrade to transition to the flush complete state
82-
* @notice This function is only callable by an authorized upgrader
83-
* WARNING: Before calling this function, the upgrader must ensure that all inflight packets have been received on the receiving chain,
84-
* and all acknowledgements written have been acknowledged on the sending chain
85-
*/
86-
function allowTransitionToFlushComplete(string calldata portId, string calldata channelId, uint64 upgradeSequence)
87-
external;
88-
}
4+
import {Channel, UpgradeFields, Timeout} from "../../proto/Channel.sol";
5+
import {IIBCHandler} from "../../core/25-handler/IIBCHandler.sol";
6+
import {IIBCModuleUpgrade} from "../../core/26-router/IIBCModuleUpgrade.sol";
7+
import {AppBase} from "./IBCAppBase.sol";
8+
import {IIBCChannelUpgradableModule, IIBCChannelUpgradableModuleErrors} from "./IIBCChannelUpgradableModule.sol";
899

9010
abstract contract IBCChannelUpgradableModuleBase is
9111
AppBase,
@@ -312,10 +232,8 @@ abstract contract IBCChannelUpgradableModuleBase is
312232
* @dev See {IERC165-supportsInterface}
313233
*/
314234
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
315-
return
316-
super.supportsInterface(interfaceId) ||
317-
interfaceId == type(IIBCModuleUpgrade).interfaceId ||
318-
interfaceId == type(IIBCChannelUpgradableModule).interfaceId;
235+
return super.supportsInterface(interfaceId) || interfaceId == type(IIBCModuleUpgrade).interfaceId
236+
|| interfaceId == type(IIBCChannelUpgradableModule).interfaceId;
319237
}
320238

321239
// ------------------- Internal Functions ------------------- //
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.20;
3+
4+
import {Channel, UpgradeFields, Timeout} from "../../proto/Channel.sol";
5+
6+
interface IIBCChannelUpgradableModuleErrors {
7+
// ------------------- Errors ------------------- //
8+
9+
error IBCChannelUpgradableModuleUnauthorizedUpgrader();
10+
error IBCChannelUpgradableModuleInvalidTimeout();
11+
error IBCChannelUpgradableModuleInvalidConnectionHops();
12+
error IBCChannelUpgradableModuleUpgradeAlreadyExists();
13+
error IBCChannelUpgradableModuleUpgradeNotFound();
14+
error IBCChannelUpgradableModuleInvalidUpgrade();
15+
16+
error IBCChannelUpgradableModuleCannotRemoveInProgressUpgrade();
17+
/// @param state The current state of the channel
18+
error IBCChannelUpgradableModuleChannelNotFlushingState(Channel.State state);
19+
/// @param actual The actual upgrade sequence
20+
error IBCChannelUpgradableModuleSequenceMismatch(uint64 actual);
21+
22+
error IBCChannelUpgradableModuleChannelNotFound();
23+
error IBCChannelUpgradableModuleCannotOverwriteUpgrade();
24+
}
25+
26+
interface IIBCChannelUpgradableModule {
27+
// ------------------- Data Structures ------------------- //
28+
29+
/**
30+
* @dev Proposed upgrade fields
31+
* @param fields Upgrade fields
32+
* @param timeout Absolute timeout for the upgrade
33+
*/
34+
struct UpgradeProposal {
35+
UpgradeFields.Data fields;
36+
Timeout.Data timeout;
37+
}
38+
39+
/**
40+
* @dev Allowed transition for the channel upgrade
41+
* @param flushComplete Whether the upgrade is allowed to transition to the flush complete state
42+
*/
43+
struct AllowedTransition {
44+
bool flushComplete;
45+
}
46+
47+
// ------------------- Functions ------------------- //
48+
49+
/**
50+
* @dev Returns the proposed upgrade for the given port, channel, and sequence
51+
*/
52+
function getUpgradeProposal(string calldata portId, string calldata channelId)
53+
external
54+
view
55+
returns (UpgradeProposal memory);
56+
57+
/**
58+
* @dev Propose an upgrade for the given port, channel, and sequence
59+
* @notice This function is only callable by an authorized upgrader
60+
* The upgrader must call this function before calling `channelUpgradeInit` or `channelUpgradeTry` of the IBC handler
61+
*/
62+
function proposeUpgrade(
63+
string calldata portId,
64+
string calldata channelId,
65+
UpgradeFields.Data calldata upgradeFields,
66+
Timeout.Data calldata timeout
67+
) external;
68+
69+
/**
70+
* @dev Removes the proposed upgrade for the given port and channel
71+
* @notice This function is only callable by an authorized upgrader
72+
* @param portId Port identifier
73+
* @param channelId Channel identifier
74+
*/
75+
function removeUpgradeProposal(string calldata portId, string calldata channelId) external;
76+
77+
/**
78+
* @dev Allow the upgrade to transition to the flush complete state
79+
* @notice This function is only callable by an authorized upgrader
80+
* WARNING: Before calling this function, the upgrader must ensure that all inflight packets have been received on the receiving chain,
81+
* and all acknowledgements written have been acknowledged on the sending chain
82+
*/
83+
function allowTransitionToFlushComplete(string calldata portId, string calldata channelId, uint64 upgradeSequence)
84+
external;
85+
}

tests/foundry/src/ICS04Upgrade.t.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import {TestIBCChannelUpgradableMockApp} from "./helpers/TestIBCChannelUpgradabl
1414
import {TestIBCChannelUpgradableMockAppInconsistentVersions} from "./helpers/TestIBCChannelUpgradableMockAppInconsistentVersions.t.sol";
1515
import {ICS04UpgradeTestHelper} from "./helpers/ICS04UpgradeTestHelper.t.sol";
1616
import {ICS04PacketEventTestHelper} from "./helpers/ICS04PacketTestHelper.t.sol";
17-
import {IIBCChannelUpgradableModule} from "./helpers/IBCChannelUpgradableModule.sol";
17+
import {
18+
IIBCChannelUpgradableModule
19+
} from "../../../contracts/apps/commons/IBCChannelUpgradableModule.sol";
1820
import {IBCMockLib} from "../../../contracts/apps/mock/IBCMockLib.sol";
1921
import {IBCMockApp} from "../../../contracts/apps/mock/IBCMockApp.sol";
2022

tests/foundry/src/ICS04UpgradeApp.t.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ pragma solidity ^0.8.20;
33

44
import "./helpers/IBCTestHelper.t.sol";
55
import {Vm} from "forge-std/Test.sol";
6-
import {Upgrade, UpgradeFields, Timeout} from "../../../contracts/proto/Channel.sol";
7-
import {LocalhostClientLib} from "../../../contracts/clients/09-localhost/LocalhostClient.sol";
6+
import {UpgradeFields, Timeout} from "../../../contracts/proto/Channel.sol";
87
import {LocalhostHelper} from "../../../contracts/clients/09-localhost/LocalhostHelper.sol";
9-
import {IIBCChannelUpgrade} from "../../../contracts/core/04-channel/IIBCChannelUpgrade.sol";
10-
import {TestIBCChannelUpgradableMockApp} from "./helpers/TestIBCChannelUpgradableMockApp.t.sol";
118
import {
129
IIBCChannelUpgradableModule, IIBCChannelUpgradableModuleErrors
13-
} from "./helpers/IBCChannelUpgradableModule.sol";
10+
} from "../../../contracts/apps/commons/IBCChannelUpgradableModule.sol";
11+
import {TestIBCChannelUpgradableMockApp} from "./helpers/TestIBCChannelUpgradableMockApp.t.sol";
1412
import {ICS04UpgradeTestHelper} from "./helpers/ICS04UpgradeTestHelper.t.sol";
1513

1614
contract TestICS04UpgradeApp is ICS04UpgradeTestHelper {

tests/foundry/src/helpers/TestIBCChannelUpgradableMockApp.t.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.20;
33

4-
import {Upgrade, UpgradeFields, Timeout} from "../../../../contracts/proto/Channel.sol";
4+
import {UpgradeFields, Timeout} from "../../../../contracts/proto/Channel.sol";
55
import {
6-
IIBCChannelUpgrade, IIBCChannelUpgradeBase
6+
IIBCChannelUpgradeBase
77
} from "../../../../contracts/core/04-channel/IIBCChannelUpgrade.sol";
88
import {IIBCHandler} from "../../../../contracts/core/25-handler/IIBCHandler.sol";
99
import {IBCMockApp} from "../../../../contracts/apps/mock/IBCMockApp.sol";
10-
import {IBCChannelUpgradableModuleBase} from "./IBCChannelUpgradableModule.sol";
10+
import {IBCChannelUpgradableModuleBase} from "../../../../contracts/apps/commons/IBCChannelUpgradableModule.sol";
1111
import {IBCAppBase} from "../../../../contracts/apps/commons/IBCAppBase.sol";
1212

1313
contract TestIBCChannelUpgradableMockApp is IBCMockApp, IBCChannelUpgradableModuleBase {

0 commit comments

Comments
 (0)