Skip to content

Instantly share code, notes, and snippets.

@Warchant
Last active July 22, 2020 20:28
Show Gist options
  • Save Warchant/784fd8f422d95a268516cad2138f3620 to your computer and use it in GitHub Desktop.
Save Warchant/784fd8f422d95a268516cad2138f3620 to your computer and use it in GitHub Desktop.

Running functional tests in vBTC

Ubuntu 18.04 is recommended.

0. Install dependencies

These are dependencies for pypopminer and vbtc build. pypopminer depends on boost-python and python3, vbtc on everything else.

sudo apt-get install \
    autoconf \
    software-properties-common \
    pkg-config \
    build-essential \
    libtool \
    autotools-dev \
    automake \
    pkg-config \
    libssl-dev \
    libevent-dev \
    bsdmainutils \
    libboost-system-dev \
    libboost-filesystem-dev \
    libboost-chrono-dev \
    libboost-test-dev \
    libboost-thread-dev \
    libb2-dev \
    libz-dev \
    xz-utils \
    libboost-dev \
    libboost-python-dev \
    python3 \
    python3-dev \
    python3-pip \
    git
sudo pip3 install cmake
apt-add-repository -y ppa:bitcoin/bitcoin
add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install \
    libdb4.8-dev \
    libdb4.8++-dev

1. Install pypopminer and alt-cpp library

git clone https://github.com/VeriBlock/alt-integration-cpp
cd alt-integration-cpp
mkdir build
cd build
cmake .. -DWITH_PYPOPMINER=ON -DCMAKE_BUILD_TYPE=Release -DTESTING=OFF
make -j
sudo make install

You should see these lines (or similar):

-- Installing: /root/.local/lib/python3.6/site-packages/pypopminer/pypopminer.so
-- Installing: /root/.local/lib/python3.6/site-packages/pypopminer/__init__.py

2. Build vBTC

git clone https://github.com/VeriBlock/vbk-ri-btc
cd vbk-ri-btc
./autogen.sh
./configure --without-gui --disable-bench --disable-tests
make -j
# no need to make install

3. Run functional tests

cd test/functional
# run all tests
./test_runner.py

# run specific test
./feature_pop_fork_resolution.py

# enable debug logger, enable RPC tracing
./feature_pop_fork_resolution.py --tracerpc -l DEBUG

# wanna see node's logs after test crashed?
# run test with flag --nocleanup
# after test run, look at test run id, it looks like this --vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
2020-07-22T20:15:38.725000Z ... Initializing test directory /tmp/bitcoin_func_test_uqgiab8_
# it is random, for every run
$ cd /tmp/bitcoin_func_test_uqgiab8_
/tmp/bitcoin_func_test_qbjor7qu » ls -la
total 8
drwx------  6 bogdan bogdan  140 лип 22 23:17 .
drwxrwxrwt 24 root   root   1040 лип 22 23:17 ..
drwxr-xr-x  5 bogdan bogdan  120 лип 22 23:17 node0
drwxr-xr-x  5 bogdan bogdan  120 лип 22 23:17 node1
drwxr-xr-x  5 bogdan bogdan  120 лип 22 23:17 node2
drwxr-xr-x  5 bogdan bogdan  120 лип 22 23:17 node3
-rw-r--r--  1 bogdan bogdan 4298 лип 22 23:18 test_framework.log
# then, you can see all datadirs of each node from the test, including its `debug.log` and `vbitcoin.conf`

4. Write functional tests

  1. Create new file, name it feature_pop_<TESTNAME>.py
  2. Copy content of one of feature_pop_*.py files
  3. Rename test, modify it for your specific case

A few tips:

  • Use endorse_block function to endorse alt block.
  • Use node.getblock(node.getbestblockhash()) to get all info about best block
  • Use node.generate(nblocks=100) to generate 100 blocks after current tip.
  • Use self.sync_blocks(self.nodes, timeout=20) to wait 20 sec until all nodes sync their blocks. Same with self.sync_pop_mempools and self.sync_mempools
  • To call any rpc, just specify its name as python function: node.<rpc>(). Example: node.getbtcbestblockhash()
  • See pypopminer docs for examples with pypopminer.
  • To see all docs for pypopminer, see source code
  • To increase alt-cpp verbosity, use arg -poplogverbosity=debug

List of useful rpc calls:

- get{btc,vbk}bestblockhash -> hex hash of best block
- get{btc,vbk}block <hash> -> block data
- get{btc,vbk}blockhash <height> -> hash
- getblock <hash> -> altchain block
- getbestblockhash -> altchain's best block hash
- getraw{atv,vtb,vbkblock} <id:hex> <verbosity:int> <containing block hash:hex> -> {atv,vtb,vbkblock} data - containing block is optional, if entity is in mempool
- getrawpopmempool -> list of IDs of entities stored in pop mempool
- generate <num> -> mine num blocks on top of current tip
- getpopdata <height:int> -> get input data for APM
- submitpop <vbkblocks:hexlist> <vtbs:hexlist> <atvs:hexlist> -> submit pop data 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment