Package: rpcemulator
Privex's JsonRPC EmulatorsPrivex's RPC Emulators are various python modules usingjsonrpcserverto
emulate a certain type of JsonRPC node for use in unit testing.+===================================================+
    |                 © 2019 Privex Inc.                |
    |               https://www.privex.io               |
    +===================================================+
    |                                                   |
    |        Originally Developed by Privex Inc.        |
    |                                                   |
    |        Core Developer(s):                         |
    |                                                   |
    |          (+)  Chris (@someguy123) [Privex]        |
    |          (+)  Kale (@kryogenic) [Privex]          |
    |                                                   |
    +===================================================+Tl;Dr; Install and use Privex RPC EmulatorsInstall from PyPi (detailed install info atInstall)pipenvinstallrpcemulator# If you use pipenv (and you should!)pip3installrpcemulator# Otherwise, standard pip installationQuick example usage:fromprivex.rpcemulator.bitcoinimportBitcoinEmulatorfromprivex.jsonrpcimportBitcoinRPCrpc=BitcoinRPC()"""You can interact with the emulated Bitcoin daemon with any JsonRPC library you prefer.However, privex-jsonrpc comes as a dependency of rpcemulator for convenience :)"""withBitcoinEmulator():print('Balance is:',rpc.getbalance())print('Network info is:',rpc.getnetworkinfo())Table of Contents (Github README)NOTE:The below Table of Contents is designed to work on Github. The links do NOT work on PyPi's description,
and may not work if you're reading this README.md elsewhere.General InformationInstall2.1Via PyPi (pip)2.2Manually via GitDocumentationLicenseExample UsesUnit TestsContributingGeneral InfoPrivex's RPC Emulators are various python modules usingjsonrpcserverto
emulate a certain type of JsonRPC node for use in unit testing.Currently there's only one emulator included:bitcoin.BitcoinEmulatorwhich emulates abitcoindRPC server,
allowing code which interacts with abitcoind(or other bitcoind-based) node to be tested, without needing
to run the coin daemon.This means you can testbitcoindinterfacing code with continuous integration systems likeTravis CI, where you would normally be unable to run a full coin daemon.InstallDownload and install from PyPiUsingPipenv(recommended)pipenvinstallrpcemulatorUsing standard Python pippip3installrpcemulator(Alternative) Manual install from GitOption 1 - Use pip to install straight from Githubpip3installgit+https://github.com/Privex/rpcemulatorOption 2 - Clone and install manually# Clone the repository from Githubgitclonehttps://github.com/Privex/rpcemulatorcdrpcemulator# RECOMMENDED MANUAL INSTALL METHOD# Use pip to install the source codepip3install.# ALTERNATIVE MANUAL INSTALL METHOD# If you don't have pip, or have issues with installing using it, then you can use setuptools instead.python3setup.pyinstallDocumentationFull documentation for this project is available above (click the Read The Docs image), including:How to install the application and it's dependenciesHow to use the various functions and classesGeneral documentation of the modules and classes for contributorsTo build the documentation:gitclonehttps://github.com/Privex/rpcemulatorcdrpcemulator/docs
pip3install-rrequirements.txt# It's recommended to run make clean to ensure old HTML files are removed# `make html` generates the .html and static files in docs/build for productionmakeclean&&makehtml# After the files are built, you can live develop the docs using `make live`# then browse to http://127.0.0.1:8100/# If you have issues with content not showing up correctly, try make clean && make html# then run make live again.makeliveLicenseThis Python module was created byPrivex Inc. of Belize City, and licensed under the
X11/MIT License.
See the fileLICENSEfor the license text.TL;DR; license:We offer no warranty. You can copy it, modify it, use it in projects with a different license, and even in commercial
(paid for) software.The most important rule is - youMUSTkeep the original license text visible (seeLICENSE) in any copies.Example usesUsing a JsonRPC emulator in a unit testimportunittestfromprivex.rpcemulator.bitcoinimportBitcoinEmulatorfromprivex.jsonrpcimportBitcoinRPCclassTestMyThing(unittest.TestCase):emulator:BitcoinEmulator"""Stores the :class:`.BitcoinEmulator` instance"""rpc=BitcoinRPC()"""For this example, we're using our BitcoinRPC class and communicating with the RPC directly"""@classmethoddefsetUpClass(cls)->None:"""Launch the Bitcoin RPC emulator in the background on default port 8332"""cls.emulator=BitcoinEmulator()@classmethoddeftearDownClass(cls)->None:"""Shutdown the Bitcoin RPC emulator process"""cls.emulator.terminate()deftest_something(self):"""Run whatever code depends on a Bitcoin RPC"""self.assertGreater(self.rpc.getbalance(),0)Using a JsonRPC emulator in your code, with a Context ManagerUse the appropriate emulator class with awithstatement so the server is automatically stopped once you're
done querying it.This prevents any risk of the web server process being leftover.fromprivex.rpcemulator.bitcoinimportBitcoinEmulatorfromprivex.jsonrpcimportBitcoinRPCrpc=BitcoinRPC()print('Starting BitcoinEmulator')withBitcoinEmulator():print('Balance is:',rpc.getbalance())print('Network info is:',rpc.getnetworkinfo())print('Stopped BitcoinEmulator')Unit TestsUnit tests are stored in thetests/folder, which are split into severaltest_xxxxfiles.We useTravis CIfor continuous integration, which runs the test
suite every time a new commit, tag, or branch is pushed to this Github repo.We also useCodeCovwhich integrates with our Travis CI setup, and
provides test coverage statistics, so ourselves and contributors can visually see how much of the code is covered
by our unit testsTL;Dr; Run the tests:pip3 install -r requirements.txt
pytest -vFor more information about using the unit tests, see theHow to use the unit testssection of
the documentation.ContributingWe're happy to accept pull requests, no matter how small.Please make sure any changes you make meet these basic requirements:Any code taken from other projects should be compatible with the MIT LicenseThis is a new project, and as such, supporting Python versions prior to 3.4 is very low priority.However, we're happy to accept PRs to improve compatibility with older versions of Python, as long as it doesn't:drastically increase the complexity of the codeOR cause problems for those on newer versions of Python.Legal Disclaimer for ContributionsNobody wants to read a long document filled with legal text, so we've summed up the important parts here.If you contribute content that you've created/own to projects that are created/owned by Privex, such as code or
documentation, then you might automatically grant us unrestricted usage of your content, regardless of the open source
license that applies to our project.If you don't want to grant us unlimited usage of your content, you should make sure to place your content
in a separate file, making sure that the license of your content is clearly displayed at the start of the file
(e.g. code comments), or inside of it's containing folder (e.g. a file named LICENSE).You should let us know in your pull request or issue that you've included files which are licensed
separately, so that we can make sure there's no license conflicts that might stop us being able
to accept your contribution.If you'd rather read the whole legal text, it should be included asprivex_contribution_agreement.txt.Thanks for reading!If this project has helped you, considergrabbing a VPS or Dedicated Server from Privex.Prices start at as little as US$8/mo (we take cryptocurrency!)