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

Function test_repro_4258

tests/test_wallet.py:2269–2320  ·  view source on GitHub ↗

Reproduces issue #4258, invalid output encoding for txprepare.

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

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