-
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 Test for Wallets Module (#1018)
* 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 * update UT in crypto module * Rename UT_Scrypt.cs to UT_SCrypt.cs * format * update UT_Murmur3 * update IO module test * delete empty line * changename * delete empty line * revert commit * add wallet test * update testUtil * delete empty line * Update UT_NEP6Wallet.cs * update ut * Optimize wallet test * fix * add change * fix nep6wallet * Fix * Optimize * fix optimize * fix * Optimize
- Loading branch information
Showing
17 changed files
with
1,669 additions
and
40 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,139 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.Cryptography; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using Neo.Wallets; | ||
using Neo.Wallets.NEP6; | ||
|
||
namespace Neo.UnitTests.Wallets.NEP6 | ||
{ | ||
[TestClass] | ||
public class UT_NEP6Account | ||
{ | ||
NEP6Account account; | ||
UInt160 hash; | ||
NEP6Wallet wallet; | ||
private static string nep2; | ||
private static KeyPair keyPair; | ||
|
||
[ClassInitialize] | ||
public static void ClassSetup(TestContext context) { | ||
byte[] privateKey = { 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}; | ||
keyPair = new KeyPair(privateKey); | ||
nep2 = keyPair.Export("Satoshi", 0, 0, 0); | ||
} | ||
|
||
[TestInitialize] | ||
public void TestSetup() | ||
{ | ||
wallet = TestUtils.GenerateTestWallet(); | ||
byte[] array1 = { 0x01 }; | ||
hash = new UInt160(Crypto.Default.Hash160(array1)); | ||
account = new NEP6Account(wallet, hash); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConstructorWithNep2Key() | ||
{ | ||
account.ScriptHash.Should().Be(hash); | ||
account.Decrypted.Should().BeTrue(); | ||
account.HasKey.Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestConstructorWithKeyPair() | ||
{ | ||
NEP6Wallet wallet = new NEP6Wallet("a"); | ||
byte[] array1 = { 0x01 }; | ||
var hash = new UInt160(Crypto.Default.Hash160(array1)); | ||
string password = "hello world"; | ||
NEP6Account account = new NEP6Account(wallet, hash, keyPair, password); | ||
account.ScriptHash.Should().Be(hash); | ||
account.Decrypted.Should().BeTrue(); | ||
account.HasKey.Should().BeTrue(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromJson() | ||
{ | ||
JObject json = new JObject(); | ||
json["address"] = "ARxgjcH2K1yeW5f5ryuRQNaBzSa9TZzmVS"; | ||
json["key"] = null; | ||
json["label"] = null; | ||
json["isDefault"] = true; | ||
json["lock"] = false; | ||
json["contract"] = null; | ||
json["extra"] = null; | ||
NEP6Account account = NEP6Account.FromJson(json, wallet); | ||
account.ScriptHash.Should().Be("ARxgjcH2K1yeW5f5ryuRQNaBzSa9TZzmVS".ToScriptHash()); | ||
account.Label.Should().BeNull(); | ||
account.IsDefault.Should().BeTrue(); | ||
account.Lock.Should().BeFalse(); | ||
account.Contract.Should().BeNull(); | ||
account.Extra.Should().BeNull(); | ||
account.GetKey().Should().BeNull(); | ||
|
||
json["key"] = "6PYRjVE1gAbCRyv81FTiFz62cxuPGw91vMjN4yPa68bnoqJtioreTznezn"; | ||
json["label"] = "label"; | ||
account = NEP6Account.FromJson(json, wallet); | ||
account.Label.Should().Be("label"); | ||
account.HasKey.Should().BeTrue(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetKey() | ||
{ | ||
account.GetKey().Should().BeNull(); | ||
wallet.Unlock("Satoshi"); | ||
account = new NEP6Account(wallet, hash, nep2); | ||
account.GetKey().Should().Be(keyPair); | ||
} | ||
|
||
[TestMethod] | ||
public void TestGetKeyWithString() | ||
{ | ||
account.GetKey("Satoshi").Should().BeNull(); | ||
account = new NEP6Account(wallet, hash, nep2); | ||
account.GetKey("Satoshi").Should().Be(keyPair); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
JObject nep6contract = new JObject(); | ||
nep6contract["script"] = "2103603f3880eb7aea0ad4500893925e4a42fea48a44ee6f898a10b3c7ce05d2a267ac"; | ||
JObject parameters = new JObject(); | ||
parameters["type"] = 0x00; | ||
parameters["name"] = "Sig"; | ||
JArray array = new JArray | ||
{ | ||
parameters | ||
}; | ||
nep6contract["parameters"] = array; | ||
nep6contract["deployed"] = false; | ||
account.Contract = NEP6Contract.FromJson(nep6contract); | ||
JObject json = account.ToJson(); | ||
json["address"].Should().Equals("AZk5bAanTtD6AvpeesmYgL8CLRYUt5JQsX"); | ||
json["label"].Should().BeNull(); | ||
json["isDefault"].ToString().Should().Be("false"); | ||
json["lock"].ToString().Should().Be("false"); | ||
json["key"].Should().BeNull(); | ||
json["contract"]["script"].ToString().Should().Be("\"2103603f3880eb7aea0ad4500893925e4a42fea48a44ee6f898a10b3c7ce05d2a267ac\""); | ||
json["extra"].Should().BeNull(); | ||
|
||
account.Contract = null; | ||
json = account.ToJson(); | ||
json["contract"].Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestVerifyPassword() | ||
{ | ||
account = new NEP6Account(wallet, hash, nep2); | ||
account.VerifyPassword("Satoshi").Should().BeTrue(); | ||
account.VerifyPassword("b").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,67 @@ | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Neo.IO.Json; | ||
using Neo.SmartContract; | ||
using Neo.Wallets.NEP6; | ||
|
||
namespace Neo.UnitTests.Wallets.NEP6 | ||
{ | ||
[TestClass] | ||
public class UT_NEP6Contract | ||
{ | ||
[TestMethod] | ||
public void TestFromNullJson() | ||
{ | ||
NEP6Contract nep6Contract = NEP6Contract.FromJson(null); | ||
nep6Contract.Should().BeNull(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFromJson() | ||
{ | ||
string json = "{\"script\":\"2103ef891df4c0b7eefb937d21ea0fb88cde8e0d82a7ff11872b5e7047969dafb4eb68747476aa\"," + | ||
"\"parameters\":[{\"name\":\"signature\",\"type\":\"Signature\"}],\"deployed\":false}"; | ||
JObject @object = JObject.Parse(json); | ||
|
||
NEP6Contract nep6Contract = NEP6Contract.FromJson(@object); | ||
nep6Contract.Script.Should().BeEquivalentTo("2103ef891df4c0b7eefb937d21ea0fb88cde8e0d82a7ff11872b5e7047969dafb4eb68747476aa".HexToBytes()); | ||
nep6Contract.ParameterList.Length.Should().Be(1); | ||
nep6Contract.ParameterList[0].Should().Be(ContractParameterType.Signature); | ||
nep6Contract.ParameterNames.Length.Should().Be(1); | ||
nep6Contract.ParameterNames[0].Should().Be("signature"); | ||
nep6Contract.Deployed.Should().BeFalse(); | ||
} | ||
|
||
[TestMethod] | ||
public void TestToJson() | ||
{ | ||
NEP6Contract nep6Contract = new NEP6Contract() | ||
{ | ||
Script = new byte[] { 0x00, 0x01 }, | ||
ParameterList = new ContractParameterType[] { ContractParameterType.Boolean, ContractParameterType.Integer }, | ||
ParameterNames = new string[] { "param1", "param2" }, | ||
Deployed = false | ||
}; | ||
|
||
JObject @object = nep6Contract.ToJson(); | ||
JString jString = (JString)@object["script"]; | ||
jString.Value.Should().Be(nep6Contract.Script.ToHexString()); | ||
|
||
JBoolean jBoolean = (JBoolean)@object["deployed"]; | ||
jBoolean.Value.Should().BeFalse(); | ||
|
||
JArray parameters = (JArray)@object["parameters"]; | ||
parameters.Count.Should().Be(2); | ||
|
||
jString = (JString)(parameters[0]["name"]); | ||
jString.Value.Should().Be("param1"); | ||
jString = (JString)(parameters[0]["type"]); | ||
jString.Value.Should().Be(ContractParameterType.Boolean.ToString()); | ||
|
||
jString = (JString)(parameters[1]["name"]); | ||
jString.Value.Should().Be("param2"); | ||
jString = (JString)(parameters[1]["type"]); | ||
jString.Value.Should().Be(ContractParameterType.Integer.ToString()); | ||
} | ||
} | ||
} |
Oops, something went wrong.