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

Unit Tests of Crypto Module #962

Merged
merged 175 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
53e0ccf
testDemo
Jul 6, 2019
877ff70
Merge remote-tracking branch 'upstream/master'
eryeer Jul 8, 2019
ad5e1a9
add dll lib
eryeer Jul 8, 2019
9d70536
add dbsnapshot dispose
eryeer Jul 8, 2019
a61cac3
Merge remote-tracking branch 'upstream/master'
eryeer Jul 9, 2019
71675aa
test get blocks in levelDBStore
eryeer Jul 9, 2019
c55415b
add levelDBStore test funcs
eryeer Jul 9, 2019
d3e55d8
fix levelDBStore funcs
eryeer Jul 9, 2019
e440d60
add DbCache addInternal
eryeer Jul 9, 2019
7598dfa
differ db path
Jul 9, 2019
2ea1f86
space
Jul 9, 2019
ada729a
Merge t push
eryeer Jul 10, 2019
e581d8a
fix delete internal test
eryeer Jul 10, 2019
53e155f
add test getInternal tryGetInternal move libleveldb.dll
eryeer Jul 10, 2019
9deaa7d
Merge pull request #1 from eryeer/fix/db-path
eryeer Jul 10, 2019
7c6b9a1
add dbCache method test
eryeer Jul 10, 2019
0f50d07
Merge branch 'master' of github.com:eryeer/neoUT
eryeer Jul 10, 2019
86ed33f
add store test
eryeer Jul 10, 2019
cf4e202
add cache unit tests
Jul 10, 2019
1190766
add cache unit tests
Jul 10, 2019
ec9f488
Merge branch 'master' of github.com:eryeer/neoUT
Jul 10, 2019
235321f
up readonly max_capacity
Jul 10, 2019
c6df5ea
Merge remote-tracking branch 'upstream/master'
eryeer Jul 11, 2019
801165a
Merge branch 'master' of github.com:eryeer/neoUT
eryeer Jul 11, 2019
7fb81c4
fix leveldbexception
eryeer Jul 11, 2019
18b3562
fix comment on UT_Cache
eryeer Jul 11, 2019
bbf66fe
format
Jul 11, 2019
299401a
fix multithread test problem
eryeer Jul 11, 2019
f0214f8
up cache
Jul 11, 2019
c97b260
Merge branch 'master' of github.com:eryeer/neoUT
Jul 11, 2019
137672c
update travis config
eryeer Jul 11, 2019
48d2af9
update travis.yml
eryeer Jul 11, 2019
ad5cff3
test DbMetaDataCache
ZhangTao1596 Jul 11, 2019
e8878d4
fix db directory
ZhangTao1596 Jul 11, 2019
08fe898
Merge pull request #2 from eryeer/test/leveldb.dbmetadatecache
ZhangTao1596 Jul 11, 2019
a16d40b
format and update travis for maxos
eryeer Jul 11, 2019
de3f249
Merge branch 'master' of github.com:eryeer/neoUT
eryeer Jul 11, 2019
0ec6a4b
Merge branch 'master' into master
vncoelho Jul 11, 2019
041e800
Merge branch 'master' into master
vncoelho Jul 11, 2019
4d13f39
fix mac env travis
eryeer Jul 12, 2019
cceceef
2019/7/12 10:34
lmy0930 Jul 12, 2019
888df61
Merge branch 'master' of https://github.com/eryeer/neoUT
lmy0930 Jul 12, 2019
3b5697d
2019/7/12 11:01
lmy0930 Jul 12, 2019
f379b9f
remove commented line
eryeer Jul 12, 2019
9ebc18c
test BigDecimal
Jul 12, 2019
205fc01
fix format and csproj
eryeer Jul 12, 2019
f9de384
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 12, 2019
0baf66b
Merge pull request #3 from eryeer/ut
eryeer Jul 12, 2019
984ddd9
rm coverage.opencover.xml
eryeer Jul 12, 2019
ea3d8be
update method name
eryeer Jul 12, 2019
4a3279c
Merge pull request #4 from eryeer/ut
eryeer Jul 12, 2019
115008e
add UT_P_Helper
Jul 12, 2019
9c23106
modify UT_P_Helper
Jul 12, 2019
583db9d
modify UT_P_helper
Jul 12, 2019
f30b58d
Clean ut
shargon Jul 12, 2019
d11b639
test Base58 & BloomFilter
Jul 12, 2019
4e014ab
Update UT_Cache.cs
shargon Jul 12, 2019
82e8754
Correct Typo
Jul 12, 2019
1d65676
test JsonArray
eryeer Jul 12, 2019
925496f
update namespace
eryeer Jul 12, 2019
f493318
Merge pull request #5 from shargon/clean-ut
eryeer Jul 12, 2019
091d655
update namespace
eryeer Jul 12, 2019
455d436
update format
eryeer Jul 12, 2019
4d53e58
update format
eryeer Jul 12, 2019
93c69f4
Merge branch 'ut' of github.com:eryeer/neoUT into ut
Jul 12, 2019
63aecea
Merge branch 'master' into master
eryeer Jul 14, 2019
9d37be7
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 15, 2019
299093b
organise folder structure
eryeer Jul 15, 2019
007165e
add UT_JString
Jul 15, 2019
6aa995b
Merge branch 'ut' of github.com:eryeer/neoUT into ut
Jul 15, 2019
2aa85b6
test JBoolean JNumber & JObject
eryeer Jul 15, 2019
d7a8174
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 15, 2019
b8fb5bf
Merge remote-tracking branch 'upstream/master'
eryeer Jul 16, 2019
6c279a0
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 16, 2019
57f740b
2019/7/16 10:30
lmy0930 Jul 16, 2019
d6dce91
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
lmy0930 Jul 16, 2019
a31d6ac
fix timestamp
eryeer Jul 16, 2019
609ba6f
test ECDsa and Crypto
Jul 16, 2019
571938e
test OrderedDictionary & complete IO.Json tests
eryeer Jul 16, 2019
5a5c3d7
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 16, 2019
1ca84d9
2019/7/16 17:33
lmy0930 Jul 16, 2019
e5c1783
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
lmy0930 Jul 16, 2019
c8402ac
test FIFOSet
eryeer Jul 16, 2019
00d2579
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 16, 2019
3369ca5
add CloneCache and DataCache unit tests
Jul 16, 2019
85404a6
Merge branch 'ut' of github.com:eryeer/neoUT into ut
Jul 16, 2019
97ec014
Merge remote-tracking branch 'upstream/master'
eryeer Jul 17, 2019
5570a5b
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 17, 2019
d094af9
fix namespace
eryeer Jul 17, 2019
4b753ef
add UT_Cryptography_Helper
Jul 17, 2019
bd4ee5a
Merge branch 'ut' of github.com:eryeer/neoUT into ut
Jul 17, 2019
327b036
format UT_CloneCache and UT_DataCache
Jul 17, 2019
b693471
add UT_DataCache.GetAndChange unit test
Jul 17, 2019
6975292
Merge remote-tracking branch 'upstream/master'
eryeer Jul 18, 2019
2ca6662
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 18, 2019
2fffcaf
update namespace
eryeer Jul 18, 2019
e220a28
remove comment code
Jul 18, 2019
c4d4acd
Merge remote-tracking branch 'upstream/master'
eryeer Jul 19, 2019
a071acb
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 19, 2019
7ad2e6e
delete Persistence part
eryeer Jul 19, 2019
269085b
2019/7/19 11:07
lmy0930 Jul 19, 2019
88a7dd9
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
lmy0930 Jul 19, 2019
0b8f79a
Fix Base58 Test
Jul 19, 2019
8403ceb
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
lmy0930 Jul 19, 2019
a752eb4
2019/7/19 11:33
lmy0930 Jul 19, 2019
9bd5702
update IOHelper exception assert
eryeer Jul 19, 2019
b66712d
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 19, 2019
2b06d6c
2019/7/19 14:22
lmy0930 Jul 19, 2019
61ded58
format IOHelper
eryeer Jul 19, 2019
de75342
merge conflict of IOHelper
eryeer Jul 19, 2019
db06a47
review IO.Wrapper
eryeer Jul 19, 2019
336c3c3
review Wallets.SQLite UT
eryeer Jul 19, 2019
e4a6fa6
Test ECFieldElement ECPoint
Jul 19, 2019
4234650
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
Jul 19, 2019
935fec4
refactor package
Jul 19, 2019
c87fd50
format ECDsa
eryeer Jul 19, 2019
3d36710
merge conflict
eryeer Jul 19, 2019
599d077
update namespace
eryeer Jul 19, 2019
61dd25a
Code fix
Jul 19, 2019
87526bd
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
Jul 19, 2019
ae5129c
review cache
Jul 19, 2019
72254eb
modify UT_JString
Jul 19, 2019
aeb5869
fomat
eryeer Jul 19, 2019
fddce6a
merge confilct
eryeer Jul 19, 2019
6232806
format UT_ECPoint
Jul 19, 2019
5169605
resolve and format UT_Ecdsa
Jul 19, 2019
a48a0c3
using Actin replace with try-catch
Jul 19, 2019
cc2dcac
add UT_CloneMetaCache and UT_MetaDataCache
Jul 19, 2019
5856bc6
Merge remote-tracking branch 'upstream/master'
eryeer Jul 19, 2019
0eb76c8
merge
eryeer Jul 19, 2019
6c44ceb
update namespace
eryeer Jul 19, 2019
0343b21
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 19, 2019
714123d
format UT_DataCache.cs
Jul 21, 2019
2b4b1d3
Merge branch 'ut' of github.com:eryeer/neoUT into ut
Jul 21, 2019
3010a2c
Merge remote-tracking branch 'upstream/master'
eryeer Jul 22, 2019
ef36ac0
Merge remote-tracking branch 'upstream/master' into ut
eryeer Jul 22, 2019
86696a1
Code Fix
Jul 22, 2019
bf0672a
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
Jul 22, 2019
47f3afe
merge conflict
eryeer Jul 22, 2019
958f319
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 22, 2019
d454960
format
eryeer Jul 22, 2019
1551d6a
update csproj
eryeer Jul 22, 2019
2ff4dc8
Code fix for UT_ECFieldElement and UT_ECPoint
Jul 22, 2019
2763eeb
Merge branch 'ut' of https://github.com/eryeer/neoUT into ut
Jul 22, 2019
5d77ca9
Code fix
Jul 22, 2019
3f36346
Merge branch 'ut' of github.com:eryeer/neoUT into ut
eryeer Jul 22, 2019
bce3f94
format
eryeer Jul 22, 2019
4f87abc
update travis
eryeer Jul 22, 2019
7150321
delete deleteFiles
eryeer Jul 22, 2019
93ee3fa
Merge pull request #6 from eryeer/ut
eryeer Jul 22, 2019
2044b11
fix path and comment
eryeer Jul 22, 2019
d396d23
Merge remote-tracking branch 'upstream/master'
eryeer Jul 22, 2019
54679e4
update travis
eryeer Jul 22, 2019
dbb7b07
Merge remote-tracking branch 'upstream/master'
eryeer Jul 23, 2019
0581b4a
delete test ToTimeStamp
eryeer Jul 23, 2019
143ab3d
Merge branch 'master' into master
eryeer Jul 23, 2019
d382be8
format UT_*Cache
Jul 23, 2019
ced2ee6
Merge pull request #7 from eryeer/ut_io_cache
eryeer Jul 23, 2019
f8c8597
update format
eryeer Jul 23, 2019
d90a850
Merge branch 'master' of github.com:eryeer/neoUT
eryeer Jul 23, 2019
1808a54
fomat
eryeer Jul 23, 2019
0f362c2
use hex extensions in Cryptography_Helper
Jul 23, 2019
e2a199d
Merge branch 'master' into master
eryeer Jul 24, 2019
9970a0a
Merge pull request #8 from ShawnYun/master
eryeer Jul 24, 2019
124e8f0
remove reflection
eryeer Jul 24, 2019
6a517e7
optimization of UT_DataCache
eryeer Jul 24, 2019
b152a49
update namespace
eryeer Jul 24, 2019
547279d
modify TestSha256
eryeer Jul 24, 2019
630f942
Merge branch 'master' into master
eryeer Jul 25, 2019
29dc9c1
Merge remote-tracking branch 'upstream/master'
eryeer Jul 29, 2019
91896fb
update UT in crypto module
eryeer Jul 29, 2019
8fd545f
Rename UT_Scrypt.cs to UT_SCrypt.cs
eryeer Jul 29, 2019
1259556
format
eryeer Jul 29, 2019
2c16837
update UT_Murmur3
eryeer Jul 29, 2019
918cfdb
Merge branch 'master' into master
eryeer Jul 29, 2019
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
42 changes: 42 additions & 0 deletions neo.UnitTests/Cryptography/ECC/UT_ECPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void TestECPointConstructor()
point.X.Should().Be(X);
point.Y.Should().Be(Y);
point.Curve.Should().Be(ECCurve.Secp256k1);
Action action = () => new ECPoint(X, null, ECCurve.Secp256k1);
action.ShouldThrow<ArgumentException>();
action = () => new ECPoint(null, Y, ECCurve.Secp256k1);
action.ShouldThrow<ArgumentException>();
}

[TestMethod]
Expand Down Expand Up @@ -145,6 +149,30 @@ public void TestEquals()
point1.Equals(point3).Should().BeFalse();
}

[TestMethod]
public void TestEqualsObject()
{
object point = ECCurve.Secp256k1.G;
point.Equals(point).Should().BeTrue();
point.Equals(null).Should().BeFalse();
point.Equals(1u).Should().BeFalse();

point = new ECPoint(null, null, ECCurve.Secp256k1);
point.Equals(new ECPoint(null, null, ECCurve.Secp256r1)).Should().BeTrue();
point.Equals(ECCurve.Secp256r1.G).Should().BeFalse();
ECCurve.Secp256r1.G.Equals(point).Should().BeFalse();

ECFieldElement X1 = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1);
ECFieldElement Y1 = new ECFieldElement(new BigInteger(200), ECCurve.Secp256k1);
ECFieldElement X2 = new ECFieldElement(new BigInteger(300), ECCurve.Secp256k1);
ECFieldElement Y2 = new ECFieldElement(new BigInteger(400), ECCurve.Secp256k1);
object point1 = new ECPoint(X1, Y1, ECCurve.Secp256k1);
object point2 = new ECPoint(X2, Y1, ECCurve.Secp256k1);
object point3 = new ECPoint(X1, Y2, ECCurve.Secp256k1);
point1.Equals(point2).Should().BeFalse();
point1.Equals(point3).Should().BeFalse();
}

[TestMethod]
public void TestFromBytes()
{
Expand Down Expand Up @@ -176,6 +204,13 @@ public void TestFromBytes()
ECCurve.Secp256k1), ECCurve.Secp256k1));
}

[TestMethod]
public void TestGetSize()
{
ECCurve.Secp256k1.G.Size.Should().Be(33);
ECCurve.Secp256k1.Infinity.Size.Should().Be(1);
}

[TestMethod]
public void TestMultiply()
{
Expand Down Expand Up @@ -279,6 +314,13 @@ public void TestOpMultiply()
new ECFieldElement(BigInteger.Parse("29236048674093813394523910922582374630829081423043497254162533033164154049666"), ECCurve.Secp256k1), ECCurve.Secp256k1));
}

[TestMethod]
public void TestOpSubtraction()
{
(ECCurve.Secp256k1.G - ECCurve.Secp256k1.Infinity).Should().Be(ECCurve.Secp256k1.G);
(ECCurve.Secp256k1.G - ECCurve.Secp256k1.G).Should().Be(ECCurve.Secp256k1.Infinity);
}

[TestMethod]
public void TestOpUnaryNegation()
{
Expand Down
80 changes: 80 additions & 0 deletions neo.UnitTests/Cryptography/UT_MerkleTree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Neo.UnitTests.Cryptography
{
[TestClass]
public class UT_MerkleTree
{
public UInt256 GetByteArrayHash(byte[] byteArray)
{
if(byteArray == null || byteArray.Length == 0) throw new ArgumentNullException();
var hash = new UInt256(Crypto.Default.Hash256(byteArray));
return hash;
}

[TestMethod]
public void TestBuildAndDepthFirstSearch()
{
IReadOnlyList<UInt256> hashNull = new UInt256[] { };
Action action = () => new MerkleTree(hashNull);
action.ShouldThrow<ArgumentException>();

byte[] array1 = { 0x01 };
var hash1 = GetByteArrayHash(array1);

byte[] array2 = { 0x02 };
var hash2 = GetByteArrayHash(array2);

byte[] array3 = { 0x03 };
var hash3 = GetByteArrayHash(array3);

IReadOnlyList<UInt256> hashes = new UInt256[] { hash1, hash2, hash3 };
MerkleTree tree = new MerkleTree(hashes);
var hashArray = tree.ToHashArray();
hashArray[0].Should().Be(hash1);
hashArray[1].Should().Be(hash2);
hashArray[2].Should().Be(hash3);
hashArray[3].Should().Be(hash3);

var rootHash = MerkleTree.ComputeRoot(hashes);
var hash4 = Crypto.Default.Hash256(hash1.ToArray().Concat(hash2.ToArray()).ToArray());
var hash5 = Crypto.Default.Hash256(hash3.ToArray().Concat(hash3.ToArray()).ToArray());
var result = new UInt256(Crypto.Default.Hash256(hash4.ToArray().Concat(hash5.ToArray()).ToArray()));
rootHash.Should().Be(result);
}

[TestMethod]
public void TestTrim()
{
byte[] array1 = { 0x01 };
var hash1 = GetByteArrayHash(array1);

byte[] array2 = { 0x02 };
var hash2 = GetByteArrayHash(array2);

byte[] array3 = { 0x03 };
var hash3 = GetByteArrayHash(array3);

IReadOnlyList<UInt256> hashes = new UInt256[] { hash1, hash2, hash3 };
MerkleTree tree = new MerkleTree(hashes);

bool[] boolArray = { false, false, false };
BitArray bitArray = new BitArray(boolArray);
tree.Trim(bitArray);
var hashArray = tree.ToHashArray();

hashArray.Length.Should().Be(1);
var rootHash = MerkleTree.ComputeRoot(hashes);
var hash4 = Crypto.Default.Hash256(hash1.ToArray().Concat(hash2.ToArray()).ToArray());
var hash5 = Crypto.Default.Hash256(hash3.ToArray().Concat(hash3.ToArray()).ToArray());
var result = new UInt256(Crypto.Default.Hash256(hash4.ToArray().Concat(hash5.ToArray()).ToArray()));
hashArray[0].Should().Be(result);
}
}
}
51 changes: 51 additions & 0 deletions neo.UnitTests/Cryptography/UT_MerkleTreeNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
using System.Text;

namespace Neo.UnitTests.Cryptography
{
[TestClass]
public class UT_MerkleTreeNode
{
private MerkleTreeNode node = new MerkleTreeNode();

[TestInitialize]
public void TestSetup()
{
node.Hash = null;
node.Parent = null;
node.LeftChild = null;
node.RightChild = null;
}

[TestMethod]
public void TestConstructor()
{
byte[] byteArray = Encoding.ASCII.GetBytes("hello world");
var hash = new UInt256(Crypto.Default.Hash256(byteArray));
node.Hash = hash;

node.Hash.Should().Be(hash);
node.Parent.Should().BeNull();
node.LeftChild.Should().BeNull();
node.RightChild.Should().BeNull();
}

[TestMethod]
public void TestGetIsLeaf()
{
node.IsLeaf.Should().BeTrue();

MerkleTreeNode child = new MerkleTreeNode();
node.LeftChild = child;
node.IsLeaf.Should().BeFalse();
}

[TestMethod]
public void TestGetIsRoot()
{
node.IsRoot.Should().BeTrue();
}
}
}
24 changes: 24 additions & 0 deletions neo.UnitTests/Cryptography/UT_Murmur3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;

namespace Neo.UnitTests.Cryptography
{
[TestClass]
public class UT_Murmur3
{
[TestMethod]
public void TestGetHashSize()
{
Murmur3 murmur3 = new Murmur3(1);
murmur3.HashSize.Should().Be(32);
}

[TestMethod]
public void TestHashCore()
{
byte[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 };
array.Murmur32(10u).Should().Be(378574820u);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Neo.Cryptography;
using System;

namespace Neo.UnitTests.Cryptography
{
[TestClass]
public class UT_Scrypt
public class UT_SCrypt
{
[TestMethod]
public void DeriveKeyTest()
Expand Down