用于帮助智能合约开发的以太坊模拟器。
项目描述
# 以太坊测试 RPC 服务器
[]( https://gitter.im/ pipermerriam/eth-testrpc?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge )
## 以太坊测试 RPC
用于自动化测试的有限 RPC 客户端。使用 [pythereum]( https://github.com/ethereum/pyethereum ) 在后台运行以太坊客户端,无需挖矿或联网。结果是一个以太坊客户端,可在开发过程中提供即时结果和快速反馈。
### 安装
通过 pip 安装很容易:
` $ pip install eth-testrpc `
或者,要升级:
` pip install eth-testrpc --upgrade `
或者,使用 gevent 线程安装
` pip install eth-testrpc[gevent] `
然后设置环境变量TESTRPC_THREADING_BACKEND=gevent
### 跑
通过 pip 安装将使testrpc-py命令在您的机器上可用:
`$ testrpc`
这将在 localhost:8545 上运行 testrpc。您可以通过不同的端口(-p、--port)或域(-d、--domain)。
### 实现的方法
目前实现的 RPC 方法有:
eth_coinbase
eth_accounts
eth_gasPrice
eth_blockNumber
eth_sendTransaction
eth_sendRawTransaction
eth_call
eth_getCompilers
eth_compileSolidity
eth_getCode(仅支持区块号“最新”)
eth_getBalance
eth_getTransactionCount
eth_getTransactionByHash
eth_getTransactionReceipt
eth_newBlockFilter (暂时移除,直到在底层库中实现)
eth_newFilter (暂时移除,直到在底层库中实现)
eth_getFilterChanges (暂时移除,直到在底层库中实现)
eth_uninstallFilter (暂时移除,直到在底层库中实现)
eth_protocolVersion(见rpc_configure)
eth_syncing(参见rpc_configure)
eth_mining(见rpc_configure)
web3_sha3
web3_client版本
net_version(见rpc_configure)
net_listening(见rpc_configure)
net_peerCount (参见rpc_configure )
还有一些特殊的非标准方法未包含在原始 RPC 规范中:
evm_reset:没有参数,没有返回值。
evm_snapshot:没有参数。返回创建的快照的整数 id。
evm_revert:一个可选参数。恢复为传递的快照 ID,或最新的快照。
当调用evm_reset时,testrpc会将其内部链的状态恢复到创世块,并且它会表现得好像没有处理任何事务。同样,您可以使用evm_snapshot和 evm_revert方法根据需要保存和恢复 evm 状态。这些方法的示例用例如下:
evm_reset:在测试套件开始时运行一次。
evm_snapshot:在每个测试开始时运行,快照 evm 的状态。
evm_revert:在每次测试结束时运行,恢复到已知的干净状态。
TestRPC 还公开了evm_mine方法,用于将测试 evm 推进一些块。
evm_mine:可选地为要挖掘的块数提供一个整数。默认为 1 个块。没有返回值。
TestRPC 公开了 testing_timeTravel方法,用于快速转发到未来的时间戳。
testing_timeTravel:采用整数时间戳,该时间戳必须大于当前最新区块的时间戳。
TestRPC 公开了rpc_configure方法,该方法可用于修改以下端点返回的静态值。
eth_protocolVersion (默认63 )
eth_syncing (默认False )
eth_mining(默认True)
net_version (默认1 )
net_listening(默认False)
net_peerCount (默认0 )
homestead_block_number (默认0 )
dao_fork_block_number (默认0 )
anti_dos_fork_block_number (默认0 )
clearing_fork_block_number (默认0 )
rpc_configure有两个参数。
key:表示要更改其返回值的 rpc 方法的字符串。
value:端点应该返回的值。
homestead、dao、anti_dos和clearing fork 配置决定了各自的分叉规则应该在哪个区块号生效。全部默认为0。
TestRPC 使用默认的气体限制 4000000。要更改此设置,请将环境变量TESTRPC_GAS_LIMIT设置为所需的值。
### 发布新版本(针对 eth-testrpc 开发者)
setup.py中的凹凸版本号
向CHANGES.txt添加条目
标记发布。
` git tag -s -m "XXX Release" vX.XX git push --tags `
去 github 上发布你刚刚推送的标签
构建并推送发布到 PyPI
` 发布 `
### 执照
麻省理工学院
### 共识系统
该库最初由 Consensys 编写,后来在不再维护时转移。非常感谢他们创建了这个非常有用的库。