|
2 | 2 |
|
3 | 3 | import static org.junit.Assert.assertEquals; |
4 | 4 | import static org.junit.Assert.assertFalse; |
| 5 | +import static org.junit.Assert.assertSame; |
5 | 6 | import static org.junit.Assert.assertTrue; |
6 | 7 | import static org.mockito.Mockito.mock; |
7 | 8 | import static org.mockito.Mockito.when; |
8 | 9 |
|
9 | 10 | import java.util.ArrayList; |
| 11 | +import java.util.Arrays; |
| 12 | +import java.util.HashMap; |
10 | 13 | import java.util.List; |
11 | | -import org.junit.Assert; |
| 14 | +import java.util.Map; |
12 | 15 | import org.junit.Test; |
13 | 16 | import org.pf4j.PluginDescriptor; |
14 | 17 | import org.pf4j.PluginManager; |
15 | 18 | import org.pf4j.PluginWrapper; |
16 | 19 | import org.tron.common.logsfilter.trigger.BlockLogTrigger; |
| 20 | +import org.tron.common.logsfilter.trigger.InternalTransactionPojo; |
| 21 | +import org.tron.common.logsfilter.trigger.LogPojo; |
17 | 22 | import org.tron.common.logsfilter.trigger.TransactionLogTrigger; |
| 23 | +import org.tron.common.logsfilter.trigger.Trigger; |
18 | 24 |
|
19 | 25 | public class EventLoaderTest { |
20 | 26 |
|
@@ -82,49 +88,97 @@ private static boolean checkVersion(String version) { |
82 | 88 | @Test |
83 | 89 | public void testBlockLogTrigger() { |
84 | 90 | BlockLogTrigger blt = new BlockLogTrigger(); |
85 | | - blt.setBlockHash(blt.getBlockHash()); |
86 | | - blt.setBlockNumber(blt.getBlockNumber()); |
87 | | - blt.setTransactionSize(blt.getTransactionSize()); |
88 | | - blt.setLatestSolidifiedBlockNumber(blt.getLatestSolidifiedBlockNumber()); |
89 | | - blt.setTriggerName(blt.getTriggerName()); |
90 | | - blt.setTimeStamp(blt.getTimeStamp()); |
91 | | - blt.setTransactionList(blt.getTransactionList()); |
92 | | - Assert.assertNotNull(blt.toString()); |
| 91 | + List<String> transactionIds = Arrays.asList("tx-1", "tx-2"); |
| 92 | + blt.setBlockHash("block-hash"); |
| 93 | + blt.setBlockNumber(42L); |
| 94 | + blt.setTransactionSize(2L); |
| 95 | + blt.setLatestSolidifiedBlockNumber(40L); |
| 96 | + blt.setTimeStamp(123456L); |
| 97 | + blt.setTransactionList(transactionIds); |
| 98 | + blt.setRemoved(true); |
| 99 | + |
| 100 | + assertEquals(Trigger.BLOCK_TRIGGER_NAME, blt.getTriggerName()); |
| 101 | + assertEquals("block-hash", blt.getBlockHash()); |
| 102 | + assertEquals(42L, blt.getBlockNumber()); |
| 103 | + assertEquals(2L, blt.getTransactionSize()); |
| 104 | + assertEquals(40L, blt.getLatestSolidifiedBlockNumber()); |
| 105 | + assertEquals(123456L, blt.getTimeStamp()); |
| 106 | + assertSame(transactionIds, blt.getTransactionList()); |
| 107 | + assertTrue(blt.isRemoved()); |
| 108 | + assertEquals("triggerName: blockTrigger, timestamp: 123456, blockNumber: 42, " |
| 109 | + + "blockhash: block-hash, transactionSize: 2, latestSolidifiedBlockNumber: 40, " |
| 110 | + + "removed: true, transactionList: [tx-1, tx-2]", blt.toString()); |
93 | 111 | } |
94 | 112 |
|
95 | 113 | @Test |
96 | 114 | public void testTransactionLogTrigger() { |
97 | 115 | TransactionLogTrigger tlt = new TransactionLogTrigger(); |
98 | | - tlt.setBlockHash(tlt.getBlockHash()); |
99 | | - tlt.setBlockNumber(tlt.getBlockNumber()); |
100 | | - tlt.setTransactionId(tlt.getTransactionId()); |
101 | | - tlt.setLatestSolidifiedBlockNumber(tlt.getLatestSolidifiedBlockNumber()); |
102 | | - tlt.setTriggerName(tlt.getTriggerName()); |
103 | | - tlt.setTimeStamp(tlt.getTimeStamp()); |
104 | | - tlt.setEnergyFee(tlt.getEnergyFee()); |
105 | | - tlt.setNetFee(tlt.getNetFee()); |
106 | | - tlt.setEnergyUsage(tlt.getEnergyUsage()); |
107 | | - tlt.setAssetAmount(tlt.getAssetAmount()); |
108 | | - tlt.setContractAddress(tlt.getContractAddress()); |
109 | | - tlt.setResult(tlt.getResult()); |
110 | | - tlt.setContractResult(tlt.getContractResult()); |
111 | | - tlt.setContractType(tlt.getContractType()); |
112 | | - tlt.setContractCallValue(tlt.getContractCallValue()); |
113 | | - tlt.setFromAddress(tlt.getFromAddress()); |
114 | | - tlt.setToAddress(tlt.getToAddress()); |
115 | | - tlt.setTransactionIndex(tlt.getTransactionIndex()); |
116 | | - tlt.setFeeLimit(tlt.getFeeLimit()); |
117 | | - tlt.setCumulativeEnergyUsed(tlt.getCumulativeEnergyUsed()); |
118 | | - tlt.setData(tlt.getData()); |
119 | | - tlt.setOriginEnergyUsage(tlt.getOriginEnergyUsage()); |
120 | | - tlt.setEnergyUsageTotal(tlt.getEnergyUsageTotal()); |
121 | | - tlt.setNetUsage(tlt.getNetUsage()); |
122 | | - tlt.setAssetName(tlt.getAssetName()); |
123 | | - tlt.setInternalTransactionList(tlt.getInternalTransactionList()); |
124 | | - tlt.setPreCumulativeLogCount(tlt.getPreCumulativeLogCount()); |
125 | | - tlt.setLogList(tlt.getLogList()); |
126 | | - tlt.setEnergyUnitPrice(tlt.getEnergyUnitPrice()); |
127 | | - tlt.setTimeStamp(1L); |
128 | | - Assert.assertNotNull(tlt.toString()); |
| 116 | + List<InternalTransactionPojo> internalTransactions = new ArrayList<>(); |
| 117 | + List<LogPojo> logs = new ArrayList<>(); |
| 118 | + Map<String, Long> extensions = new HashMap<>(); |
| 119 | + extensions.put("retryCount", 3L); |
| 120 | + |
| 121 | + tlt.setTransactionId("transaction-id"); |
| 122 | + tlt.setBlockHash("block-hash"); |
| 123 | + tlt.setBlockNumber(101L); |
| 124 | + tlt.setEnergyUsage(11L); |
| 125 | + tlt.setEnergyFee(12L); |
| 126 | + tlt.setOriginEnergyUsage(13L); |
| 127 | + tlt.setEnergyUsageTotal(14L); |
| 128 | + tlt.setNetUsage(15L); |
| 129 | + tlt.setNetFee(16L); |
| 130 | + tlt.setResult("SUCCESS"); |
| 131 | + tlt.setContractAddress("contract-address"); |
| 132 | + tlt.setContractType("TriggerSmartContract"); |
| 133 | + tlt.setFeeLimit(17L); |
| 134 | + tlt.setContractCallValue(18L); |
| 135 | + tlt.setContractResult("contract-result"); |
| 136 | + tlt.setFromAddress("from-address"); |
| 137 | + tlt.setToAddress("to-address"); |
| 138 | + tlt.setAssetName("asset-name"); |
| 139 | + tlt.setAssetAmount(19L); |
| 140 | + tlt.setLatestSolidifiedBlockNumber(100L); |
| 141 | + tlt.setInternalTransactionList(internalTransactions); |
| 142 | + tlt.setData("deadbeef"); |
| 143 | + tlt.setTransactionIndex(2); |
| 144 | + tlt.setCumulativeEnergyUsed(20L); |
| 145 | + tlt.setPreCumulativeLogCount(21L); |
| 146 | + tlt.setLogList(logs); |
| 147 | + tlt.setEnergyUnitPrice(22L); |
| 148 | + tlt.setExtMap(extensions); |
| 149 | + tlt.setRemoved(true); |
| 150 | + tlt.setTimeStamp(123456L); |
| 151 | + |
| 152 | + assertEquals(Trigger.TRANSACTION_TRIGGER_NAME, tlt.getTriggerName()); |
| 153 | + assertEquals("transaction-id", tlt.getTransactionId()); |
| 154 | + assertEquals("block-hash", tlt.getBlockHash()); |
| 155 | + assertEquals(101L, tlt.getBlockNumber()); |
| 156 | + assertEquals(11L, tlt.getEnergyUsage()); |
| 157 | + assertEquals(12L, tlt.getEnergyFee()); |
| 158 | + assertEquals(13L, tlt.getOriginEnergyUsage()); |
| 159 | + assertEquals(14L, tlt.getEnergyUsageTotal()); |
| 160 | + assertEquals(15L, tlt.getNetUsage()); |
| 161 | + assertEquals(16L, tlt.getNetFee()); |
| 162 | + assertEquals("SUCCESS", tlt.getResult()); |
| 163 | + assertEquals("contract-address", tlt.getContractAddress()); |
| 164 | + assertEquals("TriggerSmartContract", tlt.getContractType()); |
| 165 | + assertEquals(17L, tlt.getFeeLimit()); |
| 166 | + assertEquals(18L, tlt.getContractCallValue()); |
| 167 | + assertEquals("contract-result", tlt.getContractResult()); |
| 168 | + assertEquals("from-address", tlt.getFromAddress()); |
| 169 | + assertEquals("to-address", tlt.getToAddress()); |
| 170 | + assertEquals("asset-name", tlt.getAssetName()); |
| 171 | + assertEquals(19L, tlt.getAssetAmount()); |
| 172 | + assertEquals(100L, tlt.getLatestSolidifiedBlockNumber()); |
| 173 | + assertSame(internalTransactions, tlt.getInternalTransactionList()); |
| 174 | + assertEquals("deadbeef", tlt.getData()); |
| 175 | + assertEquals(2, tlt.getTransactionIndex()); |
| 176 | + assertEquals(20L, tlt.getCumulativeEnergyUsed()); |
| 177 | + assertEquals(21L, tlt.getPreCumulativeLogCount()); |
| 178 | + assertSame(logs, tlt.getLogList()); |
| 179 | + assertEquals(22L, tlt.getEnergyUnitPrice()); |
| 180 | + assertSame(extensions, tlt.getExtMap()); |
| 181 | + assertTrue(tlt.isRemoved()); |
| 182 | + assertEquals(123456L, tlt.getTimeStamp()); |
129 | 183 | } |
130 | 184 | } |
0 commit comments