Browse Source

More token tests and more error checking and better errors from internals

metaverse
Jonathan "Duke" Leto 6 years ago
parent
commit
8a3e1884d6
  1. 50
      qa/rpc-tests/cryptoconditions.py
  2. 12
      src/cc/CCassetstx.cpp
  3. 90
      src/wallet/rpcwallet.cpp

50
qa/rpc-tests/cryptoconditions.py

@ -12,6 +12,12 @@ from test_framework.util import assert_equal, assert_greater_than, \
import time
from decimal import Decimal
def assert_success(result):
assert_equal(result['result'], 'success')
def assert_error(result):
assert_equal(result['result'], 'error')
class CryptoConditionsTest (BitcoinTestFramework):
def setup_chain(self):
@ -148,8 +154,7 @@ class CryptoConditionsTest (BitcoinTestFramework):
result = rpc.tokenaddress(self.pubkey)
assert_equal(result['result'], 'success')
for x in ['AssetsCCaddress', 'myCCaddress', 'Assetsmarker', 'myaddress', 'CCaddress']:
assert_equal(result[x][0], 'R')
assert_equal(result[x][0], 'R')
# there are no tokens created yet
result = rpc.tokenlist()
assert_equal(result, [])
@ -174,8 +179,47 @@ class CryptoConditionsTest (BitcoinTestFramework):
# this is not a valid assetid
result = rpc.tokeninfo(self.pubkey)
assert_equal(result['result'], 'error')
assert_error(result)
# invalid numtokens
result = rpc.tokenask("-1", tokenid, "1")
assert_error(result)
# invalid numtokens
result = rpc.tokenask("0", tokenid, "1")
assert_error(result)
# invalid price
result = rpc.tokenask("1", tokenid, "-1")
assert_error(result)
# invalid price
result = rpc.tokenask("1", tokenid, "0")
assert_error(result)
# invalid tokenid
result = rpc.tokenask("100", "deadbeef", "1")
assert_error(result)
# valid
result = rpc.tokenask("100", tokenid, "7.77")
assert_success(result)
tokenaskhex = result['hex']
assert tokenaskhex, "got tokenask hexk"
tokenaskid = self.send_and_mine(result['hex'])
# invalid fillunits
result = rpc.tokenfillask(tokenid, tokenaskid, "0")
assert_error(result)
# invalid fillunits
result = rpc.tokenfillask(tokenid, tokenaskid, "-777")
assert_error(result)
# should this pass or fail?
result = rpc.tokenfillask(tokenid, tokenaskid, "10")
#assert_success(result)
def run_rewards_tests(self):
rpc = self.nodes[0]

12
src/cc/CCassetstx.cpp

@ -14,6 +14,7 @@
******************************************************************************/
#include "CCassets.h"
extern std::string CCerror;
int64_t AddAssetInputs(struct CCcontract_info *cp,CMutableTransaction &mtx,CPubKey pk,uint256 assetid,int64_t total,int32_t maxinputs)
{
@ -427,12 +428,14 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt
CTransaction vintx,filltx; uint256 hashBlock; CMutableTransaction mtx; CPubKey mypk; std::vector<uint8_t> origpubkey; double dprice; uint64_t mask; int32_t askvout=0; int64_t received_assetoshis,total_nValue,orig_assetoshis,paid_nValue,remaining_nValue,inputs,CCchange=0; struct CCcontract_info *cp,C;
if ( fillunits < 0 )
{
fprintf(stderr,"negative fillunits %lld\n",(long long)fillunits);
CCerror = strprintf("negative fillunits %lld\n",(long long)fillunits);
fprintf(stderr,"%s\n",CCerror.c_str());
return("");
}
if ( assetid2 != zeroid )
{
fprintf(stderr,"asset swaps disabled\n");
CCerror = "asset swaps disabled";
fprintf(stderr,"%s\n",CCerror.c_str());
return("");
}
@ -474,7 +477,10 @@ std::string FillSell(int64_t txfee,uint256 assetid,uint256 assetid2,uint256 askt
if ( CCchange != 0 )
mtx.vout.push_back(MakeCC1vout(EVAL_ASSETS,CCchange,mypk));
return(FinalizeCCTx(mask,cp,mtx,mypk,txfee,EncodeAssetOpRet(assetid2!=zeroid?'E':'S',assetid,assetid2,remaining_nValue,origpubkey)));
} else fprintf(stderr,"filltx not enough utxos\n");
} else {
CCerror = strprintf("filltx not enough utxos");
fprintf(stderr,"%s\n", CCerror.c_str());
}
}
}
return("");

90
src/wallet/rpcwallet.cpp

@ -38,8 +38,7 @@
#include <numeric>
#define ERR_RESULT(x) result.push_back(Pair("result", "error")); \
result.push_back(Pair("error", x));
#define ERR_RESULT(x) result.push_back(Pair("result", "error")) , result.push_back(Pair("error", x));
using namespace std;
@ -52,7 +51,6 @@ uint32_t komodo_segid32(char *coinaddr);
int64_t nWalletUnlockTime;
static CCriticalSection cs_nWalletUnlockTime;
//TODO: find a better place for this
std::string CCerror;
// Private method:
@ -5002,7 +5000,7 @@ UniValue rewardscreatefunding(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 funding transaction"));
} else ERR_RESULT("couldnt create rewards funding transaction");
return(result);
}
@ -5024,14 +5022,8 @@ UniValue rewardslock(const UniValue& params, bool fHelp)
{
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"));
}
} else ERR_RESULT( "couldnt create rewards lock transaction");
} else ERR_RESULT("amount must be positive");
return(result);
}
@ -5080,16 +5072,11 @@ UniValue rewardsunlock(const UniValue& params, bool fHelp)
else memset(&txid,0,sizeof(txid));
hex = RewardsUnlock(0,name,fundingtxid,txid);
if (CCerror != "") {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", CCerror));
} else if ( hex.size() > 0 )
{
ERR_RESULT(CCerror);
} else 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 unlock transaction"));
}
} else ERR_RESULT("couldnt create rewards unlock transaction");
return(result);
}
@ -5181,14 +5168,8 @@ UniValue faucetfund(const UniValue& params, bool fHelp)
{
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 faucet funding transaction"));
}
} else {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "funding amount must be positive"));
}
} else ERR_RESULT("couldnt create faucet funding transaction");
} else ERR_RESULT( "funding amount must be positive");
return(result);
}
@ -5205,10 +5186,7 @@ UniValue faucetget(const UniValue& params, bool fHelp)
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 faucet get transaction"));
}
} else ERR_RESULT("couldnt create faucet get transaction");
return(result);
}
@ -5229,14 +5207,12 @@ UniValue dicefund(const UniValue& params, bool fHelp)
timeoutblocks = atol(params[5].get_str().c_str());
hex = DiceCreateFunding(0,name,funds,minbet,maxbet,maxodds,timeoutblocks);
if (CCerror != "") {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", CCerror));
ERR_RESULT(CCerror);
} else if ( hex.size() > 0 ) {
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else {
result.push_back(Pair("error", "couldnt create dice funding transaction"));
result.push_back(Pair("result", "error"));
ERR_RESULT( "couldnt create dice funding transaction");
}
return(result);
}
@ -5256,19 +5232,12 @@ UniValue diceaddfunds(const UniValue& params, bool fHelp)
if ( amount > 0 ) {
hex = DiceAddfunding(0,name,fundingtxid,amount);
if (CCerror != "") {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", CCerror));
ERR_RESULT(CCerror);
} else 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 dice addfunding transaction"));
}
} else {
result.push_back(Pair("result", "error"));
result.push_back(Pair("error", "amount must be positive"));
}
} else ERR_RESULT("couldnt create dice addfunding transaction");
} else ERR_RESULT("amount must be positive");
return(result);
}
@ -5291,9 +5260,7 @@ UniValue dicebet(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else {
ERR_RESULT("couldnt create faucet get transaction");
}
} else ERR_RESULT("couldnt create faucet get transaction");
} else {
ERR_RESULT("amount and odds must be positive");
}
@ -5317,7 +5284,7 @@ UniValue dicefinish(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 dicefinish transaction"));
} else ERR_RESULT( "couldnt create dicefinish transaction");
return(result);
}
@ -5457,7 +5424,7 @@ UniValue tokencreate(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 transaction"));
} else ERR_RESULT("couldnt create transaction");
return(result);
}
@ -5479,7 +5446,7 @@ UniValue tokentransfer(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt transfer assets"));
} else ERR_RESULT("couldnt transfer assets");
} else {
ERR_RESULT("amount must be positive");
}
@ -5528,7 +5495,7 @@ UniValue tokencancelbid(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt cancel bid"));
} else ERR_RESULT("couldnt cancel bid");
return(result);
}
@ -5549,7 +5516,7 @@ UniValue tokenfillbid(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt fill bid"));
} else ERR_RESULT("couldnt fill bid");
return(result);
}
@ -5572,7 +5539,7 @@ UniValue tokenask(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 ask"));
} else ERR_RESULT("couldnt create ask");
} else {
ERR_RESULT("price and numtokens must be positive");
}
@ -5600,7 +5567,7 @@ UniValue tokenswapask(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 swap"));
} else ERR_RESULT("couldnt create swap");
} else {
ERR_RESULT("price and numtokens must be positive");
}
@ -5623,7 +5590,7 @@ UniValue tokencancelask(const UniValue& params, bool fHelp)
{
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else result.push_back(Pair("error", "couldnt cancel bid"));
} else ERR_RESULT("couldnt cancel bid");
return(result);
}
@ -5642,11 +5609,14 @@ UniValue tokenfillask(const UniValue& params, bool fHelp)
fillunits = atol(params[2].get_str().c_str());
hex = FillSell(0,tokenid,zeroid,asktxid,fillunits);
if (fillunits > 0) {
if ( hex.size() > 0)
{
if (CCerror != "") {
ERR_RESULT(CCerror);
} else if ( hex.size() > 0) {
result.push_back(Pair("result", "success"));
result.push_back(Pair("hex", hex));
} else ERR_RESULT("couldnt fill bid");
} else {
ERR_RESULT("couldnt fill bid");
}
} else {
ERR_RESULT("fillunits must be positive");
}

Loading…
Cancel
Save