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

Function test_repro_4258

tests/test_wallet.py:2270–2321  ·  view source on GitHub ↗

Reproduces issue #4258, invalid output encoding for txprepare.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

2268 TEST_NETWORK == 'liquid-regtest',
2269 'Blinded elementsd addresses are not recognized')
2270def test_repro_4258(node_factory, bitcoind):
2271 """Reproduces issue #4258, invalid output encoding for txprepare.
2272 """
2273 l1 = node_factory.get_node()
2274 addr = l1.rpc.newaddr('bech32')['bech32']
2275 bitcoind.rpc.sendtoaddress(addr, 1)
2276 bitcoind.generate_block(1)
2277
2278 wait_for(lambda: l1.rpc.listfunds()['outputs'] != [])
2279 out = l1.rpc.listfunds()['outputs'][0]
2280
2281 addr = bitcoind.rpc.getnewaddress()
2282
2283 # These violate the request schema!
2284 l1.rpc.check_request_schemas = False
2285
2286 # Missing array parentheses for outputs
2287 with pytest.raises(RpcError, match=r"Expected an array of outputs"):
2288 l1.rpc.txprepare(
2289 outputs="{addr}:all".format(addr=addr),
2290 feerate="slow",
2291 minconf=1,
2292 utxos=["{txid}:{output}".format(**out)]
2293 )
2294
2295 # Missing parentheses on the utxos array
2296 with pytest.raises(RpcError, match=r"Could not decode the outpoint array for utxos"):
2297 l1.rpc.txprepare(
2298 outputs=[{addr: "all"}],
2299 feerate="slow",
2300 minconf=1,
2301 utxos="{txid}:{output}".format(**out)
2302 )
2303
2304 l1.rpc.check_request_schemas = True
2305
2306 tx = l1.rpc.txprepare(
2307 outputs=[{addr: "all"}],
2308 feerate="slow",
2309 minconf=1,
2310 utxos=["{txid}:{output}".format(**out)]
2311 )
2312
2313 tx = bitcoind.rpc.decoderawtransaction(tx['unsigned_tx'])
2314
2315 assert(len(tx['vout']) == 1)
2316 o0 = tx['vout'][0]
2317 assert(scriptpubkey_addr(o0['scriptPubKey']) == addr)
2318
2319 assert(len(tx['vin']) == 1)
2320 i0 = tx['vin'][0]
2321 assert([i0['txid'], i0['vout']] == [out['txid'], out['output']])
2322
2323
2324@unittest.skipIf(TEST_NETWORK == 'liquid-regtest', "Uses regtest addresses")

Callers

nothing calls this directly

Calls 8

wait_forFunction · 0.90
scriptpubkey_addrFunction · 0.90
generate_blockMethod · 0.80
txprepareMethod · 0.80
get_nodeMethod · 0.45
newaddrMethod · 0.45
listfundsMethod · 0.45
getnewaddressMethod · 0.45

Tested by

no test coverage detected