Skip to content

Commit f5a42f8

Browse files
Little-Peonyclaude
andcommitted
test(framework): address PR review comments on test code quality
- Remove dead moreThanFrozenNumber test in FreezeBalanceV2ActuatorTest (error message no longer exists in production code) - Remove unnecessary try/catch around addAssetV2 in AccountAssetStoreTest (method declares no checked exceptions) - Replace try/catch pattern with Assert.assertThrows in FetchInvDataMsgHandlerTest Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ed42e92 commit f5a42f8

3 files changed

Lines changed: 9 additions & 46 deletions

File tree

framework/src/test/java/org/tron/core/actuator/FreezeBalanceV2ActuatorTest.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -268,33 +268,6 @@ public void lessThan1TrxTest() {
268268
}
269269
}
270270

271-
//@Test
272-
public void moreThanFrozenNumber() {
273-
long frozenBalance = 1_000_000_000L;
274-
FreezeBalanceActuator actuator = new FreezeBalanceActuator();
275-
actuator.setChainBaseManager(dbManager.getChainBaseManager())
276-
.setAny(getContractV2ForBandwidth(OWNER_ADDRESS, frozenBalance));
277-
278-
TransactionResultCapsule ret = new TransactionResultCapsule();
279-
try {
280-
actuator.validate();
281-
actuator.execute(ret);
282-
} catch (ContractValidateException | ContractExeException e) {
283-
Assert.fail();
284-
}
285-
try {
286-
actuator.validate();
287-
actuator.execute(ret);
288-
fail("cannot run here.");
289-
} catch (ContractValidateException e) {
290-
long maxFrozenNumber = ChainConstant.MAX_FROZEN_NUMBER;
291-
Assert.assertEquals("max frozen number is: " + maxFrozenNumber, e.getMessage());
292-
} catch (ContractExeException e) {
293-
Assert.fail();
294-
}
295-
}
296-
297-
298271
@Test
299272
public void commonErrorCheck() {
300273
FreezeBalanceV2Actuator actuator = new FreezeBalanceV2Actuator();

framework/src/test/java/org/tron/core/db/AccountAssetStoreTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ private long createAsset(String tokenName) {
8484
AssetIssueCapsule assetIssueCapsule = new AssetIssueCapsule(assetIssueContract);
8585
chainBaseManager.getAssetIssueV2Store()
8686
.put(assetIssueCapsule.createDbV2Key(), assetIssueCapsule);
87-
try {
88-
ownerCapsule.addAssetV2(ByteArray.fromString(String.valueOf(id)), TOTAL_SUPPLY);
89-
} catch (Exception e) {
90-
Assert.fail(e.getMessage());
91-
}
87+
ownerCapsule.addAssetV2(ByteArray.fromString(String.valueOf(id)), TOTAL_SUPPLY);
9288
accountStore.put(ownerCapsule.getAddress().toByteArray(), ownerCapsule);
9389
return id;
9490
}

framework/src/test/java/org/tron/core/net/messagehandler/FetchInvDataMsgHandlerTest.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,17 @@ public void testSyncFetchCheck() {
111111

112112
FetchInvDataMsgHandler fetchInvDataMsgHandler = new FetchInvDataMsgHandler();
113113

114-
try {
115-
Mockito.when(peer.getLastSyncBlockId())
114+
Mockito.when(peer.getLastSyncBlockId())
116115
.thenReturn(new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 1000L));
117-
fetchInvDataMsgHandler.processMessage(peer, msg);
118-
Assert.fail("Expected exception was not thrown: maxBlockNum: 1000, blockNum: 10000");
119-
} catch (Exception e) {
120-
Assert.assertEquals("maxBlockNum: 1000, blockNum: 10000", e.getMessage());
121-
}
116+
Exception e1 = Assert.assertThrows(Exception.class,
117+
() -> fetchInvDataMsgHandler.processMessage(peer, msg));
118+
Assert.assertEquals("maxBlockNum: 1000, blockNum: 10000", e1.getMessage());
122119

123-
try {
124-
Mockito.when(peer.getLastSyncBlockId())
120+
Mockito.when(peer.getLastSyncBlockId())
125121
.thenReturn(new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 20000L));
126-
fetchInvDataMsgHandler.processMessage(peer, msg);
127-
Assert.fail("Expected exception was not thrown: minBlockNum: 16000, blockNum: 10000");
128-
} catch (Exception e) {
129-
Assert.assertEquals("minBlockNum: 16000, blockNum: 10000", e.getMessage());
130-
}
122+
Exception e2 = Assert.assertThrows(Exception.class,
123+
() -> fetchInvDataMsgHandler.processMessage(peer, msg));
124+
Assert.assertEquals("minBlockNum: 16000, blockNum: 10000", e2.getMessage());
131125
}
132126

133127
@Test

0 commit comments

Comments
 (0)