Skip to content

Commit 51a84ae

Browse files
committed
refactor: standardize test function naming conventions for clarity
1 parent a6fd5fe commit 51a84ae

File tree

6 files changed

+65
-65
lines changed

6 files changed

+65
-65
lines changed

test/CrossModule.t.sol

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -70,60 +70,53 @@ contract CrossModuleTest is Test {
7070
mod = new TestableCrossModule(IIBCHandler(address(handler)));
7171
}
7272

73-
function test_Constructor_GrantsIbcRoleToHandler() public {
73+
function test_constructor_GrantsIbcRoleToHandler() public {
7474
assertTrue(mod.hasRole(mod.IBC_ROLE(), address(handler)));
7575
}
7676

77-
function test_SupportsInterface_IIBC_IAccessControl_And_Unsupported() public view {
77+
function test_supportsInterface_ReturnsTrueForIIBCAndIAccessControlAndFalseForUnsupported() public view {
7878
assertTrue(mod.supportsInterface(type(IIBCModule).interfaceId));
7979
assertTrue(mod.supportsInterface(type(IIBCModuleInitializer).interfaceId));
8080
assertTrue(mod.supportsInterface(type(IAccessControl).interfaceId));
8181
assertFalse(mod.supportsInterface(0xDEADBEEF));
8282
}
8383

84-
function test_onRecvPacket_Reverts_WithoutIbcRole() public {
85-
vm.expectRevert();
86-
mod.onRecvPacket(_emptyPacket, address(0));
87-
}
88-
89-
function test_onRecvPacket_CallsHandlerAndReturnsAck_WhenCallerHasRole() public {
84+
function test_onRecvPacket_CallsHandlerAndReturnsAckWhenCallerHasRole() public {
9085
vm.prank(address(handler));
9186
bytes memory ack = mod.onRecvPacket(_emptyPacket, address(0));
9287
assertEq(ack, bytes("ack-ok"));
9388
assertEq(mod.recvCount(), 1);
9489
}
9590

96-
function test_onAcknowledgementPacket_Reverts_WithoutIbcRole() public {
91+
function test_onRecvPacket_RevertWhen_CallerLacksIbcRole() public {
9792
vm.expectRevert();
98-
mod.onAcknowledgementPacket(_emptyPacket, bytes("ack"), address(0));
93+
mod.onRecvPacket(_emptyPacket, address(0));
9994
}
10095

101-
function test_onAcknowledgementPacket_CallsHandler_WhenCallerHasRole() public {
96+
function test_onAcknowledgementPacket_CallsHandlerWhenCallerHasRole() public {
10297
vm.prank(address(handler));
10398
mod.onAcknowledgementPacket(_emptyPacket, bytes("ack123"), address(0));
10499
assertEq(mod.ackCount(), 1);
105100
assertEq(mod.lastAckArg(), bytes("ack123"));
106101
}
107102

108-
function test_onTimeoutPacket_Reverts_WithoutIbcRole() public {
103+
function test_onAcknowledgementPacket_RevertWhen_CallerLacksIbcRole() public {
109104
vm.expectRevert();
110-
mod.onTimeoutPacket(_emptyPacket, address(0));
105+
mod.onAcknowledgementPacket(_emptyPacket, bytes("ack"), address(0));
111106
}
112107

113-
function test_onTimeoutPacket_CallsHandler_WhenCallerHasRole() public {
108+
function test_onTimeoutPacket_CallsHandlerWhenCallerHasRole() public {
114109
vm.prank(address(handler));
115110
mod.onTimeoutPacket(_emptyPacket, address(0));
116111
assertEq(mod.timeoutCount(), 1);
117112
}
118113

119-
function test_onChanOpenInit_Reverts_WithoutIbcRole() public {
120-
IIBCModuleInitializer.MsgOnChanOpenInit memory m;
121-
m.version = "v1";
114+
function test_onTimeoutPacket_RevertWhen_CallerLacksIbcRole() public {
122115
vm.expectRevert();
123-
mod.onChanOpenInit(m);
116+
mod.onTimeoutPacket(_emptyPacket, address(0));
124117
}
125118

126-
function test_onChanOpenInit_ReturnsSelfAndVersion_WhenCallerHasRole() public {
119+
function test_onChanOpenInit_ReturnsSelfAndVersionWhenCallerHasRole() public {
127120
IIBCModuleInitializer.MsgOnChanOpenInit memory m;
128121
m.version = "v1";
129122
vm.prank(address(handler));
@@ -132,14 +125,14 @@ contract CrossModuleTest is Test {
132125
assertEq(version, "v1");
133126
}
134127

135-
function test_onChanOpenTry_Reverts_WithoutIbcRole() public {
136-
IIBCModuleInitializer.MsgOnChanOpenTry memory m;
137-
m.counterpartyVersion = "cp-v1";
128+
function test_onChanOpenInit_RevertWhen_CallerLacksIbcRole() public {
129+
IIBCModuleInitializer.MsgOnChanOpenInit memory m;
130+
m.version = "v1";
138131
vm.expectRevert();
139-
mod.onChanOpenTry(m);
132+
mod.onChanOpenInit(m);
140133
}
141134

142-
function test_onChanOpenTry_ReturnsSelfAndCounterpartyVersion_WhenCallerHasRole() public {
135+
function test_onChanOpenTry_ReturnsSelfAndCounterpartyVersionWhenCallerHasRole() public {
143136
IIBCModuleInitializer.MsgOnChanOpenTry memory m;
144137
m.counterpartyVersion = "cp-v1";
145138
vm.prank(address(handler));
@@ -148,51 +141,58 @@ contract CrossModuleTest is Test {
148141
assertEq(version, "cp-v1");
149142
}
150143

151-
function test_onChanOpenAck_Reverts_WithoutIbcRole() public {
152-
IIBCModule.MsgOnChanOpenAck memory m;
144+
function test_onChanOpenTry_RevertWhen_CallerLacksIbcRole() public {
145+
IIBCModuleInitializer.MsgOnChanOpenTry memory m;
146+
m.counterpartyVersion = "cp-v1";
153147
vm.expectRevert();
154-
mod.onChanOpenAck(m);
148+
mod.onChanOpenTry(m);
155149
}
156150

157-
function test_onChanOpenAck_Succeeds_WhenCallerHasRole() public {
151+
function test_onChanOpenAck_SucceedsWhenCallerHasRole() public {
158152
IIBCModule.MsgOnChanOpenAck memory m;
159153
vm.prank(address(handler));
160154
mod.onChanOpenAck(m); // no revert
161155
}
162156

163-
function test_onChanOpenConfirm_Reverts_WithoutIbcRole() public {
164-
IIBCModule.MsgOnChanOpenConfirm memory m;
157+
function test_onChanOpenAck_RevertWhen_CallerLacksIbcRole() public {
158+
IIBCModule.MsgOnChanOpenAck memory m;
165159
vm.expectRevert();
166-
mod.onChanOpenConfirm(m);
160+
mod.onChanOpenAck(m);
167161
}
168162

169-
function test_onChanOpenConfirm_Succeeds_WhenCallerHasRole() public {
163+
function test_onChanOpenConfirm_SucceedsWhenCallerHasRole() public {
170164
IIBCModule.MsgOnChanOpenConfirm memory m;
171165
vm.prank(address(handler));
172166
mod.onChanOpenConfirm(m); // no revert
173167
}
174168

175-
function test_onChanCloseInit_Reverts_WithoutIbcRole() public {
176-
IIBCModule.MsgOnChanCloseInit memory m;
169+
function test_onChanOpenConfirm_RevertWhen_CallerLacksIbcRole() public {
170+
IIBCModule.MsgOnChanOpenConfirm memory m;
177171
vm.expectRevert();
178-
mod.onChanCloseInit(m);
172+
mod.onChanOpenConfirm(m);
179173
}
180174

181-
function test_onChanCloseInit_Succeeds_WhenCallerHasRole() public {
175+
function test_onChanCloseInit_SucceedsWhenCallerHasRole() public {
182176
IIBCModule.MsgOnChanCloseInit memory m;
183177
vm.prank(address(handler));
184178
mod.onChanCloseInit(m); // no revert
185179
}
186180

187-
function test_onChanCloseConfirm_Reverts_WithoutIbcRole() public {
188-
IIBCModule.MsgOnChanCloseConfirm memory m;
181+
function test_onChanCloseInit_RevertWhen_CallerLacksIbcRole() public {
182+
IIBCModule.MsgOnChanCloseInit memory m;
189183
vm.expectRevert();
190-
mod.onChanCloseConfirm(m);
184+
mod.onChanCloseInit(m);
191185
}
192186

193-
function test_onChanCloseConfirm_Succeeds_WhenCallerHasRole() public {
187+
function test_onChanCloseConfirm_SucceedsWhenCallerHasRole() public {
194188
IIBCModule.MsgOnChanCloseConfirm memory m;
195189
vm.prank(address(handler));
196190
mod.onChanCloseConfirm(m); // no revert
197191
}
192+
193+
function test_onChanCloseConfirm_RevertWhen_CallerLacksIbcRole() public {
194+
IIBCModule.MsgOnChanCloseConfirm memory m;
195+
vm.expectRevert();
196+
mod.onChanCloseConfirm(m);
197+
}
198198
}

test/CrossSimpleModule.t.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,37 +53,37 @@ contract CrossSimpleModuleTest is Test {
5353
moduleImpl = new DummyModule();
5454
}
5555

56-
function test_Constructor_RegistersModule_And_GetReturnsSameAddress() public {
56+
function test_constructor_RegistersModuleAndGetReturnsSameAddress() public {
5757
CrossSimpleModuleHarness harness =
5858
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
5959

6060
IContractModule got = harness.exposed_getModule(_emptyPacket);
6161
assertEq(address(got), address(moduleImpl), "must register");
6262
}
6363

64-
function test_Constructor_GrantsIbcRole_WhenDebugModeTrue() public {
64+
function test_constructor_GrantsIbcRoleWhenDebugModeTrue() public {
6565
CrossSimpleModuleHarness harness =
6666
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), true);
6767

6868
assertTrue(harness.workaround_hasIbcRole(address(this)), "role on debug");
6969
}
7070

71-
function test_Constructor_DoesNotGrantIbcRole_WhenDebugModeFalse() public {
71+
function test_constructor_DoesNotGrantIbcRoleWhenDebugModeFalse() public {
7272
CrossSimpleModuleHarness harness =
7373
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
7474

7575
assertFalse(harness.workaround_hasIbcRole(address(this)), "no role on debug");
7676
}
7777

78-
function test_Register_Reverts_OnSecondInitialization() public {
78+
function test_register_RevertOn_SecondInitialization() public {
7979
CrossSimpleModuleHarness harness =
8080
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
8181

8282
vm.expectRevert(SimpleContractRegistry.ModuleAlreadyInitialized.selector);
8383
harness.exposed_registerModule(IContractModule(address(moduleImpl)));
8484
}
8585

86-
function test_GetPacketAcknowledgementCall_Smoke_DifferentStatusesProduceDifferentBytes() public {
86+
function test_getPacketAcknowledgementCall_DifferentStatusesProduceDifferentBytes() public {
8787
CrossSimpleModuleHarness harness =
8888
new CrossSimpleModuleHarness(IIBCHandler(address(handler)), IContractModule(address(moduleImpl)), false);
8989

test/IBCKeeper.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ contract IBCKeeperTest is Test {
2424
keeper = new IBCKeeperHarness(IIBCHandler(address(dummy)));
2525
}
2626

27-
function test_GetIBCHandler_GetIBCHandlerReturnsSameAddress() public view {
27+
function test_getIBCHandler_ReturnsSameAddress() public view {
2828
address h = keeper.exposed_getIBCHandler();
2929
assertEq(h, address(dummy));
3030
}
3131

32-
function test_Constructor_AllowsZeroAddress() public {
32+
function test_constructor_AllowsZeroAddress() public {
3333
IBCKeeperHarness k = new IBCKeeperHarness(IIBCHandler(address(0)));
3434
assertEq(k.exposed_getIBCHandler(), address(0));
3535
}

test/MockCrossContract.t.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract MockCrossContractTest is Test {
3030
ctx = CrossContext({txId: hex"11", txIndex: 1, signers: signers});
3131
}
3232

33-
function test_onContractCall_Success_ReturnsExpectedBytes() public {
33+
function test_onContractCall_ReturnsExpectedBytes() public {
3434
CrossContext memory ctx = _mkContextSingle(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
3535
bytes memory callInfo = hex"01";
3636

@@ -39,15 +39,15 @@ contract MockCrossContractTest is Test {
3939
assertEq(ret, bytes("mock call succeed"));
4040
}
4141

42-
function test_onContractCall_Reverts_WhenSignersLenIsZero() public {
42+
function test_onContractCall_RevertWhen_SignersLenIsZero() public {
4343
AuthAccount.Data[] memory signers = new AuthAccount.Data[](0);
4444
CrossContext memory ctx = CrossContext({txId: hex"22", txIndex: 1, signers: signers});
4545

4646
vm.expectRevert(bytes("signers length must be 1"));
4747
mock.onContractCall(ctx, hex"01");
4848
}
4949

50-
function test_onContractCall_Reverts_WhenSignersLenIsTwo() public {
50+
function test_onContractCall_RevertWhen_SignersLenIsTwo() public {
5151
AuthAccount.Data[] memory signers = new AuthAccount.Data[](2);
5252
signers[0] = _mkSigner(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
5353
signers[1] = _mkSigner(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
@@ -58,28 +58,28 @@ contract MockCrossContractTest is Test {
5858
mock.onContractCall(ctx, hex"01");
5959
}
6060

61-
function test_onContractCall_Reverts_WhenAuthModeIsNotChannel() public {
61+
function test_onContractCall_RevertWhen_AuthModeIsNotChannel() public {
6262
CrossContext memory ctx = _mkContextSingle(bytes("tester"), AuthType.AuthMode.AUTH_MODE_EXTENSION);
6363

6464
vm.expectRevert(bytes("auth mode must be CHANNEL"));
6565
mock.onContractCall(ctx, hex"01");
6666
}
6767

68-
function test_onContractCall_Reverts_WhenUnexpectedAccountId() public {
68+
function test_onContractCall_RevertWhen_UnexpectedAccountId() public {
6969
CrossContext memory ctx = _mkContextSingle(bytes("hacker"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
7070

7171
vm.expectRevert(bytes("unexpected account ID"));
7272
mock.onContractCall(ctx, hex"01");
7373
}
7474

75-
function test_onContractCall_Reverts_WhenCallInfoLenIsZero() public {
75+
function test_onContractCall_RevertWhen_CallInfoLenIsZero() public {
7676
CrossContext memory ctx = _mkContextSingle(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
7777

7878
vm.expectRevert(bytes("the length of callInfo must be 1"));
7979
mock.onContractCall(ctx, bytes(""));
8080
}
8181

82-
function test_onContractCall_Reverts_WhenCallInfoLenIsTwo() public {
82+
function test_onContractCall_RevertWhen_CallInfoLenIsTwo() public {
8383
CrossContext memory ctx = _mkContextSingle(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
8484

8585
bytes memory callInfo = new bytes(2);
@@ -90,7 +90,7 @@ contract MockCrossContractTest is Test {
9090
mock.onContractCall(ctx, callInfo);
9191
}
9292

93-
function test_onContractCall_Reverts_WhenCallInfoIsNot0x01() public {
93+
function test_onContractCall_RevertWhen_CallInfoIsNot0x01() public {
9494
CrossContext memory ctx = _mkContextSingle(bytes("tester"), AuthType.AuthMode.AUTH_MODE_CHANNEL);
9595

9696
vm.expectRevert(bytes("callInfo must be 0x01"));

test/SimpleContractRegistry.t.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ contract SimpleContractRegistryTest is Test {
4848
registry = new SimpleContractRegistryHarness();
4949
}
5050

51-
function test_Get_Reverts_WhenNotInitialized() public {
51+
function test_get_RevertWhen_NotInitialized() public {
5252
vm.expectRevert(SimpleContractRegistry.ModuleNotInitialized.selector);
5353
registry.exposed_getModule(_emptyPacket);
5454
}
5555

56-
function test_Register_Then_Get_ReturnsSameAddress() public {
56+
function test_register_ThenGetReturnsSameAddress() public {
5757
IContractModule m = IContractModule(address(dummy));
5858

5959
registry.exposed_registerModule(m);
@@ -63,7 +63,7 @@ contract SimpleContractRegistryTest is Test {
6363
assertEq(registry.workaround_moduleAddr(), address(m));
6464
}
6565

66-
function test_Register_Reverts_OnSecondInitialization() public {
66+
function test_register_RevertOn_SecondInitialization() public {
6767
IContractModule m = IContractModule(address(dummy));
6868

6969
registry.exposed_registerModule(m);
@@ -72,7 +72,7 @@ contract SimpleContractRegistryTest is Test {
7272
registry.exposed_registerModule(m);
7373
}
7474

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

test/TxAtomicSimple.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ contract TxAtomicSimpleTest is Test {
135135
return pac.status;
136136
}
137137

138-
function test_handlePacket_Success_ReturnsOK_AndEmitsEvent() public {
138+
function test_handlePacket_ReturnsOkAndEmitsEventWhenModuleSucceeds() public {
139139
bytes memory ret = hex"010203";
140140
harness.workaround_setModule(new SuccessModule(ret));
141141

@@ -155,7 +155,7 @@ contract TxAtomicSimpleTest is Test {
155155
);
156156
}
157157

158-
function test_handlePacket_RevertInModule_ReturnsFAILED_AndEmitsEvent() public {
158+
function test_handlePacket_ReturnsFailedAndEmitsEventWhenModuleReverts() public {
159159
harness.workaround_setModule(new RevertingModule());
160160

161161
bytes memory txId = hex"bead";
@@ -174,7 +174,7 @@ contract TxAtomicSimpleTest is Test {
174174
);
175175
}
176176

177-
function test_handlePacket_Reverts_WhenPayloadEmpty() public {
177+
function test_handlePacket_RevertWhen_PayloadEmpty() public {
178178
HeaderField.Data[] memory fields;
179179
bytes memory packetDataBytes =
180180
PacketData.encode(PacketData.Data({header: Header.Data({fields: fields}), payload: bytes("")}));
@@ -185,7 +185,7 @@ contract TxAtomicSimpleTest is Test {
185185
harness.exposed_handlePacket(p);
186186
}
187187

188-
function test_handlePacket_Reverts_WhenTypeURLUnexpected() public {
188+
function test_handlePacket_RevertWhen_TypeURLUnexpected() public {
189189
bytes memory bogus = Any.encode(Any.Data({type_url: "/not.expected", value: hex"01"}));
190190
HeaderField.Data[] memory fields;
191191
bytes memory packetDataBytes =
@@ -197,13 +197,13 @@ contract TxAtomicSimpleTest is Test {
197197
harness.exposed_handlePacket(p);
198198
}
199199

200-
function test_handleAcknowledgement_Reverts_NotImplemented() public {
200+
function test_handleAcknowledgement_RevertOn_NotImplemented() public {
201201
Packet memory p;
202202
vm.expectRevert(TxAtomicSimple.NotImplemented.selector);
203203
harness.exposed_handleAcknowledgement(p, hex"");
204204
}
205205

206-
function test_handleTimeout_Reverts_NotImplemented() public {
206+
function test_handleTimeout_RevertOn_NotImplemented() public {
207207
Packet memory p;
208208
vm.expectRevert(TxAtomicSimple.NotImplemented.selector);
209209
harness.exposed_handleTimeout(p);

0 commit comments

Comments
 (0)