-
Notifications
You must be signed in to change notification settings - Fork 7
EC-799 Additional tests #394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GRYE
wants to merge
7
commits into
master
Choose a base branch
from
EC-799
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8445bd1
Small NVS refactoring
6e7fd2f
Additional tests for History
daca868
Additional tests for DM
78cc9e8
Additional tests for DM
b2973b3
Additional tests for DM
30b1565
Merge branch 'master' into EC-799
Bromel777 5b4932e
Small refactoring
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
119 changes: 119 additions & 0 deletions
119
src/test/scala/encry/network/DeliveryManagerTests/DeliveryManagerSpec.scala
This file contains hidden or 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,119 @@ | ||
| package encry.network.DeliveryManagerTests | ||
|
|
||
| import java.net.InetSocketAddress | ||
|
|
||
| import akka.actor.ActorSystem | ||
| import akka.testkit.{TestActorRef, TestKit, TestProbe} | ||
| import encry.consensus.HistoryConsensus.{Fork, Unknown} | ||
| import encry.modifiers.InstanceFactory | ||
| import encry.network.DeliveryManager.FullBlockChainIsSynced | ||
| import encry.network.DeliveryManagerTests.DMUtils.{createPeer, generateBlocks, generateDummyHistory} | ||
| import encry.network.NetworkController.ReceivableMessages.DataFromPeer | ||
| import encry.network.{DeliveryManager, NodeViewSynchronizer} | ||
| import encry.network.NodeViewSynchronizer.ReceivableMessages.{ChangedHistory, RequestFromLocal, UpdatedHistory} | ||
| import encry.network.PeerConnectionHandler.{ConnectedPeer, Incoming} | ||
| import encry.network.PeersKeeper.UpdatedPeersCollection | ||
| import encry.network.PrioritiesCalculator.PeersPriorityStatus.PeersPriorityStatus.InitialPriority | ||
| import encry.settings.TestNetSettings | ||
| import encry.view.history.History | ||
| import encry.view.mempool.MemoryPool.StopTransactionsValidation | ||
| import org.encryfoundation.common.modifiers.history.{Block, Header} | ||
| import org.encryfoundation.common.modifiers.mempool.transaction.Transaction | ||
| import org.encryfoundation.common.network.BasicMessagesRepo.{Handshake, InvNetworkMessage, ModifiersNetworkMessage, RequestModifiersNetworkMessage, SyncInfoNetworkMessage} | ||
| import org.encryfoundation.common.network.SyncInfo | ||
| import org.encryfoundation.common.utils.TaggedTypes.ModifierId | ||
| import org.scalatest.mockito.MockitoSugar | ||
| import org.scalatest.{BeforeAndAfterAll, Matchers, OneInstancePerTest, WordSpecLike} | ||
|
|
||
| class DeliveryManagerSpec extends TestKit(ActorSystem("RequestModifiersSpec")) | ||
| with WordSpecLike | ||
| with BeforeAndAfterAll | ||
| with MockitoSugar | ||
| with Matchers | ||
| with InstanceFactory | ||
| with OneInstancePerTest | ||
| with TestNetSettings { | ||
|
|
||
| override def afterAll: Unit = { | ||
| TestKit.shutdownActorSystem(system) | ||
| } | ||
|
|
||
| "DeliveryManager" should { | ||
| "correctly request modifiers from forked node" in { | ||
|
|
||
| val nvs: TestActorRef[NodeViewSynchronizer] = | ||
| TestActorRef[NodeViewSynchronizer](NodeViewSynchronizer.props(None, TestProbe().ref, settings, TestProbe().ref, TestProbe().ref)) | ||
|
|
||
| val address = new InetSocketAddress("123.123.123.124", 9001) | ||
| val handler: TestProbe = TestProbe() | ||
| val cp: ConnectedPeer = ConnectedPeer(address, handler.ref, Incoming, | ||
| Handshake(protocolToBytes(testNetSettings.network.appVersion), | ||
| "123.123.123.124", Some(address), System.currentTimeMillis())) | ||
|
|
||
| val initHistory = generateDummyHistory(testNetSettings) | ||
| val otherHistory = generateDummyHistory(testNetSettings) | ||
|
|
||
| val (_, blocks) = generateBlocks(100, generateDummyHistory(testNetSettings)) | ||
|
|
||
| val ourHistory = blocks.foldLeft(initHistory) { case (hst, block) => | ||
| hst.append(block.header) | ||
| hst.append(block.payload) | ||
| hst.reportModifierIsValid(block) | ||
| } | ||
|
|
||
| val commonHistory = blocks.take(60).foldLeft(otherHistory) { case (hst, block) => | ||
| hst.append(block.header) | ||
| hst.append(block.payload) | ||
| hst.reportModifierIsValid(block) | ||
| } | ||
|
|
||
| val (forkedHistory, forkedBlocks) = generateBlocks(40, commonHistory) | ||
|
|
||
| val syncInfo = SyncInfo((blocks.slice(50, 60) ++ forkedBlocks).map(_.id)) | ||
|
|
||
| nvs ! ChangedHistory(ourHistory) | ||
|
|
||
| nvs ! FullBlockChainIsSynced | ||
|
|
||
| nvs ! UpdatedPeersCollection(Map(address -> (cp, Fork, InitialPriority))) | ||
|
|
||
| nvs ! DataFromPeer(SyncInfoNetworkMessage(syncInfo), cp) | ||
|
|
||
| handler.expectMsg(InvNetworkMessage(Header.modifierTypeId -> blocks.drop(60).map(_.id))) | ||
|
|
||
| val idsForLocalRequest = forkedBlocks.map(_.id).filterNot(ourHistory.isModifierDefined) | ||
|
|
||
| nvs ! RequestFromLocal(cp, Header.modifierTypeId, idsForLocalRequest) | ||
|
|
||
| handler.expectMsg(RequestModifiersNetworkMessage(Header.modifierTypeId -> idsForLocalRequest)) | ||
| nvs.stop() | ||
| } | ||
|
|
||
| "not process transactions if number of transactions in mempool exceeds limit" in { | ||
|
|
||
| val downloadedModifiersValidator = TestProbe() | ||
| val address = new InetSocketAddress("123.123.123.124", 9001) | ||
| val handler: TestProbe = TestProbe() | ||
| val cp: ConnectedPeer = ConnectedPeer(address, handler.ref, Incoming, | ||
| Handshake(protocolToBytes(testNetSettings.network.appVersion), | ||
| "123.123.123.124", Some(address), System.currentTimeMillis())) | ||
|
|
||
| val deliveryManager: TestActorRef[DeliveryManager] = | ||
| TestActorRef[DeliveryManager](DeliveryManager | ||
| .props(None, TestProbe().ref, TestProbe().ref, TestProbe().ref, TestProbe().ref, downloadedModifiersValidator.ref, settings)) | ||
|
|
||
| val history: History = generateDummyHistory(settings) | ||
|
|
||
| deliveryManager ! UpdatedHistory(history) | ||
| deliveryManager ! StopTransactionsValidation | ||
|
|
||
| val txs: Map[ModifierId, Array[Byte]] = genValidPaymentTxs(100).groupBy(_.id).mapValues(_.head.bytes) | ||
| val msg = ModifiersNetworkMessage(Transaction.modifierTypeId, txs) | ||
|
|
||
| deliveryManager ! DataFromPeer(msg, cp) | ||
| downloadedModifiersValidator.expectNoMsg() | ||
| deliveryManager.stop() | ||
| } | ||
| } | ||
|
|
||
| } |
73 changes: 73 additions & 0 deletions
73
src/test/scala/encry/view/history/ContinuationIdsTest.scala
This file contains hidden or 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,73 @@ | ||
| package encry.view.history | ||
|
|
||
| import encry.modifiers.InstanceFactory | ||
| import encry.network.DeliveryManagerTests.DMUtils.generateBlocks | ||
| import encry.settings.TestNetSettings | ||
| import org.encryfoundation.common.modifiers.history.Block | ||
| import org.encryfoundation.common.network.SyncInfo | ||
| import org.scalatest.{Matchers, OneInstancePerTest, WordSpecLike} | ||
|
|
||
| class ContinuationIdsTest extends WordSpecLike | ||
| with Matchers | ||
| with InstanceFactory | ||
| with OneInstancePerTest | ||
| with TestNetSettings { | ||
|
|
||
| "History Reader" should { | ||
|
|
||
| "correctly compute continuation ids with empty history" in { | ||
| val history: History = generateDummyHistory(testNetSettings) | ||
| val blocks: List[Block] = generateBlocks(100, generateDummyHistory(testNetSettings))._2 | ||
| val syncInfo: SyncInfo = SyncInfo(blocks.map(_.header.id)) | ||
|
|
||
| val ids = history.continuationIds(syncInfo, 100) | ||
| ids shouldBe Seq.empty | ||
| } | ||
|
|
||
| "correctly compute continuation ids for empty SyncInfo" in { | ||
| val history: History = generateDummyHistory(testNetSettings) | ||
| val blocks: List[Block] = generateBlocks(100, generateDummyHistory(testNetSettings))._2 | ||
| val syncInfo: SyncInfo = SyncInfo(Seq.empty) | ||
|
|
||
| val updatedHistory: History = blocks.foldLeft(history) { case (hst, block) => | ||
| hst.append(block.header) | ||
| hst.append(block.payload) | ||
| hst.reportModifierIsValid(block) | ||
| } | ||
|
|
||
| val ids = updatedHistory.continuationIds(syncInfo, 100) | ||
| ids shouldBe blocks.map(_.header.id) | ||
| } | ||
|
|
||
| "correctly compute continuation ids if our best height is higher than others best height" in { | ||
| val history: History = generateDummyHistory(testNetSettings) | ||
| val blocks: List[Block] = generateBlocks(100, generateDummyHistory(testNetSettings))._2 | ||
| val syncInfo: SyncInfo = SyncInfo(blocks.take(30).map(_.header.id)) | ||
|
|
||
| val updatedHistory: History = blocks.foldLeft(history) { case (hst, block) => | ||
| hst.append(block.header) | ||
| hst.append(block.payload) | ||
| hst.reportModifierIsValid(block) | ||
| } | ||
|
|
||
| val ids = updatedHistory.continuationIds(syncInfo, 100) | ||
| ids shouldBe blocks.map(_.header.id).drop(30) | ||
| } | ||
|
|
||
| "correctly compute continuation ids if others best height is higher than our best height" in { | ||
| val history: History = generateDummyHistory(testNetSettings) | ||
| val blocks: List[Block] = generateBlocks(100, generateDummyHistory(testNetSettings))._2 | ||
| val syncInfo: SyncInfo = SyncInfo(blocks.map(_.header.id)) | ||
|
|
||
| val updatedHistory: History = blocks.take(30).foldLeft(history) { case (hst, block) => | ||
| hst.append(block.header) | ||
| hst.append(block.payload) | ||
| hst.reportModifierIsValid(block) | ||
| } | ||
|
|
||
| val ids = updatedHistory.continuationIds(syncInfo, 100) | ||
| ids shouldBe blocks.map(_.header.id).take(30) | ||
| } | ||
|
|
||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you sending OtherNodeSyncingStatus only when compr result is Younger | Fork?