MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_txsend

Function test_txsend

tests/test_wallet.py:1252–1291  ·  view source on GitHub ↗
(node_factory, bitcoind, chainparams)

Source from the content-addressed store, hash-verified

1250
1251@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', "BIP86 random_hsm not compatible with liquid-regtest bech32")
1252def test_txsend(node_factory, bitcoind, chainparams):
1253 amount = 1000000
1254 l1 = node_factory.get_node(random_hsm=True)
1255 addr = chainparams['example_addr']
1256
1257 # Add some funds to withdraw later
1258 for i in range(10):
1259 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr(good_addrtype())[good_addrtype()],
1260 amount / 10**8)
1261 bitcoind.generate_block(1)
1262 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10)
1263
1264 prep = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3 * 1000)}])
1265 out = l1.rpc.txsend(prep['txid'])
1266
1267 # Cannot discard after send!
1268 with pytest.raises(RpcError, match=r'not an unreleased txid'):
1269 l1.rpc.txdiscard(prep['txid'])
1270
1271 wait_for(lambda: prep['txid'] in bitcoind.rpc.getrawmempool())
1272
1273 # Signed tx should have same txid
1274 decode = bitcoind.rpc.decoderawtransaction(out['tx'])
1275 assert decode['txid'] == prep['txid']
1276
1277 bitcoind.generate_block(1)
1278
1279 # Change output should appear.
1280 if decode['vout'][0]['value'] == Decimal(amount * 3) / 10**8:
1281 changenum = 1
1282 elif decode['vout'][1]['value'] == Decimal(amount * 3) / 10**8:
1283 changenum = 0
1284 else:
1285 assert False
1286
1287 # Those spent outputs are gone, but change output has arrived.
1288 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10 - len(decode['vin']) + 1)
1289
1290 # Change address should appear in listfunds()
1291 assert scriptpubkey_addr(decode['vout'][changenum]['scriptPubKey']) in [f['address'] for f in l1.rpc.listfunds()['outputs']]
1292
1293
1294def write_all(fd, bytestr):

Callers

nothing calls this directly

Calls 11

wait_forFunction · 0.90
MillisatoshiClass · 0.90
scriptpubkey_addrFunction · 0.90
good_addrtypeFunction · 0.85
generate_blockMethod · 0.80
txprepareMethod · 0.80
txsendMethod · 0.80
txdiscardMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45

Tested by

no test coverage detected