Skip to content

Commit 9a7726f

Browse files
committed
add functional test for coinbase connection to db
1 parent 10247f7 commit 9a7726f

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2014-2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test connecting genesis coinbase"""
6+
7+
from binascii import b2a_hex
8+
9+
from test_framework.blocktools import create_coinbase
10+
from test_framework.messages import CBlock
11+
from test_framework.test_framework import BitcoinTestFramework
12+
from test_framework.util import assert_equal, assert_raises_rpc_error
13+
14+
class ConnectGenesisTest(BitcoinTestFramework):
15+
def set_test_params(self):
16+
self.num_nodes = 2
17+
self.setup_clean_chain = True
18+
# First node doesn't connect coinbase output to db, second does
19+
self.extra_args = [["-con_connect_coinbase=0"], ["-con_connect_coinbase=1"]]
20+
21+
def run_test(self):
22+
# Same genesis block
23+
assert_equal(self.nodes[0].getblockhash(0), self.nodes[1].getblockhash(0))
24+
25+
# Different UTXO set
26+
node0_info = self.nodes[0].gettxoutsetinfo()
27+
node1_info = self.nodes[1].gettxoutsetinfo()
28+
print(node0_info)
29+
print(node1_info)
30+
assert_equal(node0_info["txouts"], 0)
31+
assert_equal(node0_info["transactions"], 0)
32+
assert_equal(node0_info["total_amount"], 0)
33+
assert_equal(node1_info["txouts"], 1)
34+
assert_equal(node1_info["transactions"], 1)
35+
assert_equal(node1_info["total_amount"], 50)
36+
37+
coinbase_tx = self.nodes[0].getblock(self.nodes[0].getblockhash(0))["tx"][0]
38+
39+
# Test rpc getraw functionality
40+
assert_raises_rpc_error(-5, "The genesis block coinbase is not considered an ordinary transaction and cannot be retrieved", self.nodes[0].getrawtransaction, coinbase_tx)
41+
self.nodes[1].getrawtransaction(coinbase_tx)
42+
43+
if __name__ == '__main__':
44+
ConnectGenesisTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
'feature_config_args.py',
155155
'feature_help.py',
156156
'feature_mandatory_coinbase.py',
157+
'feature_connect_coinbase.py'
157158
# Don't append tests at the end to avoid merge conflicts
158159
# Put them in a random line within the section that fits their approximate run-time
159160
]

0 commit comments

Comments
 (0)