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

merge neo3 #7

Merged
merged 9 commits into from
Jul 16, 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
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +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="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" 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" 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://codecov.io/github/neo-project/neo/branch/master/graph/badge.svg">
<img src="https://codecov.io/github/neo-project/neo/branch/master/graph/badge.svg" alt="Current Coverage Status." />
</a>
<a href="https://github.com/neo-project/neo">
<img src="https://tokei.rs/b1/github/neo-project/neo?category=lines" alt="total lines.">
<img src="https://tokei.rs/b1/github/neo-project/neo?category=lines" alt="Current total lines.">
</a>
<a href="https://github.com/neo-project/neo/blob/master/LICENSE">
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License.">
</a>
</p>

NEO 3.0 (under development): A distributed network for the Smart Economy
Expand Down
54 changes: 54 additions & 0 deletions neo.UnitTests/UT_FifoSet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.IO.Caching;
using System.Linq;

namespace Neo.UnitTests
{
[TestClass]
public class UT_FifoSet
{
[TestMethod]
public void FifoSetTest()
{
var a = UInt256.Zero;
var b = new UInt256();
var c = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01
});

var set = new FIFOSet<UInt256>(3);

Assert.IsTrue(set.Add(a));
Assert.IsFalse(set.Add(a));
Assert.IsFalse(set.Add(b));
Assert.IsTrue(set.Add(c));

CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c });

var d = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x02
});

// Testing Fifo max size
Assert.IsTrue(set.Add(d));
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { a, c, d });

var e = new UInt256(new byte[32] {
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x03
});

Assert.IsTrue(set.Add(e));
Assert.IsFalse(set.Add(e));
CollectionAssert.AreEqual(set.ToArray(), new UInt256[] { c, d, e });
}
}
}
19 changes: 19 additions & 0 deletions neo.UnitTests/UT_Scrypt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
using System;

namespace Neo.UnitTests
{
[TestClass]
public class UT_Scrypt
{
[TestMethod]
public void DeriveKeyTest()
{
int N = 16384, r = 8, p = 8;

var derivedkey = SCrypt.DeriveKey(new byte[] { 0x01, 0x02, 0x03 }, new byte[] { 0x04, 0x05, 0x06 }, N, r, p, 64).ToHexString();
Assert.AreEqual("2bb9c7bb9c392f0dd37821b76e42b01944902520f48d00946a51e72c960fba0a3c62a87d835c9df10a8ad66a04cdf02fbb10b9d7396c20959f28d6cb3ddfdffb", derivedkey);
}
}
}
8 changes: 4 additions & 4 deletions neo.UnitTests/UT_Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ private NEP6Wallet GenerateTestWallet()
JObject wallet = new JObject();
wallet["name"] = "noname";
wallet["version"] = new System.Version().ToString();
wallet["scrypt"] = ScryptParameters.Default.ToJson();
wallet["scrypt"] = new ScryptParameters(0, 0, 0).ToJson();
wallet["accounts"] = new JArray();
wallet["extra"] = null;
wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"0.0\",\"scrypt\":{\"n\":16384,\"r\":8,\"p\":8},\"accounts\":[],\"extra\":null}");
wallet.ToString().Should().Be("{\"name\":\"noname\",\"version\":\"0.0\",\"scrypt\":{\"n\":0,\"r\":0,\"p\":0},\"accounts\":[],\"extra\":null}");
return new NEP6Wallet(wallet);
}

Expand All @@ -114,8 +114,8 @@ public void FeeIsMultiSigContract()
b.GetKey().PublicKey
});

var acc = walletA.CreateAccount(multiSignContract, a.GetKey());
acc = walletB.CreateAccount(multiSignContract, b.GetKey());
walletA.CreateAccount(multiSignContract, a.GetKey());
var acc = walletB.CreateAccount(multiSignContract, b.GetKey());

// Fake balance

Expand Down
4 changes: 0 additions & 4 deletions neo/Cryptography/ECC/ECFieldElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;

Expand Down Expand Up @@ -47,8 +46,6 @@ private static BigInteger[] FastLucasSequence(BigInteger p, BigInteger P, BigInt
int n = k.GetBitLength();
int s = k.GetLowestSetBit();

Debug.Assert(k.TestBit(s));

BigInteger Uh = 1;
BigInteger Vl = 2;
BigInteger Vh = P;
Expand Down Expand Up @@ -131,7 +128,6 @@ public ECFieldElement Sqrt()
V += curve.Q;
}
V >>= 1;
Debug.Assert((V * V).Mod(curve.Q) == Value);
return new ECFieldElement(V, curve);
}
}
Expand Down
20 changes: 14 additions & 6 deletions neo/Cryptography/ECC/ECPoint.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Neo.IO;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -113,11 +112,21 @@ public static ECPoint DeserializeFrom(BinaryReader reader, ECCurve curve)
{
case 0x02:
case 0x03:
reader.Read(buffer, 1, expectedLength);
return DecodePoint(buffer.Take(1 + expectedLength).ToArray(), curve);
{
if (reader.Read(buffer, 1, expectedLength) != expectedLength)
{
throw new FormatException();
}
return DecodePoint(buffer.Take(1 + expectedLength).ToArray(), curve);
}
case 0x04:
reader.Read(buffer, 1, expectedLength * 2);
return DecodePoint(buffer, curve);
{
if (reader.Read(buffer, 1, expectedLength * 2) != expectedLength * 2)
{
throw new FormatException();
}
return DecodePoint(buffer, curve);
}
default:
throw new FormatException("Invalid point encoding " + buffer[0]);
}
Expand Down Expand Up @@ -386,7 +395,6 @@ private static sbyte[] WindowNaf(sbyte width, BigInteger k)
{
if (x.Y.Equals(y.Y))
return x.Twice();
Debug.Assert(x.Y.Equals(-y.Y));
return x.Curve.Infinity;
}
ECFieldElement gamma = (y.Y - x.Y) / (y.X - x.X);
Expand Down
2 changes: 1 addition & 1 deletion neo/IO/Caching/FIFOSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ExceptWith(IEnumerable<UInt256> hashes)

public IEnumerator<T> GetEnumerator()
{
var entries = dictionary.Values.Cast<T>().ToArray();
var entries = dictionary.Keys.Cast<T>().ToArray();
foreach (var entry in entries) yield return entry;
}

Expand Down
3 changes: 2 additions & 1 deletion neo/Ledger/MemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ internal void UpdatePoolForBlockPersisted(Block block, Snapshot snapshot)
if (policyChanged)
{
foreach (PoolItem item in _unverifiedSortedTransactions.Reverse())
_system.Blockchain.Tell(item.Tx, ActorRefs.NoSender);
if(item.Tx.FeePerByte >= _feePerByte)
_system.Blockchain.Tell(item.Tx, ActorRefs.NoSender);
_unverifiedTransactions.Clear();
_unverifiedSortedTransactions.Clear();
}
Expand Down
12 changes: 7 additions & 5 deletions neo/UIntBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace Neo
{

/// <summary>
/// Base class for little-endian unsigned integers. Two classes inherit from this: UInt160 and UInt256.
/// Only basic comparison/serialization are proposed for these classes. For arithmetic purposes, use BigInteger class.
Expand All @@ -15,7 +14,7 @@ public abstract class UIntBase : IEquatable<UIntBase>, ISerializable
/// <summary>
/// Storing unsigned int in a little-endian byte array.
/// </summary>
private byte[] data_bytes;
private readonly byte[] data_bytes;

/// <summary>
/// Number of bytes of the unsigned int.
Expand Down Expand Up @@ -44,7 +43,10 @@ protected UIntBase(int bytes, byte[] value)
/// </summary>
void ISerializable.Deserialize(BinaryReader reader)
{
reader.Read(data_bytes, 0, data_bytes.Length);
if (reader.Read(data_bytes, 0, data_bytes.Length) != data_bytes.Length)
{
throw new FormatException();
}
}

/// <summary>
Expand All @@ -53,7 +55,7 @@ void ISerializable.Deserialize(BinaryReader reader)
/// </summary>
public bool Equals(UIntBase other)
{
if (ReferenceEquals(other, null))
if (other is null)
return false;
if (ReferenceEquals(this, other))
return true;
Expand All @@ -68,7 +70,7 @@ public bool Equals(UIntBase other)
/// </summary>
public override bool Equals(object obj)
{
if (ReferenceEquals(obj, null))
if (obj is null)
return false;
if (!(obj is UIntBase))
return false;
Expand Down