-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UT for Version/Verack messages (#853)
* UT for Version/Verack messages * Indentation * Indentation * Update ProtocolHandler.cs * Fixing ClassInit; Removing shutdown; Initializing testblockchain during class setup (only once) * Running formatter * Eriks suggestion * fix typo * removed ProtocolFactory * remove TestProtocolFactory * simplify * CreateActor * Revert "CreateActor" This reverts commit 3ad56f7. * removed parameter from RemoteNode * fix * removed unused parameters * format
- Loading branch information
Showing
3 changed files
with
159 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Akka.TestKit.Xunit2; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.P2P; | ||
using Neo.Network.P2P.Capabilities; | ||
using Neo.Network.P2P.Payloads; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ProtocolHandler : TestKit | ||
{ | ||
private NeoSystem testBlockchain; | ||
|
||
[TestCleanup] | ||
public void Cleanup() | ||
{ | ||
Shutdown(); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
testBlockchain = TestBlockchain.InitializeMockNeoSystem(); | ||
} | ||
|
||
[TestMethod] | ||
public void ProtocolHandler_Test_SendVersion_TellParent() | ||
{ | ||
var senderProbe = CreateTestProbe(); | ||
var parent = CreateTestProbe(); | ||
var protocolActor = ActorOfAsTestActorRef(() => new ProtocolHandler(testBlockchain), parent); | ||
|
||
var payload = new VersionPayload() | ||
{ | ||
UserAgent = "".PadLeft(1024, '0'), | ||
Nonce = 1, | ||
Magic = 2, | ||
Timestamp = 5, | ||
Version = 6, | ||
Capabilities = new NodeCapability[] | ||
{ | ||
new ServerCapability(NodeCapabilityType.TcpServer, 25) | ||
} | ||
}; | ||
|
||
senderProbe.Send(protocolActor, Message.Create(MessageCommand.Version, payload)); | ||
parent.ExpectMsg<VersionPayload>(); | ||
} | ||
} | ||
} |
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,85 @@ | ||
using Akka.IO; | ||
using Akka.TestKit.Xunit2; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Network.P2P; | ||
using Neo.Network.P2P.Capabilities; | ||
using Neo.Network.P2P.Payloads; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_RemoteNode : TestKit | ||
{ | ||
private static NeoSystem testBlockchain; | ||
|
||
public UT_RemoteNode() | ||
: base($"remote-node-mailbox {{ mailbox-type: \"{typeof(RemoteNodeMailbox).AssemblyQualifiedName}\" }}" + | ||
$"protocol-handler-mailbox {{ mailbox-type: \"{typeof(ProtocolHandlerMailbox).AssemblyQualifiedName}\" }}") | ||
{ | ||
} | ||
|
||
[ClassInitialize] | ||
public static void TestSetup(TestContext ctx) | ||
{ | ||
testBlockchain = TestBlockchain.InitializeMockNeoSystem(); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoteNode_Test_Abort_DifferentMagic() | ||
{ | ||
var connectionTestProbe = CreateTestProbe(); | ||
var remoteNodeActor = ActorOfAsTestActorRef(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null)); | ||
|
||
connectionTestProbe.ExpectMsg<Tcp.Write>(); | ||
|
||
var payload = new VersionPayload() | ||
{ | ||
UserAgent = "".PadLeft(1024, '0'), | ||
Nonce = 1, | ||
Magic = 2, | ||
Timestamp = 5, | ||
Version = 6, | ||
Capabilities = new NodeCapability[] | ||
{ | ||
new ServerCapability(NodeCapabilityType.TcpServer, 25) | ||
} | ||
}; | ||
|
||
var testProbe = CreateTestProbe(); | ||
testProbe.Send(remoteNodeActor, payload); | ||
|
||
connectionTestProbe.ExpectMsg<Tcp.Abort>(); | ||
} | ||
|
||
[TestMethod] | ||
public void RemoteNode_Test_Accept_IfSameMagic() | ||
{ | ||
var connectionTestProbe = CreateTestProbe(); | ||
var remoteNodeActor = ActorOfAsTestActorRef(() => new RemoteNode(testBlockchain, connectionTestProbe, null, null)); | ||
|
||
connectionTestProbe.ExpectMsg<Tcp.Write>(); | ||
|
||
var payload = new VersionPayload() | ||
{ | ||
UserAgent = "Unit Test".PadLeft(1024, '0'), | ||
Nonce = 1, | ||
Magic = ProtocolSettings.Default.Magic, | ||
Timestamp = 5, | ||
Version = 6, | ||
Capabilities = new NodeCapability[] | ||
{ | ||
new ServerCapability(NodeCapabilityType.TcpServer, 25) | ||
} | ||
}; | ||
|
||
var testProbe = CreateTestProbe(); | ||
testProbe.Send(remoteNodeActor, payload); | ||
|
||
var verackMessage = connectionTestProbe.ExpectMsg<Tcp.Write>(); | ||
|
||
//Verack | ||
verackMessage.Data.Count.Should().Be(3); | ||
} | ||
} | ||
} |