From 66027c0219598109a8fa86cddafe9a9bc7f49d80 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 13 Aug 2018 09:55:17 +0200 Subject: [PATCH] Add rewards tests --- qa/rpc-tests/cryptoconditions.py | 23 +++++++++++++++++++++-- src/wallet/rpcwallet.cpp | 25 ++++++++++++++++++------- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 9e7ddf8e5..845d387b4 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -184,7 +184,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.rewardsinfo("none") assert_equal(result['result'], 'error') - result = rpc.rewardscreatefunding("STUFF", "1000", "5", "1", "10", "10") + result = rpc.rewardscreatefunding("STUFF", "1000", "5", "0", "10", "10") assert result['hex'], 'got raw xtn' txid = rpc.sendrawtransaction(result['hex']) assert txid, 'got txid' @@ -195,7 +195,7 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_equal(result['result'], 'success') assert_equal(result['name'], 'STUFF') assert_equal(result['APR'], "5.00000000") - assert_equal(result['minseconds'], 86400) + assert_equal(result['minseconds'], 0) assert_equal(result['maxseconds'], 864000) assert_equal(result['funding'], "1000.00000000") assert_equal(result['mindeposit'], "10.00000000") @@ -210,7 +210,26 @@ class CryptoConditionsTest (BitcoinTestFramework): fundingtxid = result['hex'] assert fundingtxid, "got funding txid" + # the previous xtn has not been broadcasted yet result = rpc.rewardsunlock("STUFF", fundingtxid) + assert_equal(result['result'], 'error') + + # wrong plan name + result = rpc.rewardsunlock("SHTUFF", fundingtxid) + assert_equal(result['result'], 'error') + + txid = rpc.sendrawtransaction(fundingtxid) + assert txid, 'got txid from sendrawtransaction' + + # confirm the xtn above + rpc.generate(1) + + result = rpc.rewardsunlock("STUFF", fundingtxid) + # currently failing because reward is not > txfee? + # assert_equal(result['result'], 'success') + + result = rpc.rewardslock("STUFF", fundingtxid, "-5") + assert_equal(result['result'], 'error') def run_test (self): print("Mining blocks...") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 6329d4a52..1654be8ba 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5003,7 +5003,7 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp) UniValue rewardslock(const UniValue& params, bool fHelp) { - UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; uint64_t amount; std::string hex; + UniValue result(UniValue::VOBJ); char *name; uint256 fundingtxid; int64_t amount; std::string hex; if ( fHelp || params.size() != 3 ) throw runtime_error("rewardslock name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5014,11 +5014,19 @@ UniValue rewardslock(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsLock(0,name,fundingtxid,amount); - if ( hex.size() > 0 ) - { - result.push_back(Pair("result", "success")); - result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards lock transaction")); + if ( amount > 0 ) { + if ( hex.size() > 0 ) + { + result.push_back(Pair("result", "success")); + result.push_back(Pair("hex", hex)); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards lock transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "amount must be positive")); + } return(result); } @@ -5070,7 +5078,10 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp) { result.push_back(Pair("result", "success")); result.push_back(Pair("hex", hex)); - } else result.push_back(Pair("error", "couldnt create rewards unlock transaction")); + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "couldnt create rewards unlock transaction")); + } return(result); }