Skip to content

Commit 3b6fe6c

Browse files
committed
add witness config test
1 parent 0e0056b commit 3b6fe6c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

framework/src/test/java/org/tron/core/config/args/LocalWitnessTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,24 @@
1818
import static org.junit.Assert.fail;
1919

2020
import com.google.common.collect.Lists;
21+
import java.io.IOException;
2122
import org.junit.Assert;
2223
import org.junit.Before;
24+
import org.junit.Rule;
2325
import org.junit.Test;
26+
import org.junit.rules.TemporaryFolder;
2427
import org.tron.common.utils.LocalWitnesses;
2528
import org.tron.common.utils.PublicMethod;
29+
import org.tron.core.Constant;
2630

2731
public class LocalWitnessTest {
2832

2933
private final LocalWitnesses localWitness = new LocalWitnesses();
3034
private static final String PRIVATE_KEY = PublicMethod.getRandomPrivateKey();
3135

36+
@Rule
37+
public final TemporaryFolder temporaryFolder = new TemporaryFolder();
38+
3239
@Before
3340
public void setLocalWitness() {
3441
localWitness
@@ -89,4 +96,24 @@ public void testConstructor() {
8996
LocalWitnesses localWitnesses3 = new LocalWitnesses();
9097
Assert.assertNull(localWitnesses3.getWitnessAccountAddress(true));
9198
}
99+
100+
@Test
101+
public void testLocalWitnessConfig() throws IOException {
102+
Args.setParam(
103+
new String[]{"--output-directory", temporaryFolder.newFolder().toString(), "--debug"},
104+
"config-localtest.conf");
105+
LocalWitnesses witness = Args.getLocalWitnesses();
106+
Assert.assertNotNull(witness.getPrivateKey());
107+
Assert.assertNotNull(witness.getWitnessAccountAddress(true));
108+
}
109+
110+
@Test
111+
public void testNullLocalWitnessConfig() throws IOException {
112+
Args.setParam(
113+
new String[]{"--output-directory", temporaryFolder.newFolder().toString(), "--debug"},
114+
Constant.TEST_CONF);
115+
LocalWitnesses witness = Args.getLocalWitnesses();
116+
Assert.assertNull(witness.getPrivateKey());
117+
Assert.assertNull(witness.getWitnessAccountAddress(true));
118+
}
92119
}

framework/src/test/java/org/tron/core/net/services/RelayServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ public void testNullWitnessAddress() {
188188

189189
Object result = isActiveWitnessMethod.invoke(service);
190190
Assert.assertFalse(Boolean.TRUE.equals(result));
191-
} catch (NoSuchMethodException | NoSuchFieldException |
192-
IllegalAccessException | InvocationTargetException e) {
191+
} catch (NoSuchMethodException | NoSuchFieldException
192+
| IllegalAccessException | InvocationTargetException e) {
193193
Assert.fail("Reflection invocation failed: " + e.getMessage());
194194
}
195195
}

0 commit comments

Comments
 (0)