From c80803648aea0f3482fed4f1a92af906f2e11552 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sat, 13 Oct 2018 15:27:41 -0400 Subject: [PATCH] [test][libdotnet] refs #8 Added update submodule and remove test sha256xor --- LibskycoinNet/skycoin/InputTestData.cs | 59 ++++++ LibskycoinNet/skycoin/InputTestDataJSON.cs | 59 ++++++ LibskycoinNet/skycoin/KeysTestData.cs | 92 +++++++++ LibskycoinNet/skycoin/KeysTestDataJSON.cs | 0 LibskycoinNet/skycoin/skycoinnet_wrap.c | 1 - LibskycoinNetTest/LibskycoinNetTest.csproj | 2 - LibskycoinNetTest/check_cipher_sha256xor.cs | 197 -------------------- LibskycoinNetTest/check_coin_coin.cs | 83 --------- gopath/src/github.com/skycoin/skycoin | 2 +- 9 files changed, 211 insertions(+), 284 deletions(-) create mode 100644 LibskycoinNet/skycoin/InputTestData.cs create mode 100644 LibskycoinNet/skycoin/InputTestDataJSON.cs create mode 100644 LibskycoinNet/skycoin/KeysTestData.cs create mode 100644 LibskycoinNet/skycoin/KeysTestDataJSON.cs delete mode 100644 LibskycoinNetTest/check_cipher_sha256xor.cs delete mode 100644 LibskycoinNetTest/check_coin_coin.cs diff --git a/LibskycoinNet/skycoin/InputTestData.cs b/LibskycoinNet/skycoin/InputTestData.cs new file mode 100644 index 00000000..378e402d --- /dev/null +++ b/LibskycoinNet/skycoin/InputTestData.cs @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace skycoin { + +public class InputTestData : global::System.IDisposable { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal InputTestData(global::System.IntPtr cPtr, bool cMemoryOwn) { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(InputTestData obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~InputTestData() { + Dispose(); + } + + public virtual void Dispose() { + lock(this) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { + if (swigCMemOwn) { + swigCMemOwn = false; + skycoinPINVOKE.delete_InputTestData(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + global::System.GC.SuppressFinalize(this); + } + } + + public GoSlice Hashes { + set { + skycoinPINVOKE.set_InputTestData_Hashes(swigCPtr, GoSlice.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_InputTestData_Hashes(swigCPtr); + GoSlice ret = (cPtr == global::System.IntPtr.Zero) ? null : new GoSlice(cPtr, false); + return ret; + } + } + + public InputTestData() : this(skycoinPINVOKE.new_InputTestData(), true) { + } + +} + +} diff --git a/LibskycoinNet/skycoin/InputTestDataJSON.cs b/LibskycoinNet/skycoin/InputTestDataJSON.cs new file mode 100644 index 00000000..2e47c12b --- /dev/null +++ b/LibskycoinNet/skycoin/InputTestDataJSON.cs @@ -0,0 +1,59 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace skycoin { + +public class InputTestDataJSON : global::System.IDisposable { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal InputTestDataJSON(global::System.IntPtr cPtr, bool cMemoryOwn) { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(InputTestDataJSON obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~InputTestDataJSON() { + Dispose(); + } + + public virtual void Dispose() { + lock(this) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { + if (swigCMemOwn) { + swigCMemOwn = false; + skycoinPINVOKE.delete_InputTestDataJSON(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + global::System.GC.SuppressFinalize(this); + } + } + + public GoSlice Hashes { + set { + skycoinPINVOKE.set_InputTestDataJSON_Hashes(swigCPtr, GoSlice.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_InputTestDataJSON_Hashes(swigCPtr); + GoSlice ret = (cPtr == global::System.IntPtr.Zero) ? null : new GoSlice(cPtr, false); + return ret; + } + } + + public InputTestDataJSON() : this(skycoinPINVOKE.new_InputTestDataJSON(), true) { + } + +} + +} diff --git a/LibskycoinNet/skycoin/KeysTestData.cs b/LibskycoinNet/skycoin/KeysTestData.cs new file mode 100644 index 00000000..e792ea41 --- /dev/null +++ b/LibskycoinNet/skycoin/KeysTestData.cs @@ -0,0 +1,92 @@ +//------------------------------------------------------------------------------ +// +// +// This file was automatically generated by SWIG (http://www.swig.org). +// Version 3.0.12 +// +// Do not make changes to this file unless you know what you are doing--modify +// the SWIG interface file instead. +//------------------------------------------------------------------------------ + +namespace skycoin { + +public class KeysTestData : global::System.IDisposable { + private global::System.Runtime.InteropServices.HandleRef swigCPtr; + protected bool swigCMemOwn; + + internal KeysTestData(global::System.IntPtr cPtr, bool cMemoryOwn) { + swigCMemOwn = cMemoryOwn; + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr); + } + + internal static global::System.Runtime.InteropServices.HandleRef getCPtr(KeysTestData obj) { + return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr; + } + + ~KeysTestData() { + Dispose(); + } + + public virtual void Dispose() { + lock(this) { + if (swigCPtr.Handle != global::System.IntPtr.Zero) { + if (swigCMemOwn) { + swigCMemOwn = false; + skycoinPINVOKE.delete_KeysTestData(swigCPtr); + } + swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero); + } + global::System.GC.SuppressFinalize(this); + } + } + + public cipher__Address Address { + set { + skycoinPINVOKE.set_KeysTestData_Address(swigCPtr, cipher__Address.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_KeysTestData_Address(swigCPtr); + cipher__Address ret = (cPtr == global::System.IntPtr.Zero) ? null : new cipher__Address(cPtr, false); + return ret; + } + } + + public SWIGTYPE_p_GoUint8_ Secret { + set { + skycoinPINVOKE.set_KeysTestData_Secret(swigCPtr, SWIGTYPE_p_GoUint8_.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_KeysTestData_Secret(swigCPtr); + SWIGTYPE_p_GoUint8_ ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_GoUint8_(cPtr, false); + return ret; + } + } + + public SWIGTYPE_p_GoUint8_ Public { + set { + skycoinPINVOKE.set_KeysTestData_Public(swigCPtr, SWIGTYPE_p_GoUint8_.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_KeysTestData_Public(swigCPtr); + SWIGTYPE_p_GoUint8_ ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_GoUint8_(cPtr, false); + return ret; + } + } + + public GoSlice Signatures { + set { + skycoinPINVOKE.set_KeysTestData_Signatures(swigCPtr, GoSlice.getCPtr(value)); + } + get { + global::System.IntPtr cPtr = skycoinPINVOKE.get_KeysTestData_Signatures(swigCPtr); + GoSlice ret = (cPtr == global::System.IntPtr.Zero) ? null : new GoSlice(cPtr, false); + return ret; + } + } + + public KeysTestData() : this(skycoinPINVOKE.new_KeysTestData(), true) { + } + +} + +} diff --git a/LibskycoinNet/skycoin/KeysTestDataJSON.cs b/LibskycoinNet/skycoin/KeysTestDataJSON.cs new file mode 100644 index 00000000..e69de29b diff --git a/LibskycoinNet/skycoin/skycoinnet_wrap.c b/LibskycoinNet/skycoin/skycoinnet_wrap.c index 91fc68a1..044efbde 100644 --- a/LibskycoinNet/skycoin/skycoinnet_wrap.c +++ b/LibskycoinNet/skycoin/skycoinnet_wrap.c @@ -278,7 +278,6 @@ SWIGEXPORT void SWIGSTDCALL SWIGRegisterStringCallback_skycoin(SWIG_CSharpString #define SWIG_FILE_WITH_INIT #include "libskycoin.h" #include "swig.h" - // #include "base64.h" void destroy_cipher_SecKeys(cipher_SecKeys* p){ diff --git a/LibskycoinNetTest/LibskycoinNetTest.csproj b/LibskycoinNetTest/LibskycoinNetTest.csproj index a77b0fb2..3a396152 100644 --- a/LibskycoinNetTest/LibskycoinNetTest.csproj +++ b/LibskycoinNetTest/LibskycoinNetTest.csproj @@ -44,12 +44,10 @@ - - diff --git a/LibskycoinNetTest/check_cipher_sha256xor.cs b/LibskycoinNetTest/check_cipher_sha256xor.cs deleted file mode 100644 index 51364dbd..00000000 --- a/LibskycoinNetTest/check_cipher_sha256xor.cs +++ /dev/null @@ -1,197 +0,0 @@ -using System; -using NUnit.Framework; -using skycoin; -using utils; -namespace LibskycoinNetTest { - [TestFixture ()] - public class check_cipher_sha256xor { - utils.transutils utils = new transutils (); - int sha256XorDataLengthSize = 4; - int sha256XorBlockSize = 32; - int sha256XorNonceSize = 32; - int sha256XorChecksumSize = 32; - - struct StrTest { - public string name; - public int data; - public GoSlice password; - public int error; - } - - StrTest[] cases; - - public void FullCase1 () { - cases = new StrTest[5]; - var c = new StrTest (); - var str = new _GoString_ (); - c.name = "data length=1 password is empty=true"; - c.data = 1; - c.password = new GoSlice (); - c.error = skycoin.skycoin.SKY_ErrSHA256orMissingPassword; - cases[0] = c; - - c = new StrTest (); - str = new _GoString_ (); - c.name = "data length=1 password is empty=false"; - c.data = 1; - c.password = new GoSlice (); - str.p = "key"; - c.password.convertString (str); - c.error = skycoin.skycoin.SKY_OK; - cases[1] = c; - - c = new StrTest (); - str = new _GoString_ (); - c.name = "data length<32 password is empty=false"; - c.data = 2; - c.password = new GoSlice (); - str.p = "pwd"; - c.password.convertString (str); - c.error = skycoin.skycoin.SKY_OK; - cases[2] = c; - - c = new StrTest (); - str = new _GoString_ (); - c.name = "data length=2*32 password is empty=false"; - c.data = 64; - c.password = new GoSlice (); - str.SetString ("9JMkCPphe73NQvGhmab"); - c.password.convertString (str); - c.error = skycoin.skycoin.SKY_OK; - cases[3] = c; - - c = new StrTest (); - str = new _GoString_ (); - c.name = "data length>2*32 password is empty=false"; - c.data = 65; - c.password = new GoSlice (); - str.p = "9JMkCPphe73NQvGhmab"; - c.password.convertString (str); - c.error = skycoin.skycoin.SKY_OK; - cases[4] = c; - - } - - [Test] - public void TestEncrypt () { - FullCase1 (); - - for (int i = 0; i < cases.Length; i++) { - var t = cases[i]; - Console.WriteLine (t.name + " " + i); - var encrypted = new GoSlice (); - var data = new GoSlice (); - var err = skycoin.skycoin.SKY_cipher_RandByte (t.data, data); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_encrypt_Sha256Xor_Encrypt (data, t.password, encrypted); - Assert.AreEqual (t.error, err); - if (t.error == skycoin.skycoin.SKY_OK) { - var n = (sha256XorDataLengthSize + t.data) / sha256XorBlockSize; - var m = (sha256XorDataLengthSize + t.data) % sha256XorBlockSize; - if (m > 0) { - n += 1; - } - var str = new _GoString_ (); - encrypted.getString (str); - Console.WriteLine (str.p); - Console.WriteLine (str.n); - if (utils.IsBase64String (str.p)) { - var rdata = utils.base64Decode (str.p); - var totalEncryptedDataLen = sha256XorBlockSize + sha256XorNonceSize + 32 + n * sha256XorBlockSize; - Assert.AreEqual (rdata.Length, totalEncryptedDataLen, t.name); - } - } - - } - } - public void FullCase2 () { - cases = new StrTest[5]; - var str = new _GoString_ (); - var c = new StrTest (); - c.name = "invalid data length"; - c.error = skycoin.skycoin.SKY_ERROR; - c.data = 32; - c.password = new GoSlice (); - str.p = "pwd"; - c.password.convertString (str); - cases[0] = c; - - str = new _GoString_ (); - c = new StrTest (); - c.name = "invalid checksum"; - c.error = skycoin.skycoin.SKY_ERROR; - c.data = 32; - c.password = new GoSlice (); - str.p = "pwd"; - c.password.convertString (str); - cases[1] = c; - - str = new _GoString_ (); - c = new StrTest (); - c.name = "empty password"; - c.error = skycoin.skycoin.SKY_ErrSHA256orMissingPassword; - c.data = 32; - c.password = new GoSlice (); - str.p = string.Empty; - c.password.convertString (str); - cases[2] = c; - - str = new _GoString_ (); - c = new StrTest (); - c.name = "nil password"; - c.error = skycoin.skycoin.SKY_ErrSHA256orMissingPassword; - c.data = 32; - c.password = new GoSlice (); - str.p = string.Empty; - c.password.convertString (str); - cases[3] = c; - - str = new _GoString_ (); - c = new StrTest (); - c.name = "invalid password"; - c.error = skycoin.skycoin.SKY_ERROR; - c.data = 32; - c.password = new GoSlice (); - str.p = "wrong password"; - c.password.convertString (str); - cases[4] = c; - - } - - [Test] - public void TestDecrypt () { - FullCase2 (); - for (int i = 0; i < cases.Length; i++) { - var tc = cases[i]; - var d = new GoSlice (); - var data = new GoSlice (); - var edata = new GoSlice (); - skycoin.skycoin.SKY_cipher_RandByte (32, data); - skycoin.skycoin.makeEncryptedData (data, 65, tc.password, edata); - var err = skycoin.skycoin.SKY_encrypt_Sha256Xor_Decrypt (edata, tc.password, d); - Assert.AreEqual (err, tc.error, tc.name + " " + i); - if (err == skycoin.skycoin.SKY_OK) { - Assert.AreEqual (d.isEqual (data), 1); - } - } - - for (int i = 0; i < 64; i++) { - var data = new GoSlice (); - var err = skycoin.skycoin.SKY_cipher_RandByte (32, data); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - Assert.AreEqual (data.len, 32); - var pwd = new GoSlice (); - var encrypted = new GoSlice (); - var decrypted = new GoSlice (); - var pwdStr = new _GoString_ (); - pwdStr.SetString ("pwd"); - pwd.convertString (pwdStr); - err = skycoin.skycoin.SKY_encrypt_Sha256Xor_Encrypt (data, pwd, encrypted); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK, i.ToString () + " failed SKY_encrypt_Sha256Xor_Encrypt"); - err = skycoin.skycoin.SKY_encrypt_Sha256Xor_Decrypt (encrypted, pwd, decrypted); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK, i.ToString () + " failed SKY_encrypt_Sha256Xor_Decrypt"); - Assert.AreEqual (data.isEqual (decrypted), 1); - } - } - } -} \ No newline at end of file diff --git a/LibskycoinNetTest/check_coin_coin.cs b/LibskycoinNetTest/check_coin_coin.cs deleted file mode 100644 index c489308a..00000000 --- a/LibskycoinNetTest/check_coin_coin.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using NUnit.Framework; -using skycoin; -using utils; -namespace LibskycoinNetTest { - [TestFixture ()] - public class check_coin_coin { - - utils.transutils transutils = new utils.transutils (); - - [Test] - public void TestAddress1 () { - var address_hex = "02fa939957e9fc52140e180264e621c2576a1bfe781f88792fb315ca3d1786afb8"; - var b = new GoSlice (); - var err = skycoin.skycoin.SKY_base58_String2Hex (address_hex, b); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - var p = new cipher_PubKey (); - err = skycoin.skycoin.SKY_cipher_NewPubKey (b, p); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - var a = new cipher__Address (); - err = skycoin.skycoin.SKY_cipher_AddressFromPubKey (p, a); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - } - - [Test] - public void TestAddress2 () { - var address_hex = "5a42c0643bdb465d90bf673b99c14f5fa02db71513249d904573d2b8b63d353d"; - var p = new cipher_PubKey (); - var s = new cipher_SecKey (); - var b = new GoSlice (); - var err = skycoin.skycoin.SKY_base58_String2Hex (address_hex, b); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_cipher_NewSecKey (b, s); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_cipher_PubKeyFromSecKey (s, p); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - var a = new cipher__Address (); - err = skycoin.skycoin.SKY_cipher_AddressFromPubKey (p, a); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - } - - [Test] - public void TestCrypto1 () { - var p = new cipher_PubKey (); - var s = new cipher_SecKey (); - for (int i = 0; i < 10; i++) { - var err = skycoin.skycoin.SKY_cipher_GenerateKeyPair (p, s); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_cipher_TestSecKey (s); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - } - } - - [Test] - public void TestCrypto2 () { - var b = new GoSlice (); - var err = skycoin.skycoin.SKY_base58_String2Hex ("5a42c0643bdb465d90bf673b99c14f5fa02db71513249d904573d2b8b63d353d", b); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - Assert.AreEqual (b.len, 32); - var p = new cipher_PubKey (); - var s = new cipher_SecKey (); - err = skycoin.skycoin.SKY_cipher_NewSecKey (b, s); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_cipher_PubKeyFromSecKey (s, p); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - var a = new cipher__Address (); - err = skycoin.skycoin.SKY_cipher_AddressFromPubKey (p, a); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - var text = "test message"; - var sha = new cipher_SHA256 (); - b = new GoSlice (); - var text_str = new _GoString_ (); - text_str.p = text; - b.convertString (text_str); - err = skycoin.skycoin.SKY_cipher_SumSHA256 (b, sha); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - err = skycoin.skycoin.SKY_cipher_TestSecKeyHash (s, sha); - Assert.AreEqual (err, skycoin.skycoin.SKY_OK); - - } - - } -} \ No newline at end of file diff --git a/gopath/src/github.com/skycoin/skycoin b/gopath/src/github.com/skycoin/skycoin index 85682f19..e8ef2c46 160000 --- a/gopath/src/github.com/skycoin/skycoin +++ b/gopath/src/github.com/skycoin/skycoin @@ -1 +1 @@ -Subproject commit 85682f190b91237e4704382a962b53116a3135ea +Subproject commit e8ef2c46b2f29103e92fa94b6e92b8599ace9ad0