Merge pull request #830 from letolabs/cctests

cctests sync
This commit is contained in:
jl777
2018-08-24 05:40:40 -11:00
committed by GitHub
2 changed files with 24 additions and 17 deletions

View File

@@ -7,7 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import assert_equal, assert_greater_than, \ from test_framework.util import assert_equal, assert_greater_than, \
initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \ initialize_chain_clean, initialize_chain, start_nodes, start_node, connect_nodes_bi, \
stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port stop_nodes, sync_blocks, sync_mempools, wait_bitcoinds, rpc_port, assert_raises
import time import time
from decimal import Decimal from decimal import Decimal
@@ -117,17 +117,14 @@ class CryptoConditionsTest (BitcoinTestFramework):
assert_success(result) assert_success(result)
assert result['hex'], "hex key found" assert result['hex'], "hex key found"
# broadcast the xtn # try to broadcast the xtn, but we will get 'faucet is only for brand new addresses'
result = rpc.sendrawtransaction(result['hex']) assert_raises(JSONRPCException, rpc.sendrawtransaction, [ result['hex'] ])
txid = result[0]
assert txid, "found txid"
# confirm above tx newaddr = rpc.getnewaddress()
rpc.generate(1) assert newaddr, "got a new address"
result = rpc.getwalletinfo() result = rpc.validateaddress(newaddr)
newpubkey = result['pubkey']
# we should have slightly more funds from the faucet now assert newpubkey, "got a pubkey for new address"
assert_greater_than(result['balance'], balance2)
def run_dice_tests(self): def run_dice_tests(self):
rpc = self.nodes[0] rpc = self.nodes[0]

View File

@@ -16,6 +16,7 @@
#include "CCdice.h" #include "CCdice.h"
extern std::string CCerror; extern std::string CCerror;
#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x));
// timeout // timeout
@@ -238,9 +239,16 @@ uint64_t DiceCalc(int64_t bet,int64_t odds,int64_t minbet,int64_t maxbet,int64_t
if ( odds < 10000 ) if ( odds < 10000 )
return(0); return(0);
else odds -= 10000; else odds -= 10000;
if ( bet < minbet || bet > maxbet || odds > maxodds ) if ( bet < minbet || bet > maxbet )
{ {
fprintf(stderr,"bet size violation %.8f\n",(double)bet/COIN); CCerror = strprintf("bet size violation %.8f",(double)bet/COIN);
fprintf(stderr,"%s\n", CCerror.c_str() );
return(0);
}
if ( odds > maxodds )
{
CCerror = strprintf("invalid odds %d, must be <= %d",odds, maxodds);
fprintf(stderr,"%s\n", CCerror.c_str() );
return(0); return(0);
} }
//fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,houseentropy),uint256_str(str2,bettorentropy)); //fprintf(stderr,"calc house entropy %s vs bettor %s\n",uint256_str(str,houseentropy),uint256_str(str2,bettorentropy));
@@ -810,13 +818,13 @@ UniValue DiceInfo(uint256 diceid)
if ( GetTransaction(diceid,vintx,hashBlock,false) == 0 ) if ( GetTransaction(diceid,vintx,hashBlock,false) == 0 )
{ {
fprintf(stderr,"cant find fundingtxid\n"); fprintf(stderr,"cant find fundingtxid\n");
result.push_back(Pair("error","cant find fundingtxid")); ERR_RESULT("error","cant find fundingtxid");
return(result); return(result);
} }
if ( vintx.vout.size() > 0 && DecodeDiceFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 0 ) if ( vintx.vout.size() > 0 && DecodeDiceFundingOpRet(vintx.vout[vintx.vout.size()-1].scriptPubKey,sbits,minbet,maxbet,maxodds,timeoutblocks) == 0 )
{ {
fprintf(stderr,"fundingtxid isnt dice creation txid\n"); fprintf(stderr,"fundingtxid isnt dice creation txid\n");
result.push_back(Pair("error","fundingtxid isnt dice creation txid")); ERR_RESULT("fundingtxid isnt dice creation txid");
return(result); return(result);
} }
result.push_back(Pair("result","success")); result.push_back(Pair("result","success"));
@@ -1155,7 +1163,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
return(0.); return(0.);
else return((double)spenttx.vout[2].nValue/COIN); else return((double)spenttx.vout[2].nValue/COIN);
} }
fprintf(stderr,"couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid)); CCerror = "couldnt find bettx or spenttx %s\n",uint256_str(str,spenttxid);
fprintf(stderr,"%s\n", CCerror.c_str());
return(0.); return(0.);
} }
else if ( scriptPubKey == fundingPubKey ) else if ( scriptPubKey == fundingPubKey )
@@ -1175,7 +1184,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx
else return((double)spenttx.vout[2].nValue/COIN); else return((double)spenttx.vout[2].nValue/COIN);
} else return(0.); } else return(0.);
} }
fprintf(stderr,"didnt find dicefinish tx\n"); CCerror = "didnt find dicefinish tx";
fprintf(stderr,"%s\n", CCerror.c_str());
} }
return(-1.); return(-1.);
} }