Skip to main content

A tiny and non-exhaustive mock for bitcoind

Project description

bitcoind mock

tippin.me

bitcoind mock is an approach to simulate bitcoind for unit testing. It is specially useful for Continuous integration (CI) tools.

The mock provides a JSON-RPC interface with some of the RPC commands available in bitcoind along with a zmq interface for transaction and block notification. The mock also provides additional endpoints to generate blocks on demand (/generate) and to create forks (/fork).

The mock can be run either by time, where blocks will be generated in fix time intervals, or by events where a block will be generated each time /generate is called.

This are the current partially covered commands:

decoderawtransaction:   querying for the decoding of a raw transaction will return a dictionary with a single
                        field: "txid".

sendrawtransaction:     sending a rawtransaction will notify our mining simulator to include such transaction in
                        a subsequent block (add it to mempool).

getrawtransaction:      requesting a rawtransaction from a txid will return a dictionary containing a single
                        field: "confirmations", since rawtransactions are only queried to check whether a
                        transaction has made it to a block or not.

getblockcount:          the block count represents the length of the longest chain.

getblock:               querying for a block will return a dictionary with three fields: "tx" representing a
                        list of transactions, "height" representing the block height and "hash" representing the
                        block hash.

getblockhash:           returns the hash of a block given its height.

getbestblockhash:       returns the hash of the block in the tip of the chain.

help:                   help is only used as a sample command to test if bitcoind is running when bootstrapping.
                        It will return a 200/OK with no data.

Known limitations

  • The implemented commands do not return every single field that bitcoind would, only the most important ones (or the ones that I've required so for my own unit tests).

  • The mock works well when interacting with via python but not if queried directly by bitcoin-cli (check #1).

  • zmq only notifies about blocks being mined, but not about transactions.

  • Requesting a fork while running the mock by time will not reset the timer for the block that will be mined on top of the forked one.

Dependencies

Refer to DEPENCENCIES.md.

Installation

You can get the package from PyPi:

pip install bitcoind-mock

Or install it manually (refer to INSTALL.md).

Contributing

If you'd like to add / extend any command, feel free to send a PR. We can make this as complete as we'd like by joining efforts :smile:

Refer to CONTRIBUTING.md for the style guidelines to follow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bitcoind_mock-0.0.4.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

bitcoind_mock-0.0.4-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file bitcoind_mock-0.0.4.tar.gz.

File metadata

  • Download URL: bitcoind_mock-0.0.4.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for bitcoind_mock-0.0.4.tar.gz
Algorithm Hash digest
SHA256 4bd741fa16cd2a84a2e3cd8822e5be8b45fef6cc3185622a6f42ab3527e5813e
MD5 cdc60216918f9df8bc283cc6d7014369
BLAKE2b-256 745ef9d1cfe7abd52487ed3efab753900ea2d788e3979aa5f5b9630d00ee44d9

See more details on using hashes here.

File details

Details for the file bitcoind_mock-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: bitcoind_mock-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for bitcoind_mock-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1c5a8d91e2678f07abf77e33edc397b8d72a21b89914561be02ec07503f5ebb8
MD5 5ca8574767c6bf0d43dba6f7b848bd84
BLAKE2b-256 00986b11673a232b6f225cc7e6db046e1e475513ab35f7d3351c85fb63eba92f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page