aboutsummaryrefslogtreecommitdiff
path: root/test/functional/rpc_blockchain.py
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-12-24 15:32:02 +0100
committerMarcoFalke <falke.marco@gmail.com>2020-12-24 15:32:10 +0100
commitf656165e9c0d09e654efabd56e6581638e35c26c (patch)
tree4346a432ef3d3c855964d3c594d89fe06db50289 /test/functional/rpc_blockchain.py
parentcc592a85ea0c371f7269dbcad32857c181b657d1 (diff)
parent66d012ad7f9381bacfc9b8388fa2ebf82cb86c9e (diff)
Merge #18772: rpc: calculate fees in getblock using BlockUndo data
66d012ad7f9381bacfc9b8388fa2ebf82cb86c9e test: RPC: getblock fee calculations (Elliott Jin) bf7d6e31b1062ab5f90e14e83c56309f499fa2e9 RPC: getblock: tx fee calculation for verbosity 2 via Undo data (Elliott Jin) Pull request description: This change is progress towards #18771 . It adapts the fee calculation part of #16083 and addresses some feedback. The additional "verbosity level 3" features are planned for a future PR. **Original PR description:** > Using block undo data (like in #14802) we can now show fee information for each transaction in a block without the need for additional -txindex and/or a ton of costly lookups. For a start we'll add transaction fee information to getblock verbosity level 2. This comes at a negligible speed penalty (<1%). ACKs for top commit: luke-jr: tACK 66d012ad7f9381bacfc9b8388fa2ebf82cb86c9e fjahr: tACK 66d012ad7f9381bacfc9b8388fa2ebf82cb86c9e MarcoFalke: review ACK 66d012ad7f9381bacfc9b8388fa2ebf82cb86c9e 🗜 Tree-SHA512: be1fe4b866946a8dc36427f7dc72a20e10860e320a28fa49bc85bd2a93a0d699768179be29fa52e18b2ed8505d3ec272e586753ef2239b4230e0aefd233acaa2
Diffstat (limited to 'test/functional/rpc_blockchain.py')
-rwxr-xr-xtest/functional/rpc_blockchain.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py
index f965677408..99be6b7b8e 100755
--- a/test/functional/rpc_blockchain.py
+++ b/test/functional/rpc_blockchain.py
@@ -20,6 +20,7 @@ Tests correspond to code in rpc/blockchain.cpp.
from decimal import Decimal
import http.client
+import os
import subprocess
from test_framework.blocktools import (
@@ -42,7 +43,9 @@ from test_framework.util import (
assert_raises_rpc_error,
assert_is_hex_string,
assert_is_hash_string,
+ get_datadir_path,
)
+from test_framework.wallet import MiniWallet
class BlockchainTest(BitcoinTestFramework):
@@ -63,6 +66,7 @@ class BlockchainTest(BitcoinTestFramework):
self._test_getnetworkhashps()
self._test_stopatheight()
self._test_waitforblockheight()
+ self._test_getblock()
assert self.nodes[0].verifychain(4, 0)
def mine_chain(self):
@@ -364,6 +368,46 @@ class BlockchainTest(BitcoinTestFramework):
assert_waitforheight(current_height)
assert_waitforheight(current_height + 1)
+ def _test_getblock(self):
+ node = self.nodes[0]
+
+ miniwallet = MiniWallet(node)
+ miniwallet.generate(5)
+ node.generate(100)
+
+ fee_per_byte = Decimal('0.00000010')
+ fee_per_kb = 1000 * fee_per_byte
+
+ miniwallet.send_self_transfer(fee_rate=fee_per_kb, from_node=node)
+ blockhash = node.generate(1)[0]
+
+ self.log.info("Test that getblock with verbosity 1 doesn't include fee")
+ block = node.getblock(blockhash, 1)
+ assert 'fee' not in block['tx'][1]
+
+ self.log.info('Test that getblock with verbosity 2 includes expected fee')
+ block = node.getblock(blockhash, 2)
+ tx = block['tx'][1]
+ assert 'fee' in tx
+ assert_equal(tx['fee'], tx['vsize'] * fee_per_byte)
+
+ self.log.info("Test that getblock with verbosity 2 still works with pruned Undo data")
+ datadir = get_datadir_path(self.options.tmpdir, 0)
+
+ def move_block_file(old, new):
+ old_path = os.path.join(datadir, self.chain, 'blocks', old)
+ new_path = os.path.join(datadir, self.chain, 'blocks', new)
+ os.rename(old_path, new_path)
+
+ # Move instead of deleting so we can restore chain state afterwards
+ move_block_file('rev00000.dat', 'rev_wrong')
+
+ block = node.getblock(blockhash, 2)
+ assert 'fee' not in block['tx'][1]
+
+ # Restore chain state
+ move_block_file('rev_wrong', 'rev00000.dat')
+
if __name__ == '__main__':
BlockchainTest().main()