diff options
author | Sjors Provoost <sjors@sprovoost.nl> | 2024-08-20 10:45:04 +0200 |
---|---|---|
committer | Sjors Provoost <sjors@sprovoost.nl> | 2024-08-20 18:51:37 +0200 |
commit | 59ff17e5af4e382cbe16f183767beef1bdcd9131 (patch) | |
tree | b0680f22dfb41f8fba0139b23ef7e55e8e368924 /test | |
parent | e929054e12210353812f440c685a23329e7040f7 (diff) |
miner: adjust clock to timewarp rule
Diffstat (limited to 'test')
-rwxr-xr-x | test/functional/mining_basic.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/test/functional/mining_basic.py b/test/functional/mining_basic.py index b183023b2f..c0df120c65 100755 --- a/test/functional/mining_basic.py +++ b/test/functional/mining_basic.py @@ -28,6 +28,7 @@ from test_framework.p2p import P2PDataStore from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, + assert_greater_than_or_equal, assert_raises_rpc_error, get_fee, ) @@ -139,24 +140,24 @@ class MiningTest(BitcoinTestFramework): self.log.info("First block template of retarget period can't use wall clock time") self.nodes[0].setmocktime(t) - assert_raises_rpc_error(-1, "time-timewarp-attack, block's timestamp is too early on diff adjustment block", - lambda: node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)) - - # Create template with an acceptable timestamp and then modify it - self.nodes[0].setmocktime(t + MAX_FUTURE_BLOCK_TIME) + # The template will have an adjusted timestamp, which we then modify tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS) + assert_greater_than_or_equal(tmpl['curtime'], t + MAX_FUTURE_BLOCK_TIME - MAX_TIMEWARP) block = CBlock() block.nVersion = tmpl["version"] block.hashPrevBlock = int(tmpl["previousblockhash"], 16) - block.nTime = t + block.nTime = tmpl["curtime"] block.nBits = int(tmpl["bits"], 16) block.nNonce = 0 block.vtx = [create_coinbase(height=int(tmpl["height"]))] block.solve() + assert_template(node, block, None) - self.nodes[0].setmocktime(t) - assert_raises_rpc_error(-25, 'time-timewarp-attack', lambda: node.submitheader(hexdata=CBlockHeader(block).serialize().hex())) + bad_block = copy.deepcopy(block) + bad_block.nTime = t + bad_block.solve() + assert_raises_rpc_error(-25, 'time-timewarp-attack', lambda: node.submitheader(hexdata=CBlockHeader(bad_block).serialize().hex())) def run_test(self): node = self.nodes[0] |