-
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.
Unit tests for IO, Cryptography, Wallets and VM modules (#943)
* testDemo * add dll lib * add dbsnapshot dispose * test get blocks in levelDBStore * add levelDBStore test funcs * fix levelDBStore funcs * add DbCache addInternal * differ db path * space * fix delete internal test * add test getInternal tryGetInternal move libleveldb.dll * add dbCache method test * add store test * add cache unit tests * add cache unit tests * up readonly max_capacity * fix leveldbexception * fix comment on UT_Cache * format * fix multithread test problem * up cache * update travis config * update travis.yml * test DbMetaDataCache * fix db directory * format and update travis for maxos * fix mac env travis * 2019/7/12 10:34 * 2019/7/12 11:01 * remove commented line * test BigDecimal * fix format and csproj * rm coverage.opencover.xml * update method name * add UT_P_Helper * modify UT_P_Helper * modify UT_P_helper * Clean ut * test Base58 & BloomFilter * Update UT_Cache.cs * Correct Typo * test JsonArray * update namespace * update namespace * update format * update format * organise folder structure * add UT_JString * test JBoolean JNumber & JObject * 2019/7/16 10:30 add some test case for UInt32Wrapper and SerializableWrapper * fix timestamp * test ECDsa and Crypto * test OrderedDictionary & complete IO.Json tests * 2019/7/16 17:33 add some test case of SQLiteWallet * test FIFOSet * add CloneCache and DataCache unit tests * fix namespace * add UT_Cryptography_Helper * format UT_CloneCache and UT_DataCache * add UT_DataCache.GetAndChange unit test * update namespace * remove comment code * delete Persistence part * 2019/7/19 11:07 add some test case for Helper in VM * Fix Base58 Test * 2019/7/19 11:33 change some format * update IOHelper exception assert * 2019/7/19 14:22 change format * format IOHelper * review IO.Wrapper * review Wallets.SQLite UT * Test ECFieldElement ECPoint * refactor package * format ECDsa * update namespace * Code fix * review cache * modify UT_JString * fomat * using Actin replace with try-catch * add UT_CloneMetaCache and UT_MetaDataCache * update namespace * format UT_DataCache.cs * Code Fix * format * update csproj * Code fix for UT_ECFieldElement and UT_ECPoint * Code fix * format * update travis * delete deleteFiles * fix path and comment * update travis * delete test ToTimeStamp * format UT_*Cache * update format * fomat * use hex extensions in Cryptography_Helper * remove reflection * optimization of UT_DataCache * update namespace * modify TestSha256
- Loading branch information
Showing
64 changed files
with
3,625 additions
and
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Wallets; | ||
using System; | ||
using System.Numerics; | ||
using ECDsa = Neo.Cryptography.ECC.ECDsa; | ||
|
||
namespace Neo.UnitTests.Cryptography | ||
{ | ||
[TestClass] | ||
public class UT_ECDsa | ||
{ | ||
private KeyPair key = null; | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
key = UT_Crypto.generateCertainKey(32); | ||
} | ||
|
||
[TestMethod] | ||
public void TestECDsaConstructor() | ||
{ | ||
Action action = () => new ECDsa(key.PublicKey); | ||
action.ShouldNotThrow(); | ||
action = () => new ECDsa(key.PrivateKey, key.PublicKey.Curve); | ||
action.ShouldNotThrow(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGenerateSignature() | ||
{ | ||
ECDsa sa = new ECDsa(key.PrivateKey, key.PublicKey.Curve); | ||
byte[] message = System.Text.Encoding.Default.GetBytes("HelloWorld"); | ||
for (int i = 0; i < 30; i++) | ||
{ | ||
BigInteger[] result = sa.GenerateSignature(message); | ||
result.Length.Should().Be(2); | ||
} | ||
sa = new ECDsa(key.PublicKey); | ||
Action action = () => sa.GenerateSignature(message); | ||
action.ShouldThrow<InvalidOperationException>(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestVerifySignature() | ||
{ | ||
ECDsa sa = new ECDsa(key.PrivateKey, key.PublicKey.Curve); | ||
byte[] message = System.Text.Encoding.Default.GetBytes("HelloWorld"); | ||
BigInteger[] result = sa.GenerateSignature(message); | ||
sa.VerifySignature(message, result[0], result[1]).Should().BeTrue(); | ||
sa.VerifySignature(message, new BigInteger(-100), result[1]).Should().BeFalse(); | ||
} | ||
} | ||
} |
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,69 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Cryptography.ECC; | ||
using System; | ||
using System.Globalization; | ||
using System.Numerics; | ||
using System.Reflection; | ||
|
||
namespace Neo.UnitTests.Cryptography.ECC | ||
{ | ||
[TestClass] | ||
public class UT_ECFieldElement | ||
{ | ||
[TestMethod] | ||
public void TestECFieldElementConstructor() | ||
{ | ||
BigInteger input = new BigInteger(100); | ||
Action action = () => new ECFieldElement(input, ECCurve.Secp256k1); | ||
action.ShouldNotThrow(); | ||
|
||
input = ECCurve.Secp256k1.Q; | ||
action = () => new ECFieldElement(input, ECCurve.Secp256k1); | ||
action.ShouldThrow<ArgumentException>(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestEquals() | ||
{ | ||
BigInteger input = new BigInteger(100); | ||
object element = new ECFieldElement(input, ECCurve.Secp256k1); | ||
element.Equals(element).Should().BeTrue(); | ||
element.Equals(1).Should().BeFalse(); | ||
|
||
input = new BigInteger(200); | ||
element.Equals(new ECFieldElement(input, ECCurve.Secp256k1)).Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestSqrt() | ||
{ | ||
ECFieldElement element = new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1); | ||
element.Sqrt().Should().Be(new ECFieldElement(BigInteger.Parse("115792089237316195423570985008687907853269984665640564039457584007908834671653"), ECCurve.Secp256k1)); | ||
|
||
ConstructorInfo constructor = typeof(ECCurve).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(BigInteger), typeof(BigInteger), typeof(BigInteger), typeof(BigInteger), typeof(byte[]) }, null); | ||
ECCurve testCruve = constructor.Invoke(new object[] { | ||
BigInteger.Parse("00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFF0", NumberStyles.AllowHexSpecifier), | ||
BigInteger.Parse("00FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFF00", NumberStyles.AllowHexSpecifier), | ||
BigInteger.Parse("005AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B", NumberStyles.AllowHexSpecifier), | ||
BigInteger.Parse("00FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551", NumberStyles.AllowHexSpecifier), | ||
("04" + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296" + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5").HexToBytes() }) as ECCurve; | ||
element = new ECFieldElement(new BigInteger(200), testCruve); | ||
element.Sqrt().Should().Be(null); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToByteArray() | ||
{ | ||
byte[] result = new byte[32]; | ||
result[31] = 100; | ||
new ECFieldElement(new BigInteger(100), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result); | ||
|
||
byte[] result2 = { 2, 53, 250, 221, 129, 194, 130, 43, 179, 240, 120, 119, 151, 61, 80, 242, 139, 242, 42, 49, 190, 142, 232, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
new ECFieldElement(BigInteger.Pow(new BigInteger(10), 75), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result2); | ||
|
||
byte[] result3 = { 221, 21, 254, 134, 175, 250, 217, 18, 73, 239, 14, 183, 19, 243, 158, 190, 170, 152, 123, 110, 111, 210, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
new ECFieldElement(BigInteger.Pow(new BigInteger(10), 77), ECCurve.Secp256k1).ToByteArray().Should().BeEquivalentTo(result3); | ||
} | ||
} | ||
} |
Oops, something went wrong.