From 95a709e8196b4f0d356435c3c6c81d7daf04d460 Mon Sep 17 00:00:00 2001 From: James Prestwich Date: Thu, 14 Sep 2017 14:37:26 -0600 Subject: [PATCH] set up testrunner --- .gitignore | 14 ++++++++-- requirements-test.txt | 3 +++ tox.ini | 26 ++++++++++++++++++ xcat/bitcoinRPC.py | 62 +++++++++++++++++++++---------------------- 4 files changed, 72 insertions(+), 33 deletions(-) create mode 100644 requirements-test.txt create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index c08d1ce..f3921a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,14 @@ -*.pyc -xcat.egg-info/ +# xcat .tmp/ + +# Python +*.pyc +*.egg-info/ + +# Virtual environment venv/ + +# Unit test / coverage reports +.tox/ +coverage/ +.coverage diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..f6320d3 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1,3 @@ +flake8 +pytest +pytest-cov diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e39156e --- /dev/null +++ b/tox.ini @@ -0,0 +1,26 @@ +[tox] +envlist = + py3{5} + +[pytest] +nonrecursedirs = .git .tox venv coverage + +[testenv] +usedevelop = True +deps = + -rrequirements.txt + -rrequirements-test.txt + +commands = + flake8 \ + --ignore=E501,E266 \ + --exclude test.py \ + xcat + pytest \ + -q \ + --junitxml=coverage/unit.xml \ + --cov xcat \ + --cov-report xml:coverage/coverage.xml \ + --cov-report html:coverage/html/ \ + --cov-report term-missing \ + {posargs} diff --git a/xcat/bitcoinRPC.py b/xcat/bitcoinRPC.py index e1fb00e..cfa650d 100644 --- a/xcat/bitcoinRPC.py +++ b/xcat/bitcoinRPC.py @@ -14,7 +14,7 @@ from bitcoin.core.scripteval import VerifyScript, SCRIPT_VERIFY_P2SH from bitcoin.wallet import CBitcoinAddress, P2SHBitcoinAddress from bitcoin.wallet import P2PKHBitcoinAddress -import xcat.utils as utils +# import xcat.utils as utils import logging if sys.version_info.major < 3: @@ -52,15 +52,15 @@ class bitcoinProxy(): print("Redeem transaction with secret not found") return - def parse_secret(self, txid): - raw = zcashd.gettransaction(txid, True)['hex'] - decoded = zcashd.call('decoderawtransaction', raw) - scriptSig = decoded['vin'][0]['scriptSig'] - asm = scriptSig['asm'].split(" ") - # pubkey = asm[1] - secret = utils.x2s(asm[2]) - # redeemPubkey = P2PKHBitcoinAddress.from_pubkey(x(pubkey)) - return secret + # def parse_secret(self, txid): + # raw = zcashd.gettransaction(txid, True)['hex'] + # decoded = zcashd.call('decoderawtransaction', raw) + # scriptSig = decoded['vin'][0]['scriptSig'] + # asm = scriptSig['asm'].split(" ") + # # pubkey = asm[1] + # secret = utils.x2s(asm[2]) + # # redeemPubkey = P2PKHBitcoinAddress.from_pubkey(x(pubkey)) + # return secret def get_keys(self, funder_address, redeemer_address): fundpubkey = CBitcoinAddress(funder_address) @@ -131,27 +131,27 @@ class bitcoinProxy(): return 'empty' # TODO: FIX search for p2sh in block - def search_p2sh(self, block, p2sh): - print("Fetching block...") - blockdata = self.bitcoind.getblock(lx(block)) - print("done fetching block") - txs = blockdata.vtx - print("txs", txs) - for tx in txs: - txhex = b2x(tx.serialize()) - # Using my fork of python-zcashlib to get result of decoderawtransaction - txhex = txhex + '00' - rawtx = zcashd.decoderawtransaction(txhex) - # print('rawtx', rawtx) - print(rawtx) - for vout in rawtx['vout']: - if 'addresses' in vout['scriptPubKey']: - for addr in vout['scriptPubKey']['addresses']: - print("Sent to address:", addr) - if addr == p2sh: - print("Address to p2sh found in transaction! ", - addr) - print("Returning from search_p2sh") + # def search_p2sh(self, block, p2sh): + # print("Fetching block...") + # blockdata = self.bitcoind.getblock(lx(block)) + # print("done fetching block") + # txs = blockdata.vtx + # print("txs", txs) + # for tx in txs: + # txhex = b2x(tx.serialize()) + # # Using my fork of python-zcashlib to get result of decoderawtransaction + # txhex = txhex + '00' + # rawtx = zcashd.decoderawtransaction(txhex) + # # print('rawtx', rawtx) + # print(rawtx) + # for vout in rawtx['vout']: + # if 'addresses' in vout['scriptPubKey']: + # for addr in vout['scriptPubKey']['addresses']: + # print("Sent to address:", addr) + # if addr == p2sh: + # print("Address to p2sh found in transaction! ", + # addr) + # print("Returning from search_p2sh") def get_tx_details(self, txid): # must convert txid string to bytes x(txid)