-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
The script regtest.py
in the main joinmarket directory is designed to run automated tests on a simulation of a joinmarket pit. The idea is to use the -regtest flag to bitcoind/bitcoin-cli to set up a local Bitcoin blockchain, populate it with some coins, then create yield generator, sendpayment and other bots which connect to a testing IRC channel and carry out trades with these test coins.
In this I am assuming that you already have a live instance of joinmarket (e.g. a yield generator) running against a Bitcoin Core instance on your machine; if you don't, then some of these steps may be skipped or simplified.
- Create a new
bitcoin.conf
file in any arbitrary directory, e.g./home/joinmarketeer/bitcoin.conf
Then add or modify these lines for the wallet notification and for rpc access:
rpcuser=bitcoinrpc rpcpassword=123456abcdef walletnotify=curl -sI --connect-timeout 1 http://localhost:62612/walletnotify?%s alertnotify=curl -sI --connect-timeout 1 http://localhost:62612/alertnotify?%s
No other modifications should be needed. This probably means changing only the port number from 62602 to 62612. You can choose any (unused) port not in the range 62602-62611 as this is the range reserved for use by the live joinmarket system.
-
Start a regtest instance of Bitcoin:
/path/to/bitcoin/bitcoind -regtest -daemon -conf=/home/joinmarketeer/bitcoin.conf
-
Generate enough blocks to start:
/path/to/bitcoin/bitcoin-cli -regtest -rpcpassword=123456abcdef generate 101
This is explained in the Bitcoin Developer Guide.
There should now be 50 coins in the wallet:
```
/path/to/bitcoin/bitcoin-cli -regtest getbalance
```
-
Edit
joinmarket.cfg
. There are several edits to make; here is a sample (I have stripped comments):[BLOCKCHAIN] blockchain_source = regtest rpc_host = localhost rpc_port = 18332 rpc_user = bitcoinrpc rpc_password = 123456abcdef network = testnet bitcoin_cli_cmd = bitcoin-cli #only required for regtest simultaneous operation; must not be in range 62602-62611 notify_port = 62612 [MESSAGING] host = chat.freenode.net channel = joinmarket-myname port = 6697 usessl = true socks5 = false socks5_host = localhost socks5_port = 9150
Notes: first, the network is 'testnet', not 'regtest', because regtest uses testnet style bitcoin addresses. The blockchain interface must be 'regtest', else you might end up confusing your live joinmarket instance (if you have one).
The 'notify_port' option is an extra one for regtest-ing. It must be set to the same port that you specified in the walletnotify in the bitcoin.conf above (see those notes about allowable values).
The IRC server, port and channel name are your choice; needless to say you must change it from the live joinmarket pit! I recommend freenode rather than cyberguerrilla as the latter is very strict about concurrent connections, but there is nothing to stop you using a different IRC server. For channel name, I recommend a convention like #joinmarket-myname
to avoid conflicts between different testers, but NOTE that the actual channel name will be in that case #joinmarket-myname-test
(joinmarket appends -test to a channel name for the test network).
This is very simple; simply run the script: python regtest.py
Monitor the IRC channel #joinmarket-myname-test
or similar to see the bots running. There is also some feedback on the command line. A successful test run will output something like this at the end:
----------------------------------------------------------------------
Ran 2 tests in 216.593s
OK
In case of errors, the bot logs in joinmarket/logs
may be very useful debugging information (as this is not seen on the terminal).
The initial version only has a couple of 2 party and 3 party joins. It will be fairly easy to create different scenarios and add new test classes that inherit from python's unittest.TestCase
class. Notice that common.bc_interface
is now an instance of RegtestBitcoinCoreInterface
, which has two special methods tick_forward_chain
, which instantly creates a new block (and assigns 50 coins to the main wallet), and grab_coins
which allows you to send coins to any address.