mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
backports
This commit is contained in:
@@ -315,6 +315,146 @@ class Test(BaseTest):
|
||||
break
|
||||
assert len(tx_wallet["blockhash"]) == 64
|
||||
|
||||
def test_004_native_segwit(self):
|
||||
test_coin_from = Coins.PART
|
||||
# p2wpkh
|
||||
logging.info("---------- Test {} segwit".format(test_coin_from.name))
|
||||
ci = self.swap_clients[0].ci(test_coin_from)
|
||||
|
||||
addr_native = ci.rpc_wallet("getnewaddress", ["p2pkh segwit test"])
|
||||
addr_info = ci.rpc_wallet(
|
||||
"getaddressinfo",
|
||||
[
|
||||
addr_native,
|
||||
],
|
||||
)
|
||||
assert addr_info["iswitness"] is False # address is p2pkh, not p2wpkh
|
||||
addr_segwit = ci.rpc_wallet(
|
||||
"getnewaddress", ["p2wpkh segwit test", True, False, False, "bech32"]
|
||||
)
|
||||
addr_info = ci.rpc_wallet(
|
||||
"getaddressinfo",
|
||||
[
|
||||
addr_segwit,
|
||||
],
|
||||
)
|
||||
assert addr_info["iswitness"] is True
|
||||
|
||||
txid = ci.rpc_wallet(
|
||||
"sendtypeto",
|
||||
[
|
||||
"part",
|
||||
"part",
|
||||
[
|
||||
{"address": addr_native, "amount": 1.0},
|
||||
{"address": addr_segwit, "amount": 1.0},
|
||||
],
|
||||
],
|
||||
)
|
||||
assert len(txid) == 64
|
||||
tx_wallet = ci.rpc_wallet(
|
||||
"gettransaction",
|
||||
[
|
||||
txid,
|
||||
],
|
||||
)["hex"]
|
||||
tx = ci.rpc(
|
||||
"decoderawtransaction",
|
||||
[
|
||||
tx_wallet,
|
||||
],
|
||||
)
|
||||
|
||||
# Wait for stake
|
||||
for i in range(20):
|
||||
test_delay_event.wait(1)
|
||||
ro = ci.rpc("scantxoutset", ["start", ["addr({})".format(addr_native)]])
|
||||
if len(ro["unspents"]) > 0:
|
||||
break
|
||||
|
||||
ro = ci.rpc("scantxoutset", ["start", ["addr({})".format(addr_native)]])
|
||||
assert len(ro["unspents"]) == 1
|
||||
assert ro["unspents"][0]["txid"] == txid
|
||||
ro = ci.rpc("scantxoutset", ["start", ["addr({})".format(addr_segwit)]])
|
||||
assert len(ro["unspents"]) == 1
|
||||
assert ro["unspents"][0]["txid"] == txid
|
||||
|
||||
prevout_p2pkh_n: int = -1
|
||||
prevout_p2wpkh_n: int = -1
|
||||
for txo in tx["vout"]:
|
||||
if addr_native == txo["scriptPubKey"]["address"]:
|
||||
prevout_p2pkh_n = txo["n"]
|
||||
if addr_segwit == txo["scriptPubKey"]["address"]:
|
||||
prevout_p2wpkh_n = txo["n"]
|
||||
assert prevout_p2pkh_n > -1
|
||||
assert prevout_p2wpkh_n > -1
|
||||
|
||||
tx_funded = ci.rpc(
|
||||
"createrawtransaction",
|
||||
[[{"txid": txid, "vout": prevout_p2pkh_n}], {addr_segwit: 0.99}],
|
||||
)
|
||||
tx_signed = ci.rpc_wallet(
|
||||
"signrawtransactionwithwallet",
|
||||
[
|
||||
tx_funded,
|
||||
],
|
||||
)["hex"]
|
||||
tx_funded_decoded = ci.rpc(
|
||||
"decoderawtransaction",
|
||||
[
|
||||
tx_funded,
|
||||
],
|
||||
)
|
||||
tx_signed_decoded = ci.rpc(
|
||||
"decoderawtransaction",
|
||||
[
|
||||
tx_signed,
|
||||
],
|
||||
)
|
||||
prev_txo = tx["vout"][tx_signed_decoded["vin"][0]["vout"]]
|
||||
prevscript: bytes = bytes.fromhex(prev_txo["scriptPubKey"]["hex"])
|
||||
assert ci.isScriptP2PKH(prevscript) is True
|
||||
assert ci.isScriptP2WPKH(prevscript) is False
|
||||
txin_witness = tx_signed_decoded["vin"][0]["txinwitness"]
|
||||
assert len(txin_witness) == 2
|
||||
txin_witness_0 = bytes.fromhex(txin_witness[0])
|
||||
assert len(txin_witness_0) > 68 and len(txin_witness_0) <= 72
|
||||
assert len(bytes.fromhex(txin_witness[1])) == 33
|
||||
assert tx_funded_decoded["txid"] == tx_signed_decoded["txid"]
|
||||
|
||||
tx_funded = ci.rpc(
|
||||
"createrawtransaction",
|
||||
[[{"txid": txid, "vout": prevout_p2wpkh_n}], {addr_segwit: 0.99}],
|
||||
)
|
||||
tx_signed = ci.rpc_wallet(
|
||||
"signrawtransactionwithwallet",
|
||||
[
|
||||
tx_funded,
|
||||
],
|
||||
)["hex"]
|
||||
tx_funded_decoded = ci.rpc(
|
||||
"decoderawtransaction",
|
||||
[
|
||||
tx_funded,
|
||||
],
|
||||
)
|
||||
tx_signed_decoded = ci.rpc(
|
||||
"decoderawtransaction",
|
||||
[
|
||||
tx_signed,
|
||||
],
|
||||
)
|
||||
prev_txo = tx["vout"][tx_signed_decoded["vin"][0]["vout"]]
|
||||
prevscript: bytes = bytes.fromhex(prev_txo["scriptPubKey"]["hex"])
|
||||
assert ci.isScriptP2PKH(prevscript) is False
|
||||
assert ci.isScriptP2WPKH(prevscript) is True
|
||||
txin_witness = tx_signed_decoded["vin"][0]["txinwitness"]
|
||||
assert len(txin_witness) == 2
|
||||
txin_witness_0 = bytes.fromhex(txin_witness[0])
|
||||
assert len(txin_witness_0) > 68 and len(txin_witness_0) <= 72
|
||||
assert len(bytes.fromhex(txin_witness[1])) == 33
|
||||
assert tx_funded_decoded["txid"] == tx_signed_decoded["txid"]
|
||||
|
||||
def test_01_verifyrawtransaction(self):
|
||||
txn = "0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000"
|
||||
prevout = {
|
||||
|
||||
Reference in New Issue
Block a user