From 7b7883e1f0f5212517375f6532dd79fdccb4f5bc Mon Sep 17 00:00:00 2001 From: liuxincheng Date: Wed, 28 Aug 2024 18:28:49 +0800 Subject: [PATCH] feat(test): improve unit test coverage --- .../tron/common/MultiLayoutPatternTest.java | 72 + .../common/logsfilter/FilterQueryTest.java | 52 +- .../capsule/BlockFilterCapsuleTest.java | 38 + .../capsule/BlockLogTriggerCapsuleTest.java | 35 + .../ContractLogTriggerCapsuleTest.java | 35 + .../capsule/ContractTriggerCapsuleTest.java | 52 + .../capsule/LogsFilterCapsuleTest.java | 33 + .../logsfilter/capsule/RawDataTest.java | 33 + .../capsule/SolidityEventCapsuleTest.java | 29 + .../capsule/SolidityLogCapsuleTest.java | 29 + .../capsule/SolidityTriggerCapsuleTest.java | 36 + .../trigger/ContractLogTriggerTest.java | 82 ++ .../trigger/InternalTransactionPojoTest.java | 87 ++ .../logsfilter/trigger/LogPojoTest.java | 74 ++ .../common/zksnark/ZksnarkClientTest.java | 43 + .../java/org/tron/core/CoreExceptionTest.java | 1162 +++++++++++++++++ .../tron/core/capsule/utils/RLPListTest.java | 6 +- .../core/config/args/LocalWitnessTest.java | 25 +- .../java/org/tron/core/db/ManagerTest.java | 12 +- .../org/tron/core/db/api/pojo/PojoTest.java | 80 ++ .../ChainInventoryMsgHandlerTest.java | 13 +- .../SyncBlockChainMsgHandlerTest.java | 10 +- .../net/service/nodepersist/DBNodeTest.java | 52 + .../tron/core/zksnark/SendCoinShieldTest.java | 17 + .../core/zksnark/ShieldedReceiveTest.java | 31 +- .../java/org/tron/program/SupplementTest.java | 17 + 26 files changed, 2121 insertions(+), 34 deletions(-) create mode 100644 framework/src/test/java/org/tron/common/MultiLayoutPatternTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/BlockFilterCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/BlockLogTriggerCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/ContractLogTriggerCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/ContractTriggerCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/LogsFilterCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/RawDataTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityEventCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityLogCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityTriggerCapsuleTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/trigger/ContractLogTriggerTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/trigger/InternalTransactionPojoTest.java create mode 100644 framework/src/test/java/org/tron/common/logsfilter/trigger/LogPojoTest.java create mode 100644 framework/src/test/java/org/tron/common/zksnark/ZksnarkClientTest.java create mode 100644 framework/src/test/java/org/tron/core/CoreExceptionTest.java create mode 100644 framework/src/test/java/org/tron/core/db/api/pojo/PojoTest.java create mode 100644 framework/src/test/java/org/tron/core/net/service/nodepersist/DBNodeTest.java diff --git a/framework/src/test/java/org/tron/common/MultiLayoutPatternTest.java b/framework/src/test/java/org/tron/common/MultiLayoutPatternTest.java new file mode 100644 index 00000000000..87223757e8e --- /dev/null +++ b/framework/src/test/java/org/tron/common/MultiLayoutPatternTest.java @@ -0,0 +1,72 @@ +package org.tron.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import ch.qos.logback.classic.LoggerContext; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.classic.spi.LoggingEvent; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.LoggerFactory; +import org.tron.common.log.layout.MultiLayoutPattern; + +public class MultiLayoutPatternTest { + + private MultiLayoutPattern multiLayoutPattern; + private LoggerContext context; + + @Before + public void setUp() { + context = new LoggerContext(); + multiLayoutPattern = new MultiLayoutPattern(); + multiLayoutPattern.setContext(context); + + MultiLayoutPattern.Rule rule1 = new MultiLayoutPattern.Rule(); + rule1.setLogger("com.example.app1"); + assertNotNull(rule1.getLogger()); + rule1.setPattern("%date [%thread] %-5level %logger{36} - %msg%n"); + assertNotNull(rule1.getPattern()); + rule1.setOutputPatternAsHeader(true); + assertTrue(rule1.isOutputPatternAsHeader()); + multiLayoutPattern.addRule(rule1); + + MultiLayoutPattern.Rule rule2 = new MultiLayoutPattern.Rule(); + rule2.setLogger("com.example.app2"); + rule2.setPattern("%msg%n"); + multiLayoutPattern.addRule(rule2); + + multiLayoutPattern.start(); + } + + @Test + public void testEncodeForSpecificLogger() { + ILoggingEvent event1 = createLoggingEvent("com.example.app1", "Test message 1"); + byte[] encoded1 = multiLayoutPattern.encode(event1); + String result1 = new String(encoded1); + assertTrue(result1.contains("Test message 1")); + + ILoggingEvent event2 = createLoggingEvent("com.example.app2", "Test message 2"); + byte[] encoded2 = multiLayoutPattern.encode(event2); + String result2 = new String(encoded2); + assertEquals("Test message 2\n", result2); + } + + @Test + public void testEncodeForRootLogger() { + ILoggingEvent event = createLoggingEvent(Logger.ROOT_LOGGER_NAME, "Root logger message"); + byte[] encoded = multiLayoutPattern.encode(event); + String result = new String(encoded); + assertFalse(result.contains("Root logger message")); + } + + private ILoggingEvent createLoggingEvent(String loggerName, String message) { + Logger logger = (Logger) LoggerFactory.getLogger(loggerName); + return new LoggingEvent(loggerName, logger, Level.INFO, message, null, null); + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/FilterQueryTest.java b/framework/src/test/java/org/tron/common/logsfilter/FilterQueryTest.java index 601cf72b294..541bf2939c9 100644 --- a/framework/src/test/java/org/tron/common/logsfilter/FilterQueryTest.java +++ b/framework/src/test/java/org/tron/common/logsfilter/FilterQueryTest.java @@ -9,12 +9,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.Test; import org.tron.common.logsfilter.capsule.ContractEventTriggerCapsule; +import org.tron.common.logsfilter.capsule.FilterTriggerCapsule; +import org.tron.common.logsfilter.capsule.TriggerCapsule; import org.tron.common.runtime.LogEventWrapper; import org.tron.protos.contract.SmartContractOuterClass.SmartContract.ABI.Entry; +@Slf4j public class FilterQueryTest { @Test @@ -37,26 +41,31 @@ public synchronized void testParseFilterQueryBlockNumber() { @Test public synchronized void testMatchFilter() { - String[] addrList = {"address1", "address2"}; + String[] adrList = {"address1", "address2"}; String[] topList = {"top1", "top2"}; - Map topMap = new HashMap(); + Map topMap = new HashMap<>(); List addressList = new ArrayList<>(); - addressList.add(addrList[0].getBytes()); - addressList.add(addrList[1].getBytes()); + addressList.add(adrList[0].getBytes()); + addressList.add(adrList[1].getBytes()); topMap.put("1", topList[0]); topMap.put("2", topList[1]); LogEventWrapper event = new LogEventWrapper(); - ((LogEventWrapper) event).setTopicList(addressList); - ((LogEventWrapper) event).setData(new byte[]{}); - ((LogEventWrapper) event).setEventSignature(""); - ((LogEventWrapper) event).setAbiEntry(Entry.newBuilder().setName("testABI").build()); - event.setBlockNumber(new Long(123)); + event.setTopicList(addressList); + event.setData(new byte[]{}); + event.setEventSignature(""); + event.setAbiEntry(Entry.newBuilder().setName("testABI").build()); + event.setBlockNumber(123L); ContractEventTriggerCapsule capsule = new ContractEventTriggerCapsule(event); + capsule.setContractEventTrigger(capsule.getContractEventTrigger()); capsule.getContractEventTrigger().setContractAddress("address1"); + capsule.setLatestSolidifiedBlockNumber(0L); + capsule.setData(capsule.getData()); + capsule.setTopicList(capsule.getTopicList()); + capsule.setAbiEntry(capsule.getAbiEntry()); capsule.getContractEventTrigger().setTopicMap(topMap); { - Assert.assertEquals(true, matchFilter(capsule.getContractEventTrigger())); + Assert.assertTrue(matchFilter(capsule.getContractEventTrigger())); } { @@ -64,7 +73,7 @@ public synchronized void testMatchFilter() { filterQuery.setFromBlock(1); filterQuery.setToBlock(100); EventPluginLoader.getInstance().setFilterQuery(filterQuery); - Assert.assertEquals(false, matchFilter(capsule.getContractEventTrigger())); + Assert.assertFalse(matchFilter(capsule.getContractEventTrigger())); } { @@ -72,17 +81,32 @@ public synchronized void testMatchFilter() { filterQuery.setFromBlock(133); filterQuery.setToBlock(190); EventPluginLoader.getInstance().setFilterQuery(filterQuery); - Assert.assertEquals(false, matchFilter(capsule.getContractEventTrigger())); + Assert.assertFalse(matchFilter(capsule.getContractEventTrigger())); } { FilterQuery filterQuery = new FilterQuery(); filterQuery.setFromBlock(100); filterQuery.setToBlock(190); - filterQuery.setContractAddressList(Arrays.asList(addrList)); + filterQuery.setContractAddressList(Arrays.asList(adrList)); filterQuery.setContractTopicList(Arrays.asList(topList)); EventPluginLoader.getInstance().setFilterQuery(filterQuery); - Assert.assertEquals(true, matchFilter(capsule.getContractEventTrigger())); + Assert.assertTrue(matchFilter(capsule.getContractEventTrigger())); + capsule.processTrigger(); + } + + FilterTriggerCapsule filterTriggerCapsule = new FilterTriggerCapsule(); + try { + filterTriggerCapsule.processFilterTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + + TriggerCapsule triggerCapsule = new TriggerCapsule(); + try { + triggerCapsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); } } } diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockFilterCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockFilterCapsuleTest.java new file mode 100644 index 00000000000..5381c6ab2de --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockFilterCapsuleTest.java @@ -0,0 +1,38 @@ +package org.tron.common.logsfilter.capsule; + +import com.google.protobuf.ByteString; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.utils.Sha256Hash; +import org.tron.core.capsule.BlockCapsule; + +public class BlockFilterCapsuleTest { + + private BlockFilterCapsule blockFilterCapsule; + + @Before + public void setUp() { + BlockCapsule blockCapsule = new BlockCapsule(1, Sha256Hash.ZERO_HASH, + System.currentTimeMillis(), ByteString.EMPTY); + blockFilterCapsule = new BlockFilterCapsule(blockCapsule, false); + } + + @Test + public void testSetAndGetBlockHash() { + blockFilterCapsule + .setBlockHash("e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"); + System.out.println(blockFilterCapsule); + Assert.assertEquals("e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f", + blockFilterCapsule.getBlockHash()); + } + + @Test + public void testSetAndIsSolidified() { + blockFilterCapsule = new BlockFilterCapsule( + "e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f", false); + blockFilterCapsule.setSolidified(true); + blockFilterCapsule.processFilterTrigger(); + Assert.assertTrue(blockFilterCapsule.isSolidified()); + } +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockLogTriggerCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockLogTriggerCapsuleTest.java new file mode 100644 index 00000000000..fcb125349c5 --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/BlockLogTriggerCapsuleTest.java @@ -0,0 +1,35 @@ +package org.tron.common.logsfilter.capsule; + +import com.google.protobuf.ByteString; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.utils.Sha256Hash; +import org.tron.core.capsule.BlockCapsule; + +public class BlockLogTriggerCapsuleTest { + + private BlockLogTriggerCapsule blockLogTriggerCapsule; + + @Before + public void setUp() { + BlockCapsule blockCapsule = new BlockCapsule(1, Sha256Hash.ZERO_HASH, + System.currentTimeMillis(), ByteString.EMPTY); + blockLogTriggerCapsule = new BlockLogTriggerCapsule(blockCapsule); + } + + @Test + public void testSetAndGetBlockLogTrigger() { + blockLogTriggerCapsule + .setBlockLogTrigger(blockLogTriggerCapsule.getBlockLogTrigger()); + Assert.assertEquals(1, + blockLogTriggerCapsule.getBlockLogTrigger().getBlockNumber()); + } + + @Test + public void testSetLatestSolidifiedBlockNumber() { + blockLogTriggerCapsule.setLatestSolidifiedBlockNumber(0); + Assert.assertEquals(0, + blockLogTriggerCapsule.getBlockLogTrigger().getLatestSolidifiedBlockNumber()); + } +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractLogTriggerCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractLogTriggerCapsuleTest.java new file mode 100644 index 00000000000..de17154cacd --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractLogTriggerCapsuleTest.java @@ -0,0 +1,35 @@ +package org.tron.common.logsfilter.capsule; + +import static org.junit.Assert.assertEquals; +import static org.tron.common.logsfilter.trigger.Trigger.CONTRACTLOG_TRIGGER_NAME; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.trigger.ContractLogTrigger; + +@Slf4j +public class ContractLogTriggerCapsuleTest { + + private ContractLogTriggerCapsule capsule; + + @Before + public void setUp() { + ContractLogTrigger contractLogTrigger = new ContractLogTrigger(); + contractLogTrigger.setBlockNumber(0L); + capsule = new ContractLogTriggerCapsule(contractLogTrigger); + capsule.setLatestSolidifiedBlockNumber(0); + } + + @Test + public void testSetAndGetContractLogTrigger() { + capsule.setContractLogTrigger(capsule.getContractLogTrigger()); + assertEquals(CONTRACTLOG_TRIGGER_NAME, capsule.getContractLogTrigger().getTriggerName()); + try { + capsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractTriggerCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractTriggerCapsuleTest.java new file mode 100644 index 00000000000..9541977656b --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/ContractTriggerCapsuleTest.java @@ -0,0 +1,52 @@ +package org.tron.common.logsfilter.capsule; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.trigger.ContractTrigger; +import org.tron.common.runtime.vm.LogInfo; + +@Slf4j +public class ContractTriggerCapsuleTest { + + private ContractTriggerCapsule capsule; + + @Before + public void setUp() { + ContractTrigger contractTrigger = new ContractTrigger(); + contractTrigger.setBlockNumber(0L); + contractTrigger.setRemoved(false); + LogInfo logInfo = + new LogInfo(bytesToAddress(new byte[] {0x11}), new ArrayList<>(), new byte[0]); + contractTrigger.setLogInfo(logInfo); + contractTrigger.setRawData(new RawData(null, null, null)); + contractTrigger.setAbi(contractTrigger.getAbi()); + capsule = new ContractTriggerCapsule(contractTrigger); + + } + + private byte[] bytesToAddress(byte[] address) { + byte[] data = new byte[20]; + System.arraycopy(address, 0, data, 20 - address.length, address.length); + return data; + } + + @Test + public void testSetAndGetContractTrigger() { + capsule.setContractTrigger(capsule.getContractTrigger()); + capsule.setBlockHash("e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f"); + capsule.setLatestSolidifiedBlockNumber(0); + assertEquals(0, capsule.getContractTrigger().getLatestSolidifiedBlockNumber()); + assertEquals("e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f", + capsule.getContractTrigger().getBlockHash()); + try { + capsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/LogsFilterCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/LogsFilterCapsuleTest.java new file mode 100644 index 00000000000..691a3106b49 --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/LogsFilterCapsuleTest.java @@ -0,0 +1,33 @@ +package org.tron.common.logsfilter.capsule; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.bloom.Bloom; + +public class LogsFilterCapsuleTest { + + private LogsFilterCapsule capsule; + + @Before + public void setUp() { + capsule = new LogsFilterCapsule(0, + "e58f33f9baf9305dc6f82b9f1934ea8f0ade2defb951258d50167028c780351f", + new Bloom(), new ArrayList<>(), true, false); + } + + @Test + public void testSetAndGetLogsFilterCapsule() { + capsule.setBlockNumber(capsule.getBlockNumber()); + capsule.setBlockHash(capsule.getBlockHash()); + capsule.setSolidified(capsule.isSolidified()); + capsule.setBloom(capsule.getBloom()); + capsule.setRemoved(capsule.isRemoved()); + capsule.setTxInfoList(capsule.getTxInfoList()); + assertNotNull(capsule.toString()); + capsule.processFilterTrigger(); + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/RawDataTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/RawDataTest.java new file mode 100644 index 00000000000..c14afcd903b --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/RawDataTest.java @@ -0,0 +1,33 @@ +package org.tron.common.logsfilter.capsule; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.tron.common.runtime.vm.DataWord; + +public class RawDataTest { + @Test + public void testRawDataConstructor() { + byte[] addressBytes = {0x01, 0x02, 0x03, 0x04}; + byte[] dataBytes = {0x10, 0x20, 0x30, 0x40}; + List topics = Arrays.asList( + new DataWord("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + new DataWord("0000000000000000000000000000000000000000000000000000000000000001")); + + RawData rawData = new RawData(addressBytes, topics, dataBytes); + + assertEquals("01020304", rawData.getAddress()); + assertEquals(topics, rawData.getTopics()); + assertEquals("10203040", rawData.getData()); + + rawData = new RawData(null, null, null); + assertEquals("", rawData.getAddress()); + assertTrue(rawData.getTopics().isEmpty()); + assertEquals("", rawData.getData()); + assertNotNull(rawData.toString()); + } +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityEventCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityEventCapsuleTest.java new file mode 100644 index 00000000000..1d257e92ee5 --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityEventCapsuleTest.java @@ -0,0 +1,29 @@ +package org.tron.common.logsfilter.capsule; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.trigger.ContractEventTrigger; + +@Slf4j +public class SolidityEventCapsuleTest { + + private SolidityEventCapsule capsule; + + @Before + public void setUp() { + ContractEventTrigger contractEventTrigger = new ContractEventTrigger(); + capsule = new SolidityEventCapsule(contractEventTrigger); + } + + @Test + public void testSetAndGetSolidityEventCapsule() { + capsule.setSolidityEventTrigger(capsule.getSolidityEventTrigger()); + try { + capsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityLogCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityLogCapsuleTest.java new file mode 100644 index 00000000000..30e186548dc --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityLogCapsuleTest.java @@ -0,0 +1,29 @@ +package org.tron.common.logsfilter.capsule; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.trigger.ContractLogTrigger; + +@Slf4j +public class SolidityLogCapsuleTest { + + private SolidityLogCapsule capsule; + + @Before + public void setUp() { + ContractLogTrigger trigger = new ContractLogTrigger(); + capsule = new SolidityLogCapsule(trigger); + } + + @Test + public void testSetAndGetSolidityLogCapsule() { + capsule.setSolidityLogTrigger(capsule.getSolidityLogTrigger()); + try { + capsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityTriggerCapsuleTest.java b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityTriggerCapsuleTest.java new file mode 100644 index 00000000000..a3d6b494a13 --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/capsule/SolidityTriggerCapsuleTest.java @@ -0,0 +1,36 @@ +package org.tron.common.logsfilter.capsule; + +import static org.junit.Assert.assertNotNull; + +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.trigger.SolidityTrigger; + +@Slf4j +public class SolidityTriggerCapsuleTest { + + private SolidityTriggerCapsule capsule; + + @Before + public void setUp() { + capsule = new SolidityTriggerCapsule(0); + SolidityTrigger trigger = new SolidityTrigger(); + assertNotNull(trigger.toString()); + capsule.setSolidityTrigger(trigger); + capsule.setTimeStamp(System.currentTimeMillis()); + } + + @Test + public void testSetAndGetSolidityLogCapsule() { + capsule.setSolidityTrigger(capsule.getSolidityTrigger()); + capsule.setTimeStamp(capsule.getSolidityTrigger().getTimeStamp()); + try { + capsule.processTrigger(); + } catch (Exception e) { + logger.info(e.getMessage()); + } + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/trigger/ContractLogTriggerTest.java b/framework/src/test/java/org/tron/common/logsfilter/trigger/ContractLogTriggerTest.java new file mode 100644 index 00000000000..8d6e044c134 --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/trigger/ContractLogTriggerTest.java @@ -0,0 +1,82 @@ +package org.tron.common.logsfilter.trigger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.logsfilter.capsule.RawData; +import org.tron.common.runtime.vm.DataWord; + +public class ContractLogTriggerTest { + private ContractEventTrigger mockEventTrigger; + + @Before + public void setUp() { + mockEventTrigger = new ContractEventTrigger(); + byte[] addressBytes = {0x01, 0x02, 0x03, 0x04}; + byte[] dataBytes = {0x10, 0x20, 0x30, 0x40}; + List topics = Arrays.asList( + new DataWord("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"), + new DataWord("0000000000000000000000000000000000000000000000000000000000000001")); + + RawData rawData = new RawData(addressBytes, topics, dataBytes); + mockEventTrigger.setRawData(rawData); + mockEventTrigger.setLatestSolidifiedBlockNumber(12345L); + mockEventTrigger.setRemoved(false); + mockEventTrigger.setUniqueId("unique-id"); + mockEventTrigger.setTransactionId("tx-id"); + mockEventTrigger.setContractAddress("contract-addr"); + mockEventTrigger.setOriginAddress("origin-addr"); + mockEventTrigger.setCreatorAddress("creator-addr"); + mockEventTrigger.setBlockNumber(67890L); + mockEventTrigger.setTimeStamp(1622547200L); + mockEventTrigger.setBlockHash("block-hash"); + } + + @Test + public void testDefaultConstructor() { + ContractLogTrigger trigger = new ContractLogTrigger(); + assertEquals(Trigger.CONTRACTLOG_TRIGGER_NAME, trigger.getTriggerName()); + assertNull(trigger.getTopicList()); + assertNull(trigger.getData()); + } + + @Test + public void testConstructorWithEventTrigger() { + ContractLogTrigger trigger = new ContractLogTrigger(mockEventTrigger); + assertEquals(Trigger.CONTRACTLOG_TRIGGER_NAME, trigger.getTriggerName()); + assertEquals(mockEventTrigger.getRawData(), trigger.getRawData()); + assertEquals(mockEventTrigger.getLatestSolidifiedBlockNumber(), + trigger.getLatestSolidifiedBlockNumber()); + assertEquals(mockEventTrigger.isRemoved(), trigger.isRemoved()); + assertEquals(mockEventTrigger.getUniqueId(), trigger.getUniqueId()); + assertEquals(mockEventTrigger.getTransactionId(), trigger.getTransactionId()); + assertEquals(mockEventTrigger.getContractAddress(), trigger.getContractAddress()); + assertEquals(mockEventTrigger.getOriginAddress(), trigger.getOriginAddress()); + assertEquals("", trigger.getCallerAddress()); // Explicitly set to empty string + assertEquals(mockEventTrigger.getCreatorAddress(), trigger.getCreatorAddress()); + assertEquals(mockEventTrigger.getBlockNumber(), trigger.getBlockNumber()); + assertEquals(mockEventTrigger.getTimeStamp(), trigger.getTimeStamp()); + assertEquals(mockEventTrigger.getBlockHash(), trigger.getBlockHash()); + } + + @Test + public void testSetAndGetTopicList() { + ContractLogTrigger trigger = new ContractLogTrigger(); + List topics = Arrays.asList("topic1", "topic2"); + trigger.setTopicList(topics); + assertEquals(topics, trigger.getTopicList()); + } + + @Test + public void testSetAndGetData() { + ContractLogTrigger trigger = new ContractLogTrigger(); + String testData = "log data"; + trigger.setData(testData); + assertEquals(testData, trigger.getData()); + } + +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/trigger/InternalTransactionPojoTest.java b/framework/src/test/java/org/tron/common/logsfilter/trigger/InternalTransactionPojoTest.java new file mode 100644 index 00000000000..9948c5535af --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/trigger/InternalTransactionPojoTest.java @@ -0,0 +1,87 @@ +package org.tron.common.logsfilter.trigger; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; + +public class InternalTransactionPojoTest { + private InternalTransactionPojo internalTransactionPojo; + + @Before + public void setUp() { + internalTransactionPojo = new InternalTransactionPojo(); + } + + @Test + public void testHash() { + String testHash = "0x123456789abcdef0123456789abcdef0"; + internalTransactionPojo.setHash(testHash); + assertEquals(testHash, internalTransactionPojo.getHash()); + } + + @Test + public void testCallValue() { + long testCallValue = 123456789L; + internalTransactionPojo.setCallValue(testCallValue); + assertEquals(testCallValue, internalTransactionPojo.getCallValue()); + } + + @Test + public void testTokenInfo() { + Map testTokenInfo = new HashMap<>(); + testTokenInfo.put("token1", 100L); + testTokenInfo.put("token2", 200L); + internalTransactionPojo.setTokenInfo(testTokenInfo); + assertEquals(testTokenInfo, internalTransactionPojo.getTokenInfo()); + } + + @Test + public void testTransferToAddress() { + String testAddress = "0x0000000000000000000000000000000000000001"; + internalTransactionPojo.setTransferTo_address(testAddress); + assertEquals(testAddress, internalTransactionPojo.getTransferTo_address()); + } + + @Test + public void testData() { + String testData = "0x6060604052341561000f57600080fd5b5b6040516020806101158339810160405280805" + + "19060200190929190505050"; + internalTransactionPojo.setData(testData); + assertEquals(testData, internalTransactionPojo.getData()); + } + + @Test + public void testCallerAddress() { + String testCallerAddress = "0x0000000000000000000000000000000000000002"; + internalTransactionPojo.setCaller_address(testCallerAddress); + assertEquals(testCallerAddress, internalTransactionPojo.getCaller_address()); + } + + @Test + public void testRejected() { + internalTransactionPojo.setRejected(true); + assertTrue(internalTransactionPojo.isRejected()); + + internalTransactionPojo.setRejected(false); + assertFalse(internalTransactionPojo.isRejected()); + } + + @Test + public void testNote() { + String testNote = "This is a test note"; + internalTransactionPojo.setNote(testNote); + assertEquals(testNote, internalTransactionPojo.getNote()); + } + + @Test + public void testExtra() { + String testExtra = "extra_data_for_vote_witness"; + internalTransactionPojo.setExtra(testExtra); + assertEquals(testExtra, internalTransactionPojo.getExtra()); + } +} diff --git a/framework/src/test/java/org/tron/common/logsfilter/trigger/LogPojoTest.java b/framework/src/test/java/org/tron/common/logsfilter/trigger/LogPojoTest.java new file mode 100644 index 00000000000..7c94ec4f7ad --- /dev/null +++ b/framework/src/test/java/org/tron/common/logsfilter/trigger/LogPojoTest.java @@ -0,0 +1,74 @@ +package org.tron.common.logsfilter.trigger; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.List; +import org.junit.Before; +import org.junit.Test; + +public class LogPojoTest { + + private LogPojo logPojo; + + @Before + public void setUp() { + logPojo = new LogPojo(); + } + + @Test + public void testAddress() { + String testAddress = "123 Test Address"; + logPojo.setAddress(testAddress); + assertEquals(testAddress, logPojo.getAddress()); + } + + @Test + public void testBlockHash() { + String testBlockHash = "abcdef1234567890abcdef1234567890abcdef12"; + logPojo.setBlockHash(testBlockHash); + assertEquals(testBlockHash, logPojo.getBlockHash()); + } + + @Test + public void testBlockNumber() { + long testBlockNumber = 1234567L; + logPojo.setBlockNumber(testBlockNumber); + assertEquals(testBlockNumber, logPojo.getBlockNumber()); + } + + @Test + public void testData() { + String testData = "Some data here"; + logPojo.setData(testData); + assertEquals(testData, logPojo.getData()); + } + + @Test + public void testLogIndex() { + long testLogIndex = 5L; + logPojo.setLogIndex(testLogIndex); + assertEquals(testLogIndex, logPojo.getLogIndex()); + } + + @Test + public void testTopicList() { + List testTopicList = Arrays.asList("topic1", "topic2", "topic3"); + logPojo.setTopicList(testTopicList); + assertEquals(testTopicList, logPojo.getTopicList()); + } + + @Test + public void testTransactionHash() { + String testTransactionHash = "abcdef1234567890abcdef1234567890abcdef12"; + logPojo.setTransactionHash(testTransactionHash); + assertEquals(testTransactionHash, logPojo.getTransactionHash()); + } + + @Test + public void testTransactionIndex() { + long testTransactionIndex = 3L; + logPojo.setTransactionIndex(testTransactionIndex); + assertEquals(testTransactionIndex, logPojo.getTransactionIndex()); + } +} diff --git a/framework/src/test/java/org/tron/common/zksnark/ZksnarkClientTest.java b/framework/src/test/java/org/tron/common/zksnark/ZksnarkClientTest.java new file mode 100644 index 00000000000..21275d548a0 --- /dev/null +++ b/framework/src/test/java/org/tron/common/zksnark/ZksnarkClientTest.java @@ -0,0 +1,43 @@ +package org.tron.common.zksnark; + +import static org.junit.Assert.assertThrows; + +import com.google.protobuf.Any; +import com.google.protobuf.ByteString; +import io.grpc.StatusRuntimeException; +import java.nio.charset.StandardCharsets; +import org.junit.Before; +import org.junit.Test; +import org.tron.common.utils.ByteArray; +import org.tron.protos.Protocol.Transaction; +import org.tron.protos.contract.BalanceContract; + +public class ZksnarkClientTest { + + public ZksnarkClient zksnarkClient; + + @Before + public void setUp() { + zksnarkClient = ZksnarkClient.getInstance(); + } + + @Test + public void testCheckZksnarkProof() { + BalanceContract.TransferContract transferContract = + BalanceContract.TransferContract.newBuilder() + .setAmount(10) + .setOwnerAddress(ByteString.copyFromUtf8("aaa")) + .setToAddress(ByteString.copyFromUtf8("bbb")) + .build(); + Transaction transaction = Transaction.newBuilder().setRawData(Transaction.raw.newBuilder() + .setData(ByteString.copyFrom("transfer".getBytes(StandardCharsets.UTF_8))) + .addContract(Transaction.Contract.newBuilder().setParameter(Any.pack(transferContract)) + .setType(Transaction.Contract.ContractType.TransferContract))) + .addRet(Transaction.Result.newBuilder().setAssetIssueID("1234567").build()).build(); + byte[] b = ByteArray + .fromHexString("ded9c2181fd7ea468a7a7b1475defe90bb0fc0ca8d0f2096b0617465cea6568c"); + assertThrows(StatusRuntimeException.class, () -> zksnarkClient.checkZksnarkProof(transaction, b, + 10000L)); + } + +} \ No newline at end of file diff --git a/framework/src/test/java/org/tron/core/CoreExceptionTest.java b/framework/src/test/java/org/tron/core/CoreExceptionTest.java new file mode 100644 index 00000000000..90946f8d1aa --- /dev/null +++ b/framework/src/test/java/org/tron/core/CoreExceptionTest.java @@ -0,0 +1,1162 @@ +package org.tron.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.tron.core.exception.BadBlockException.TypeEnum.CALC_MERKLE_ROOT_FAILED; +import static org.tron.core.exception.BadBlockException.TypeEnum.DEFAULT; +import static org.tron.core.exception.P2pException.TypeEnum.NO_SUCH_MESSAGE; +import static org.tron.core.exception.P2pException.TypeEnum.PARSE_MESSAGE_FAILED; +import static org.tron.core.exception.P2pException.TypeEnum.SYNC_FAILED; + +import org.junit.Test; +import org.tron.common.error.TronDBException; +import org.tron.core.exception.AccountResourceInsufficientException; +import org.tron.core.exception.BadBlockException; +import org.tron.core.exception.BadItemException; +import org.tron.core.exception.BadNumberBlockException; +import org.tron.core.exception.BadTransactionException; +import org.tron.core.exception.BalanceInsufficientException; +import org.tron.core.exception.CancelException; +import org.tron.core.exception.CipherException; +import org.tron.core.exception.ContractExeException; +import org.tron.core.exception.ContractSizeNotEqualToOneException; +import org.tron.core.exception.ContractValidateException; +import org.tron.core.exception.DupTransactionException; +import org.tron.core.exception.EventBloomException; +import org.tron.core.exception.HeaderNotFound; +import org.tron.core.exception.HighFreqException; +import org.tron.core.exception.ItemNotFoundException; +import org.tron.core.exception.JsonRpcInternalException; +import org.tron.core.exception.JsonRpcInvalidParamsException; +import org.tron.core.exception.JsonRpcInvalidRequestException; +import org.tron.core.exception.JsonRpcMethodNotFoundException; +import org.tron.core.exception.JsonRpcTooManyResultException; +import org.tron.core.exception.NonCommonBlockException; +import org.tron.core.exception.NonUniqueObjectException; +import org.tron.core.exception.P2pException; +import org.tron.core.exception.PermissionException; +import org.tron.core.exception.ReceiptCheckErrException; +import org.tron.core.exception.RevokingStoreIllegalStateException; +import org.tron.core.exception.SignatureFormatException; +import org.tron.core.exception.StoreException; +import org.tron.core.exception.TaposException; +import org.tron.core.exception.TooBigTransactionException; +import org.tron.core.exception.TooBigTransactionResultException; +import org.tron.core.exception.TraitorPeerException; +import org.tron.core.exception.TransactionExpirationException; +import org.tron.core.exception.TronRuntimeException; +import org.tron.core.exception.TypeMismatchNamingException; +import org.tron.core.exception.UnLinkedBlockException; +import org.tron.core.exception.UnReachBlockException; +import org.tron.core.exception.VMIllegalException; +import org.tron.core.exception.ValidateScheduleException; +import org.tron.core.exception.ValidateSignatureException; +import org.tron.core.exception.ZkProofValidateException; +import org.tron.core.exception.ZksnarkException; + +public class CoreExceptionTest { + + @Test + public void testAccountResourceInsufficientExceptionMessage() { + String expectedMessage = "Account resources are insufficient"; + AccountResourceInsufficientException exception = + new AccountResourceInsufficientException(expectedMessage); + + assertEquals(expectedMessage, exception.getMessage()); + } + + @Test + public void testBadBlockExceptionWithNoMessageAndDefaultType() { + BadBlockException exception = new BadBlockException(); + + assertNull(exception.getMessage()); + + assertEquals(DEFAULT, exception.getType()); + } + + @Test + public void testBadBlockExceptionWithMessageAndDefaultType() { + String testMessage = "Block is bad due to some reason"; + + BadBlockException exception = new BadBlockException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + + assertEquals(DEFAULT, exception.getType()); + } + + @Test + public void testBadBlockExceptionWithSpecificTypeAndMessage() { + String testMessage = "Failed to calculate Merkle root"; + + BadBlockException exception = new BadBlockException(CALC_MERKLE_ROOT_FAILED, testMessage); + + assertEquals(testMessage, exception.getMessage()); + + assertEquals(CALC_MERKLE_ROOT_FAILED, exception.getType()); + } + + @Test + public void testTypeEnumValues() { + assertEquals(Integer.valueOf(1), CALC_MERKLE_ROOT_FAILED.getValue()); + + assertEquals(Integer.valueOf(100), DEFAULT.getValue()); + } + + @Test + public void testBadItemExceptionDefaultConstructor() { + BadItemException exception = new BadItemException(); + assertNotNull(exception); + } + + @Test + public void testBadItemExceptionMessageConstructor() { + String expectedMessage = "This item is bad!"; + BadItemException exception = new BadItemException(expectedMessage); + assertEquals(expectedMessage, exception.getMessage()); + assertNull(exception.getCause()); + assertNotNull(exception); + } + + @Test + public void testBadItemExceptionMessageAndCauseConstructor() { + String expectedMessage = "This item is really bad!"; + Throwable expectedCause = new Throwable("Some underlying cause"); + BadItemException exception = new BadItemException(expectedMessage, expectedCause); + assertEquals(expectedMessage, exception.getMessage()); + assertEquals(expectedCause, exception.getCause()); + assertNotNull(exception); + } + + @Test + public void testBadNumberBlockExceptionDefaultConstructor() { + BadNumberBlockException exception = new BadNumberBlockException(); + assertNull(exception.getMessage()); + assertNotNull(exception); + } + + @Test + public void testBadNumberBlockExceptionMessageConstructor() { + String expectedMessage = "Number block is bad!"; + BadNumberBlockException exception = new BadNumberBlockException(expectedMessage); + assertEquals(expectedMessage, exception.getMessage()); + assertNotNull(exception); + } + + @Test + public void testBadTransactionExceptionDefaultConstructor() { + BadTransactionException exception = new BadTransactionException(); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + assertNotNull(exception); + } + + @Test + public void testBadTransactionExceptionMessageConstructor() { + String expectedMessage = "Transaction is bad!"; + BadTransactionException exception = new BadTransactionException(expectedMessage); + + assertEquals(expectedMessage, exception.getMessage()); + + assertNull(exception.getCause()); + + assertNotNull(exception); + } + + @Test + public void testBadTransactionExceptionMessageAndCauseConstructor() { + String expectedMessage = "Transaction failed due to an error"; + Throwable cause = new IllegalArgumentException("Invalid transaction data"); + + BadTransactionException exception = new BadTransactionException(expectedMessage, cause); + + assertEquals(expectedMessage, exception.getMessage()); + + assertEquals(cause, exception.getCause()); + + assertNotNull(exception); + } + + @Test + public void testBalanceInsufficientExceptionWithNoMessage() { + BalanceInsufficientException exception = new BalanceInsufficientException(); + assertNull(exception.getMessage()); + } + + @Test + public void testBalanceInsufficientExceptionWithMessage() { + String testMessage = "Balance is insufficient for this transaction"; + BalanceInsufficientException exception = new BalanceInsufficientException(testMessage); + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testCancelExceptionWithNoMessage() { + CancelException exception = new CancelException(); + + assertNull(exception.getMessage()); + } + + @Test + public void testCancelExceptionWithMessage() { + String testMessage = "Operation canceled by user"; + + CancelException exception = new CancelException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testCipherExceptionWithMessage() { + String testMessage = "Cipher operation failed"; + + CipherException exception = new CipherException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + + assertNull(exception.getCause()); + } + + @Test + public void testCipherExceptionWithCause() { + Throwable testCause = new Throwable("Underlying error"); + + CipherException exception = new CipherException(testCause); + + assertSame(testCause, exception.getCause()); + + } + + @Test + public void testCipherExceptionWithMessageAndCause() { + String testMessage = "Cipher operation failed due to error"; + + Throwable testCause = new Throwable("Underlying error"); + CipherException exception = new CipherException(testMessage, testCause); + + assertEquals(testMessage, exception.getMessage()); + + assertSame(testCause, exception.getCause()); + } + + @Test + public void testContractExeExceptionWithNoMessage() { + ContractExeException exception = new ContractExeException(); + + assertNull(exception.getMessage()); + } + + @Test + public void testContractExeExceptionWithMessage() { + String testMessage = "Contract execution failed"; + + ContractExeException exception = new ContractExeException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testContractSizeNotEqualToOneExceptionWithNoMessage() { + ContractSizeNotEqualToOneException exception = new ContractSizeNotEqualToOneException(); + + assertNull(exception.getMessage()); + } + + @Test + public void testContractSizeNotEqualToOneExceptionWithMessage() { + String testMessage = "Contract size is not equal to one"; + + ContractSizeNotEqualToOneException exception = + new ContractSizeNotEqualToOneException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testContractValidateExceptionWithNoMessageOrThrowable() { + ContractValidateException exception = new ContractValidateException(); + + assertNull(exception.getMessage()); + + assertNull(exception.getCause()); + } + + @Test + public void testContractValidateExceptionWithMessage() { + String testMessage = "Contract validation failed"; + + ContractValidateException exception = new ContractValidateException(testMessage); + + assertEquals(testMessage, exception.getMessage()); + + assertNull(exception.getCause()); + } + + @Test + public void testContractValidateExceptionWithMessageAndThrowable() { + String testMessage = "Contract validation failed due to internal error"; + + Throwable cause = new RuntimeException("Internal error"); + + ContractValidateException exception = new ContractValidateException(testMessage, cause); + + assertEquals(testMessage, exception.getMessage()); + + assertSame(cause, exception.getCause()); + } + + @Test + public void testDupTransactionExceptionDefaultConstructor() { + DupTransactionException exception = new DupTransactionException(); + + assertNotNull(exception); + + } + + @Test + public void testDupTransactionExceptionMessageConstructor() { + String testMessage = "Duplicate Transaction Exception"; + DupTransactionException exception = new DupTransactionException(testMessage); + + assertNotNull(exception); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testEventBloomExceptionDefaultConstructor() { + EventBloomException exception = new EventBloomException(); + + assertNotNull(exception); + + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testEventBloomExceptionMessageConstructor() { + String testMessage = "Event Bloom Exception occurred"; + EventBloomException exception = new EventBloomException(testMessage); + + assertNotNull(exception); + + assertEquals(testMessage, exception.getMessage()); + + assertNull(exception.getCause()); + } + + @Test + public void testEventBloomExceptionMessageAndCauseConstructor() { + String testMessage = "Event Bloom Exception with cause"; + Throwable testCause = new Throwable("Root cause"); + EventBloomException exception = new EventBloomException(testMessage, testCause); + + assertNotNull(exception); + + assertEquals(testMessage, exception.getMessage()); + + assertEquals(testCause, exception.getCause()); + } + + @Test + public void testHeaderNotFoundDefaultConstructor() { + HeaderNotFound exception = new HeaderNotFound(); + + assertNotNull(exception); + + assertNull(exception.getMessage()); + } + + @Test + public void testHeaderNotFoundMessageConstructor() { + String testMessage = "Header not found"; + HeaderNotFound exception = new HeaderNotFound(testMessage); + + assertNotNull(exception); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testHighFreqExceptionDefaultConstructor() { + HighFreqException exception = new HighFreqException(); + + assertNotNull("Exception object should not be null", exception); + + assertNull("Exception message should be null", exception.getMessage()); + } + + @Test + public void testHighFreqExceptionMessageConstructor() { + String testMessage = "High frequency error occurred"; + HighFreqException exception = new HighFreqException(testMessage); + + assertNotNull("Exception object should not be null", exception); + + assertEquals("Exception message should match the provided message", + testMessage, exception.getMessage()); + } + + @Test + public void testItemNotFoundExceptionWithMessage() { + String testMessage = "Item not found"; + ItemNotFoundException exception = new ItemNotFoundException(testMessage); + + assertNotNull("Exception object should not be null", exception); + assertEquals("Exception message should match the provided message", testMessage, + exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testItemNotFoundExceptionDefaultConstructor() { + ItemNotFoundException exception = new ItemNotFoundException(); + + assertNotNull("Exception object should not be null", exception); + assertNull("Exception message should be null when no message is provided", + exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testItemNotFoundExceptionWithMessageAndCause() { + String testMessage = "Item not found in database"; + Throwable testCause = new Throwable("Database error"); + ItemNotFoundException exception = new ItemNotFoundException(testMessage, testCause); + + assertNotNull("Exception object should not be null", exception); + assertEquals("Exception message should match the provided message", + testMessage, exception.getMessage()); + assertEquals("Cause should match the provided Throwable", testCause, exception.getCause()); + } + + @Test + public void testJsonRpcInternalExceptionDefaultConstructor() { + JsonRpcInternalException exception = new JsonRpcInternalException(); + + assertNotNull("Exception object should not be null", exception); + assertNull("Exception message should be null when no message is provided", + exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testJsonRpcInternalExceptionWithMessage() { + String testMessage = "Internal JSON-RPC error occurred"; + JsonRpcInternalException exception = new JsonRpcInternalException(testMessage); + + assertNotNull("Exception object should not be null", exception); + assertEquals("Exception message should match the provided message", testMessage, + exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testJsonRpcInternalExceptionWithMessageAndCause() { + String testMessage = "Internal JSON-RPC processing failed"; + Throwable testCause = new Throwable("Underlying system error"); + JsonRpcInternalException exception = new JsonRpcInternalException(testMessage, testCause); + + assertNotNull("Exception object should not be null", exception); + assertEquals("Exception message should match the provided message", + testMessage, exception.getMessage()); + assertEquals("Cause should match the provided Throwable", testCause, exception.getCause()); + } + + @Test + public void testJsonRpcInvalidParamsExceptionDefaultConstructor() { + JsonRpcInvalidParamsException exception = new JsonRpcInvalidParamsException(); + + assertNotNull("Exception object should not be null", exception); + assertNull("Exception message should be null when no message is provided", + exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testJsonRpcInvalidParamsExceptionWithMessage() { + String testMessage = "Invalid parameters provided"; + JsonRpcInvalidParamsException exception = new JsonRpcInvalidParamsException(testMessage); + + assertNotNull("Exception object should not be null", exception); + assertEquals("Exception message should match the provided message", + testMessage, exception.getMessage()); + assertNull("Cause should be null when not provided", exception.getCause()); + } + + @Test + public void testJsonRpcInvalidParamsExceptionWithMessageAndCause() { + String testMessage = "Parameter validation failed"; + Throwable testCause = new Throwable("Underlying validation error"); + JsonRpcInvalidParamsException e = new JsonRpcInvalidParamsException(testMessage, testCause); + + assertNotNull("Exception object should not be null", e); + assertEquals("Exception message should match the provided message", testMessage, + e.getMessage()); + assertEquals("Cause should match the provided Throwable", testCause, e.getCause()); + } + + @Test + public void testJsonRpcInvalidRequestExceptionDefaultConstructor() { + JsonRpcInvalidRequestException exception = new JsonRpcInvalidRequestException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testJsonRpcInvalidRequestExceptionConstructorWithMessage() { + String testMessage = "Invalid JSON-RPC request"; + JsonRpcInvalidRequestException exception = new JsonRpcInvalidRequestException(testMessage); + assertNotNull(exception); + assertEquals(testMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testJsonRpcInvalidRequestExceptionConstructorWithMessageAndCause() { + String testMessage = "Invalid JSON-RPC request with cause"; + Throwable testCause = new Throwable("Root cause"); + JsonRpcInvalidRequestException e = new JsonRpcInvalidRequestException(testMessage, testCause); + assertNotNull(e); + assertEquals(testMessage, e.getMessage()); + assertEquals(testCause, e.getCause()); + } + + @Test + public void testJsonRpcMethodNotFoundExceptionDefaultConstructor() { + JsonRpcMethodNotFoundException exception = new JsonRpcMethodNotFoundException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testJsonRpcMethodNotFoundExceptionConstructorWithMessage() { + String testMessage = "JSON-RPC method not found"; + JsonRpcMethodNotFoundException exception = new JsonRpcMethodNotFoundException(testMessage); + assertNotNull(exception); + assertEquals(testMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testJsonRpcMethodNotFoundExceptionConstructorWithMessageAndCause() { + String testMessage = "JSON-RPC method not found with cause"; + Throwable testCause = new Throwable("Root cause"); + JsonRpcMethodNotFoundException e = new JsonRpcMethodNotFoundException(testMessage, testCause); + assertNotNull(e); + assertEquals(testMessage, e.getMessage()); + assertEquals(testCause, e.getCause()); + } + + @Test + public void testJsonRpcTooManyResultExceptionDefaultConstructor() { + JsonRpcTooManyResultException exception = new JsonRpcTooManyResultException(); + assertNotNull("Exception object should not be null", exception); + assertNull(exception.getMessage()); + assertNull("Cause should be null for default constructor", exception.getCause()); + } + + @Test + public void testJsonRpcTooManyResultExceptionWithMessage() { + String testMessage = "Too many results returned by JSON-RPC method"; + JsonRpcTooManyResultException exception = new JsonRpcTooManyResultException(testMessage); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the provided message", testMessage, exception.getMessage()); + assertNull("Cause should be null when only message is provided", exception.getCause()); + } + + @Test + public void testJsonRpcTooManyResultExceptionWithMessageAndCause() { + String testMessage = "Too many results returned with cause"; + Throwable testCause = new Throwable("Root cause"); + JsonRpcTooManyResultException e = new JsonRpcTooManyResultException(testMessage, testCause); + assertNotNull("Exception object should not be null", e); + assertEquals("Message should match the provided message", testMessage, e.getMessage()); + assertEquals("Cause should match the provided cause", testCause, e.getCause()); + } + + @Test + public void testNonCommonBlockExceptionDefaultConstructor() { + NonCommonBlockException exception = new NonCommonBlockException(); + assertNotNull("Exception object should not be null", exception); + assertNull("Message should be null for default constructor", exception.getMessage()); + assertNull("Cause should be null for default constructor", exception.getCause()); + } + + @Test + public void testNonCommonBlockExceptionWithMessage() { + String testMessage = "Block is not common"; + NonCommonBlockException exception = new NonCommonBlockException(testMessage); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the provided message", testMessage, exception.getMessage()); + assertNull("Cause should be null when only message is provided", exception.getCause()); + } + + @Test + public void testNonCommonBlockExceptionWithMessageAndCause() { + String testMessage = "Block is not common due to some error"; + Throwable testCause = new Throwable("Root cause of the error"); + NonCommonBlockException exception = new NonCommonBlockException(testMessage, testCause); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the provided message", testMessage, exception.getMessage()); + assertEquals("Cause should match the provided cause", testCause, exception.getCause()); + } + + @Test + public void testDefaultConstructor() { + NonUniqueObjectException exception = new NonUniqueObjectException(); + assertNotNull("Exception object should not be null", exception); + assertNull("Message should be null for default constructor", exception.getMessage()); + assertNull("Cause should be null for default constructor", exception.getCause()); + } + + @Test + public void testConstructorWithMessage() { + String testMessage = "Object is not unique"; + NonUniqueObjectException exception = new NonUniqueObjectException(testMessage); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the provided message", testMessage, exception.getMessage()); + assertNull("Cause should be null when only message is provided", exception.getCause()); + } + + @Test + public void testConstructorWithMessageAndCause() { + String testMessage = "Object is not unique due to a conflict"; + Throwable testCause = new Throwable("Conflict error"); + NonUniqueObjectException exception = new NonUniqueObjectException(testMessage, testCause); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the provided message", testMessage, exception.getMessage()); + assertEquals("Cause should match the provided cause", testCause, exception.getCause()); + } + + @Test + public void testConstructorWithCauseOnly() { + Throwable testCause = new Throwable("Root cause of non-uniqueness"); + NonUniqueObjectException exception = new NonUniqueObjectException(testCause); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should be empty string when only cause is provided", "", + exception.getMessage()); + assertEquals("Cause should match the provided cause", testCause, exception.getCause()); + } + + @Test + public void testConstructorWithTypeEnumAndErrMsg() { + P2pException exception = new P2pException(NO_SUCH_MESSAGE, "Test error message"); + assertNotNull("Exception should not be null", exception); + assertEquals("Error message should match", "Test error message", exception.getMessage()); + assertEquals("Exception type should be NO_SUCH_MESSAGE", NO_SUCH_MESSAGE, exception.getType()); + } + + @Test + public void testConstructorWithTypeEnumAndThrowable() { + Throwable cause = new Throwable("Cause of the error"); + P2pException exception = new P2pException(PARSE_MESSAGE_FAILED, cause); + assertNotNull("Exception should not be null", exception); + assertEquals("Cause should match", cause, exception.getCause()); + } + + @Test + public void testConstructorWithTypeEnumErrMsgAndThrowable() { + Throwable cause = new Throwable("Cause of the error"); + P2pException exception = new P2pException(SYNC_FAILED, "Test error message", cause); + assertNotNull("Exception should not be null", exception); + assertEquals("Error message should match", + "Test error message", exception.getMessage()); + assertEquals("Cause should match", cause, exception.getCause()); + assertEquals("Exception type should be SYNC_FAILED", SYNC_FAILED, exception.getType()); + } + + @Test + public void testP2pExceptionTypeEnumValues() { + assertNotNull(NO_SUCH_MESSAGE.toString()); + assertEquals("NO_SUCH_MESSAGE value should be 1", + Integer.valueOf(1), NO_SUCH_MESSAGE.getValue()); + assertEquals("NO_SUCH_MESSAGE desc should be 'no such message'", + "no such message", NO_SUCH_MESSAGE.getDesc()); + + assertEquals("DEFAULT value should be 100", Integer.valueOf(100), + P2pException.TypeEnum.DEFAULT.getValue()); + assertEquals("DEFAULT desc should be 'default exception'", + "default exception", P2pException.TypeEnum.DEFAULT.getDesc()); + } + + @Test + public void testPermissionExceptionDefaultConstructor() { + PermissionException exception = new PermissionException(); + assertNotNull(exception); + } + + @Test + public void testPermissionExceptionWithMessage() { + String errorMessage = "You do not have sufficient permissions to perform this operation"; + PermissionException exception = new PermissionException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + public void testReceiptCheckErrExceptionDefaultConstructor() { + ReceiptCheckErrException exception = new ReceiptCheckErrException(); + assertNotNull("Exception object should not be null", exception); + assertNull("Message should be null for default constructor", exception.getMessage()); + assertNull("Cause should be null for default constructor", exception.getCause()); + } + + @Test + public void testReceiptCheckErrExceptionConstructorWithMessage() { + String errorMessage = "Receipt check failed due to invalid data"; + ReceiptCheckErrException exception = new ReceiptCheckErrException(errorMessage); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the input message", errorMessage, exception.getMessage()); + assertNull("Cause should be null when only message is provided", exception.getCause()); + } + + @Test + public void testReceiptCheckErrExceptionConstructorWithMessageAndCause() { + String errorMessage = "Receipt check error"; + Throwable cause = new Throwable("Underlying database error"); + ReceiptCheckErrException exception = new ReceiptCheckErrException(errorMessage, cause); + assertNotNull("Exception object should not be null", exception); + assertEquals("Message should match the input message", errorMessage, exception.getMessage()); + assertEquals("Cause should match the input cause", cause, exception.getCause()); + } + + @Test + public void testRevokingStoreIllegalStateExceptionDefaultConstructor() { + RevokingStoreIllegalStateException exception = new RevokingStoreIllegalStateException(); + assertNotNull("Exception should not be null", exception); + assertNull("Message should be null", exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testRevokingStoreIllegalStateExceptionConstructorWithMessage() { + String errorMessage = "Invalid state for revoking store"; + RevokingStoreIllegalStateException e = new RevokingStoreIllegalStateException(errorMessage); + assertNotNull("Exception should not be null", e); + assertEquals("Message should match the input message", errorMessage, e.getMessage()); + assertNull("Cause should be null", e.getCause()); + } + + @Test + public void testRevokingStoreIllegalStateExceptionConstructorWithMessageAndCause() { + String errorMessage = "Error occurred during revocation"; + Throwable cause = new Throwable("Database connection failed"); + RevokingStoreIllegalStateException e = + new RevokingStoreIllegalStateException(errorMessage, cause); + assertNotNull("Exception should not be null", e); + assertEquals("Message should match the input message", errorMessage, e.getMessage()); + assertEquals("Cause should match the input cause", cause, e.getCause()); + } + + @Test + public void testRevokingStoreIllegalStateExceptionConstructorWithCauseOnly() { + Throwable cause = new Throwable("Unknown error"); + RevokingStoreIllegalStateException exception = new RevokingStoreIllegalStateException(cause); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should be empty string", "", exception.getMessage()); + assertEquals("Cause should match the input cause", cause, exception.getCause()); + } + + @Test + public void testRevokingStoreIllegalStateExceptionConstructorWithActiveSession() { + int activeSession = 0; + RevokingStoreIllegalStateException e = new RevokingStoreIllegalStateException(activeSession); + assertNotNull("Exception should not be null", e); + assertEquals("Message should indicate activeSession is not greater than 0", + "activeSession 0 has to be greater than 0", e.getMessage()); + } + + @Test + public void testSignatureFormatExceptionDefaultConstructor() { + SignatureFormatException exception = new SignatureFormatException(); + assertNotNull("Exception should not be null", exception); + assertNull("Message should be null", exception.getMessage()); + } + + @Test + public void testSignatureFormatExceptionWithMessage() { + String errorMessage = "Invalid signature format"; + SignatureFormatException exception = new SignatureFormatException(errorMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match the provided error message", + errorMessage, exception.getMessage()); + } + + @Test + public void testStoreExceptionDefaultConstructor() { + StoreException exception = new StoreException(); + assertNotNull("Exception should not be null", exception); + assertNull("Message should be null", exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testStoreExceptionWithMessage() { + String errorMessage = "Store error occurred"; + StoreException exception = new StoreException(errorMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match the provided error message", + errorMessage, exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testStoreExceptionWithMessageAndCause() { + String errorMessage = "Store error occurred"; + Throwable cause = new Throwable("Root cause"); + StoreException exception = new StoreException(errorMessage, cause); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match the provided error message", + errorMessage, exception.getMessage()); + assertEquals("Cause should match the provided cause", cause, exception.getCause()); + } + + @Test + public void testStoreExceptionWithCause() { + Throwable cause = new Throwable("Root cause"); + StoreException exception = new StoreException(cause); + assertNotNull("Exception should not be null", exception); + } + + + @Test + public void testTaposExceptionDefaultConstructor() { + TaposException exception = new TaposException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTaposExceptionWithMessage() { + String errorMessage = "Tapos error occurred"; + TaposException exception = new TaposException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTaposExceptionWithMessageAndCause() { + String errorMessage = "Tapos error occurred"; + Throwable cause = new Throwable("Root cause"); + TaposException exception = new TaposException(errorMessage, cause); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertEquals(cause, exception.getCause()); + } + + @Test + public void testTooBigTransactionExceptionDefaultConstructor() { + TooBigTransactionException exception = new TooBigTransactionException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + } + + @Test + public void testTooBigTransactionExceptionWithMessage() { + String errorMessage = "Transaction is too big"; + TooBigTransactionException exception = new TooBigTransactionException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + public void testTooBigTransactionResultExceptionDefaultConstructor() { + TooBigTransactionResultException exception = new TooBigTransactionResultException(); + assertNotNull(exception); + assertEquals("too big transaction result", + exception.getMessage()); + } + + @Test + public void testTooBigTransactionResultExceptionWithMessage() { + String customMessage = "Custom error message for too big transaction result"; + TooBigTransactionResultException e = new TooBigTransactionResultException(customMessage); + assertNotNull(e); + assertEquals(customMessage, e.getMessage()); + } + + @Test + public void testTraitorPeerExceptionDefaultConstructor() { + TraitorPeerException exception = new TraitorPeerException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTraitorPeerExceptionWithMessage() { + String errorMessage = "Peer is a traitor"; + TraitorPeerException exception = new TraitorPeerException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTraitorPeerExceptionWithMessageAndCause() { + String errorMessage = "Peer is a traitor and caused an error"; + Throwable cause = new Throwable("Underlying cause"); + TraitorPeerException exception = new TraitorPeerException(errorMessage, cause); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertEquals(cause, exception.getCause()); + } + + @Test + public void testTransactionExpirationExceptionDefaultConstructor() { + TransactionExpirationException exception = new TransactionExpirationException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + } + + @Test + public void testTransactionExpirationExceptionWithMessage() { + String errorMessage = "Transaction has expired"; + TransactionExpirationException exception = new TransactionExpirationException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + public void testTronRuntimeExceptionDefaultConstructor() { + TronRuntimeException exception = new TronRuntimeException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTronRuntimeExceptionWithMessage() { + String errorMessage = "An error occurred"; + TronRuntimeException exception = new TronRuntimeException(errorMessage); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testTronRuntimeExceptionWithMessageAndCause() { + String errorMessage = "An error occurred due to a cause"; + Throwable cause = new Throwable("Underlying cause"); + TronRuntimeException exception = new TronRuntimeException(errorMessage, cause); + assertNotNull(exception); + assertEquals(errorMessage, exception.getMessage()); + assertEquals(cause, exception.getCause()); + } + + @Test + public void testTronRuntimeExceptionWithCause() { + Throwable cause = new Throwable("Underlying cause without message"); + TronRuntimeException exception = new TronRuntimeException(cause); + assertEquals(cause, exception.getCause()); + } + + @Test + public void testTypeMismatchNamingException_WithRequiredAndActualTypes() { + try { + throw new TypeMismatchNamingException("someName", String.class, Integer.class); + } catch (TypeMismatchNamingException e) { + assertEquals("Object of type [class java.lang.Integer] available at store location " + + "[someName] is not assignable to [java.lang.String]", e.getMessage()); + assertEquals(String.class, e.getRequiredType()); + assertEquals(Integer.class, e.getActualType()); + } + } + + @Test + public void testTypeMismatchNamingException_WithExplanation() { + try { + throw new TypeMismatchNamingException("Custom explanation"); + } catch (TypeMismatchNamingException e) { + assertEquals("Custom explanation", e.getMessage()); + assertNull(e.getRequiredType()); + assertNull(e.getActualType()); + } + } + + @Test + public void testUnLinkedBlockExceptionDefaultConstructor() { + UnLinkedBlockException exception = new UnLinkedBlockException(); + assertNotNull("Exception should not be null", exception); + assertNull(exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testUnLinkedBlockExceptionWithMessage() { + String testMessage = "This block is not linked"; + UnLinkedBlockException exception = new UnLinkedBlockException(testMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testUnLinkedBlockExceptionWithMessageAndCause() { + String testMessage = "This block is not linked due to an error"; + Throwable testCause = new Throwable("Cause of the error"); + UnLinkedBlockException exception = new UnLinkedBlockException(testMessage, testCause); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertEquals("Cause should match", testCause, exception.getCause()); + } + + @Test + public void testUnReachBlockExceptionDefaultConstructor() { + UnReachBlockException exception = new UnReachBlockException(); + assertNotNull(exception); + assertNull(exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testUnReachBlockExceptionWithMessage() { + String testMessage = "Block is unreachable"; + UnReachBlockException exception = new UnReachBlockException(testMessage); + assertNotNull(exception); + assertEquals(testMessage, exception.getMessage()); + assertNull(exception.getCause()); + } + + @Test + public void testUnReachBlockExceptionWithMessageAndCause() { + String testMessage = "Block is unreachable due to an error"; + Throwable testCause = new Throwable("Cause of the error"); + UnReachBlockException exception = new UnReachBlockException(testMessage, testCause); + assertNotNull(exception); + assertEquals(testCause, exception.getCause()); + } + + @Test + public void testValidateScheduleExceptionDefaultConstructor() { + ValidateScheduleException exception = new ValidateScheduleException(); + + assertNotNull(exception); + + assertNull(exception.getMessage()); + } + + @Test + public void testValidateScheduleExceptionConstructorWithMessage() { + String testMessage = "Schedule validation failed"; + + ValidateScheduleException exception = new ValidateScheduleException(testMessage); + + assertNotNull(exception); + + assertEquals(testMessage, exception.getMessage()); + } + + @Test + public void testValidateSignatureExceptionDefaultConstructor() { + ValidateSignatureException exception = new ValidateSignatureException(); + assertNotNull("Exception should not be null", exception); + assertNull(exception.getMessage()); + } + + @Test + public void testValidateSignatureExceptionConstructorWithMessage() { + String testMessage = "Signature validation failed"; + ValidateSignatureException exception = new ValidateSignatureException(testMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + } + + @Test + public void testVMIllegalExceptionDefaultConstructor() { + // 测试无参构造函数 + VMIllegalException exception = new VMIllegalException(); + assertNotNull("Exception should not be null", exception); + assertNull(exception.getMessage()); + } + + @Test + public void testVMIllegalExceptionConstructorWithMessage() { + String testMessage = "VM operation is illegal"; + VMIllegalException exception = new VMIllegalException(testMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + } + + @Test + public void testZkProofValidateExceptionWithFirstValidatedTrue() { + String testMessage = "Zero-knowledge proof validation failed, but first part was validated"; + boolean firstValidated = true; + + ZkProofValidateException exception = new ZkProofValidateException(testMessage, firstValidated); + + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertTrue("firstValidated should be true", exception.isFirstValidated()); + } + + @Test + public void testZkProofValidateExceptionWithFirstValidatedFalse() { + String testMessage = "Zero-knowledge proof validation failed, first part not validated"; + boolean firstValidated = false; + + ZkProofValidateException exception = new ZkProofValidateException(testMessage, firstValidated); + exception.setFirstValidated(true); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertTrue("firstValidated should be true", exception.isFirstValidated()); + } + + @Test + public void testZksnarkExceptionNoMessage() { + ZksnarkException exception = new ZksnarkException(); + assertNotNull("Exception should not be null", exception); + assertNull(exception.getMessage()); + } + + @Test + public void testZksnarkExceptionWithMessage() { + String testMessage = "Zksnark validation failed"; + ZksnarkException exception = new ZksnarkException(testMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + } + + @Test + public void testTronDBExceptionNoArgs() { + TronDBException exception = new TronDBException(); + assertNotNull("Exception should not be null", exception); + assertNull("Message should be null", exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testTronDBExceptionWithMessage() { + String testMessage = "Database error occurred"; + TronDBException exception = new TronDBException(testMessage); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertNull("Cause should be null", exception.getCause()); + } + + @Test + public void testTronDBExceptionWithMessageAndThrowable() { + String testMessage = "Database error with specific cause"; + Throwable testCause = new Throwable("Root cause"); + TronDBException exception = new TronDBException(testMessage, testCause); + assertNotNull("Exception should not be null", exception); + assertEquals("Message should match", testMessage, exception.getMessage()); + assertEquals("Cause should match", testCause, exception.getCause()); + } + + @Test + public void testTronDBExceptionWithThrowable() { + Throwable testCause = new Throwable("Root cause without message"); + TronDBException exception = new TronDBException(testCause); + assertNotNull("Exception should not be null", exception); + assertEquals("Cause should match", testCause, exception.getCause()); + } +} diff --git a/framework/src/test/java/org/tron/core/capsule/utils/RLPListTest.java b/framework/src/test/java/org/tron/core/capsule/utils/RLPListTest.java index cba4a7d8040..500e7454dbe 100644 --- a/framework/src/test/java/org/tron/core/capsule/utils/RLPListTest.java +++ b/framework/src/test/java/org/tron/core/capsule/utils/RLPListTest.java @@ -14,12 +14,16 @@ public class RLPListTest { @Test public void testRecursivePrint() { RLPItem element = new RLPItem("rlpItem".getBytes()); - Assert.assertEquals(new String(element.getRLPData()), "rlpItem"); + Assert.assertEquals("rlpItem", new String(element.getRLPData())); RLPList.recursivePrint(element); RLPList rlpList = new RLPList(); rlpList.add(new RLPItem("rlpItem0".getBytes())); RLPList.recursivePrint(rlpList); Assert.assertThrows(RuntimeException.class, () -> RLPList.recursivePrint(null)); + + RLPItem rlpItem = new RLPItem(new byte[0]); + Assert.assertNull(rlpItem.getRLPData()); + } @Test diff --git a/framework/src/test/java/org/tron/core/config/args/LocalWitnessTest.java b/framework/src/test/java/org/tron/core/config/args/LocalWitnessTest.java index d0222254c7d..27d5effd6b1 100644 --- a/framework/src/test/java/org/tron/core/config/args/LocalWitnessTest.java +++ b/framework/src/test/java/org/tron/core/config/args/LocalWitnessTest.java @@ -24,8 +24,8 @@ public class LocalWitnessTest { - private LocalWitnesses localWitness = new LocalWitnesses(); - private static String PRIVATE_KEY = PublicMethod.getRandomPrivateKey(); + private final LocalWitnesses localWitness = new LocalWitnesses(); + private static final String PRIVATE_KEY = PublicMethod.getRandomPrivateKey(); @Before public void setLocalWitness() { @@ -38,11 +38,15 @@ public void setLocalWitness() { @Test public void whenSetNullPrivateKey() { localWitness.setPrivateKeys(null); + Assert.assertNotNull(localWitness.getPrivateKey()); + Assert.assertNotNull(localWitness.getPublicKey()); } @Test public void whenSetEmptyPrivateKey() { localWitness.setPrivateKeys(Lists.newArrayList("")); + Assert.assertNotNull(localWitness.getPrivateKey()); + Assert.assertNotNull(localWitness.getPublicKey()); } @Test(expected = IllegalArgumentException.class) @@ -58,6 +62,7 @@ public void whenSetPrefixPrivateKey() { localWitness .setPrivateKeys(Lists .newArrayList("0X" + PRIVATE_KEY)); + Assert.assertNotNull(localWitness.getPrivateKey()); } @Test @@ -66,4 +71,20 @@ public void getPrivateKey() { .newArrayList(PRIVATE_KEY), localWitness.getPrivateKeys()); } + + @Test + public void testConstructor() { + LocalWitnesses localWitnesses = new LocalWitnesses(PublicMethod.getRandomPrivateKey()); + LocalWitnesses localWitnesses1 = + new LocalWitnesses(Lists.newArrayList(PublicMethod.getRandomPrivateKey())); + localWitnesses.setWitnessAccountAddress(new byte[0]); + Assert.assertNotNull(localWitnesses1.getPublicKey()); + + LocalWitnesses localWitnesses2 = new LocalWitnesses(); + Assert.assertNull(localWitnesses2.getPrivateKey()); + Assert.assertNull(localWitnesses2.getPublicKey()); + localWitnesses2.initWitnessAccountAddress(true); + LocalWitnesses localWitnesses3 = new LocalWitnesses(); + Assert.assertNotNull(localWitnesses3.getWitnessAccountAddress(true)); + } } diff --git a/framework/src/test/java/org/tron/core/db/ManagerTest.java b/framework/src/test/java/org/tron/core/db/ManagerTest.java index ddf741fb6fa..07440435f41 100755 --- a/framework/src/test/java/org/tron/core/db/ManagerTest.java +++ b/framework/src/test/java/org/tron/core/db/ManagerTest.java @@ -367,12 +367,12 @@ public void entityTest() { Assert.assertTrue(trie.isEmpty()); AccountStateEntity entity = new AccountStateEntity(); AccountStateEntity parsedEntity = AccountStateEntity.parse("".getBytes()); - Assert.assertTrue(parsedEntity != null); - Assert.assertTrue(parsedEntity.getAccount() != null); - Assert.assertTrue(org.tron.core.db.api.pojo.Account.of() != null); - Assert.assertTrue(org.tron.core.db.api.pojo.AssetIssue.of() != null); - Assert.assertTrue(org.tron.core.db.api.pojo.Block.of() != null); - Assert.assertTrue(org.tron.core.db.api.pojo.Transaction.of() != null); + Assert.assertNotNull(parsedEntity); + Assert.assertNotNull(parsedEntity.getAccount()); + Assert.assertNotNull(org.tron.core.db.api.pojo.Account.of()); + Assert.assertNotNull(org.tron.core.db.api.pojo.AssetIssue.of()); + Assert.assertNotNull(org.tron.core.db.api.pojo.Block.of()); + Assert.assertNotNull(org.tron.core.db.api.pojo.Transaction.of()); } diff --git a/framework/src/test/java/org/tron/core/db/api/pojo/PojoTest.java b/framework/src/test/java/org/tron/core/db/api/pojo/PojoTest.java new file mode 100644 index 00000000000..f4661725a02 --- /dev/null +++ b/framework/src/test/java/org/tron/core/db/api/pojo/PojoTest.java @@ -0,0 +1,80 @@ +package org.tron.core.db.api.pojo; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.google.common.collect.Lists; +import org.junit.Test; + +public class PojoTest { + + @Test + public void testAccountCreation() { + Account account = Account.of(); + account.setName("testName"); + account.setAddress("testAddress"); + account.setBalance(1622548800000L); + + assertNotNull(account); + assertEquals("testName", account.getName()); + assertEquals("testAddress", account.getAddress()); + assertEquals(1622548800000L, account.getBalance()); + } + + @Test + public void testAssetIssueCreation() { + AssetIssue assetIssue = AssetIssue.of(); + assetIssue.setName("testName"); + assetIssue.setAddress("testAddress"); + assetIssue.setStart(1622548800000L); + assetIssue.setEnd(1654084800000L); + + assertNotNull(assetIssue); + assertEquals("testName", assetIssue.getName()); + assertEquals("testAddress", assetIssue.getAddress()); + assertEquals(1622548800000L, assetIssue.getStart()); + assertEquals(1654084800000L, assetIssue.getEnd()); + } + + @Test + public void testBlockCreation() { + Block block = Block.of(); + block.setId("7654321"); + block.setNumber(1000L); + block.setTransactionIds(Lists.newArrayList("1234567")); + + assertNotNull(block); + assertEquals("7654321", block.getId()); + assertEquals(1000L, block.getNumber()); + assertEquals("1234567", block.getTransactionIds().get(0)); + } + + @Test + public void testTransactionCreation() { + Transaction transaction = Transaction.of(); + transaction.setId("7654321"); + transaction.setFrom("from"); + transaction.setTo("to"); + + assertNotNull(transaction); + assertEquals("7654321", transaction.getId()); + assertEquals("from", transaction.getFrom()); + assertEquals("to", transaction.getTo()); + } + + @Test + public void testWitnessCreation() { + Witness witness = Witness.of(); + witness.setAddress("testAddress"); + witness.setJobs(true); + witness.setUrl("https://cryptoai.com"); + witness.setPublicKey("wergfsioejgbrotjsdfdoqwj"); + + assertNotNull(witness); + assertEquals("testAddress", witness.getAddress()); + assertTrue(witness.isJobs()); + assertEquals("https://cryptoai.com", witness.getUrl()); + assertEquals("wergfsioejgbrotjsdfdoqwj", witness.getPublicKey()); + } +} diff --git a/framework/src/test/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandlerTest.java b/framework/src/test/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandlerTest.java index 95cb9d0597f..dab76cfcb46 100644 --- a/framework/src/test/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandlerTest.java +++ b/framework/src/test/java/org/tron/core/net/messagehandler/ChainInventoryMsgHandlerTest.java @@ -9,6 +9,7 @@ import org.tron.core.capsule.BlockCapsule.BlockId; import org.tron.core.config.Parameter.NetConstants; import org.tron.core.exception.P2pException; +import org.tron.core.net.message.keepalive.PingMessage; import org.tron.core.net.message.sync.ChainInventoryMessage; import org.tron.core.net.peer.PeerConnection; @@ -20,11 +21,11 @@ public class ChainInventoryMsgHandlerTest { private List blockIds = new ArrayList<>(); @Test - public void testProcessMessage() { + public void testProcessMessage() throws Exception { try { handler.processMessage(peer, msg); } catch (P2pException e) { - Assert.assertTrue(e.getMessage().equals("not send syncBlockChainMsg")); + Assert.assertEquals("not send syncBlockChainMsg", e.getMessage()); } peer.setSyncChainRequested(new Pair<>(new LinkedList<>(), System.currentTimeMillis())); @@ -32,7 +33,7 @@ public void testProcessMessage() { try { handler.processMessage(peer, msg); } catch (P2pException e) { - Assert.assertTrue(e.getMessage().equals("blockIds is empty")); + Assert.assertEquals("blockIds is empty", e.getMessage()); } long size = NetConstants.SYNC_FETCH_BATCH_NUM + 2; @@ -44,7 +45,7 @@ public void testProcessMessage() { try { handler.processMessage(peer, msg); } catch (P2pException e) { - Assert.assertTrue(e.getMessage().equals("big blockIds size: " + size)); + Assert.assertEquals(e.getMessage(), "big blockIds size: " + size); } blockIds.clear(); @@ -57,8 +58,10 @@ public void testProcessMessage() { try { handler.processMessage(peer, msg); } catch (P2pException e) { - Assert.assertTrue(e.getMessage().equals("remain: 100, blockIds size: " + size)); + Assert.assertEquals(e.getMessage(), "remain: 100, blockIds size: " + size); } + Assert.assertNotNull(msg.toString()); + Assert.assertNull(msg.getAnswerMessage()); } } diff --git a/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java b/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java index d4ad32dd34f..e654e1c9cc2 100644 --- a/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java +++ b/framework/src/test/java/org/tron/core/net/messagehandler/SyncBlockChainMsgHandlerTest.java @@ -19,6 +19,7 @@ import org.tron.core.config.DefaultConfig; import org.tron.core.config.args.Args; import org.tron.core.exception.P2pException; +import org.tron.core.net.message.sync.BlockInventoryMessage; import org.tron.core.net.message.sync.SyncBlockChainMessage; import org.tron.core.net.peer.PeerConnection; import org.tron.p2p.connection.Channel; @@ -56,7 +57,7 @@ public void testProcessMessage() throws Exception { try { handler.processMessage(peer, new SyncBlockChainMessage(new ArrayList<>())); } catch (P2pException e) { - Assert.assertTrue(e.getMessage().equals("SyncBlockChain blockIds is empty")); + Assert.assertEquals("SyncBlockChain blockIds is empty", e.getMessage()); } List blockIds = new ArrayList<>(); @@ -66,7 +67,10 @@ public void testProcessMessage() throws Exception { "check", PeerConnection.class, SyncBlockChainMessage.class); method.setAccessible(true); boolean f = (boolean)method.invoke(handler, peer, message); - Assert.assertTrue(!f); + Assert.assertNotNull(message.getAnswerMessage()); + Assert.assertNotNull(message.toString()); + Assert.assertNotNull(((BlockInventoryMessage) message).getAnswerMessage()); + Assert.assertFalse(f); Method method1 = handler.getClass().getDeclaredMethod( "getLostBlockIds", List.class, BlockId.class); @@ -80,7 +84,7 @@ public void testProcessMessage() throws Exception { Method method2 = handler.getClass().getDeclaredMethod( "getBlockIds", Long.class, BlockId.class); method2.setAccessible(true); - List list = (List) method2.invoke(handler, 0L, new BlockCapsule.BlockId()); + List list = (List) method2.invoke(handler, 0L, new BlockCapsule.BlockId()); Assert.assertEquals(1, list.size()); } diff --git a/framework/src/test/java/org/tron/core/net/service/nodepersist/DBNodeTest.java b/framework/src/test/java/org/tron/core/net/service/nodepersist/DBNodeTest.java new file mode 100644 index 00000000000..171701762ee --- /dev/null +++ b/framework/src/test/java/org/tron/core/net/service/nodepersist/DBNodeTest.java @@ -0,0 +1,52 @@ +package org.tron.core.net.service.nodepersist; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import com.beust.jcommander.internal.Lists; +import org.junit.Before; +import org.junit.Test; + +public class DBNodeTest { + private DBNode dbNode1; + private DBNode dbNode2; + + @Before + public void setUp() { + dbNode1 = new DBNode("localhost", 3306); + dbNode2 = new DBNode(); + } + + @Test + public void testConstructorWithParameters() { + assertEquals("localhost", dbNode1.getHost()); + assertEquals(3306, dbNode1.getPort()); + } + + @Test + public void testDefaultConstructor() { + assertNull(dbNode2.getHost()); + assertEquals(0, dbNode2.getPort()); + } + + @Test + public void testSetAndGetHost() { + dbNode2.setHost("127.0.0.1"); + assertEquals("127.0.0.1", dbNode2.getHost()); + } + + @Test + public void testSetAndGetPort() { + dbNode2.setPort(5432); + assertEquals(5432, dbNode2.getPort()); + } + + + @Test + public void testDBNodes() { + DBNodes dbNodes = new DBNodes(); + dbNodes.setNodes(Lists.newArrayList(dbNode1, dbNode2)); + assertEquals(3306, dbNodes.getNodes().get(0).getPort()); + assertEquals(0, dbNodes.getNodes().get(1).getPort()); + } +} \ No newline at end of file diff --git a/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java b/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java index 4a844c49c3c..7746066abfa 100644 --- a/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/SendCoinShieldTest.java @@ -1695,6 +1695,7 @@ public SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, lo System.out.println( "rk:" + ByteArray.toHexString(spendDescriptionCapsule.getRk().toByteArray())); spendDescriptionCapsule.setRk(fakeRk); + spendDescriptionCapsule.setRk(ByteString.copyFrom(fakeRk)); return spendDescriptionCapsule; } }; @@ -1737,6 +1738,9 @@ public SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, lo .toHexString(spendDescriptionCapsule.getZkproof().toByteArray())); spendDescriptionCapsule.setZkproof(fakeProof); + spendDescriptionCapsule.setZkproof(ByteString.copyFrom(fakeProof)); + spendDescriptionCapsule.setSpendAuthoritySignature(spendDescriptionCapsule + .getSpendAuthoritySignature()); return spendDescriptionCapsule; } }; @@ -1775,6 +1779,7 @@ public SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, lo System.out.println( "nf:" + ByteArray.toHexString(spendDescriptionCapsule.getNullifier().toByteArray())); spendDescriptionCapsule.setNullifier(bytes); + spendDescriptionCapsule.setNullifier(ByteString.copyFrom(bytes)); return spendDescriptionCapsule; } }; @@ -1811,6 +1816,9 @@ public SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, lo System.out.println( "bytes:" + ByteArray.toHexString(spendDescriptionCapsule.getAnchor().toByteArray())); spendDescriptionCapsule.setAnchor(bytes); + spendDescriptionCapsule.setAnchor(ByteString.copyFrom(bytes)); + spendDescriptionCapsule.setValueCommitment(new byte[32]); + spendDescriptionCapsule.setValueCommitment(ByteString.copyFrom(new byte[32])); return spendDescriptionCapsule; } }; @@ -1827,5 +1835,14 @@ public SpendDescriptionCapsule generateSpendProof(SpendDescriptionInfo spend, lo System.out.println("Done"); } } + + SpendDescriptionCapsule c = new SpendDescriptionCapsule(new byte[32]); + SpendDescriptionCapsule c1 = new SpendDescriptionCapsule(ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]),ByteString.copyFrom(new byte[32])); + Assert.assertNotNull(c); + Assert.assertNotNull(c1); } } diff --git a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java index f3ad1f36cd1..157a7ba732f 100755 --- a/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java +++ b/framework/src/test/java/org/tron/core/zksnark/ShieldedReceiveTest.java @@ -369,6 +369,8 @@ public String[] generateSpendAndOutputParams() throws ZksnarkException, BadItemE // generate checkSpendParams SpendDescription spendDescription = builder.getContractBuilder().getSpendDescription(0); + SpendDescriptionCapsule spendDescriptionCapsule = new SpendDescriptionCapsule(spendDescription); + Assert.assertNotNull(spendDescriptionCapsule); CheckSpendParams checkSpendParams = new CheckSpendParams(ctx, spendDescription.getValueCommitment().toByteArray(), spendDescription.getAnchor().toByteArray(), @@ -873,20 +875,43 @@ private ReceiveDescriptionCapsule changeGenerateOutputProof(ReceiveDescriptionIn JLibrustzcash.librustzcashSaplingProvingCtxFree(ctx); throw new ZksnarkException("Output proof failed"); } - + ReceiveDescriptionCapsule c = new ReceiveDescriptionCapsule(new byte[32]); + ReceiveDescriptionCapsule c1 = + new ReceiveDescriptionCapsule(ReceiveDescription.newBuilder().build()); + ReceiveDescriptionCapsule c2 = + new ReceiveDescriptionCapsule(ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32]), + ByteString.copyFrom(new byte[32])); + Assert.assertNotNull(c); + Assert.assertNotNull(c1); + Assert.assertNotNull(c2); ReceiveDescriptionCapsule receiveDescriptionCapsule = new ReceiveDescriptionCapsule(); receiveDescriptionCapsule.setValueCommitment(cv); + receiveDescriptionCapsule.setValueCommitment(ByteString.copyFrom(cv)); receiveDescriptionCapsule.setNoteCommitment(cm); + receiveDescriptionCapsule.setNoteCommitment(ByteString.copyFrom(cm)); receiveDescriptionCapsule.setEpk(encryptor.getEpk()); + receiveDescriptionCapsule.setEpk(ByteString.copyFrom(encryptor.getEpk())); receiveDescriptionCapsule.setCEnc(enc.getEncCiphertext()); + receiveDescriptionCapsule.setCEnc(ByteString.copyFrom(enc.getEncCiphertext())); receiveDescriptionCapsule.setZkproof(zkProof); + receiveDescriptionCapsule.setZkproof(ByteString.copyFrom(zkProof)); + receiveDescriptionCapsule.getEphemeralKey(); + receiveDescriptionCapsule.getData(); + receiveDescriptionCapsule.getZkproof(); + receiveDescriptionCapsule.getOutCiphertext(); OutgoingPlaintext outPlaintext = new OutgoingPlaintext(output.getNote().getPkD(), encryptor.getEsk()); - receiveDescriptionCapsule.setCOut(outPlaintext + byte[] bytes = outPlaintext .encrypt(output.getOvk(), receiveDescriptionCapsule.getValueCommitment().toByteArray(), receiveDescriptionCapsule.getCm().toByteArray(), - encryptor).getData()); + encryptor).getData(); + receiveDescriptionCapsule.setCOut(bytes); + receiveDescriptionCapsule.setCOut(ByteString.copyFrom(bytes)); Note newNote = output.getNote(); byte[] newCm; diff --git a/framework/src/test/java/org/tron/program/SupplementTest.java b/framework/src/test/java/org/tron/program/SupplementTest.java index ffa6b14f46b..3dfa23dfce4 100644 --- a/framework/src/test/java/org/tron/program/SupplementTest.java +++ b/framework/src/test/java/org/tron/program/SupplementTest.java @@ -1,8 +1,10 @@ package org.tron.program; +import static org.apache.commons.lang3.StringUtils.EMPTY; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.tron.keystore.WalletUtils.passwordValid; import java.io.File; import java.io.IOException; @@ -21,6 +23,7 @@ import org.tron.core.Constant; import org.tron.core.capsule.StorageRowCapsule; import org.tron.core.capsule.utils.RLP; +import org.tron.core.config.TronLogShutdownHook; import org.tron.core.config.args.Args; import org.tron.core.services.http.HttpSelfFormatFieldName; import org.tron.core.store.StorageRowStore; @@ -130,4 +133,18 @@ public void testGet() throws Exception { RLP.unwrapList(new byte[] {1,2,3,4,5,6,7}); } + @Test + public void testPasswordValid() { + assertFalse(passwordValid(EMPTY)); + assertFalse(passwordValid("12345")); + assertTrue(passwordValid("123456")); + } + + @Test + public void testRun() { + TronLogShutdownHook hook = new TronLogShutdownHook(); + hook.run(); + assertTrue(true); + } + }