Skip to content

Bitcoin and Mastercoin Integration Testing using Spock

License

Notifications You must be signed in to change notification settings

CraigSellars/bitcoin-spock

 
 

Repository files navigation

bitcoin-spock

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.

Installing pre-requisites

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.

Running the tests manually

  1. Check out this project using Git

    $ git clone https://github.com/msgilligan/bitcoin-spock.git
  2. 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
  3. Open a shell and set the current working directory

    cd bitcoin-spock
  4. 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 with regTest for the Mastercoin RegTests or with regTestBTC for the Bitcoin RegTests.

Running the tests from Jenkins

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 in copied-artifacts/src directory.

test-msc-integ-regtest.sh

Runs Mastercoin RPC regtest test against a built executable of bitcoind in copied-artifacts/src directory.

test-msc-consensus-mainnet.sh

Runs consensus tests against a built executable of bitcoind in copied-artifacts/src directory.

Note
Read the scripts carefully to make sure you understand how they work.

Sample Test

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)
}

Supporting Libraries

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).

Regression Test Mode

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.

Simple Demo of RegTest mode with Bash Scripts

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.

About

Bitcoin and Mastercoin Integration Testing using Spock

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Groovy 63.1%
  • Java 33.9%
  • Shell 3.0%