Skip to content

alun/bitcoin-regtest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bitcoin regtest

Aka regtest mode is an environment where you can easily issue new bitcoins perform transactions etc.

This is extremely helpful to be used as mock to create integration tests for your bitcoin application.

This image provides a way of building a docker image for your needs. It creates several bitcoind instances running in regtest mode and connects each other into a single network.

Each daemon provides their own JSON-RPC port in order to support mimic of several wallets/users.

Using the image

Configuration

npm install

This step is optional - generated users.json is already included with the source files.

node generate config [number] [startPort]

this will create users.json file which is used for further configuration. It specifies test user names and JSON-RPC port for sending commands on their behalf. Each user will have their own bitcoind process in a single container.

After this step you can edit generated users.json file if required.

node generate

Creates Dockerfile, main script for the image - run_servers, several cli/user* scripts to call bitcoin commands on a user behalf. And bitcoin config dir for using by bitcoind servers.

Build and install image to your docker environment

s/build

Running the container

s/run

Since this all is about testing, it would be good to clean up to refresh environment for subsequent tests:

s/stop

This opearations could be also easily done using mupliple docker clients availiable whithin your test suites.

Connecting to the container

Use scripts generated by generate to run bit coin commands. E.g.

$ cli/user1 generate 101
# ...
$ cli/user3 listreceivedbyaddress 0 true
[
  {
    "address": "mwXtxU5AFw8T88SggNYGrR5CXxqajdEc2t",
    "account": "",
    "amount": 0.00000000,
    "confirmations": 0,
    "label": "",
    "txids": [
    ]
  }
]
$ cli/user1 sendtoaddress mwXtxU5AFw8T88SggNYGrR5CXxqajdEc2t 5
16ac9f1bbb9d66e973bd26fd12cee33f9f8f347ded1ce715b438a3b964605dce 
$ cli/user3 listreceivedbyaddress 0 true
[
  {
    "address": "mwXtxU5AFw8T88SggNYGrR5CXxqajdEc2t",
    "account": "",
    "amount": 5.00000000,
    "confirmations": 0,
    "label": "",
    "txids": [
      "16ac9f1bbb9d66e973bd26fd12cee33f9f8f347ded1ce715b438a3b964605dce"
    ]
  }
]

That's it user3 has received 5 BTC generated by user1 on to his address.

(c) 2015-2016 Alexey Lunacharsky

About

One click way to enroll bitcoin testing environment for your application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published