Merge branch 'jl777' into FSM

This commit is contained in:
jl777
2018-09-05 05:30:59 -11:00
2 changed files with 73 additions and 37 deletions

View File

@@ -280,7 +280,6 @@ class CryptoConditionsTest (BitcoinTestFramework):
fundinfoactual = rpc.diceinfo(diceid) fundinfoactual = rpc.diceinfo(diceid)
assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding']))) assert_equal(round(fundbalanceguess),round(float(fundinfoactual['funding'])))
def run_token_tests(self): def run_token_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]
result = rpc.tokenaddress() result = rpc.tokenaddress()
@@ -491,14 +490,31 @@ class CryptoConditionsTest (BitcoinTestFramework):
result = rpc.rewardsinfo("none") result = rpc.rewardsinfo("none")
assert_error(result) assert_error(result)
# creating rewards plan with name > 8 chars, should return error
result = rpc.rewardscreatefunding("STUFFSTUFF", "7777", "25", "0", "10", "10")
assert_error(result)
# creating rewards plan with 0 funding
result = rpc.rewardscreatefunding("STUFF", "0", "25", "0", "10", "10")
assert_error(result)
# creating rewards plan with 0 maxdays
result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "0")
assert_error(result)
# creating rewards plan with > 25% APR
result = rpc.rewardscreatefunding("STUFF", "7777", "30", "0", "10", "10")
assert_error(result)
# creating valid rewards plan
result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10") result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10")
assert result['hex'], 'got raw xtn' assert result['hex'], 'got raw xtn'
txid = rpc.sendrawtransaction(result['hex']) fundingtxid = rpc.sendrawtransaction(result['hex'])
assert txid, 'got txid' assert fundingtxid, 'got txid'
# confirm the above xtn # confirm the above xtn
rpc.generate(1) rpc.generate(1)
result = rpc.rewardsinfo(txid) result = rpc.rewardsinfo(fundingtxid)
assert_success(result) assert_success(result)
assert_equal(result['name'], 'STUFF') assert_equal(result['name'], 'STUFF')
assert_equal(result['APR'], "25.00000000") assert_equal(result['APR'], "25.00000000")
@@ -506,39 +522,38 @@ class CryptoConditionsTest (BitcoinTestFramework):
assert_equal(result['maxseconds'], 864000) assert_equal(result['maxseconds'], 864000)
assert_equal(result['funding'], "7777.00000000") assert_equal(result['funding'], "7777.00000000")
assert_equal(result['mindeposit'], "10.00000000") assert_equal(result['mindeposit'], "10.00000000")
assert_equal(result['fundingtxid'], txid) assert_equal(result['fundingtxid'], fundingtxid)
# funding amount must be positive # checking if new plan in rewardslist
result = rpc.rewardsaddfunding("STUFF", txid, "0") result = rpc.rewardslist()
assert_equal(result[0], fundingtxid)
# creating reward plan with already existing name, should return error
result = rpc.rewardscreatefunding("STUFF", "7777", "25", "0", "10", "10")
assert_error(result) assert_error(result)
result = rpc.rewardsaddfunding("STUFF", txid, "555") # add funding amount must be positive
assert_success(result) result = rpc.rewardsaddfunding("STUFF", fundingtxid, "-1")
fundingtxid = result['hex']
assert fundingtxid, "got funding txid"
result = rpc.rewardslock("STUFF", fundingtxid, "7")
assert_error(result) assert_error(result)
# the previous xtn has not been broadcasted yet # add funding amount must be positive
result = rpc.rewardsunlock("STUFF", fundingtxid) result = rpc.rewardsaddfunding("STUFF", fundingtxid, "0")
assert_error(result) assert_error(result)
# wrong plan name # adding valid funding
result = rpc.rewardsunlock("SHTUFF", fundingtxid) result = rpc.rewardsaddfunding("STUFF", fundingtxid, "555")
assert_error(result) addfundingtxid = self.send_and_mine(result['hex'])
assert addfundingtxid, 'got funding txid'
txid = rpc.sendrawtransaction(fundingtxid) # checking if funding added to rewardsplan
assert txid, 'got txid from sendrawtransaction' result = rpc.rewardsinfo(fundingtxid)
assert_equal(result['funding'], "8332.00000000")
# confirm the xtn above # trying to lock funds, locking funds amount must be positive
rpc.generate(1)
# amount must be positive
result = rpc.rewardslock("STUFF", fundingtxid, "-5") result = rpc.rewardslock("STUFF", fundingtxid, "-5")
assert_error(result) assert_error(result)
# amount must be positive # trying to lock funds, locking funds amount must be positive
result = rpc.rewardslock("STUFF", fundingtxid, "0") result = rpc.rewardslock("STUFF", fundingtxid, "0")
assert_error(result) assert_error(result)
@@ -546,25 +561,26 @@ class CryptoConditionsTest (BitcoinTestFramework):
result = rpc.rewardslock("STUFF", fundingtxid, "7") result = rpc.rewardslock("STUFF", fundingtxid, "7")
assert_error(result) assert_error(result)
# not working # locking funds in rewards plan
#result = rpc.rewardslock("STUFF", fundingtxid, "10") result = rpc.rewardslock("STUFF", fundingtxid, "10")
#assert_success(result) assert_success(result)
#locktxid = result['hex'] locktxid = result['hex']
#assert locktxid, "got lock txid" assert locktxid, "got lock txid"
# locktxid has not been broadcast yet # locktxid has not been broadcast yet
#result = rpc.rewardsunlock("STUFF", locktxid) result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
#assert_error(result) assert_error(result)
# broadcast xtn # broadcast xtn
#txid = rpc.sendrawtransaction(locktxid) txid = rpc.sendrawtransaction(locktxid)
#assert txid, 'got txid from sendrawtransaction' assert txid, 'got txid from sendrawtransaction'
# confirm the xtn above # confirm the xtn above
#rpc.generate(1) rpc.generate(1)
#result = rpc.rewardsunlock("STUFF", locktxid) # will not unlock since reward amount is less than tx fee
#assert_error(result) result = rpc.rewardsunlock("STUFF", fundingtxid, locktxid)
assert_error(result)
def run_test (self): def run_test (self):

View File

@@ -5219,6 +5219,11 @@ UniValue rewardscreatefunding(const UniValue& params, bool fHelp)
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
funds = atof(params[1].get_str().c_str()) * COIN; funds = atof(params[1].get_str().c_str()) * COIN;
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if ( funds <= 0 ) { if ( funds <= 0 ) {
ERR_RESULT("funds must be positive"); ERR_RESULT("funds must be positive");
return result; return result;
@@ -5280,6 +5285,11 @@ UniValue rewardslock(const UniValue& params, bool fHelp)
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
hex = RewardsLock(0,name,fundingtxid,amount); hex = RewardsLock(0,name,fundingtxid,amount);
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if ( CCerror != "" ){ if ( CCerror != "" ){
ERR_RESULT(CCerror); ERR_RESULT(CCerror);
} else if ( amount > 0 ) { } else if ( amount > 0 ) {
@@ -5305,6 +5315,11 @@ UniValue rewardsaddfunding(const UniValue& params, bool fHelp)
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
amount = atof(params[2].get_str().c_str()) * COIN; amount = atof(params[2].get_str().c_str()) * COIN;
hex = RewardsAddfunding(0,name,fundingtxid,amount); hex = RewardsAddfunding(0,name,fundingtxid,amount);
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if (CCerror != "") { if (CCerror != "") {
ERR_RESULT(CCerror); ERR_RESULT(CCerror);
} else if (amount > 0) { } else if (amount > 0) {
@@ -5333,6 +5348,11 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp)
LOCK2(cs_main, pwalletMain->cs_wallet); LOCK2(cs_main, pwalletMain->cs_wallet);
name = (char *)params[0].get_str().c_str(); name = (char *)params[0].get_str().c_str();
fundingtxid = Parseuint256((char *)params[1].get_str().c_str()); fundingtxid = Parseuint256((char *)params[1].get_str().c_str());
if (!VALID_PLAN_NAME(name)) {
ERR_RESULT(strprintf("Plan name can be at most %d ASCII characters",PLAN_NAME_MAX));
return(result);
}
if ( params.size() > 2 ) if ( params.size() > 2 )
txid = Parseuint256((char *)params[2].get_str().c_str()); txid = Parseuint256((char *)params[2].get_str().c_str());
else memset(&txid,0,sizeof(txid)); else memset(&txid,0,sizeof(txid));