aboutsummaryrefslogtreecommitdiff
path: root/test/functional/rpc_getblockstats.py
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2022-12-05 17:38:27 -0500
committerAndrew Chow <github@achow101.com>2022-12-05 17:46:54 -0500
commit5d9b5305af4aaf9d4903d9d2996c5eea613b51a1 (patch)
tree73525029d75b2589b4452e72e4cd5f88613605a6 /test/functional/rpc_getblockstats.py
parent2ce3d26757ed08f2e580120af9bc5e26881302a0 (diff)
parentd885bb2f6ea34cd21dacfebe763a07dbb389c1bd (diff)
downloadbitcoin-5d9b5305af4aaf9d4903d9d2996c5eea613b51a1.tar.xz
Merge bitcoin/bitcoin#19888: rpc, test: Improve getblockstats for unspendables
d885bb2f6ea34cd21dacfebe763a07dbb389c1bd test: Test exclusion of OP_RETURN from getblockstats (Fabian Jahr) ba9d288b2468f047e5a8e4637dd8749e247ff547 test: Fix getblockstats test data generator (Fabian Jahr) 2ca5a496c2f3cbcc63ea15fa05c1658e7f527bbc rpc: Improve getblockstats (Fabian Jahr) cb94db119f4643f49da63520d64efc99fb0c0795 validation, index: Add unspendable coinbase helper functions (Fabian Jahr) Pull request description: Fixes #19885 The genesis block does not have undo data saved to disk so the RPC errored because of that. ACKs for top commit: achow101: ACK d885bb2f6ea34cd21dacfebe763a07dbb389c1bd aureleoules: ACK d885bb2f6ea34cd21dacfebe763a07dbb389c1bd stickies-v: ACK d885bb2f6 Tree-SHA512: f37bda736ed605b7a41a81eeb4bfbb5d2b8518f847819e5d6a090548a61caf1455623e15165d72589ab3f4478252b00e7b624f9313ad6708cac06dd5edb62e9a
Diffstat (limited to 'test/functional/rpc_getblockstats.py')
-rwxr-xr-xtest/functional/rpc_getblockstats.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/functional/rpc_getblockstats.py b/test/functional/rpc_getblockstats.py
index 1ea1ee5659..bf261befcc 100755
--- a/test/functional/rpc_getblockstats.py
+++ b/test/functional/rpc_getblockstats.py
@@ -43,6 +43,10 @@ class GetblockstatsTest(BitcoinTestFramework):
def generate_test_data(self, filename):
mocktime = 1525107225
self.nodes[0].setmocktime(mocktime)
+ self.nodes[0].createwallet(wallet_name='test')
+ privkey = self.nodes[0].get_deterministic_priv_key().key
+ self.nodes[0].importprivkey(privkey)
+
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
address = self.nodes[0].get_deterministic_priv_key().address
@@ -53,6 +57,8 @@ class GetblockstatsTest(BitcoinTestFramework):
self.nodes[0].sendtoaddress(address=address, amount=10, subtractfeefromamount=False)
self.nodes[0].settxfee(amount=0.003)
self.nodes[0].sendtoaddress(address=address, amount=1, subtractfeefromamount=True)
+ # Send to OP_RETURN output to test its exclusion from statistics
+ self.nodes[0].send(outputs={"data": "21"})
self.sync_all()
self.generate(self.nodes[0], 1)
@@ -161,6 +167,20 @@ class GetblockstatsTest(BitcoinTestFramework):
assert_raises_rpc_error(-1, 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats, '00', 1, 2)
assert_raises_rpc_error(-1, 'getblockstats hash_or_height ( stats )', self.nodes[0].getblockstats)
+ self.log.info('Test block height 0')
+ genesis_stats = self.nodes[0].getblockstats(0)
+ assert_equal(genesis_stats["blockhash"], "0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")
+ assert_equal(genesis_stats["utxo_increase"], 1)
+ assert_equal(genesis_stats["utxo_size_inc"], 117)
+ assert_equal(genesis_stats["utxo_increase_actual"], 0)
+ assert_equal(genesis_stats["utxo_size_inc_actual"], 0)
+
+ self.log.info('Test tip including OP_RETURN')
+ tip_stats = self.nodes[0].getblockstats(tip)
+ assert_equal(tip_stats["utxo_increase"], 6)
+ assert_equal(tip_stats["utxo_size_inc"], 441)
+ assert_equal(tip_stats["utxo_increase_actual"], 4)
+ assert_equal(tip_stats["utxo_size_inc_actual"], 300)
if __name__ == '__main__':
GetblockstatsTest().main()