-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): improve unit test coverage
- Loading branch information
Showing
4 changed files
with
123 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
framework/src/test/java/org/tron/common/logsfilter/capsule/BlockFilterCapsuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
framework/src/test/java/org/tron/common/logsfilter/capsule/BlockLogTriggerCapsuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...ework/src/test/java/org/tron/common/logsfilter/capsule/ContractLogTriggerCapsuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.tron.common.logsfilter.capsule; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.tron.common.logsfilter.trigger.Trigger.CONTRACTLOG_TRIGGER_NAME; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.tron.common.logsfilter.trigger.ContractLogTrigger; | ||
|
||
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()); | ||
assertThrows(NullPointerException.class, capsule::processTrigger); | ||
} | ||
|
||
} |