Skip to content

Commit 13d6bfc

Browse files
committed
refactor: rename test contracts and expose functions for better clarity
1 parent d90e8de commit 13d6bfc

File tree

4 files changed

+57
-60
lines changed

4 files changed

+57
-60
lines changed

test/CrossSimpleModule.t.sol

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ contract DummyModule is IContractModule {
2727
}
2828
}
2929

30-
contract TestableCrossSimpleModule is CrossSimpleModule {
30+
contract CrossSimpleModuleHarness is CrossSimpleModule {
3131
constructor(IIBCHandler h, IContractModule m, bool debugMode) CrossSimpleModule(h, m, debugMode) {}
3232

33-
function extGetModule(Packet calldata p) external returns (IContractModule) {
33+
function exposed_getModule(Packet calldata p) external returns (IContractModule) {
3434
return getModule(p);
3535
}
3636

37-
function extRegisterModule(IContractModule m) external {
37+
function exposed_registerModule(IContractModule m) external {
3838
registerModule(m);
3939
}
4040

41-
function hasIbcRole(address a) external view returns (bool) {
41+
function workaround_hasIbcRole(address a) external view returns (bool) {
4242
return hasRole(IBC_ROLE, a);
4343
}
4444
}
@@ -54,41 +54,42 @@ contract CrossSimpleModuleTest is Test {
5454
}
5555

5656
function test_Constructor_RegistersModule_And_GetReturnsSameAddress() public {
57-
TestableCrossSimpleModule mod =
58-
new TestableCrossSimpleModule(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
57+
CrossSimpleModuleHarness harness =
58+
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
5959

60-
IContractModule got = mod.extGetModule(_emptyPacket);
60+
IContractModule got = harness.exposed_getModule(_emptyPacket);
6161
assertEq(address(got), address(moduleImpl), "must register");
6262
}
6363

6464
function test_Constructor_GrantsIbcRole_WhenDebugModeTrue() public {
65-
TestableCrossSimpleModule mod =
66-
new TestableCrossSimpleModule(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), true);
65+
CrossSimpleModuleHarness harness =
66+
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), true);
6767

68-
assertTrue(mod.hasIbcRole(address(this)), "role on debug");
68+
assertTrue(harness.workaround_hasIbcRole(address(this)), "role on debug");
6969
}
7070

7171
function test_Constructor_DoesNotGrantIbcRole_WhenDebugModeFalse() public {
72-
TestableCrossSimpleModule mod =
73-
new TestableCrossSimpleModule(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
72+
CrossSimpleModuleHarness harness =
73+
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
7474

75-
assertFalse(mod.hasIbcRole(address(this)), "no role on debug");
75+
assertFalse(harness.workaround_hasIbcRole(address(this)), "no role on debug");
7676
}
7777

7878
function test_Register_Reverts_OnSecondInitialization() public {
79-
TestableCrossSimpleModule mod =
80-
new TestableCrossSimpleModule(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
79+
CrossSimpleModuleHarness harness =
80+
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
8181

8282
vm.expectRevert(SimpleContractRegistry.ModuleAlreadyInitialized.selector);
83-
mod.extRegisterModule(IContractModule(address(moduleImpl)));
83+
harness.exposed_registerModule(IContractModule(address(moduleImpl)));
8484
}
8585

8686
function test_GetPacketAcknowledgementCall_Smoke_DifferentStatusesProduceDifferentBytes() public {
87-
TestableCrossSimpleModule mod =
88-
new TestableCrossSimpleModule(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
87+
CrossSimpleModuleHarness harness =
88+
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
8989

90-
bytes memory a = mod.getPacketAcknowledgementCall(PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_OK);
91-
bytes memory b = mod.getPacketAcknowledgementCall(PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_FAILED);
90+
bytes memory a = harness.getPacketAcknowledgementCall(PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_OK);
91+
bytes memory b =
92+
harness.getPacketAcknowledgementCall(PacketAcknowledgementCall.CommitStatus.COMMIT_STATUS_FAILED);
9293

9394
assertGt(a.length, 0, "ack nonempty");
9495
assertGt(b.length, 0, "ack nonempty");

test/IBCKeeper.t.sol

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,30 @@ import "../src/core/IBCKeeper.sol";
77

88
contract DummyHandler {}
99

10-
contract TestableIBCKeeper is IBCKeeper {
10+
contract IBCKeeperHarness is IBCKeeper {
1111
constructor(IIBCHandler h) IBCKeeper(h) {}
1212

13-
function handlerAddr() external view returns (address) {
13+
function exposed_getIBCHandler() external view returns (address) {
1414
return address(getIBCHandler());
1515
}
1616
}
1717

1818
contract IBCKeeperTest is Test {
1919
DummyHandler private dummy;
20-
TestableIBCKeeper private keeper;
20+
IBCKeeperHarness private keeper;
2121

2222
function setUp() public {
2323
dummy = new DummyHandler();
24-
keeper = new TestableIBCKeeper(IIBCHandler(address(dummy)));
24+
keeper = new IBCKeeperHarness(IIBCHandler(address(dummy)));
2525
}
2626

2727
function test_GetIBCHandler_GetIBCHandlerReturnsSameAddress() public view {
28-
address h = keeper.handlerAddr();
28+
address h = keeper.exposed_getIBCHandler();
2929
assertEq(h, address(dummy));
3030
}
3131

3232
function test_Constructor_AllowsZeroAddress() public {
33-
TestableIBCKeeper k = new TestableIBCKeeper(IIBCHandler(address(0)));
34-
assertEq(k.handlerAddr(), address(0));
33+
IBCKeeperHarness k = new IBCKeeperHarness(IIBCHandler(address(0)));
34+
assertEq(k.exposed_getIBCHandler(), address(0));
3535
}
3636
}

test/SimpleContractRegistry.t.sol

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,62 +23,62 @@ contract DummyModule is IContractModule {
2323
}
2424
}
2525

26-
contract TestableSimpleContractRegistry is SimpleContractRegistry {
27-
function register(IContractModule m) external {
26+
contract SimpleContractRegistryHarness is SimpleContractRegistry {
27+
function exposed_registerModule(IContractModule m) external {
2828
registerModule(m);
2929
}
3030

31-
function get(Packet calldata p) external returns (IContractModule) {
31+
function exposed_getModule(Packet calldata p) external returns (IContractModule) {
3232
return getModule(p);
3333
}
3434

35-
function moduleAddr() external view returns (address) {
35+
function workaround_moduleAddr() external view returns (address) {
3636
return address(contractModule);
3737
}
3838
}
3939

4040
contract SimpleContractRegistryTest is Test {
4141
DummyModule private dummy;
42-
TestableSimpleContractRegistry private registry;
42+
SimpleContractRegistryHarness private registry;
4343

4444
Packet internal _emptyPacket;
4545

4646
function setUp() public {
4747
dummy = new DummyModule();
48-
registry = new TestableSimpleContractRegistry();
48+
registry = new SimpleContractRegistryHarness();
4949
}
5050

5151
function test_Get_Reverts_WhenNotInitialized() public {
5252
vm.expectRevert(SimpleContractRegistry.ModuleNotInitialized.selector);
53-
registry.get(_emptyPacket);
53+
registry.exposed_getModule(_emptyPacket);
5454
}
5555

5656
function test_Register_Then_Get_ReturnsSameAddress() public {
5757
IContractModule m = IContractModule(address(dummy));
5858

59-
registry.register(m);
59+
registry.exposed_registerModule(m);
6060

61-
IContractModule got = registry.get(_emptyPacket);
61+
IContractModule got = registry.exposed_getModule(_emptyPacket);
6262
assertEq(address(got), address(m));
63-
assertEq(registry.moduleAddr(), address(m));
63+
assertEq(registry.workaround_moduleAddr(), address(m));
6464
}
6565

6666
function test_Register_Reverts_OnSecondInitialization() public {
6767
IContractModule m = IContractModule(address(dummy));
6868

69-
registry.register(m);
69+
registry.exposed_registerModule(m);
7070

7171
vm.expectRevert(SimpleContractRegistry.ModuleAlreadyInitialized.selector);
72-
registry.register(m);
72+
registry.exposed_registerModule(m);
7373
}
7474

7575
function testFuzz_Register_Then_Get_ReturnsSameAddress(address anyAddr) public {
7676
vm.assume(anyAddr != address(0));
7777
IContractModule m = IContractModule(anyAddr);
7878

79-
registry.register(m);
79+
registry.exposed_registerModule(m);
8080

81-
IContractModule got = registry.get(_emptyPacket);
81+
IContractModule got = registry.exposed_getModule(_emptyPacket);
8282
assertEq(address(got), anyAddr);
8383
}
8484
}

test/TxAtomicSimple.t.sol

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ contract RevertingModule is IContractModule {
5050
}
5151
}
5252

53-
contract TestableTxAtomicSimple is TxAtomicSimple {
53+
contract TxAtomicSimpleHarness is TxAtomicSimple {
5454
IContractModule internal _module;
5555

5656
constructor(IIBCHandler h) IBCKeeper(h) {}
@@ -69,38 +69,34 @@ contract TestableTxAtomicSimple is TxAtomicSimple {
6969
return _module;
7070
}
7171

72-
function extHandlePacket(Packet calldata p) external returns (bytes memory ack) {
72+
function exposed_handlePacket(Packet calldata p) external returns (bytes memory ack) {
7373
return handlePacket(p);
7474
}
7575

76-
function extHandleAcknowledgement(Packet calldata p, bytes calldata ackBytes) external {
76+
function exposed_handleAcknowledgement(Packet calldata p, bytes calldata ackBytes) external {
7777
handleAcknowledgement(p, ackBytes);
7878
}
7979

80-
function extHandleTimeout(Packet calldata p) external {
80+
function exposed_handleTimeout(Packet calldata p) external {
8181
handleTimeout(p);
8282
}
8383

84-
function setModule(IContractModule m) external {
84+
function workaround_setModule(IContractModule m) external {
8585
_module = m;
8686
}
8787
}
8888

89-
/// -------- Tests --------
90-
9189
contract TxAtomicSimpleTest is Test {
9290
DummyHandler private handler;
93-
TestableTxAtomicSimple private harness;
91+
TxAtomicSimpleHarness private harness;
9492

9593
event OnContractCall(bytes indexed txId, uint8 indexed txIndex, bool indexed success, bytes ret);
9694

9795
function setUp() public {
9896
handler = new DummyHandler();
99-
harness = new TestableTxAtomicSimple(IIBCHandler(address(handler)));
97+
harness = new TxAtomicSimpleHarness(IIBCHandler(address(handler)));
10098
}
10199

102-
/// ---- Helpers ----
103-
104100
function _mkPacketWithCall(bytes memory txId, bytes memory callInfo) internal pure returns (Packet memory p) {
105101
Any.Data memory emptyAny = Any.Data({type_url: "", value: ""});
106102
ReturnValue.Data memory emptyRet = ReturnValue.Data({value: ""});
@@ -141,7 +137,7 @@ contract TxAtomicSimpleTest is Test {
141137

142138
function test_handlePacket_Success_ReturnsOK_AndEmitsEvent() public {
143139
bytes memory ret = hex"010203";
144-
harness.setModule(new SuccessModule(ret));
140+
harness.workaround_setModule(new SuccessModule(ret));
145141

146142
bytes memory txId = hex"deadbeef";
147143
bytes memory callInfo = hex"c0ffee";
@@ -151,7 +147,7 @@ contract TxAtomicSimpleTest is Test {
151147
vm.expectEmit(true, true, true, true);
152148
emit OnContractCall(txId, 1, true, ret);
153149

154-
bytes memory ack = harness.extHandlePacket(packet);
150+
bytes memory ack = harness.exposed_handlePacket(packet);
155151

156152
assertEq(
157153
uint256(_decodeAckStatus(ack)),
@@ -161,7 +157,7 @@ contract TxAtomicSimpleTest is Test {
161157
}
162158

163159
function test_handlePacket_RevertInModule_ReturnsFAILED_AndEmitsEvent() public {
164-
harness.setModule(new RevertingModule());
160+
harness.workaround_setModule(new RevertingModule());
165161

166162
bytes memory txId = hex"bead";
167163
bytes memory callInfo = hex"00";
@@ -171,7 +167,7 @@ contract TxAtomicSimpleTest is Test {
171167
vm.expectEmit(true, true, true, true);
172168
emit OnContractCall(txId, 1, false, "");
173169

174-
bytes memory ack = harness.extHandlePacket(packet);
170+
bytes memory ack = harness.exposed_handlePacket(packet);
175171

176172
assertEq(
177173
uint256(_decodeAckStatus(ack)),
@@ -188,7 +184,7 @@ contract TxAtomicSimpleTest is Test {
188184
p.data = packetDataBytes;
189185

190186
vm.expectRevert(TxAtomicSimple.PayloadDecodeFailed.selector);
191-
harness.extHandlePacket(p);
187+
harness.exposed_handlePacket(p);
192188
}
193189

194190
function test_handlePacket_Reverts_WhenTypeURLUnexpected() public {
@@ -200,18 +196,18 @@ contract TxAtomicSimpleTest is Test {
200196
p.data = packetDataBytes;
201197

202198
vm.expectRevert(TxAtomicSimple.UnexpectedTypeURL.selector);
203-
harness.extHandlePacket(p);
199+
harness.exposed_handlePacket(p);
204200
}
205201

206202
function test_handleAcknowledgement_Reverts_NotImplemented() public {
207203
Packet memory p;
208204
vm.expectRevert(TxAtomicSimple.NotImplemented.selector);
209-
harness.extHandleAcknowledgement(p, hex"");
205+
harness.exposed_handleAcknowledgement(p, hex"");
210206
}
211207

212208
function test_handleTimeout_Reverts_NotImplemented() public {
213209
Packet memory p;
214210
vm.expectRevert(TxAtomicSimple.NotImplemented.selector);
215-
harness.extHandleTimeout(p);
211+
harness.exposed_handleTimeout(p);
216212
}
217213
}

0 commit comments

Comments
 (0)