Test if a plugin gets notifications when a new block is found
(node_factory, bitcoind)
| 3549 | |
| 3550 | |
| 3551 | def test_block_added_notifications(node_factory, bitcoind): |
| 3552 | """Test if a plugin gets notifications when a new block is found""" |
| 3553 | base = bitcoind.rpc.getblockchaininfo()["blocks"] |
| 3554 | plugin = [ |
| 3555 | os.path.join(os.getcwd(), "tests/plugins/block_added.py"), |
| 3556 | ] |
| 3557 | l1 = node_factory.get_node(options={"plugin": plugin}) |
| 3558 | ret = l1.rpc.call("blockscatched") |
| 3559 | assert len(ret) == 1 and ret[0] == base + 0 |
| 3560 | |
| 3561 | bitcoind.generate_block(2) |
| 3562 | sync_blockheight(bitcoind, [l1]) |
| 3563 | ret = l1.rpc.call("blockscatched") |
| 3564 | assert len(ret) == 3 and ret[0] == base + 0 and ret[2] == base + 2 |
| 3565 | |
| 3566 | l2 = node_factory.get_node(options={"plugin": plugin}) |
| 3567 | ret = l2.rpc.call("blockscatched") |
| 3568 | assert len(ret) == 1 and ret[0] == base + 2 |
| 3569 | |
| 3570 | l2.stop() |
| 3571 | next_l2_base = bitcoind.rpc.getblockchaininfo()["blocks"] |
| 3572 | |
| 3573 | bitcoind.generate_block(2) |
| 3574 | sync_blockheight(bitcoind, [l1]) |
| 3575 | ret = l1.rpc.call("blockscatched") |
| 3576 | assert len(ret) == 5 and ret[4] == base + 4 |
| 3577 | |
| 3578 | l2.start() |
| 3579 | sync_blockheight(bitcoind, [l2]) |
| 3580 | ret = l2.rpc.call("blockscatched") |
| 3581 | assert len(ret) == 3 and ret[1] == next_l2_base + 1 and ret[2] == next_l2_base + 2 |
| 3582 | |
| 3583 | |
| 3584 | @unittest.skipIf(TEST_NETWORK != 'regtest', 'elementsd doesnt yet support PSBT features we need') |
nothing calls this directly
no test coverage detected