对比特币的一个小小的、非炫耀性的模仿
bitcoind-mock的Python项目详细描述
比特币模拟
bitcoindmock是一种为单元测试模拟bitcoind的方法。它对于Continuous integration (CI)
工具特别有用。在
mock提供了一个JSON-RPC
接口,其中包含bitcoind
中可用的一些RPC命令以及zmq
事务和块通知接口。mock还提供了额外的端点来生成块
请求(/generate
)并创建分叉(/fork
)。在
模拟可以由time
运行,其中块将以固定的时间间隔生成,也可以由events
运行,其中一个块
将在每次调用/generate
时生成。在
以下是当前部分覆盖的命令:
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.
已知限制
- 在
实现的命令不会返回
在bitcoind
将返回的每个字段,只返回最重要的字段(或 在我自己的单元测试中需要的)。在 - 在
当与via
在python
交互时,mock可以很好地工作,但是如果由bitcoin-cli
直接查询(检查#1),则不能正常工作。在 - 在
在zmq
只通知正在挖掘的块,但不通知事务。在 - 在
运行mock by
在time
时请求fork将不会重置将在其上挖掘的块的计时器 叉形的那个。在
依赖性
请参阅DEPENCENCIES.md。在
安装
您可以从PyPi获取包:
pip install bitcoind-mock
或手动安装(请参阅INSTALL.md)。在
贡献
如果您想添加/扩展任何命令,请随时发送一份PR。我们可以通过加入来完成此任务 努力:微笑:
请参阅CONTRIBUTING.md以了解要遵循的样式准则。在
- 项目
标签: