diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 8fa4389a0..e42759c1d 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -7,7 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ 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 from decimal import Decimal @@ -117,17 +117,14 @@ class CryptoConditionsTest (BitcoinTestFramework): assert_success(result) assert result['hex'], "hex key found" - # broadcast the xtn - result = rpc.sendrawtransaction(result['hex']) - txid = result[0] - assert txid, "found txid" + # try to broadcast the xtn, but we will get 'faucet is only for brand new addresses' + assert_raises(JSONRPCException, rpc.sendrawtransaction, [ result['hex'] ]) - # confirm above tx - rpc.generate(1) - result = rpc.getwalletinfo() - - # we should have slightly more funds from the faucet now - assert_greater_than(result['balance'], balance2) + newaddr = rpc.getnewaddress() + assert newaddr, "got a new address" + result = rpc.validateaddress(newaddr) + newpubkey = result['pubkey'] + assert newpubkey, "got a pubkey for new address" def run_dice_tests(self): rpc = self.nodes[0] @@ -170,16 +167,38 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenorders() assert_equal(result, []) + # getting token balance for pubkey result = rpc.tokenbalance(self.pubkey) - assert_equal(result['balance'], 0) assert_success(result) + assert_equal(result['balance'], 0) assert_equal(result['CCaddress'], 'RCRsm3VBXz8kKTsYaXKpy7pSEzrtNNQGJC') assert_equal(result['tokenid'], self.pubkey) + # get token balance for token with pubkey + result = rpc.tokenbalance(tokenid, self.pubkey) + assert_success(result) + assert_equal(result['balance'], 198742000000) + assert_equal(result['tokenid'], tokenid) + + # get token balance for token without pubkey + result = rpc.tokenbalance(tokenid) + assert_success(result) + assert_equal(result['balance'], 198742000000) + assert_equal(result['tokenid'], tokenid) + # this is not a valid assetid result = rpc.tokeninfo(self.pubkey) assert_error(result) + # check tokeninfo for valid token + result = rpc.tokeninfo(tokenid) + assert_success(result) + assert_equal(result['tokenid'], tokenid) + assert_equal(result['owner'], self.pubkey) + assert_equal(result['name'], "DUKE") + assert_equal(result['supply'], 198742000000) + assert_equal(result['description'], "duke") + # invalid numtokens ask result = rpc.tokenask("-1", tokenid, "1") assert_error(result) @@ -196,7 +215,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenask("1", tokenid, "0") assert_error(result) - # invalid tokenid + # invalid tokenid ask result = rpc.tokenask("100", "deadbeef", "1") assert_error(result) @@ -234,7 +253,26 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenorders() assert_equal(result, []) - # valid bid + # invalid numtokens bid (have to add status to CC code!) + result = rpc.tokenbid("-1", tokenid, "1") + assert_equal(result['error'], 'invalid parameter') + + # invalid numtokens bid (have to add status to CC code!) + result = rpc.tokenbid("0", tokenid, "1") + assert_equal(result['error'], 'invalid parameter') + + # invalid price bid (have to add status to CC code!) + result = rpc.tokenbid("1", tokenid, "-1") + assert_equal(result['error'], 'invalid parameter') + + # invalid price bid (have to add status to CC code!) + result = rpc.tokenbid("1", tokenid, "0") + assert_equal(result['error'], 'invalid parameter') + + # invalid tokenid bid (have to add status to CC code!) + result = rpc.tokenbid("100", "deadbeef", "1") + assert_equal(result['error'], 'invalid parameter') + tokenbid = rpc.tokenbid("100", tokenid, "10") tokenbidhex = tokenbid['hex'] tokenbidid = self.send_and_mine(tokenbid['hex']) @@ -242,6 +280,14 @@ class CryptoConditionsTest (BitcoinTestFramework): order = result[0] assert order, "found order" + # invalid bid fillunits + result = rpc.tokenfillbid(tokenid, tokenbidid, "0") + assert_error(result) + + # invalid bid fillunits + result = rpc.tokenfillbid(tokenid, tokenbidid, "-777") + assert_error(result) + # valid bid fillunits fillbid = rpc.tokenfillbid(tokenid, tokenbidid, "1000") result = self.send_and_mine(fillbid['hex']) @@ -260,7 +306,7 @@ class CryptoConditionsTest (BitcoinTestFramework): result = rpc.tokenorders() assert_equal(result, []) - # invalid token transfer amount (have to add stderr to CC code!) + # invalid token transfer amount (have to add status to CC code!) randompubkey = "021a559101e355c907d9c553671044d619769a6e71d624f68bfec7d0afa6bd6a96" result = rpc.tokentransfer(tokenid,randompubkey,"0") assert_equal(result['error'], 'invalid parameter') diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index dd9322eeb..61dfcbba1 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -16,6 +16,7 @@ #include "CCdice.h" extern std::string CCerror; +#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x)); // 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 ) return(0); 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); } //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 ) { fprintf(stderr,"cant find fundingtxid\n"); - result.push_back(Pair("error","cant find fundingtxid")); + ERR_RESULT("cant find fundingtxid"); return(result); } 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"); - result.push_back(Pair("error","fundingtxid isnt dice creation txid")); + ERR_RESULT("fundingtxid isnt dice creation txid"); return(result); } result.push_back(Pair("result","success")); @@ -1155,7 +1163,8 @@ double DiceStatus(uint64_t txfee,char *planstr,uint256 fundingtxid,uint256 bettx return(0.); 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.); } 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(0.); } - fprintf(stderr,"didnt find dicefinish tx\n"); + CCerror = "didnt find dicefinish tx"; + fprintf(stderr,"%s\n", CCerror.c_str()); } return(-1.); } diff --git a/src/main.cpp b/src/main.cpp index 548ce2011..aa6bece16 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1116,6 +1116,8 @@ bool CheckTransactionWithoutProofVerification(const CTransaction& tx, CValidatio if ( (txout.nValue > 0 && iscoinbase == 0) || tx.GetJoinSplitValueOut() > 0 ) return state.DoS(100, error("CheckTransaction(): this is a private chain, no public allowed"),REJECT_INVALID, "bad-txns-acprivacy-chain"); } + if ( txout.scriptPubKey.size() > IGUANA_MAXSCRIPTSIZE ) + return state.DoS(100, error("CheckTransaction(): txout.scriptPubKey.size() too big"),REJECT_INVALID, "bad-txns-vout-negative"); nValueOut += txout.nValue; if (!MoneyRange(nValueOut)) return state.DoS(100, error("CheckTransaction(): txout total out of range"), diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 309708c7f..b86dfef15 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -212,10 +212,10 @@ bool IsStandard(const CScript& scriptPubKey, txnouttype& whichType) vector vSolutions; if (!Solver(scriptPubKey, whichType, vSolutions)) { - int32_t i; uint8_t *ptr = (uint8_t *)scriptPubKey.data(); - for (i=0; i