Welcome! This exercise introduces MiniWallet as a practical helper for building test scenarios without using the Core wallet :)
This exercise introduces MiniWallet as lightweight test support.
MiniWallet is not the full wallet RPC interface used in the first exercise. Instead, it is a helper in the functional test framework that makes it faster to create UTXOs and construct transactions for test scenarios. It is especially useful because many non-wallet tests still need spendable coins, and MiniWallet provides that without requiring that Bitcoin Core is compiled with wallet support.
The MiniWallet code is fairly short, and you can inspect its methods directly in test/functional/test_framework/wallet.py.
A common pattern is:
# Create a MiniWallet bound to node 0
wallet = MiniWallet(self.nodes[0])
# MiniWallet usually starts with mature UTXOs from the cached chain
assert_greater_than(wallet.get_balance(), 0)
# Build + broadcast a simple self-transfer transaction
tx = wallet.send_self_transfer(from_node=self.nodes[0])
# If needed, you can also create txs without broadcasting:
# tx = wallet.create_self_transfer()
# ...do stuff with tx...
# self.nodes[0].sendrawtransaction(tx["hex"])Create a functional test that:
- Uses one node.
- Creates a
MiniWalletconnected toself.nodes[0]. - The MiniWallet starts with funds by default. Assert that its balance is greater than
0. - Creates and broadcasts one self-transfer using MiniWallet.
- Checks that the transaction is in the mempool.
- Mines one block and checks that the transaction leaves the mempool.
Suggested filename in b4os-bitcoin/:
test/functional/feature_miniwallet.py
Do not forget to add the test to test/functional/test_runner.py so you can run it through the harness.
Big hint
Construct MiniWallet with MiniWallet(self.nodes[0]).
Small hint
Use assert_greater_than and MiniWallet's get_balance() method.
Small hint
MiniWallet has a self-transfer helper that creates and sends the tx.Big hint
Use `send_self_transfer`, and keep the returned transaction identifier so you can track its lifecycle.Small hint
Check that the transaction is in `getrawmempool()` before mining, then mine one block and check it is no longer in mempool.Continue with 04-easy-p2p-ping-pong.md.