Integration testing for Bitcoin and Mastercoin using the Spock Framework.
There are currently three test suites contained in this project.
- Bitcoin RegTest Tests
-
Test Bitcoin RPC calls against an instance of
bitcoind
running in RegTest mode. - Mastercoin RegTest Tests
-
Test Bitcoin and Mastercoin RPC calls against an instance of
mastercored
running in RegTest mode. - Mastercoin Consensus Tests
-
Use the
getallbalancesforid_MP
RPC to get balances for multiple Mastercoin currencies and compare them against balance information from several well-known public Mastercoin servers with consensus-checking Web APIs.
The only prerequisite for running these tests is an installed Java Runtime Environment. Either an Oracle or OpenJDK VM will work. Java 7 or later is recommended.
All other dependencies are automatically downloaded and cached by the test startup script.
-
Check out this project using Git
$ git clone https://github.com/msgilligan/bitcoin-spock.git
-
Start Master Core (or bitciond) on MainNet listening on the standard RPC port on
localhost
. The tests are configured to use the following username and password:rpcuser=bitcoinrpc rpcpassword=pass
-
Open a shell and set the current working directory
cd bitcoin-spock
-
Run the tests with the provided Gradle wrapper scripts. For Unix/Mac:
./gradlew consensusTest
or for Windows:
./gradlew.bat consensusTest
The above examples are for the Consensus Test, to run the other test suites replace the
consensusTest
Gradle target withregTest
for the Mastercoin RegTests or withregTestBTC
for the Bitcoin RegTests.
To run the test from Jenkins you can use on of the following (UNIX) shell scripts:
- test-btc-integ-regtest.sh
-
Runs BTC RPC RegTest tests against a built executable of
bitcoind
incopied-artifacts/src
directory. - test-msc-integ-regtest.sh
-
Runs Mastercoin RPC regtest test against a built executable of
bitcoind
incopied-artifacts/src
directory. - test-msc-consensus-mainnet.sh
-
Runs consensus tests against a built executable of
bitcoind
incopied-artifacts/src
directory.
Note
|
Read the scripts carefully to make sure you understand how they work. |
Should "Send an amount to a newly created address"() {
when: "we create a new address and send testAmount to it"
def destinationAddress = getNewAddress()
sendToAddress(destinationAddress, testAmount, "comment", "comment-to")
generateBlocks(1)
then: "the new address has a balance of testAmount"
testAmount == getReceivedByAddress(destinationAddress)
}
This project includes a variety of supporting classes necessary to implement the functional/integration tests. For an quick overview of these classes look at their API documentation (GroovyDoc).
Bitcoin 0.9 and later include support for Regression Test Mode (aka RegTest mode). RegTest mode creates a single node Bitcoin "network" that can confirm blocks upon command.
For example the following command will generate 101 blocks
./bitcoin-cli -regtest setgenerate true 101
And yes, you get the newly mined coins. They can’t be spent anywhere, but they’re great for testing.
The best documentation of RegTest mode that I’ve seen so far is How to test applications on the new Bitcoinj website.
These are some really rough Bash scripts that can drive bitcoind in RegTest mode.
- Procedure
-
-
Make sure Bitcoin Core 0.9 or later is installed and in your path.
-
Run the server script
./server.sh &
-
Run the client setup script to mine some coins to get started:
./setup-client.sh
-
Run the client script (repeat as desired)
./client.sh
-
A directory named regtest-datadir is created in the current directory.
-