Skip to content

Commit 5b3cbc0

Browse files
committed
add testcase of external.ip is null
1 parent 4fad7e1 commit 5b3cbc0

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

common/src/test/java/org/tron/core/config/args/NodeConfigTest.java

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public void testShieldedApiLegacyKeyRespected() {
316316
}
317317

318318
@Test
319-
public void testShieldedApiLegacyKeyTakesPriorityOverModern() {
319+
public void testShieldedApiModernKeyTakesPriorityOverLegacy() {
320320
// Consistent with maxActiveNodesWithSameIp: legacy key presence wins over modern.
321321
NodeConfig nc = NodeConfig.fromConfig(
322322
withRef("node {\n"
@@ -343,4 +343,41 @@ public void testShieldedApiLegacyKeyTakesPriorityOverModern() {
343343
+ "}"));
344344
assertFalse(nc.isAllowShieldedTransactionApi());
345345
}
346+
347+
// ----- discovery.external.ip: null / "null" sentinel handling -----
348+
349+
@Test
350+
public void testExternalIpAbsentDefaultsToEmpty() {
351+
NodeConfig nc = NodeConfig.fromConfig(withRef());
352+
assertEquals("", nc.getDiscoveryExternalIp());
353+
}
354+
355+
@Test
356+
public void testExternalIpHoconNullTreatedAsEmpty() {
357+
// HOCON `null` makes hasPath() return false; getString falls back to "".
358+
NodeConfig nc = NodeConfig.fromConfig(
359+
withRef("node.discovery.external.ip = null"));
360+
assertEquals("", nc.getDiscoveryExternalIp());
361+
}
362+
363+
@Test
364+
public void testExternalIpStringNullSentinelConvertedToEmpty() {
365+
// String literal "null" (case-insensitive) is an explicit sentinel that must map to "".
366+
NodeConfig nc = NodeConfig.fromConfig(
367+
withRef("node.discovery.external.ip = \"null\""));
368+
assertEquals("", nc.getDiscoveryExternalIp());
369+
370+
nc = NodeConfig.fromConfig(
371+
withRef("node.discovery.external.ip = \"NULL\""));
372+
assertEquals("", nc.getDiscoveryExternalIp());
373+
}
374+
375+
@Test
376+
public void testExternalIpValidValuePreserved() {
377+
NodeConfig nc = NodeConfig.fromConfig(
378+
withRef("node.discovery.external.ip = \"1.2.3.4\""));
379+
assertEquals("1.2.3.4", nc.getDiscoveryExternalIp());
380+
}
381+
382+
346383
}

0 commit comments

Comments
 (0)