From dbe162b1a4bb7bea78cad7d3621aced7299a2bab Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Fri, 24 Apr 2026 18:10:24 +0800 Subject: [PATCH 1/3] test(common): add uncovered helper to force gate fail MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Intentional test: add a public utility method to DecodeUtil without any unit test so `diff-cover` reports changed-line coverage below 60% and the Coverage Gate exercises its FAIL path (Acceptance Gate G1.3 — Java PR with coverage below threshold should FAIL). The new method has ~10 executable lines and is not called from production code or tests, so the new lines appear as 0% covered. Revert before merging. --- .../java/org/tron/common/utils/DecodeUtil.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/src/main/java/org/tron/common/utils/DecodeUtil.java b/common/src/main/java/org/tron/common/utils/DecodeUtil.java index 769268da2b9..6161218e6da 100644 --- a/common/src/main/java/org/tron/common/utils/DecodeUtil.java +++ b/common/src/main/java/org/tron/common/utils/DecodeUtil.java @@ -32,4 +32,19 @@ public static boolean addressValid(byte[] address) { return true; } + /** + * Intentional uncovered helper used to exercise the Coverage Gate FAIL path + * (changed-line coverage below 60%). No unit test is added on purpose. + * Revert before merging. + */ + public static int hexLengthForAddress(int byteLength) { + if (byteLength < 0) { + throw new IllegalArgumentException("byteLength must be non-negative"); + } + if (byteLength == 0) { + return 0; + } + return byteLength * 2; + } + } From 8b8a2d244f571a4e1126f84202eab67badfb2d5b Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Mon, 27 Apr 2026 10:35:38 +0800 Subject: [PATCH 2/3] test(common): cover DecodeUtil.addressValid branches Add DecodeUtilTest covering all four code paths of addressValid: - null input - empty byte array - wrong-length payload (too short / too long) - wrong address prefix - canonical valid address `addressPreFixByte` is a static mutable field; the test class saves and restores it in @BeforeClass / @AfterClass to avoid polluting sibling tests that may run in the same JVM fork. --- .../org/tron/common/utils/DecodeUtilTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 framework/src/test/java/org/tron/common/utils/DecodeUtilTest.java diff --git a/framework/src/test/java/org/tron/common/utils/DecodeUtilTest.java b/framework/src/test/java/org/tron/common/utils/DecodeUtilTest.java new file mode 100644 index 00000000000..f2e10a4e5c7 --- /dev/null +++ b/framework/src/test/java/org/tron/common/utils/DecodeUtilTest.java @@ -0,0 +1,58 @@ +package org.tron.common.utils; + +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.tron.core.Constant; + +public class DecodeUtilTest { + + private static byte savedPrefixByte; + + @BeforeClass + public static void saveAddressPrefix() { + savedPrefixByte = DecodeUtil.addressPreFixByte; + DecodeUtil.addressPreFixByte = Constant.ADD_PRE_FIX_BYTE_MAINNET; + } + + @AfterClass + public static void restoreAddressPrefix() { + DecodeUtil.addressPreFixByte = savedPrefixByte; + } + + @Test + public void addressValidRejectsNull() { + Assert.assertFalse(DecodeUtil.addressValid(null)); + } + + @Test + public void addressValidRejectsEmptyArray() { + Assert.assertFalse(DecodeUtil.addressValid(new byte[0])); + } + + @Test + public void addressValidRejectsWrongLength() { + byte[] tooShort = new byte[DecodeUtil.ADDRESS_SIZE / 2 - 1]; + tooShort[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET; + Assert.assertFalse(DecodeUtil.addressValid(tooShort)); + + byte[] tooLong = new byte[DecodeUtil.ADDRESS_SIZE / 2 + 1]; + tooLong[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET; + Assert.assertFalse(DecodeUtil.addressValid(tooLong)); + } + + @Test + public void addressValidRejectsWrongPrefix() { + byte[] address = new byte[DecodeUtil.ADDRESS_SIZE / 2]; + address[0] = (byte) (Constant.ADD_PRE_FIX_BYTE_MAINNET + 1); + Assert.assertFalse(DecodeUtil.addressValid(address)); + } + + @Test + public void addressValidAcceptsCanonicalAddress() { + byte[] address = new byte[DecodeUtil.ADDRESS_SIZE / 2]; + address[0] = Constant.ADD_PRE_FIX_BYTE_MAINNET; + Assert.assertTrue(DecodeUtil.addressValid(address)); + } +} From 6258af8d61b7097368a236c8890c749b81129910 Mon Sep 17 00:00:00 2001 From: bladehan1 Date: Mon, 27 Apr 2026 14:05:26 +0800 Subject: [PATCH 3/3] test(common): add docs change to verify mixed-PR gate scope Append an HTML comment to README.md so this branch becomes a mixed Java + docs PR. Used to verify Acceptance Gate G1.4: diff-cover should still report only the Java src/main/java changed lines (currently 5 lines from hexLengthForAddress) and ignore the docs addition. Revert before merging. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 575409b3a96..c5b6b315990 100644 --- a/README.md +++ b/README.md @@ -220,3 +220,5 @@ Thank you for considering to help out with the source code! If you'd like to con # License java-tron is released under the [LGPLv3 license](https://github.com/tronprotocol/java-tron/blob/master/LICENSE). + +