-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Tests for ProtocolHandler Mailboxes (Neo 3.x) #809
Merged
igormcoelho
merged 15 commits into
neo-project:master
from
igormcoelho:tests_mailbox_3x
Jun 12, 2019
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ed1f3a0
tests for mailboxes on 3x
igormcoelho ebf1889
Merge branch 'master' of github.com:neo-project/neo into tests_mailbo…
igormcoelho 6839843
Merge branch 'master' into tests_mailbox_3x
vncoelho a032172
Merge branch 'master' into tests_mailbox_3x
vncoelho 9f20cf1
Fixing UT to MessageCommand
vncoelho c664785
Fixing string
vncoelho 755a889
Merge branch 'master' into tests_mailbox_3x
vncoelho 1ff56dd
Explicit Byte
vncoelho 8707e09
MessageCommand with random byte
vncoelho 00e8562
space
igormcoelho f91ad9e
testing all cases
igormcoelho 233ad86
Update UT_ConsensusServiceMailbox.cs
shargon 2f66b94
Update UT_RemoteNodeMailbox.cs
shargon 1b2b185
Update UT_TaskManagerMailbox.cs
shargon 650f416
Merge branch 'master' into tests_mailbox_3x
vncoelho 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 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,37 @@ | ||
using Akka.TestKit; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using Moq; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.P2P; | ||
using Akka.Configuration; | ||
using Neo.Consensus; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ConsensusServiceMailbox : TestKit | ||
{ | ||
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism | ||
|
||
ConsensusServiceMailbox uut; | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
Akka.Actor.ActorSystem system = Sys; | ||
var config = TestKit.DefaultConfig; | ||
var akkaSettings = new Akka.Actor.Settings(system, config); | ||
uut = new ConsensusServiceMailbox(akkaSettings, config); | ||
} | ||
} | ||
} |
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,194 @@ | ||
using Akka.TestKit; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using Moq; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.P2P; | ||
using Akka.Configuration; | ||
using Neo.IO; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ProtocolHandlerMailbox : TestKit | ||
{ | ||
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism | ||
|
||
ProtocolHandlerMailbox uut; | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
Akka.Actor.ActorSystem system = Sys; | ||
var config = TestKit.DefaultConfig; | ||
var akkaSettings = new Akka.Actor.Settings(system, config); | ||
uut = new ProtocolHandlerMailbox(akkaSettings, config); | ||
} | ||
|
||
[TestMethod] | ||
public void ProtocolHandlerMailbox_Test_IsHighPriority() | ||
{ | ||
ISerializable s = null; | ||
|
||
//handshaking | ||
uut.IsHighPriority(Message.Create(MessageCommand.Version, s)).Should().Be(true); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Verack, s)).Should().Be(true); | ||
|
||
//connectivity | ||
uut.IsHighPriority(Message.Create(MessageCommand.GetAddr, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Addr, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Ping, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Pong, s)).Should().Be(false); | ||
|
||
//synchronization | ||
uut.IsHighPriority(Message.Create(MessageCommand.GetHeaders, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Headers, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.GetBlocks, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Mempool, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Inv, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.GetData, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.NotFound, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Transaction, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Block, s)).Should().Be(false); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Consensus, s)).Should().Be(true); | ||
uut.IsHighPriority(Message.Create(MessageCommand.Reject, s)).Should().Be(false); | ||
|
||
//SPV protocol | ||
uut.IsHighPriority(Message.Create(MessageCommand.FilterLoad, s)).Should().Be(true); | ||
uut.IsHighPriority(Message.Create(MessageCommand.FilterAdd, s)).Should().Be(true); | ||
uut.IsHighPriority(Message.Create(MessageCommand.FilterClear, s)).Should().Be(true); | ||
uut.IsHighPriority(Message.Create(MessageCommand.MerkleBlock, s)).Should().Be(false); | ||
|
||
//others | ||
uut.IsHighPriority(Message.Create(MessageCommand.Alert, s)).Should().Be(true); | ||
|
||
// any random object (non Message) should not have priority | ||
object obj = null; | ||
uut.IsHighPriority(obj).Should().Be(false); | ||
} | ||
|
||
|
||
[TestMethod] | ||
public void ProtocolHandlerMailbox_Test_ShallDrop() | ||
{ | ||
// using this for messages | ||
ISerializable s = null; | ||
Message msg = null; // multiple uses | ||
// empty queue | ||
IEnumerable<object> emptyQueue = Enumerable.Empty<object>(); | ||
|
||
// any random object (non Message) should be dropped | ||
object obj = null; | ||
uut.ShallDrop(obj, emptyQueue).Should().Be(true); | ||
|
||
//handshaking | ||
// Version (no drop) | ||
msg = Message.Create(MessageCommand.Version, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Verack (no drop) | ||
msg = Message.Create(MessageCommand.Verack, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
|
||
//connectivity | ||
// GetAddr (drop) | ||
msg = Message.Create(MessageCommand.GetAddr, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); | ||
// Addr (no drop) | ||
msg = Message.Create(MessageCommand.Addr, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Ping (no drop) | ||
msg = Message.Create(MessageCommand.Ping, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Pong (no drop) | ||
msg = Message.Create(MessageCommand.Pong, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
|
||
//synchronization | ||
// GetHeaders (drop) | ||
msg = Message.Create(MessageCommand.GetHeaders, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); | ||
// Headers (no drop) | ||
msg = Message.Create(MessageCommand.Headers, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// GetBlocks (drop) | ||
msg = Message.Create(MessageCommand.GetBlocks, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); | ||
// Mempool (drop) | ||
msg = Message.Create(MessageCommand.Mempool, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); | ||
// Inv (no drop) | ||
msg = Message.Create(MessageCommand.Inv, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// GetData (drop) | ||
msg = Message.Create(MessageCommand.GetData, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(true); | ||
// NotFound (no drop) | ||
msg = Message.Create(MessageCommand.NotFound, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Transaction (no drop) | ||
msg = Message.Create(MessageCommand.Transaction, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Block (no drop) | ||
msg = Message.Create(MessageCommand.Block, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Consensus (no drop) | ||
msg = Message.Create(MessageCommand.Consensus, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// Reject (no drop) | ||
msg = Message.Create(MessageCommand.Reject, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
|
||
//SPV protocol | ||
// FilterLoad (no drop) | ||
msg = Message.Create(MessageCommand.FilterLoad, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// FilterAdd (no drop) | ||
msg = Message.Create(MessageCommand.FilterAdd, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// FilterClear (no drop) | ||
msg = Message.Create(MessageCommand.FilterClear, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
// MerkleBlock (no drop) | ||
msg = Message.Create(MessageCommand.MerkleBlock, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
|
||
//others | ||
// Alert (no drop) | ||
msg = Message.Create(MessageCommand.Alert, s); | ||
uut.ShallDrop(msg, emptyQueue).Should().Be(false); | ||
uut.ShallDrop(msg, new object[]{ msg }).Should().Be(false); | ||
} | ||
} | ||
} |
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,36 @@ | ||
using Akka.TestKit; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using Moq; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.P2P; | ||
using Akka.Configuration; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_RemoteNodeMailbox : TestKit | ||
{ | ||
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism | ||
|
||
RemoteNodeMailbox uut; | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
Akka.Actor.ActorSystem system = Sys; | ||
var config = TestKit.DefaultConfig; | ||
var akkaSettings = new Akka.Actor.Settings(system, config); | ||
uut = new RemoteNodeMailbox(akkaSettings, config); | ||
} | ||
} | ||
} |
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,36 @@ | ||
using Akka.TestKit; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using Moq; | ||
using Neo.Ledger; | ||
using Neo.Network.P2P.Payloads; | ||
using Neo.Network.P2P; | ||
using Akka.Configuration; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_TaskManagerMailbox : TestKit | ||
{ | ||
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism | ||
|
||
TaskManagerMailbox uut; | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
Akka.Actor.ActorSystem system = Sys; | ||
var config = TestKit.DefaultConfig; | ||
var akkaSettings = new Akka.Actor.Settings(system, config); | ||
uut = new TaskManagerMailbox(akkaSettings, config); | ||
} | ||
} | ||
} |
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
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.
Here the tests @shargon! hahaha
Focused on ProtocolHandler this time... Coverage increased a lot already, and on future we cover others ;)