-
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.
Merge pull request #5643 from ss3344520/block_unsolid_solution
feat(net): stop tx broadcasting if block cannot solidified
- Loading branch information
Showing
10 changed files
with
127 additions
and
2 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
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
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
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
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
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
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
51 changes: 51 additions & 0 deletions
51
framework/src/test/java/org/tron/core/net/TronNetDelegateTest.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,51 @@ | ||
package org.tron.core.net; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
import java.lang.reflect.Field; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.tron.common.parameter.CommonParameter; | ||
import org.tron.common.utils.Sha256Hash; | ||
import org.tron.core.ChainBaseManager; | ||
import org.tron.core.Constant; | ||
import org.tron.core.capsule.BlockCapsule; | ||
import org.tron.core.config.args.Args; | ||
|
||
public class TronNetDelegateTest { | ||
|
||
@Test | ||
public void test() throws Exception { | ||
Args.setParam(new String[] {"-w"}, Constant.TEST_CONF); | ||
CommonParameter parameter = Args.getInstance(); | ||
Args.logConfig(); | ||
|
||
BlockCapsule.BlockId blockId = new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 10000L); | ||
|
||
TronNetDelegate tronNetDelegate = new TronNetDelegate(); | ||
|
||
ChainBaseManager chainBaseManager = mock(ChainBaseManager.class); | ||
Mockito.when(chainBaseManager.getHeadBlockNum()).thenReturn(10000L); | ||
Mockito.when(chainBaseManager.getSolidBlockId()).thenReturn(blockId); | ||
|
||
Field field = tronNetDelegate.getClass().getDeclaredField("chainBaseManager"); | ||
field.setAccessible(true); | ||
field.set(tronNetDelegate, chainBaseManager); | ||
|
||
Assert.assertTrue(!tronNetDelegate.isBlockUnsolidified()); | ||
|
||
blockId = new BlockCapsule.BlockId(Sha256Hash.ZERO_HASH, 1L); | ||
Mockito.when(chainBaseManager.getSolidBlockId()).thenReturn(blockId); | ||
Assert.assertTrue(tronNetDelegate.isBlockUnsolidified()); | ||
|
||
parameter.setUnsolidifiedBlockCheck(false); | ||
tronNetDelegate = new TronNetDelegate(); | ||
|
||
field = tronNetDelegate.getClass().getDeclaredField("unsolidifiedBlockCheck"); | ||
field.setAccessible(true); | ||
field.set(tronNetDelegate, false); | ||
|
||
Assert.assertTrue(!tronNetDelegate.isBlockUnsolidified()); | ||
} | ||
} |
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
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