-
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.
Merge branch 'master' into 3.0/SVM-3
- Loading branch information
Showing
5 changed files
with
198 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Persistence; | ||
using Neo.SmartContract.Native; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_AssetDescription | ||
{ | ||
private Store Store; | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
TestBlockchain.InitializeMockNeoSystem(); | ||
Store = TestBlockchain.GetStore(); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_GAS() | ||
{ | ||
var descriptor = new Wallets.AssetDescriptor(NativeContract.GAS.Hash); | ||
descriptor.AssetId.Should().Be(NativeContract.GAS.Hash); | ||
descriptor.AssetName.Should().Be("GAS"); | ||
descriptor.Decimals.Should().Be(8); | ||
} | ||
|
||
[TestMethod] | ||
public void Check_NEO() | ||
{ | ||
var descriptor = new Wallets.AssetDescriptor(NativeContract.NEO.Hash); | ||
descriptor.AssetId.Should().Be(NativeContract.NEO.Hash); | ||
descriptor.AssetName.Should().Be("NEO"); | ||
descriptor.Decimals.Should().Be(0); | ||
} | ||
} | ||
} |
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); | ||
} | ||
} | ||
} |
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