Developing cryptoassets.core

Running tests

Unit tests are PyTest based.

Testing prerequisites

To run all tests several components must be in-place

  • pip install test-extra-requirements.txt`

  • Check credentials in tests/config.yaml files (hardcoded accounts, testnet coins)

  • bitcoind running testnet on localhost, configured for named UNIX pipe wallet notifications (see config snipped below). bitcoind must have account cryptoassets with enough balance to do withdraw tests.

  • PostgreSQL database unittest-conflict-resolution where you can connect on localhost without username and password

  • Redis installed, with preferable empty database 0

  • ngrok account is required for running webhook tests. You need to create export NGROK_AUTH_TOKEN environment variable in order run tests:

    export NGROK_AUTH_TOKEN=xxx

Examples for running tests

Running all tests:

py.test cryptoassets

Running a single test case:

py.test cryptoassets/core/tests/

Running a single test:

py.test -k "BitcoindTestCase.test_send_internal" cryptoassets

Running a single test with verbose Python logging output to stdout (useful for pinning down why the test fails):

VERBOSE_TEST=1 py.test -k "BitcoindTestCase.test_send_internal" cryptoassets

Running tests for continuous integration service (15 minute timeout) and skipping slow tests where transactions are routed through cryptocurrency network (full BTC send/receive test, etc.):

CI=true py.test cryptoassets

Running unittests using vanilla Python 3 unittest:

python -m unittest discover

(This ignores all skipping hints)

More info

Bitcoind testnet

Setting up TESTNET bitcoind on OSX

Edit /Users/mikko/Library/Application Support/Bitcoin/bitcoin.conf:

walletnotify=gtimeout --kill-after=10 5 /bin/bash -c "echo %s >> /tmp/cryptoassets-unittest-walletnotify-pipe

Restart Bitcoin-Qt. Now it should give green icon instead of standard orange.

Test the JSON-RPC server connection:

curl --user foo:bar --data-binary '{"id":"t0", "method": "getinfo", "params": [] }'

Starting bitcoind in debug mode:

/Applications/ -printtoconsole -debug

Topping up bitcoind

First create a receiving address under bitcoind accounting account cryptoassets:

curl --user foo:bar --data-binary '{"id":"t0", "method": "getnewaddress", "params": ["cryptoassets"] }'

Write down the result.

Testnet faucet

Get Testnet coins from here:

(Alternative testnet faucets.)

Send them to the receiving address you created.

Then list bitcoind accounts and balances, to see you have the new receiving address and the balance arrives there:

curl –user foo:bar –data-binary ‘{“id”:”t0”, “method”: “listaccounts”, “params”: [] }’

Dumping your TESTNET private address for importing in tests

Example using public address mk2o9anFwtHFGFKeD89Qxh5YBhNMQk7NrS:

curl --user foo:bar --data-binary '{"id":"t0", "method": "dumpprivkey", "params": ["mk2o9anFwtHFGFKeD89Qxh5YBhNMQk7NrS"] }'

Using bitcoind with multiple backends

If you are using same bitcoind testnet instance to drive several cryptoassets backends, you can multiplex incoming transactions to several wallet notify pipes with a shell script like:

echo "Got txid $1" >> /tmp/txlist.txt
# Timeout is needed to work around for hanging named pipe cases where Bitcoin-QT process starts to write to a named pipe, but nobody is reading it, thus preventing clean shutdown of the parent process (bitcoind)
gtimeout --kill-after=10 5 /bin/bash -c "echo $1 >> /tmp/cryptoassets-unittest-walletnotify-pipe"
gtimeout --kill-after=10 5 /bin/bash -c "echo $1 >> /tmp/tatianastore-cryptoassets-helper-walletnotify"
exit 0

Also needs coreutils on OSX:

brew install coreutils

Conflicted transactions

If Bitcoin-QT starts to display transactions sent via RPC as conflicted status

  1. Your walletnotifty script might be broken, CTRL+C abort Bitcoin-QT in terminal, check error messages:

    /Users/mikko/code/ line 3: timeout: command not found
    runCommand error: system(/Users/mikko/code/ 94506c797452745b87e734caf35ec4b62c0ef61f6c7efa5869f22ec0f1a71abf) returned 32512
  2. rescan blockchain (unclean shutdown?):

    /Applications/ -printtoconsole -debug -rescan
  3. Make sure “Spend unconfirmed outputs” is toggled off in Bitcoin-QT preferences

  4. Make sure you are displaying correct transactions and not old ones (Bitcoin QT pops old conflicting transactions at the top of the history list). Choose “Today” from Bitcoin QT transaction list filters.

Continuous integration

Continuous integration is running on <>`_.

See tests/ how tests are executed.

Full CI test suite

Because some tests may take more than 15 minutes to execute, full test suite cannot be run on CI environment. There is script which can be used to run tests on Linux VM + bitcoind testnet instance.

Run this script on a server having running Bitcoind instance.