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

Function test_txsend

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

Source from the content-addressed store, hash-verified

924
925
926def test_txsend(node_factory, bitcoind, chainparams):
927 amount = 1000000
928 l1 = node_factory.get_node(random_hsm=True)
929 addr = chainparams['example_addr']
930
931 # Add some funds to withdraw later: both bech32 and p2sh
932 for i in range(5):
933 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr()['bech32'],
934 amount / 10**8)
935 bitcoind.rpc.sendtoaddress(l1.rpc.newaddr('p2sh-segwit')['p2sh-segwit'],
936 amount / 10**8)
937 bitcoind.generate_block(1)
938 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10)
939
940 prep = l1.rpc.txprepare([{addr: Millisatoshi(amount * 3 * 1000)}])
941 out = l1.rpc.txsend(prep['txid'])
942
943 # Cannot discard after send!
944 with pytest.raises(RpcError, match=r'not an unreleased txid'):
945 l1.rpc.txdiscard(prep['txid'])
946
947 wait_for(lambda: prep['txid'] in bitcoind.rpc.getrawmempool())
948
949 # Signed tx should have same txid
950 decode = bitcoind.rpc.decoderawtransaction(out['tx'])
951 assert decode['txid'] == prep['txid']
952
953 bitcoind.generate_block(1)
954
955 # Change output should appear.
956 if decode['vout'][0]['value'] == Decimal(amount * 3) / 10**8:
957 changenum = 1
958 elif decode['vout'][1]['value'] == Decimal(amount * 3) / 10**8:
959 changenum = 0
960 else:
961 assert False
962
963 # Those spent outputs are gone, but change output has arrived.
964 wait_for(lambda: len(l1.rpc.listfunds()['outputs']) == 10 - len(decode['vin']) + 1)
965
966 # Change address should appear in listfunds()
967 assert scriptpubkey_addr(decode['vout'][changenum]['scriptPubKey']) in [f['address'] for f in l1.rpc.listfunds()['outputs']]
968
969
970@unittest.skipIf(TEST_NETWORK != 'regtest', "Fee outputs throw off our output matching logic")

Callers

nothing calls this directly

Calls 10

wait_forFunction · 0.90
MillisatoshiClass · 0.90
scriptpubkey_addrFunction · 0.90
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