Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

TestRPC 3.0.0 - I wanna be like you ooh ooh

Compare
Choose a tag to compare
@tcoulter tcoulter released this 05 Oct 17:23
· 477 commits to master since this release

The TestRPC is always striving to be closer to a real blockchain environment, with added benefits for testing and development. Often, we use geth as our oracle, constantly ensuring that when you deploy to the TestRPC, you're setting yourself up to deploy to geth. So this release is our "more like geth" release, like Mowgli in the Jungle Book. 😃

Install

$ npm install ethereumjs-testrpc

Breaking Changes

This version contains many changes, some of them breaking changes. The biggest are the following:

  • Default gas price is now 0.02 szabo, mimicking geth
  • Default gas limit for transactions is now 90000 gas instead of the full block gas limit. This also mimics geth, and sets users up for deploying to live blockchains.

Both of these change the default values of the TestRPC. The gas price change affects the total amount of Ether required to send a transaction, which may break some tests. The gas limit change, however, is likely to cause a wide range of failures, making many previously-successful transactions now run out of gas. The reason we made this change is so the TestRPC will behave more like geth, so that you're aware of gas limit issues during development before being blindsided later when deploying to production. Without this change, you could easily write code for the TestRPC that wouldn't run correctly on the live network.

To avoid these new out of gas errors, you can now pass a higher gas limit as a parameter to web3:

web3.eth.sendTransaction({..., gas: 3141592}) // choose your own gas limit suitable for you

New Features

Along with breaking changes we have some new features -- features that have been in the works for awhile.

  • We've added support for the miner_start and miner_stop requests, like those supported by geth. You can use these to toggle mining on and off, and allow transactions to be queued when mining is off (great for tests). Mining is on by default.
  • We added support for the rpc_modules request, which is used by geth. You can now use geth attach to attach to the TestRPC.
  • Similarly, we added support for the eth_getTransactionByBlockHashAndIndex and eth_getTransactionByBlockNumberAndIndex requests, which are fairly new additions to the RPC spec.
  • Perhaps our biggest feature is under the hood, where block processing has been significantly improved. Queued transactions are now ordered by price, nonce and gas limit (also like geth) and the TestRPC will attempt to fit as many transactions in a block as possible.
  • There are now three block processing strategies available that should improve testing and development. These are: instamine (default behavior), mine on interval (--blocktime), and mine by request (miner_stop + transaction queuing + multiple evm_mine requests). You can stop mining whenever you'd like and continue to queue transactions. While mining is stopped, you can send an evm_mine request to make TestRPC process one block with as many transactions as it can fit. Huge thanks to @area for making this and many of the above features a reality.
  • --blocktime is now disjointed from instamining, and will now act like a real blockchain. If you specify --blocktime, transactions will only be processed on the interval, and won't be instamined (this differs from TestRPC 2.x behavior where transactions were instamined in addition to blocks being processed on interval). You can use this feature to test how your dapp behaves when transactions aren't processed immediately. Note that, like geth errors aren't returned in transaction requests when --blocktime is used since block processing is disjoint from transactions.
  • Transaction errors are now printed to the TestRPC log, so you know exactly which transaction failed.
  • We've added the --secure flag, which automatically makes all accounts locked by default, meaning transactions won't be signed by the TestRPC. This is useful if you want to ensure signing is working properly through other mechanisms (like Metamask) and you want to be sure the TestRPC isn't performing that signing.
  • In addition to --secure, we added the --unlock/-u flags, which can be used any number of times to unlock any account, even ones you don't own. When used with --secure you can unlock accounts that are created for you via the TestRPC. When used with --fork you can use this feature to "impersonate" any account on the blockchain, allowing you to bypass transaction signing and use that address as if you owned it. This has wide implications for testing and dynamic analysis.
  • To keep up with new features, error handling has been overhauled to support multiple transactions per block and therefore multiple errors per evm_mine request (when using miner_start/miner_stop and transaction queuing)
  • We fixed an issue with -a not working properly. Now testrpc -a 3 will only create 3 accounts.
  • As requested, we upgraded solc version to 0.4.x
  • We also added a ton more tests. Our testing has been significantly hardened, which benefits everyone.

Special Thanks

Many people have contributed PRs and written tickets that supported this release. Thanks goes to @tjade273, @uzyn and @chevdor for the PRs, @FlySwatter and @PeterBorah for the feature requests. Very special thanks goes to @area for contributing the bulk of these new features and laying the groundwork for them to become a reality.

We sincerely hope the TestRPC continues to be useful for testing and development. Please let us know how you're using it, and if you run into any trouble or have feature requests. Cheers!