|
8 | 8 | from decimal import Decimal |
9 | 9 | from io import BytesIO |
10 | 10 |
|
| 11 | +from test_framework.blocktools import ( |
| 12 | + create_block, |
| 13 | + create_coinbase, |
| 14 | +) |
11 | 15 | from test_framework.authproxy import JSONRPCException |
12 | 16 | from test_framework.key import ECKey |
13 | 17 | from test_framework.messages import ( |
@@ -158,6 +162,7 @@ def run_test(self): |
158 | 162 | coins = node.listunspent() |
159 | 163 | coin = coins.pop() |
160 | 164 | locked_1 = 10 * COIN + 141421 |
| 165 | + locked_2 = 10 * COIN + 314159 |
161 | 166 | asset_lock_tx = create_assetlock(node, coin, locked_1, pubkey) |
162 | 167 |
|
163 | 168 | self.check_mempool_result( |
@@ -189,15 +194,18 @@ def run_test(self): |
189 | 194 | self.sync_all() |
190 | 195 | assert_equal(get_credit_pool_amount(node), 0) |
191 | 196 | self.log.info("Resubmit asset lock tx to new chain...") |
192 | | - txid_in_block = node.sendrawtransaction(hexstring=asset_lock_tx.serialize().hex(), maxfeerate=0) |
193 | | - node.generate(3) |
| 197 | + # NEW tx appears |
| 198 | + asset_lock_tx_2 = create_assetlock(node, coin, locked_2, pubkey) |
| 199 | + |
| 200 | + txid_in_block = node.sendrawtransaction(hexstring=asset_lock_tx_2.serialize().hex(), maxfeerate=0) |
| 201 | + node.generate(1) |
194 | 202 | self.sync_all() |
195 | 203 |
|
196 | | - assert_equal(get_credit_pool_amount(node), locked_1) |
| 204 | + assert_equal(get_credit_pool_amount(node), locked_2) |
197 | 205 |
|
198 | 206 | node.generate(3) |
199 | 207 | self.sync_all() |
200 | | - assert_equal(get_credit_pool_amount(node), locked_1) |
| 208 | + assert_equal(get_credit_pool_amount(node), locked_2) |
201 | 209 | self.log.info("Reconsider old blocks...") |
202 | 210 | for inode in self.nodes: |
203 | 211 | inode.reconsiderblock(block_hash_1) |
@@ -237,17 +245,7 @@ def run_test(self): |
237 | 245 | except JSONRPCException as e: |
238 | 246 | assert "Transaction already in block chain" in e.error['message'] |
239 | 247 |
|
240 | | - self.log.info("Invalidate block with asset unlock tx...") |
241 | 248 | block_asset_unlock = node.getbestblockhash() |
242 | | - for inode in self.nodes: |
243 | | - inode.invalidateblock(block_asset_unlock) |
244 | | - assert_equal(get_credit_pool_amount(node), locked_1) |
245 | | - # TODO: strange, fails if generate there new blocks |
246 | | - #node.generate(3) |
247 | | - #self.sync_all() |
248 | | - for inode in self.nodes: |
249 | | - inode.reconsiderblock(block_asset_unlock) |
250 | | - assert_equal(get_credit_pool_amount(node), locked_1 - COIN) |
251 | 249 |
|
252 | 250 | # mine next quorum, tx should be still accepted |
253 | 251 | self.mine_quorum() |
@@ -279,6 +277,39 @@ def run_test(self): |
279 | 277 | result_expected=[{'txid': asset_unlock_tx_inactive_quorum.rehash(), 'allowed': False, 'reject-reason' : '16: bad-assetunlock-not-active-quorum'}], |
280 | 278 | rawtxs=[asset_unlock_tx_inactive_quorum.serialize().hex()], |
281 | 279 | ) |
| 280 | + block_to_reconsider = node.getbestblockhash() |
| 281 | + self.log.info("Test block invalidation with asset unlock tx...") |
| 282 | + for inode in self.nodes: |
| 283 | + inode.invalidateblock(block_asset_unlock) |
| 284 | + assert_equal(get_credit_pool_amount(node), locked_1) |
| 285 | + # generate some new blocks |
| 286 | + node.generate(90) |
| 287 | + self.sync_all() |
| 288 | + assert_equal(get_credit_pool_amount(node), locked_1) |
| 289 | + for inode in self.nodes: |
| 290 | + inode.reconsiderblock(block_to_reconsider) |
| 291 | + assert_equal(get_credit_pool_amount(node), locked_1 - 2 * COIN) |
| 292 | + |
| 293 | + # Forcibly mine asset_unlock_tx_too_late and ensure block is invalid |
| 294 | + hh = node.getbestblockhash() |
| 295 | + best_block = node.getblock(hh) |
| 296 | + tip = int(node.getbestblockhash(), 16) |
| 297 | + height = best_block["height"] + 1 |
| 298 | + block_time = best_block["time"] + 1 |
| 299 | + |
| 300 | + |
| 301 | + cbb = create_coinbase(height, dip4_activated=True, dip27_activated=True) |
| 302 | + block = create_block(tip, cbb, block_time, version=3) |
| 303 | + block.vtx.append(asset_unlock_tx_too_late) |
| 304 | + block.hashMerkleRoot = block.calc_merkle_root() |
| 305 | + block.solve() |
| 306 | + result = node.submitblock(block.serialize().hex()) |
| 307 | + # Expect an error here |
| 308 | + expected_error = "bad-assetunlock-not-active-quorum" |
| 309 | + if result != expected_error: |
| 310 | + raise AssertionError('mining the block should have failed with error %s, but submitblock returned %s' % (expected_error, result)) |
| 311 | + |
| 312 | + # ---- |
282 | 313 |
|
283 | 314 | node.generate(13) |
284 | 315 | self.sync_all() |
|
0 commit comments