forked from neo-project/neo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase coverage until 80% (neo-project#1823)
* Increase coverage * Add more UT * More UT * Increase coverage * More UT * FixUT * Add UT and fixed TaskSession when no FullNodeCapability * dotnet format * Add UT * Add UT * More UT * More UT * Comparer UT * Use Helper in in ApplicationEngine * Increase coverage * dotnet format * Add message UT * Increase UT * Rename test * dotnet format * Add UT * Dotnet format * Add UT * Add coverage * Add UT * Add UT * Remove internal and add UT
- Loading branch information
Showing
48 changed files
with
1,603 additions
and
25 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
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
46 changes: 46 additions & 0 deletions
46
tests/neo.UnitTests/Consensus/UT_ChangeViewPayloadCompact.cs
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,46 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Consensus; | ||
using Neo.IO; | ||
using Neo.Network.P2P.Payloads; | ||
|
||
namespace Neo.UnitTests.Consensus | ||
{ | ||
[TestClass] | ||
public class UT_ChangeViewPayloadCompact | ||
{ | ||
[TestMethod] | ||
public void Size_Get() | ||
{ | ||
var test = new RecoveryMessage.ChangeViewPayloadCompact() { Timestamp = 1, ValidatorIndex = 1, InvocationScript = new byte[0], OriginalViewNumber = 1 }; | ||
((ISerializable)test).Size.Should().Be(12); | ||
|
||
test = new RecoveryMessage.ChangeViewPayloadCompact() { Timestamp = 1, ValidatorIndex = 1, InvocationScript = new byte[1024], OriginalViewNumber = 1 }; | ||
((ISerializable)test).Size.Should().Be(1038); | ||
} | ||
|
||
[TestMethod] | ||
public void DeserializeAndSerialize() | ||
{ | ||
var test = new RecoveryMessage.ChangeViewPayloadCompact() { Timestamp = 1, ValidatorIndex = 2, InvocationScript = new byte[] { 1, 2, 3 }, OriginalViewNumber = 3 }; | ||
var clone = test.ToArray().AsSerializable<RecoveryMessage.ChangeViewPayloadCompact>(); | ||
|
||
Assert.AreEqual(test.Timestamp, clone.Timestamp); | ||
Assert.AreEqual(test.ValidatorIndex, clone.ValidatorIndex); | ||
Assert.AreEqual(test.OriginalViewNumber, clone.OriginalViewNumber); | ||
CollectionAssert.AreEqual(test.InvocationScript, clone.InvocationScript); | ||
|
||
clone = RecoveryMessage.ChangeViewPayloadCompact.FromPayload(new ConsensusPayload() | ||
{ | ||
Data = new ChangeView() { Timestamp = 1, ViewNumber = 3 }.ToArray(), | ||
ValidatorIndex = 2, | ||
Witness = new Witness() { InvocationScript = new byte[] { 1, 2, 3 } } | ||
}); | ||
|
||
Assert.AreEqual(test.Timestamp, clone.Timestamp); | ||
Assert.AreEqual(test.ValidatorIndex, clone.ValidatorIndex); | ||
Assert.AreEqual(test.OriginalViewNumber, clone.OriginalViewNumber); | ||
CollectionAssert.AreEqual(test.InvocationScript, clone.InvocationScript); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Consensus; | ||
using Neo.IO; | ||
|
||
namespace Neo.UnitTests.Consensus | ||
{ | ||
[TestClass] | ||
public class UT_RecoveryRequest | ||
{ | ||
[TestMethod] | ||
public void Size_Get() | ||
{ | ||
var test = new RecoveryRequest() { Timestamp = 1, ViewNumber = 1 }; | ||
test.Size.Should().Be(10); | ||
} | ||
|
||
[TestMethod] | ||
public void DeserializeAndSerialize() | ||
{ | ||
var test = new RecoveryRequest() { ViewNumber = 1, Timestamp = 123 }; | ||
var clone = test.ToArray().AsSerializable<RecoveryRequest>(); | ||
|
||
Assert.AreEqual(test.Timestamp, clone.Timestamp); | ||
Assert.AreEqual(test.Type, clone.Type); | ||
Assert.AreEqual(test.ViewNumber, clone.ViewNumber); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Cryptography.ECC; | ||
using System; | ||
using ECCurve = Neo.Cryptography.ECC.ECCurve; | ||
|
||
namespace Neo.UnitTests.Cryptography.ECC | ||
{ | ||
[TestClass] | ||
public class UT_ECDSA | ||
{ | ||
[TestMethod] | ||
public void GenerateSignature() | ||
{ | ||
var ecdsa = new ECDsa(ECCurve.Secp256k1.Infinity); | ||
Assert.ThrowsException<InvalidOperationException>(() => ecdsa.GenerateSignature(new byte[0])); | ||
|
||
var pk = new byte[32]; | ||
for (int x = 0; x < pk.Length; x++) pk[x] = (byte)x; | ||
|
||
ecdsa = new ECDsa(pk, ECCurve.Secp256k1); | ||
var sig = ecdsa.GenerateSignature(new byte[] { 1 }); | ||
|
||
Assert.IsTrue(ecdsa.VerifySignature(new byte[] { 1 }, sig[0], sig[1])); | ||
Assert.IsFalse(ecdsa.VerifySignature(new byte[] { 2 }, sig[0], sig[1])); | ||
Assert.IsFalse(ecdsa.VerifySignature(new byte[] { 1 }, sig[0] + 1, sig[1])); | ||
Assert.IsFalse(ecdsa.VerifySignature(new byte[] { 1 }, sig[0], sig[1] + 1)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ByteArrayEqualityComparer | ||
{ | ||
[TestMethod] | ||
public void TestEqual() | ||
{ | ||
var a = new byte[] { 1, 2, 3, 4, 1, 2, 3, 4, 5 }; | ||
var b = new byte[] { 1, 2, 3, 4, 1, 2, 3, 4, 5 }; | ||
var check = ByteArrayEqualityComparer.Default; | ||
|
||
Assert.IsTrue(check.Equals(a, a)); | ||
Assert.IsTrue(check.Equals(a, b)); | ||
Assert.IsFalse(check.Equals(null, b)); | ||
Assert.IsFalse(check.Equals(a, null)); | ||
Assert.IsTrue(check.Equals(null, null)); | ||
|
||
Assert.IsFalse(check.Equals(a, new byte[] { 1, 2, 3 })); | ||
Assert.IsTrue(check.Equals(Array.Empty<byte>(), Array.Empty<byte>())); | ||
|
||
b[8]++; | ||
Assert.IsFalse(check.Equals(a, b)); | ||
b[8]--; | ||
b[0]--; | ||
Assert.IsFalse(check.Equals(a, b)); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetHashCode() | ||
{ | ||
var a = new byte[] { 1, 2, 3, 4, 1, 2, 3, 4, 5 }; | ||
var b = new byte[] { 1, 2, 3, 4, 1, 2, 3, 4, 5 }; | ||
var check = ByteArrayEqualityComparer.Default; | ||
|
||
Assert.AreEqual(check.GetHashCode(a), check.GetHashCode(b)); | ||
Assert.AreNotEqual(check.GetHashCode(a), check.GetHashCode(b.Take(8).ToArray())); | ||
} | ||
} | ||
} |
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 Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Neo.UnitTests | ||
{ | ||
[TestClass] | ||
public class UT_ReferenceEqualityComparer | ||
{ | ||
private class FakeEquals : IEquatable<FakeEquals> | ||
{ | ||
public bool Equals([AllowNull] FakeEquals other) | ||
{ | ||
return true; | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return 123; | ||
} | ||
} | ||
|
||
[TestMethod] | ||
public void TestEqual() | ||
{ | ||
var a = new FakeEquals(); | ||
var b = new FakeEquals(); | ||
var check = ReferenceEqualityComparer.Default; | ||
|
||
Assert.IsFalse(check.Equals(a, b)); | ||
Assert.AreNotEqual(check.GetHashCode(a), check.GetHashCode(b)); | ||
Assert.AreNotEqual(123, check.GetHashCode(a)); | ||
Assert.AreNotEqual(123, check.GetHashCode(b)); | ||
} | ||
} | ||
} |
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,48 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO; | ||
using Neo.Ledger; | ||
using System; | ||
|
||
namespace Neo.UnitTests.Ledger | ||
{ | ||
[TestClass] | ||
public class UT_ContractIdState | ||
{ | ||
[TestMethod] | ||
public void Size_Get() | ||
{ | ||
var test = new ContractIdState() { NextId = 1 }; | ||
((ISerializable)test).Size.Should().Be(4); | ||
|
||
test = new ContractIdState() { NextId = int.MaxValue }; | ||
((ISerializable)test).Size.Should().Be(4); | ||
} | ||
|
||
[TestMethod] | ||
public void Clone() | ||
{ | ||
var test = new ContractIdState() { NextId = 1 }; | ||
var clone = ((ICloneable<ContractIdState>)test).Clone(); | ||
|
||
Assert.AreEqual(test.NextId, clone.NextId); | ||
|
||
clone = new ContractIdState() { NextId = 2 }; | ||
((ICloneable<ContractIdState>)clone).FromReplica(test); | ||
|
||
Assert.AreEqual(test.NextId, clone.NextId); | ||
} | ||
|
||
[TestMethod] | ||
public void DeserializeAndSerialize() | ||
{ | ||
var test = new ContractIdState() { NextId = int.MaxValue }; | ||
var clone = test.ToArray().AsSerializable<ContractIdState>(); | ||
|
||
Assert.AreEqual(test.NextId, clone.NextId); | ||
|
||
test = new ContractIdState() { NextId = -1 }; | ||
Assert.ThrowsException<FormatException>(() => test.ToArray().AsSerializable<ContractIdState>()); | ||
} | ||
} | ||
} |
Oops, something went wrong.