Skip to content

Instantly share code, notes, and snippets.

@notmandatory
Last active April 25, 2025 21:33
Show Gist options
  • Save notmandatory/376c56f53f22c802ce34259636c9ed4b to your computer and use it in GitHub Desktop.
Save notmandatory/376c56f53f22c802ce34259636c9ed4b to your computer and use it in GitHub Desktop.
justfile for bitcoind regtest testing
set quiet := true
default_wallet := 'test'
# list of recipes
default:
echo default_wallet = {{default_wallet}}
echo
just --list
# start regtest bitcoind in /tmp/bitcoind directory
[group('regtest')]
start:
mkdir -p /tmp/bitcoind; bitcoind -datadir=/tmp/bitcoind -regtest -server -fallbackfee=0.0002 -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -blockfilterindex=1 -peerblockfilters=1 -daemon
# stop regtest bitcoind
[group('regtest')]
stop:
pkill bitcoind
# stop and delete regtest bitcoind data
[group('regtest')]
reset: stop
rm -rf /tmp/bitcoind
# create a regtest wallet
[group('regtest')]
create wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest createwallet {{wallet}}
# load regtest wallet
[group('regtest')]
load wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest loadwallet {{wallet}}
# unload regtest wallet
[group('regtest')]
unload wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest unloadwallet {{wallet}}
# view debug log for regtest wallet address
[group('regtest')]
debug:
less +G /tmp/bitcoind/regtest/debug.log
# get regtest wallet address
[group('regtest')]
address wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest -rpcwallet={{wallet}} getnewaddress
# generate n new blocks to given address
[group('regtest')]
generate n address:
bitcoin-cli -datadir=/tmp/bitcoind -regtest generatetoaddress {{n}} {{address}}
# get regtest wallet balance
[group('regtest')]
balance wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest -rpcwallet={{wallet}} getbalance
# list wallet descriptors info, private = (true | false)
[group('regtest')]
descriptors private wallet=default_wallet:
bitcoin-cli -datadir=/tmp/bitcoind -regtest -rpcwallet={{wallet}} listdescriptors {{private}}
# send n btc to address from wallet
[group('regtest')]
send n address wallet=default_wallet:
bitcoin-cli -named -datadir=/tmp/bitcoind -regtest -rpcwallet={{wallet}} sendtoaddress address={{address}} amount={{n}}
# manually created bitcoin-cli RPC command, see just rpc help
[group('regtest')]
rpc command wallet=default_wallet:
bitcoin-cli -named -datadir=/tmp/bitcoind -regtest -rpcwallet={{wallet}} {{command}}
@notmandatory
Copy link
Author

notmandatory commented Apr 25, 2025

Prerequisites

  1. Install: bitcoind, bitcoin-cli, just
  2. Put above justfile in your project directory

Setup regtest bitcoind with just commands

  1. Start bitcoind in regtest mode and create a test wallet
    just start
    just create
  2. Generate blocks to a new test wallet address
    just generate 110 $(just address)
  3. Get the test wallet balance and look at the debug log
    just balance
    just debug

Create test wallets and get their descriptors

  1. Create test wallets in bitcoind
    just create wallet1
    just create wallet2
  2. Get wpkh descriptors for test wallets
    just descriptors true wallet1 | jq '[.descriptors[].desc]' | grep \"wpkh
    just descriptors false wallet2 | jq '[.descriptors[].desc]' | grep \"wpkh

Send to and from test wallets

  1. Send from default wallet to test wallets
    just send 10 $(just address wallet1)
    just send 20 $(just address wallet2)
  2. Confirm new transactions with a new block
    just generate 1 $(just address)
  3. Send from test wallet1 back to default wallet
    just send 1 $(just address) wallet1
    just send 2 $(just address) wallet2
  4. Confirm new transactions with a new block
    just generate 1 $(just address)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment