From 88e714577b1ce5740431e39f23fd20538125f87b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 11 Aug 2018 16:47:24 +0200 Subject: [PATCH] More rewards tests --- qa/rpc-tests/cryptoconditions.py | 14 ++++++++++++++ src/wallet/rpcwallet.cpp | 20 ++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 53c733ab0..9367055d7 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -192,6 +192,20 @@ class CryptoConditionsTest (BitcoinTestFramework): rpc.generate(1) result = rpc.rewardsinfo(txid) assert_equal(result['result'], 'success') + assert_equal(result['name'], 'STUFF') + assert_equal(result['APR'], "5.00000000") + assert_equal(result['minseconds'], 86400) + assert_equal(result['maxseconds'], 864000) + assert_equal(result['funding'], "1000.00000000") + assert_equal(result['mindeposit'], "10.00000000") + assert_equal(result['fundingtxid'], txid) + + # funding amount must be positive + result = rpc.rewardsaddfunding("STUFF", txid, "0") + assert_equal(result['result'], 'error') + + result = rpc.rewardsaddfunding("STUFF", txid, "100") + assert_equal(result['result'], 'success') def run_test (self): print("Mining blocks...") diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 10b1f1676..6329d4a52 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -5024,7 +5024,7 @@ UniValue rewardslock(const UniValue& params, bool fHelp) UniValue rewardsaddfunding(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("rewardsaddfunding name fundingtxid amount\n"); if ( ensure_CCrequirements() < 0 ) @@ -5035,11 +5035,19 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp) fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); amount = atof(params[2].get_str().c_str()) * COIN; hex = RewardsAddfunding(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 addfunding 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 addfunding transaction")); + } + } else { + result.push_back(Pair("result", "error")); + result.push_back(Pair("error", "funding amount must be positive")); + } return(result); }