|
28 | 28 | from test_framework.test_framework import BitcoinTestFramework
|
29 | 29 | from test_framework.util import (
|
30 | 30 | assert_equal,
|
| 31 | + assert_greater_than_or_equal, |
31 | 32 | assert_raises_rpc_error,
|
32 | 33 | get_fee,
|
33 | 34 | )
|
@@ -139,24 +140,24 @@ def test_timewarp(self):
|
139 | 140 |
|
140 | 141 | self.log.info("First block template of retarget period can't use wall clock time")
|
141 | 142 | self.nodes[0].setmocktime(t)
|
142 |
| - assert_raises_rpc_error(-1, "time-timewarp-attack, block's timestamp is too early on diff adjustment block", |
143 |
| - lambda: node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)) |
144 |
| - |
145 |
| - # Create template with an acceptable timestamp and then modify it |
146 |
| - self.nodes[0].setmocktime(t + MAX_FUTURE_BLOCK_TIME) |
| 143 | + # The template will have an adjusted timestamp, which we then modify |
147 | 144 | tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
|
| 145 | + assert_greater_than_or_equal(tmpl['curtime'], t + MAX_FUTURE_BLOCK_TIME - MAX_TIMEWARP) |
148 | 146 |
|
149 | 147 | block = CBlock()
|
150 | 148 | block.nVersion = tmpl["version"]
|
151 | 149 | block.hashPrevBlock = int(tmpl["previousblockhash"], 16)
|
152 |
| - block.nTime = t |
| 150 | + block.nTime = tmpl["curtime"] |
153 | 151 | block.nBits = int(tmpl["bits"], 16)
|
154 | 152 | block.nNonce = 0
|
155 | 153 | block.vtx = [create_coinbase(height=int(tmpl["height"]))]
|
156 | 154 | block.solve()
|
| 155 | + assert_template(node, block, None) |
157 | 156 |
|
158 |
| - self.nodes[0].setmocktime(t) |
159 |
| - assert_raises_rpc_error(-25, 'time-timewarp-attack', lambda: node.submitheader(hexdata=CBlockHeader(block).serialize().hex())) |
| 157 | + bad_block = copy.deepcopy(block) |
| 158 | + bad_block.nTime = t |
| 159 | + bad_block.solve() |
| 160 | + assert_raises_rpc_error(-25, 'time-timewarp-attack', lambda: node.submitheader(hexdata=CBlockHeader(bad_block).serialize().hex())) |
160 | 161 |
|
161 | 162 | def run_test(self):
|
162 | 163 | node = self.nodes[0]
|
|
0 commit comments