From f0da310ae7720f23a4c720293aab46d0ff846ef7 Mon Sep 17 00:00:00 2001 From: Maykel Arias Torres Date: Sun, 14 Oct 2018 10:04:12 -0400 Subject: [PATCH] [test] refs #8 Testing data type callback --- LibskycoinNet/skycoin/skycoinnet_wrap.c | 44 +++---------------------- LibskycoinNetTest/check_coin_block.cs | 12 ++++--- LibskycoinNetTest/transutils.cs | 5 +-- gopath/src/github.com/skycoin/skycoin | 2 +- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/LibskycoinNet/skycoin/skycoinnet_wrap.c b/LibskycoinNet/skycoin/skycoinnet_wrap.c index 71f07225..cb5c23cb 100644 --- a/LibskycoinNet/skycoin/skycoinnet_wrap.c +++ b/LibskycoinNet/skycoin/skycoinnet_wrap.c @@ -1874,18 +1874,6 @@ void makeEncryptedData(GoSlice data, GoUint32 dataLength, GoSlice pwd, coin__UxA return result; } - - -GoUint32_ _WrapperFeeCalculator(Transaction__Handle handle, GoUint64_* pFee, void* context){ - FeeCalcFunc* feeCalc = (FeeCalcFunc*)context; - int *result = callFeeCalculator(feeCalc, handle, pFee); - GoUint32_ error = 0; - if(result != 0) - return error; - - return 0; -} - SWIGINTERN int cipher_PubKey_isEqual(cipher_PubKey *self,cipher_PubKey *a){ return memcmp(self->data, a->data, sizeof(a->data)) == 0; } @@ -6411,7 +6399,6 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_NewBlock__SWIG_1(voi Block__Handle *arg6 = (Block__Handle *) 0 ; Block__Handle *argp1 ; Transactions__Handle *argp4 ; - FeeCalculator temp5 ; GoUint32 result; argp1 = (Block__Handle *)jarg1; @@ -6428,12 +6415,7 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_NewBlock__SWIG_1(voi return 0; } arg4 = *argp4; - { - if (!PyCallable_Check(jarg5)) return ; - temp5.callback = _WrapperFeeCalculator; - temp5.context = jarg5; - arg5 = &temp5; - } + arg5 = (FeeCalculator *)jarg5; arg6 = (Block__Handle *)jarg6; result = (GoUint32)SKY_coin_NewBlock(arg1,arg2,(GoUint8_ (*)[32])arg3,arg4,arg5,arg6); jresult = result; @@ -14939,7 +14921,6 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_Transactions_Fees(vo FeeCalculator *arg2 = (FeeCalculator *) 0 ; GoUint64 *arg3 = (GoUint64 *) 0 ; Transactions__Handle *argp1 ; - FeeCalculator temp2 ; GoUint32 result; argp1 = (Transactions__Handle *)jarg1; @@ -14948,12 +14929,7 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_Transactions_Fees(vo return 0; } arg1 = *argp1; - { - if (!PyCallable_Check(jarg2)) return ; - temp2.callback = _WrapperFeeCalculator; - temp2.context = jarg2; - arg2 = &temp2; - } + arg2 = (FeeCalculator *)jarg2; arg3 = (GoUint64 *)jarg3; result = (GoUint32)SKY_coin_Transactions_Fees(arg1,arg2,arg3); jresult = result; @@ -15051,7 +15027,6 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_SortTransactions(voi FeeCalculator *arg2 = (FeeCalculator *) 0 ; Transactions__Handle *arg3 = (Transactions__Handle *) 0 ; Transactions__Handle *argp1 ; - FeeCalculator temp2 ; GoUint32 result; argp1 = (Transactions__Handle *)jarg1; @@ -15060,12 +15035,7 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_SortTransactions(voi return 0; } arg1 = *argp1; - { - if (!PyCallable_Check(jarg2)) return ; - temp2.callback = _WrapperFeeCalculator; - temp2.context = jarg2; - arg2 = &temp2; - } + arg2 = (FeeCalculator *)jarg2; arg3 = (Transactions__Handle *)jarg3; result = (GoUint32)SKY_coin_SortTransactions(arg1,arg2,arg3); jresult = result; @@ -15079,7 +15049,6 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_NewSortableTransacti FeeCalculator *arg2 = (FeeCalculator *) 0 ; SortableTransactionResult_Handle *arg3 = (SortableTransactionResult_Handle *) 0 ; Transactions__Handle *argp1 ; - FeeCalculator temp2 ; GoUint32 result; argp1 = (Transactions__Handle *)jarg1; @@ -15088,12 +15057,7 @@ SWIGEXPORT unsigned int SWIGSTDCALL CSharp_skycoin_SKY_coin_NewSortableTransacti return 0; } arg1 = *argp1; - { - if (!PyCallable_Check(jarg2)) return ; - temp2.callback = _WrapperFeeCalculator; - temp2.context = jarg2; - arg2 = &temp2; - } + arg2 = (FeeCalculator *)jarg2; arg3 = (SortableTransactionResult_Handle *)jarg3; result = (GoUint32)SKY_coin_NewSortableTransactions(arg1,arg2,arg3); jresult = result; diff --git a/LibskycoinNetTest/check_coin_block.cs b/LibskycoinNetTest/check_coin_block.cs index 37a9706e..a483b037 100644 --- a/LibskycoinNetTest/check_coin_block.cs +++ b/LibskycoinNetTest/check_coin_block.cs @@ -3,7 +3,6 @@ using skycoin; using utils; -public delegate uint call (object sender, object fee, object context); namespace LibskycoinNetTest { [TestFixture ()] public class check_coin_block { @@ -19,6 +18,12 @@ public SWIGTYPE_p_Transactions__Handle makeTestTransactions () { return txns; } + public uint zeroFeeCalculator (SWIGTYPE_p_Transaction__Handle tranas, SWIGTYPE_p_unsigned_long_long fee, SWIGTYPE_p_FeeCalcFunc context) { + skycoin.skycoin.GoUint64p_assign (fee, 0); + return 0; + + } + [Test] public void TestNewBlock () { var txns = makeTestTransactions (); @@ -32,10 +37,7 @@ public void TestNewBlock () { pBlock.Head.Time = 100; pBlock.Head.BkSeq = 98; var uxHash = transutils.RandSHA256 (); - // TODO: Not complete by callback - var zf = skycoin.skycoin.new_FeeCalculatorPtr(); - // var a = skycoin.skycoin.new_FeeCalcFuncPtr (); - // zf.setCallBack (a); + var zf = skycoin.skycoin.new_FeeCalculatorPtr (); err = skycoin.skycoin.SKY_coin_NewBlock (block, 133, uxHash, txns, zf, block); Assert.AreEqual (err, skycoin.skycoin.SKY_OK); } diff --git a/LibskycoinNetTest/transutils.cs b/LibskycoinNetTest/transutils.cs index 1904fdde..8fabe5d9 100644 --- a/LibskycoinNetTest/transutils.cs +++ b/LibskycoinNetTest/transutils.cs @@ -1,9 +1,10 @@ using System; +using System.Text.RegularExpressions; using NUnit.Framework; using skycoin; -using System.Text.RegularExpressions; namespace utils { public class transutils { + public delegate uint call (SWIGTYPE_p_Transaction__Handle tranas, SWIGTYPE_p_GoInt64_ fee, SWIGTYPE_p_FeeCalcFunc context); public cipher__Address makeAddress () { var pubkey = new cipher_PubKey (); var seckey = new cipher_SecKey (); @@ -146,7 +147,7 @@ public GoSlice RandBytes (int n) { return b; } - public bool IsBase64String (string s) { + public bool IsBase64String (string s) { s = s.Trim (); return (s.Length % 4 == 0) && Regex.IsMatch (s, @"^[a-zA-Z0-9\+/]*={0,3}$", RegexOptions.None); diff --git a/gopath/src/github.com/skycoin/skycoin b/gopath/src/github.com/skycoin/skycoin index 02be5560..9a67e2b8 160000 --- a/gopath/src/github.com/skycoin/skycoin +++ b/gopath/src/github.com/skycoin/skycoin @@ -1 +1 @@ -Subproject commit 02be5560c7b87abe79d5e44e4b6d4166b78e6913 +Subproject commit 9a67e2b8b4db7c49ed1d2391044513def77589a9