Skip to content

Commit

Permalink
libnspv pytest-based rpc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SirSevenG committed Aug 8, 2019
1 parent a3f1570 commit a6cf312
Show file tree
Hide file tree
Showing 9 changed files with 656 additions and 92 deletions.
117 changes: 28 additions & 89 deletions .travis.yml
@@ -1,95 +1,34 @@
dist: bionic
language: c

cache:
apt: true
directories:
- depends/built
- depends/sdk-sources
- $HOME/Library/Caches/Homebrew

- pip
- ccache
env:
global:
- secure: tdQoakwaYJcfmRX1nI3kQgR4I7xjP3PYSHaQ9FZBUF5N5O5fJlgns5WF2ofh5WhvjuTKABMGBGqjNC9R7E68L24UCS2JftGHVQ0UQANtDdf3fN3wsD4Ev4tOM27blNj77Ud5fx2xZQfASDdh0Mrrz3GtE/FaLGoN3g9X03vRYnrD+z8aXn/j8oIVej26sOmy5DZfKbhtRv57f9A5ek9yMFkRD6NEbaisbTxvoW7Qri+6h9Rf3M4P8izufDsBBGj/eEoEOPfL5oDVJDOpy+cixAmaCc8GfGY5Kqd3pH8aBflaigdE0UOVUGD5EHQaHmth3P5Wzqz+tqVaGhNfhTh+blOlI1JId7ovEJPYnFur+RzLFhABqYjlhm6smCpNIOow/Q8gXAnMXNFq5460vlrOvHB3d0z20Gsb7cZamZsv0Nf6MfoXJQd9DniF45rAIGUGDFojg9xqVLuxzuMcTTTOaaSxYZ9g8pTDOFwwF5oCQLQ7gdeagv1EjexD3N3RhYQ/rR6TfbWbY98OhncDL4OYR5s48Nw+j747OVnp8N87S1R+AYWwgEDxRYFo8ykqsAPOzZCFazS+rXp4X9yA9VtgG0fWgpUh7cVeB9J0aZIps7yFu4oyFqltsRIcv6KgwtGukxVgnhT6RCMZGXazLorafJpDDwWjD+Ba66uyHwjVIhw=
- secure: qFwNrx16rhlX5KKpkIfcgfwjlKXO1LtjN1uK5h+mp4ZnrFHiitCJl6wct2ZwKtBEc0V4ux57ZdggE9uff0Ur0ZAwal5QkQSpBToO99Gpk8S2TB4OFQq5wbD1EDzsq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phphTUq6VD9hkeCPzRcmIfTGbKwoWIUq8JSOvScUpT3rrTuXs7O2pFrgYVnOz6ewYtiJLkG5TjJ21r0wVrdoHhk96CoZP18cCtyU0HReolTj0lgs6n0s/SSQEy41249TkoiRo2jvmhPjsWsaDX1AtRAHMI8gGSS+F4QJeRH2z/XUlGs65eE3XU=
addons:
apt:
packages:
- valgrind
- binutils-mingw-w64
- g++-mingw-w64-x86-64
- gcc-mingw-w64
- wine1.6
- libevent-dev

before_install:
- if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew install valgrind gnu-sed --default-names; fi

matrix:
fast_finish:
- true
include:
- os: osx
compiler: clang
env: RUN_MAKE_CHECK="yes" $BUILD_CONFIG='--enable-debug'
- os: osx
compiler: gcc
env: RUN_TOOLTESTS="yes" $BUILD_CONFIG=""
- os: linux
compiler: gcc
env: VALGRIND_UNIT_TESTS="yes" RUN_TOOLTESTS="yes" SUBMIT_COVERALLS="yes" $BUILD_CONFIG=''
- os: linux
compiler: x86_64-w64-mingw32
env: HOST="x86_64-w64-mingw32" CROSS_COMPILE="yes" RUN_WINE_UNIT_TESTS="yes" $BUILD_CONFIG="--disable-shared --enable-static --disable-net"
- os: linux
compiler: i686-w64-mingw32
env: HOST="i686-w64-mingw32" CROSS_COMPILE="yes" RUN_WINE_UNIT_TESTS="yes" $BUILD_CONFIG="--disable-shared --enable-static --disable-net"
- os: linux
compiler: arm-linux-gnueabihf
env: HOST="arm-linux-gnueabihf" CROSS_COMPILE="yes"
addons:
apt:
packages:
- g++-arm-linux-gnueabihf
sources:
- ubuntu-toolchain-r-test
# - os: linux
# compiler: i686-pc-linux-gnu
# env: HOST="i686-pc-linux-gnu" CROSS_COMPILE="yes"
# addons:
# apt:
# packages:
# - g++-arm-linux-gnueabihf
# - g++-multilib

- cmake
- python3
- python3-pip
- python3-setuptools
- python3-dev
- libevent-2.1-6
- libevent-dev
- libsodium23
- libsodium-dev
compiler:
- gcc
before_install: pip3 install --upgrade --user travis pip setuptools wheel virtualenv
install: pip3 install --user -r rpctest/requirements.txt
before_script:
- ./autogen.sh
- if [ "$CROSS_COMPILE" == "yes" ]; then
make -C depends HOST=$HOST;
LIBTOOL_APP_LDFLAGS='-all-static' LDFLAGS='-static' ./configure --prefix=$TRAVIS_BUILD_DIR/depends/$HOST $BUILD_CONFIG; cat config.log;
elif [ "$SUBMIT_COVERALLS" == "yes" ]; then
./configure $BUILD_CONFIG CFLAGS='-fprofile-arcs -ftest-coverage'; cat config.log;
else
./configure $BUILD_CONFIG; cat config.log;
fi

script:
- make -j2 V=1
- ls -la
- if ( [ "$VALGRIND_UNIT_TESTS" == "yes" ] ); then
valgrind --track-origins=yes --leak-check=full --error-exitcode=1 ./tests;
./tests;
fi
- if ( [ "$RUN_MAKE_CHECK" == "yes" ] ); then
make check;
if [ ! -f test-suite.log; ]; then
cat test-suite.log;
fi
fi
- if ( [ "$RUN_WINE_UNIT_TESTS" == "yes" ] ); then
wine /home/travis/build/libbtc/libbtc/tests.exe;
fi
- if ( [ "$RUN_TOOLTESTS" == "yes" ] ); then
./tooltests.py;
fi

after_success:
- if [ "$SUBMIT_COVERALLS" == "yes" ]; then
sudo pip install -U "cpp-coveralls";
coveralls --verbose -i src -x c -e src/logdb -e src/secp256k1 -r $TRAVIS_BUILD_DIR -b $TRAVIS_BUILD_DIR --gcov-options '\-lp';
fi
- "./travis-build.sh"
script:
- "./nspv ILN &"
- sleep 10
- cd rpctest
- python3 travis.py $PARAM1 $PARAM2 $PARAM3
- python3 -m pytest test_nspv.py
2 changes: 1 addition & 1 deletion coins
Expand Up @@ -94,7 +94,7 @@
"mm2": 1,
"p2p": 12985,
"magic":"feb4cb23",
"nSPV":"5.9.102.210, 5.9.253.195, 5.9.253.196, 5.9.253.197, 5.9.253.198, 5.9.253.199, 5.9.253.200, 5.9.253.201, 5.9.253.202, 5.9.253.203"
"nSPV": "159.69.45.70, 5.9.102.210, 5.9.253.195, 5.9.253.196, 5.9.253.197, 5.9.253.198, 5.9.253.199, 5.9.253.200, 5.9.253.201, 5.9.253.202, 5.9.253.203"
},
{
"coin": "NSPV",
Expand Down
11 changes: 11 additions & 0 deletions rpctest/requirements.txt
@@ -0,0 +1,11 @@
pycurl
python-bitcoinrpc>=1.0
python-dateutil>=2.6.1
PyYAML>=3.12
requests>=2.18.4
requests-unixsocket>=0.1.5
slick-bitcoinrpc>=0.1.4
ujson>=1.35
urllib3>=1.22
pycrypto>=2.6.1
pytest>=5.0.1
226 changes: 226 additions & 0 deletions rpctest/test_framework/nspvlib.py
@@ -0,0 +1,226 @@
#!/usr/bin/env python3
import requests
import json
import ast
import time
import os.path
import sys
sys.path.append(os.path.join(os.path.dirname(__file__)))


class NspvRpcCalls:

def __init__(self, node_ip="", user_pass=""):
self.node_ip = node_ip
self.user_pass = user_pass

@ staticmethod
def assert_equal(first, second):
if first != second:
raise AssertionError(first, "not equal to", second)

def assert_success(self, result):
result_d = self.type_convert(result)
self.assert_equal(result_d.get('result'), 'success')

def assert_in(self, result, key, compare_list):
result_d = self.type_convert(result)
content = result_d.get(key)
if content in compare_list:
pass
else:
raise AssertionError("Error:", content, "not in", compare_list)

def assert_contains(self, result, key):
"""assert key contains expected data"""
if type(result) == bytes:
result = self.type_convert(result)
content = result.get(key)
if content:
pass
else:
raise AssertionError("Unexpected response, missing param: ", key)

def assert_not_contains(self, result, key):
"""assert key contains expected data"""
result_d = self.type_convert(result)
content = result_d.get(key)
if not content:
pass
else:
raise AssertionError("Unexpected response, missing param: ", key)

def assert_error(self, result):
""" assert there is an error with known error message """
error_msg = ['no height', 'invalid height range', 'invalid method', 'timeout', 'error', 'no hex',
'couldnt get addressutxos', 'invalid address or amount too small', 'not enough funds',
'invalid address or amount too small', 'invalid utxo', 'wif expired']
result_d = self.type_convert(result)
error = result_d.get('error')
if error:
if error in error_msg:
pass
else:
raise AssertionError("Unknown error message")
else:
raise AssertionError("Unexpected response")

@ staticmethod
def type_convert(bytez):
"""Wraps nspv_call response"""
# r = json.loads(bytes.decode("utf-8"))
r = ast.literal_eval(bytez.decode("utf-8"))
time.sleep(1)
return r

def nspv_broadcast(self, rawhex):
params = {'userpass': self.user_pass,
'method': 'broadcast'}
if rawhex:
params.update({'hex': rawhex})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_getinfo(self, height=False):
params = {'userpass': self.user_pass,
'method': 'getinfo'}
if height:
params.update({'height':height})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_getnewaddress(self):
params = {'userpass': self.user_pass,
'method': 'getnewaddress'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_getpeerinfo(self):
params = {'userpass': self.user_pass,
'method': 'getpeerinfo'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_hdrsproof(self, prevheight, nextheight):
params = {'userpass': self.user_pass,
'method': 'hdrsproof'}
if prevheight:
params.update({'prevheight':prevheight})
if nextheight:
params.update({'nextheight':nextheight})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_help(self):
params = {'userpass': self.user_pass,
'method': 'help'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_listtransactions(self, address=False, isCC=False, skipcount=False, txfilter=False):
params = {'userpass': self.user_pass,
'method': 'listtransactions'}
if address:
params.update({'address': address})
if isCC:
params.update({'isCC': isCC})
if skipcount:
params.update({'skipcount': skipcount})
if txfilter:
params.update({'filter': txfilter})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_listunspent(self, address=False, isCC=False, skipcount=False, txfilter=False):
params = {'userpass': self.user_pass,
'method': 'listunspent'}
if address:
params.update({'address': address})
if isCC:
params.update({'isCC': isCC})
if skipcount:
params.update({'skipcount': skipcount})
if txfilter:
params.update({'filter': txfilter})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_login(self, wif=False):
params = {'userpass': self.user_pass,
'method': 'login'}
if wif:
params.update({'wif': wif})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_logout(self):
params = {'userpass': self.user_pass,
'method': 'logout'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_mempool(self):
params = {'userpass': self.user_pass,
'method': 'mempool'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_notarizations(self, height):
params = {'userpass': self.user_pass,
'method': 'notarizations'}
if height:
params.update({'height': height})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_spend(self, address, amount):
params = {'userpass': self.user_pass,
'method': 'spend'}
if address:
params.update({'address': address})
if amount:
params.update({'amount': amount})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_spentinfo(self, txid, vout):
params = {'userpass': self.user_pass,
'method': 'spentinfo'}
if txid:
params.update({'txid': txid})
if vout:
params.update({'vout': vout})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_stop(self):
params = {'userpass': self.user_pass,
'method': 'stop'}
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content

def nspv_txproof(self, txid, height):
params = {'userpass': self.user_pass,
'method': 'txproof'}
if txid:
params.update({'txid': txid})
if height:
params.update({'height': height})
r = requests.post(self.node_ip, json=params)
time.sleep(1)
return r.content
4 changes: 2 additions & 2 deletions rpctest/test_framework/util.py
Expand Up @@ -21,8 +21,8 @@
import errno
import logging

from . import coverage
from .authproxy import AuthServiceProxy, JSONRPCException
import coverage
from authproxy import AuthServiceProxy, JSONRPCException

COVERAGE_DIR = None

Expand Down

0 comments on commit a6cf312

Please sign in to comment.