Skip to content

Commit 7343e96

Browse files
halibobo1205claude
andcommitted
fix: resolve PR #120 review comments — exact token assertions and deterministic fuzz
- Use exact token_id/sell_token_id/buy_token_id byte assertions instead of non-empty checks in Exchange and Market servlet tests - Add account_id byte assertion in SetAccountIdServletTest - Switch fuzz test from non-deterministic SecureRandom to seeded Random for reproducible CI failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 42cc80d commit 7343e96

7 files changed

Lines changed: 20 additions & 10 deletions

framework/src/test/java/org/tron/core/services/http/ExchangeCreateServletTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ && addressEquals(((ExchangeCreateContract) c)
4848
.getOwnerAddress(), ownerAddr)
4949
&& ((ExchangeCreateContract) c).getFirstTokenBalance() == 100
5050
&& ((ExchangeCreateContract) c).getSecondTokenBalance() == 200
51-
&& !((ExchangeCreateContract) c).getFirstTokenId().isEmpty()
52-
&& !((ExchangeCreateContract) c).getSecondTokenId().isEmpty()),
51+
&& ((ExchangeCreateContract) c)
52+
.getFirstTokenId().toStringUtf8().equals("_")
53+
&& ((ExchangeCreateContract) c)
54+
.getSecondTokenId().toStringUtf8().equals("a")),
5355
eq(ContractType.ExchangeCreateContract));
5456
assertTransactionResponse(response);
5557
}

framework/src/test/java/org/tron/core/services/http/ExchangeInjectServletTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ && addressEquals(((ExchangeContract.ExchangeInjectContract) c)
4848
.getOwnerAddress(), ownerAddr)
4949
&& ((ExchangeContract.ExchangeInjectContract) c).getExchangeId() == 1
5050
&& ((ExchangeContract.ExchangeInjectContract) c).getQuant() == 100
51-
&& !((ExchangeContract.ExchangeInjectContract) c).getTokenId().isEmpty()),
51+
&& ((ExchangeContract.ExchangeInjectContract) c)
52+
.getTokenId().toStringUtf8().equals("_")),
5253
eq(Protocol.Transaction.Contract.ContractType.ExchangeInjectContract));
5354
assertTransactionResponse(response);
5455
}

framework/src/test/java/org/tron/core/services/http/ExchangeTransactionServletTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ && addressEquals(((ExchangeContract.ExchangeTransactionContract) c)
5050
&& ((ExchangeContract.ExchangeTransactionContract) c).getExchangeId() == 1
5151
&& ((ExchangeContract.ExchangeTransactionContract) c).getQuant() == 100
5252
&& ((ExchangeContract.ExchangeTransactionContract) c).getExpected() == 10
53-
&& !((ExchangeContract.ExchangeTransactionContract) c).getTokenId().isEmpty()),
53+
&& ((ExchangeContract.ExchangeTransactionContract) c)
54+
.getTokenId().toStringUtf8().equals("_")),
5455
eq(Protocol.Transaction.Contract.ContractType.ExchangeTransactionContract));
5556
assertTransactionResponse(response);
5657
}

framework/src/test/java/org/tron/core/services/http/ExchangeWithdrawServletTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ && addressEquals(((ExchangeContract.ExchangeWithdrawContract) c)
4848
.getOwnerAddress(), ownerAddr)
4949
&& ((ExchangeContract.ExchangeWithdrawContract) c).getExchangeId() == 1
5050
&& ((ExchangeContract.ExchangeWithdrawContract) c).getQuant() == 50
51-
&& !((ExchangeContract.ExchangeWithdrawContract) c).getTokenId().isEmpty()),
51+
&& ((ExchangeContract.ExchangeWithdrawContract) c)
52+
.getTokenId().toStringUtf8().equals("_")),
5253
eq(Protocol.Transaction.Contract.ContractType.ExchangeWithdrawContract));
5354
assertTransactionResponse(response);
5455
}

framework/src/test/java/org/tron/core/services/http/MarketSellAssetServletTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ && addressEquals(((MarketContract.MarketSellAssetContract) c)
4949
.getOwnerAddress(), ownerAddr)
5050
&& ((MarketContract.MarketSellAssetContract) c).getSellTokenQuantity() == 100
5151
&& ((MarketContract.MarketSellAssetContract) c).getBuyTokenQuantity() == 200
52-
&& !((MarketContract.MarketSellAssetContract) c).getSellTokenId().isEmpty()
53-
&& !((MarketContract.MarketSellAssetContract) c).getBuyTokenId().isEmpty()),
52+
&& ((MarketContract.MarketSellAssetContract) c)
53+
.getSellTokenId().toStringUtf8().equals("_")
54+
&& ((MarketContract.MarketSellAssetContract) c)
55+
.getBuyTokenId().toStringUtf8().equals("`")),
5456
eq(Protocol.Transaction.Contract.ContractType.MarketSellAssetContract));
5557
assertTransactionResponse(response);
5658
}

framework/src/test/java/org/tron/core/services/http/SetAccountIdServletTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public void testSetAccountId() throws Exception {
4242
verify(wallet).createTransactionCapsule(
4343
argThat(c -> c instanceof AccountContract.SetAccountIdContract
4444
&& addressEquals(((AccountContract.SetAccountIdContract) c)
45-
.getOwnerAddress(), ownerAddr)),
45+
.getOwnerAddress(), ownerAddr)
46+
&& ((AccountContract.SetAccountIdContract) c)
47+
.getAccountId().toStringUtf8().equals("aaaabbbb")),
4648
eq(Protocol.Transaction.Contract.ContractType.SetAccountIdContract));
4749
assertTransactionResponse(response);
4850
}

framework/src/test/java/org/tron/json/JsonCompatibilityFuzzTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import java.math.BigDecimal;
1111
import java.math.BigInteger;
12-
import java.security.SecureRandom;
12+
1313
import java.util.ArrayList;
1414
import java.util.Arrays;
1515
import java.util.List;
@@ -29,7 +29,8 @@
2929
public class JsonCompatibilityFuzzTest {
3030

3131
private static final int FUZZ_ROUNDS = 500;
32-
private static final SecureRandom RNG = new SecureRandom();
32+
private static final long SEED = 20260404L;
33+
private static final Random RNG = new Random(SEED);
3334

3435
// -------------------------------------------------------------------------
3536
// 1. JSON.parse — must throw on invalid JSON, return non-null on valid

0 commit comments

Comments
 (0)