Skip to content

Commit 3aa591f

Browse files
authored
refactor: move test constant out of production code and rename NET_CONF (tronprotocol#6555)
1 parent 111b967 commit 3aa591f

220 files changed

Lines changed: 649 additions & 433 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/pr-check.yml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
name: PR Check
2+
3+
on:
4+
pull_request:
5+
branches: [ 'develop', 'release_**' ]
6+
types: [ opened, edited, synchronize, reopened ]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
pr-lint:
14+
name: PR Lint
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Check PR title format
19+
uses: actions/github-script@v7
20+
with:
21+
script: |
22+
const title = context.payload.pull_request.title;
23+
24+
const errors = [];
25+
26+
// Title should not be empty or too short
27+
if (!title || title.trim().length < 10) {
28+
errors.push('PR title is too short (minimum 10 characters).');
29+
}
30+
31+
// Title should not exceed 72 characters
32+
if (title.length > 72) {
33+
errors.push(`PR title is too long (${title.length}/72 characters).`);
34+
}
35+
36+
// Title should follow conventional format: type: description
37+
// Allowed types: feat, fix, refactor, docs, style, test, chore, ci, perf, build, revert
38+
const conventionalRegex = /^(feat|fix|refactor|docs|style|test|chore|ci|perf|build|revert)(\(.+\))?:\s.+/;
39+
if (!conventionalRegex.test(title)) {
40+
errors.push(
41+
'PR title must follow conventional format: `type: description`\n' +
42+
'Allowed types: feat, fix, refactor, docs, style, test, chore, ci, perf, build, revert\n' +
43+
'Example: `feat: add new transaction validation`'
44+
);
45+
}
46+
47+
if (errors.length > 0) {
48+
const message = '### PR Title Check Failed\n\n' + errors.map(e => `- ${e}`).join('\n');
49+
core.setFailed(message);
50+
} else {
51+
core.info('PR title format is valid.');
52+
}
53+
54+
- name: Check PR description
55+
uses: actions/github-script@v7
56+
with:
57+
script: |
58+
const body = context.payload.pull_request.body;
59+
60+
if (!body || body.trim().length < 20) {
61+
core.setFailed(
62+
'### PR Description Check Failed\n\n' +
63+
'PR description is too short or empty. Please describe what this PR does and why.'
64+
);
65+
} else {
66+
core.info('PR description is valid.');
67+
}
68+
69+
build:
70+
name: Build (JDK ${{ matrix.java }} / ${{ matrix.arch }})
71+
runs-on: ${{ matrix.runner }}
72+
strategy:
73+
fail-fast: false
74+
matrix:
75+
include:
76+
- java: '8'
77+
runner: ubuntu-latest
78+
arch: x86_64
79+
- java: '17'
80+
runner: ubuntu-24.04-arm
81+
arch: aarch64
82+
83+
steps:
84+
- uses: actions/checkout@v4
85+
86+
- name: Set up JDK ${{ matrix.java }}
87+
uses: actions/setup-java@v4
88+
with:
89+
java-version: ${{ matrix.java }}
90+
distribution: 'temurin'
91+
92+
- name: Cache Gradle packages
93+
uses: actions/cache@v4
94+
with:
95+
path: |
96+
~/.gradle/caches
97+
~/.gradle/wrapper
98+
key: ${{ runner.os }}-${{ matrix.arch }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
99+
restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle-
100+
101+
- name: Build
102+
run: ./gradlew clean build -x test
103+
104+
checkstyle:
105+
name: Checkstyle
106+
runs-on: ubuntu-latest
107+
108+
steps:
109+
- uses: actions/checkout@v4
110+
111+
- name: Set up JDK 8
112+
uses: actions/setup-java@v4
113+
with:
114+
java-version: '8'
115+
distribution: 'temurin'
116+
117+
- name: Cache Gradle packages
118+
uses: actions/cache@v4
119+
with:
120+
path: |
121+
~/.gradle/caches
122+
~/.gradle/wrapper
123+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
124+
restore-keys: ${{ runner.os }}-gradle-
125+
126+
- name: Run Checkstyle
127+
run: ./gradlew :framework:checkstyleMain :framework:checkstyleTest :plugins:checkstyleMain
128+
129+
- name: Upload Checkstyle reports
130+
if: failure()
131+
uses: actions/upload-artifact@v4
132+
with:
133+
name: checkstyle-reports
134+
path: |
135+
framework/build/reports/checkstyle/
136+
plugins/build/reports/checkstyle/
137+
138+
test:
139+
name: Unit Tests (JDK ${{ matrix.java }} / ${{ matrix.arch }})
140+
runs-on: ${{ matrix.runner }}
141+
needs: build
142+
timeout-minutes: 60
143+
strategy:
144+
fail-fast: false
145+
matrix:
146+
include:
147+
- java: '8'
148+
runner: ubuntu-latest
149+
arch: x86_64
150+
- java: '17'
151+
runner: ubuntu-24.04-arm
152+
arch: aarch64
153+
154+
steps:
155+
- uses: actions/checkout@v4
156+
157+
- name: Set up JDK ${{ matrix.java }}
158+
uses: actions/setup-java@v4
159+
with:
160+
java-version: ${{ matrix.java }}
161+
distribution: 'temurin'
162+
163+
- name: Cache Gradle packages
164+
uses: actions/cache@v4
165+
with:
166+
path: |
167+
~/.gradle/caches
168+
~/.gradle/wrapper
169+
key: ${{ runner.os }}-${{ matrix.arch }}-gradle-${{ hashFiles('**/*.gradle', '**/gradle-wrapper.properties') }}
170+
restore-keys: ${{ runner.os }}-${{ matrix.arch }}-gradle-
171+
172+
- name: Run tests
173+
run: ./gradlew test
174+
175+
- name: Upload test reports
176+
if: failure()
177+
uses: actions/upload-artifact@v4
178+
with:
179+
name: test-reports-${{ matrix.arch }}
180+
path: |
181+
**/build/reports/tests/

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</h4>
88

99
<p align="center">
10-
<a href="https://gitter.im/tronprotocol/allcoredev"><img src="https://img.shields.io/gitter/room/tronprotocol/java-tron.svg"></a>
10+
<a href="https://discord.gg/hqKvyAM"><img src="https://img.shields.io/badge/chat-on%20discord-7289da.svg"></a>
1111
<a href="https://codecov.io/gh/tronprotocol/java-tron"><img src="https://codecov.io/gh/tronprotocol/java-tron/branch/develop/graph/badge.svg" /></a>
1212
<a href="https://github.com/tronprotocol/java-tron/issues"><img src="https://img.shields.io/github/issues/tronprotocol/java-tron.svg"></a>
1313
<a href="https://github.com/tronprotocol/java-tron/pulls"><img src="https://img.shields.io/github/issues-pr/tronprotocol/java-tron.svg"></a>
@@ -84,7 +84,7 @@ The java-tron project comes with several runnable artifacts and helper scripts f
8484
| Deployment Tier | CPU Cores | Memory | High-performance SSD Storage | Network Downstream |
8585
|--------------------------|-------|--------|---------------------------|-----------------|
8686
| FullNode (Minimum) | 8 | 16 GB | 200 GB ([Lite](https://tronprotocol.github.io/documentation-en/using_javatron/litefullnode/#lite-fullnode)) | ≥ 5 MBit/sec |
87-
| FullNode (Stable) | 8 | 32 GB | 200 GB (Lite) 3.5 TB (Full) | ≥ 5 MBit/sec |
87+
| FullNode (Stable) | 8 | 32 GB | 200 GB (Lite) / 3.5 TB (Full) | ≥ 5 MBit/sec |
8888
| FullNode (Recommend) | 16+ | 32 GB+ | 4 TB | ≥ 50 MBit/sec |
8989
| Super Representative | 32+ | 64 GB+ | 4 TB | ≥ 50 MBit/sec |
9090

@@ -201,14 +201,14 @@ Thank you for considering to help out with the source code! If you'd like to con
201201

202202
# Resources
203203

204-
- [Medium](https://medium.com/@coredevs) - java-tron's official technical articles are published here.
205-
- [Documentation](https://tronprotocol.github.io/documentation-en/) and [TRON Developer Hub](https://developers.tron.network/) serve as java-tron’s primary documentation websites.
206-
- [TronScan](https://tronscan.org/) - TRON main network blockchain browser.
207-
- [Nile Test Network](https://nileex.io/) - Forward-looking testnet for developers to experience.
208-
- [Shasta Test Network](https://shasta.tronex.io/) - Stable testnet that closely mirrors Mainnet features, providing a realistic testing environment .
209-
- [Wallet-cli](https://github.com/tronprotocol/wallet-cli) - TRON network wallet using command line.
210-
- [TIP](https://github.com/tronprotocol/tips) - TRON Improvement Proposal (TIP) describes standards for the TRON network.
211-
- [TP](https://github.com/tronprotocol/tips/tree/master/tp) - TRON Protocol (TP) describes standards already implemented in TRON network but not published as a TIP.
204+
- [Medium](https://medium.com/@coredevs) — Official technical articles from the java-tron core development team.
205+
- [Documentation](https://tronprotocol.github.io/documentation-en/) and [TRON Developer Hub](https://developers.tron.network/) — Primary documentation for java-tron developers.
206+
- [TronScan](https://tronscan.org/#/) TRON mainnet blockchain explorer.
207+
- [Nile Test Network](http://nileex.io/) — A stable test network for TRON development and testing.
208+
- [Shasta Test Network](https://shasta.tronex.io/) — A stable test network mirroring mainnet features.
209+
- [Wallet-cli](https://github.com/tronprotocol/wallet-cli) — Command-line wallet for the TRON network.
210+
- [TIP](https://github.com/tronprotocol/tips) TRON Improvement Proposals describing standards for the TRON network.
211+
- [TP](https://github.com/tronprotocol/tips/tree/master/tp) TRON Protocols already implemented but not yet published as TIPs.
212212

213213
# Integrity Check
214214

common/src/main/java/org/tron/core/Constant.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
public class Constant {
44

55
//config for testnet, mainnet, beta
6-
public static final String TESTNET_CONF = "config.conf";
7-
8-
//config for junit test
9-
public static final String TEST_CONF = "config-test.conf";
6+
public static final String NET_CONF = "config.conf";
107

118
// locate in storageDbDirectory, store the db infos,
129
// now only has the split block number

framework/src/main/java/org/tron/core/config/args/DynamicArgs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private File getConfigFile() {
6767
if (isNoneBlank(parameter.getShellConfFileName())) {
6868
confFilePath = parameter.getShellConfFileName();
6969
} else {
70-
confFilePath = Constant.TESTNET_CONF;
70+
confFilePath = Constant.NET_CONF;
7171
}
7272

7373
File confFile = new File(confFilePath);
@@ -81,7 +81,7 @@ private File getConfigFile() {
8181
public void reload() {
8282
logger.debug("Reloading ... ");
8383
Config config = Configuration.getByFileName(parameter.getShellConfFileName(),
84-
Constant.TESTNET_CONF);
84+
Constant.NET_CONF);
8585

8686
updateActiveNodes(config);
8787

framework/src/main/java/org/tron/program/FullNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class FullNode {
2121
*/
2222
public static void main(String[] args) {
2323
ExitManager.initExceptionHandler();
24-
Args.setParam(args, Constant.TESTNET_CONF);
24+
Args.setParam(args, Constant.NET_CONF);
2525
CommonParameter parameter = Args.getInstance();
2626

2727
LogService.load(parameter.getLogbackPath());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.tron.common;
2+
3+
public class TestConstants {
4+
5+
public static final String TEST_CONF = "config-test.conf";
6+
}

framework/src/test/java/org/tron/common/backup/BackupManagerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import org.junit.Rule;
1313
import org.junit.Test;
1414
import org.junit.rules.TemporaryFolder;
15+
import org.tron.common.TestConstants;
1516
import org.tron.common.backup.BackupManager.BackupStatusEnum;
1617
import org.tron.common.backup.message.KeepAliveMessage;
1718
import org.tron.common.backup.socket.BackupServer;
1819
import org.tron.common.backup.socket.UdpEvent;
1920
import org.tron.common.parameter.CommonParameter;
2021
import org.tron.common.utils.PublicMethod;
21-
import org.tron.core.Constant;
2222
import org.tron.core.config.args.Args;
2323

2424
public class BackupManagerTest {
@@ -30,7 +30,8 @@ public class BackupManagerTest {
3030

3131
@Before
3232
public void setUp() throws Exception {
33-
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
33+
Args.setParam(new String[] {"-d", temporaryFolder.newFolder().toString()},
34+
TestConstants.TEST_CONF);
3435
CommonParameter.getInstance().setBackupPort(PublicMethod.chooseRandomPort());
3536
manager = new BackupManager();
3637
backupServer = new BackupServer(manager);

framework/src/test/java/org/tron/common/backup/BackupServerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import org.junit.Test;
99
import org.junit.rules.TemporaryFolder;
1010
import org.junit.rules.Timeout;
11+
import org.tron.common.TestConstants;
1112
import org.tron.common.backup.socket.BackupServer;
1213
import org.tron.common.parameter.CommonParameter;
1314
import org.tron.common.utils.PublicMethod;
14-
import org.tron.core.Constant;
1515
import org.tron.core.config.args.Args;
1616

1717

@@ -26,7 +26,8 @@ public class BackupServerTest {
2626

2727
@Before
2828
public void setUp() throws Exception {
29-
Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()}, Constant.TEST_CONF);
29+
Args.setParam(new String[]{"-d", temporaryFolder.newFolder().toString()},
30+
TestConstants.TEST_CONF);
3031
CommonParameter.getInstance().setBackupPort(PublicMethod.chooseRandomPort());
3132
List<String> members = new ArrayList<>();
3233
members.add("127.0.0.2");

framework/src/test/java/org/tron/common/config/args/ArgsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import org.junit.Rule;
1111
import org.junit.Test;
1212
import org.junit.rules.TemporaryFolder;
13+
import org.tron.common.TestConstants;
1314
import org.tron.common.parameter.RateLimiterInitialization;
14-
import org.tron.core.Constant;
1515
import org.tron.core.config.args.Args;
1616

1717
public class ArgsTest {
@@ -23,7 +23,7 @@ public class ArgsTest {
2323
public void init() throws IOException {
2424
Args.setParam(new String[] {"--output-directory",
2525
temporaryFolder.newFolder().toString(), "--p2p-disable", "true",
26-
"--debug"}, Constant.TEST_CONF);
26+
"--debug"}, TestConstants.TEST_CONF);
2727
}
2828

2929
@After

framework/src/test/java/org/tron/common/runtime/InheritanceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.junit.Before;
77
import org.junit.Test;
88
import org.tron.common.BaseTest;
9-
import org.tron.core.Constant;
9+
import org.tron.common.TestConstants;
1010
import org.tron.core.Wallet;
1111
import org.tron.core.config.args.Args;
1212
import org.tron.core.exception.ContractExeException;
@@ -25,7 +25,7 @@ public class InheritanceTest extends BaseTest {
2525
private static boolean init;
2626

2727
static {
28-
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, Constant.TEST_CONF);
28+
Args.setParam(new String[]{"--output-directory", dbPath(), "--debug"}, TestConstants.TEST_CONF);
2929
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049abc";
3030
}
3131

0 commit comments

Comments
 (0)