Skip to content
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

up NEO3 #6

Merged
merged 6 commits into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
</p>

<p align="center">
<a href='https://coveralls.io/github/neo-project/neo?branch=master'>
<img src='https://coveralls.io/repos/github/neo-project/neo/badge.svg?branch=master' alt='Coverage Status' />
<a href="https://coveralls.io/github/neo-project/neo?branch=master">
<img src="https://coveralls.io/repos/github/neo-project/neo/badge.svg?branch=master" alt="Current Coverage Status" />
</a>
<a href="https://travis-ci.org/neo-project/neo">
<img src="https://travis-ci.org/neo-project/neo.svg?branch=master">
<img src="https://travis-ci.org/neo-project/neo.svg?branch=master" alt="Current TravisCI build status.">
</a>
<a href="https://github.com/neo-project/neo/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License">
</a>

<a href="https://github.com/neo-project/neo/releases">
<img src="https://badge.fury.io/gh/neo-project%2Fneo.svg" alt="Current neo version.">
</a>
<a href="https://github.com/neo-project/neo">
<img src="https://tokei.rs/b1/github/neo-project/neo?category=lines" alt="total lines.">
</a>
</p>

NEO 3.0 (under development): A distributed network for the Smart Economy
Expand Down
38 changes: 38 additions & 0 deletions neo.UnitTests/UT_AssetDescription.cs
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);
}
}
}
6 changes: 3 additions & 3 deletions neo.UnitTests/UT_ConsensusServiceMailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Neo.UnitTests
{
[TestClass]
public class UT_ConsensusServiceMailbox : TestKit
public class UT_ConsensusServiceMailbox : TestKit
{
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism

Expand Down Expand Up @@ -42,10 +42,10 @@ public void ConsensusServiceMailbox_Test_IsHighPriority()
uut.IsHighPriority(new ConsensusService.SetViewNumber()).Should().Be(true);
uut.IsHighPriority(new ConsensusService.Timer()).Should().Be(true);
uut.IsHighPriority(new Blockchain.PersistCompleted()).Should().Be(true);

// any random object should not have priority
object obj = null;
uut.IsHighPriority(obj).Should().Be(false);
uut.IsHighPriority(obj).Should().Be(false);
}
}
}
31 changes: 24 additions & 7 deletions neo.UnitTests/UT_Culture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -36,7 +37,8 @@ where t.GetCustomAttribute<TestClassAttribute>() != null

var cultures = new string[] { "en-US", "zh-CN", "de-DE", "ko-KR", "ja-JP" };
var originalUICulture = CultureInfo.CurrentCulture;
var emtpyObjArray = new object[] { };
var emptyObjArray = new object[] { };
var testContext = new object[] { new UnitTestContext() };

// run all the tests, varying the culture each time.
try
Expand All @@ -47,26 +49,26 @@ where t.GetCustomAttribute<TestClassAttribute>() != null

foreach (var c in testClasses)
{
var instance = c.Constructor.Invoke(emtpyObjArray);
var instance = c.Constructor.Invoke(emptyObjArray);
if (c.ClassInit != null)
{
c.ClassInit.Invoke(instance, emtpyObjArray);
c.ClassInit.Invoke(instance, testContext);
}
foreach (var m in c.TestMethods)
{
if (c.TestInit != null)
{
c.TestInit.Invoke(instance, emtpyObjArray);
c.TestInit.Invoke(instance, emptyObjArray);
}
m.Invoke(instance, emtpyObjArray);
m.Invoke(instance, emptyObjArray);
if (c.TestCleanup != null)
{
c.TestCleanup.Invoke(instance, emtpyObjArray);
c.TestCleanup.Invoke(instance, emptyObjArray);
}
}
if (c.ClassCleanup != null)
{
c.ClassCleanup.Invoke(instance, emtpyObjArray);
c.ClassCleanup.Invoke(instance, emptyObjArray);
}
}
}
Expand All @@ -79,6 +81,21 @@ where t.GetCustomAttribute<TestClassAttribute>() != null
}
}

public class UnitTestContext : TestContext
{
public override IDictionary<string, object> Properties => throw new NotImplementedException();

public override void WriteLine(string message)
{
Console.WriteLine(message);
}

public override void WriteLine(string format, params object[] args)
{
Console.WriteLine(format, args);
}
}

public class NotReRunnableAttribute : Attribute
{

Expand Down
1 change: 1 addition & 0 deletions neo.UnitTests/UT_MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ private Transaction CreateTransactionWithFee(long fee)
var randomBytes = new byte[16];
random.NextBytes(randomBytes);
Mock<Transaction> mock = new Mock<Transaction>();
mock.Setup(p => p.Reverify(It.IsAny<Snapshot>(), It.IsAny<IEnumerable<Transaction>>())).Returns(true);
mock.Setup(p => p.Verify(It.IsAny<Snapshot>(), It.IsAny<IEnumerable<Transaction>>())).Returns(true);
mock.Object.Script = randomBytes;
mock.Object.Sender = UInt160.Zero;
Expand Down
50 changes: 50 additions & 0 deletions neo.UnitTests/UT_ProtocolHandler.cs
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>();
}
}
}
46 changes: 23 additions & 23 deletions neo.UnitTests/UT_ProtocolHandlerMailbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace Neo.UnitTests
{
[TestClass]
public class UT_ProtocolHandlerMailbox : TestKit
public class UT_ProtocolHandlerMailbox : TestKit
{
private static readonly Random TestRandom = new Random(1337); // use fixed seed for guaranteed determinism

Expand Down Expand Up @@ -96,99 +96,99 @@ public void ProtocolHandlerMailbox_Test_ShallDrop()
// 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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
uut.ShallDrop(msg, new object[] { msg }).Should().Be(false);
}
}
}
Loading