Code Monkey home page Code Monkey logo

bitcoin-spock's Introduction

bitcoin-spock

Integration testing for Bitcoin and Omni Protocol 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.