diff --git a/contrib/pyln-testing/pyln/testing/utils.py b/contrib/pyln-testing/pyln/testing/utils.py index 944fd2c86ef5..dff897eb6b52 100644 --- a/contrib/pyln-testing/pyln/testing/utils.py +++ b/contrib/pyln-testing/pyln/testing/utils.py @@ -742,18 +742,20 @@ def fundbalancedchannel(self, remote_node, total_capacity, announce=True): # Make sure the fundchannel is confirmed. num_tx = len(self.bitcoin.rpc.getrawmempool()) - tx = self.rpc.fundchannel(remote_node.info['id'], chan_capacity, feerate='slow', minconf=0, announce=announce, push_msat=Millisatoshi(chan_capacity * 500))['tx'] + res = self.rpc.fundchannel(remote_node.info['id'], chan_capacity, feerate='slow', minconf=0, announce=announce, push_msat=Millisatoshi(chan_capacity * 500)) wait_for(lambda: len(self.bitcoin.rpc.getrawmempool()) == num_tx + 1) - self.bitcoin.generate_block(1) + blockid = self.bitcoin.generate_block(1)[0] # Generate the scid. - # NOTE This assumes only the coinbase and the fundchannel is - # confirmed in the block. - outnum = get_tx_p2wsh_outnum(self.bitcoin, tx, total_capacity) + outnum = get_tx_p2wsh_outnum(self.bitcoin, res['tx'], total_capacity) if outnum is None: - raise ValueError("no outnum found. capacity {} tx {}".format(total_capacity, tx)) + raise ValueError("no outnum found. capacity {} tx {}".format(total_capacity, res['tx'])) + + for i, txid in enumerate(self.bitcoin.rpc.getblock(blockid)['tx']): + if txid == res['txid']: + txnum = i - return '{}x1x{}'.format(self.bitcoin.rpc.getblockcount(), outnum) + return '{}x{}x{}'.format(self.bitcoin.rpc.getblockcount(), txnum, outnum) def getactivechannels(self): return [c for c in self.rpc.listchannels()['channels'] if c['active']] @@ -855,11 +857,15 @@ def has_funds_on_addr(addr): announce=announce_channel, **kwargs) wait_for(lambda: res['txid'] in self.bitcoin.rpc.getrawmempool()) - self.bitcoin.generate_block(1) + blockid = self.bitcoin.generate_block(1)[0] + + for i, txid in enumerate(self.bitcoin.rpc.getblock(blockid)['tx']): + if txid == res['txid']: + txnum = i - # Hacky way to find our output. - scid = "{}x1x{}".format(self.bitcoin.rpc.getblockcount(), - get_tx_p2wsh_outnum(self.bitcoin, res['tx'], amount)) + scid = "{}x{}x{}".format(self.bitcoin.rpc.getblockcount(), + txnum, + get_tx_p2wsh_outnum(self.bitcoin, res['tx'], amount)) if wait_for_active: self.wait_channel_active(scid)