Skip to content

Commit

Permalink
[test] refs #8 Testing data type callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Maykel Arias Torres committed Oct 14, 2018
1 parent 0597095 commit f0da310
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
44 changes: 4 additions & 40 deletions LibskycoinNet/skycoin/skycoinnet_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions LibskycoinNetTest/check_coin_block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 ();
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions LibskycoinNetTest/transutils.cs
Original file line number Diff line number Diff line change
@@ -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 ();
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion gopath/src/github.com/skycoin/skycoin

0 comments on commit f0da310

Please sign in to comment.