def test_multiple_topups( channel_manager: ChannelManager, confirmed_open_channel: Channel, wait_for_blocks ): blockchain = channel_manager.blockchain channel_id = (confirmed_open_channel.sender, confirmed_open_channel.block) channel_rec = channel_manager.channels[channel_id] # first unconfirmed topup assert channel_rec.deposit == 10 confirmed_open_channel.topup(5) wait_for_blocks(1) gevent.sleep(blockchain.poll_interval) channel_rec = channel_manager.channels[channel_id] assert len(channel_rec.unconfirmed_topups) == 1 assert list(channel_rec.unconfirmed_topups.values()) == [5] assert channel_rec.deposit == 10 # second unconfirmed_topups confirmed_open_channel.topup(10) wait_for_blocks(1) gevent.sleep(blockchain.poll_interval) channel_rec = channel_manager.channels[channel_id] assert len(channel_rec.unconfirmed_topups) >= 1 # equality if first is confirmed assert 10 in channel_rec.unconfirmed_topups.values() assert channel_rec.deposit in [10, 15] # depends if first topup is confirmed or not # wait for confirmations wait_for_blocks(blockchain.n_confirmations) gevent.sleep(blockchain.poll_interval) channel_rec = channel_manager.channels[channel_id] assert len(channel_rec.unconfirmed_topups) == 0 assert channel_rec.deposit == 25
def test_topup( channel_manager: ChannelManager, confirmed_open_channel: Channel, wait_for_blocks ): blockchain = channel_manager.blockchain channel_manager.wait_sync() channel_id = (confirmed_open_channel.sender, confirmed_open_channel.block) confirmed_open_channel.topup(5) wait_for_blocks(1) gevent.sleep(blockchain.poll_interval) channel_rec = channel_manager.channels[channel_id] topup_txs = channel_rec.unconfirmed_topups assert len(topup_txs) == 1 and list(topup_txs.values())[0] == 5 wait_for_blocks(channel_manager.blockchain.n_confirmations) gevent.sleep(blockchain.poll_interval) channel_rec = channel_manager.channels[channel_id] topup_txs = channel_rec.unconfirmed_topups assert len(topup_txs) == 0 assert channel_rec.deposit == 15