Skip to content

Commit

Permalink
Test raw transaction peg-in
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Oct 15, 2019
1 parent ac6f052 commit 5a4d611
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
assert_equal,
bytes_to_hex_str,
hex_str_to_bytes,
find_vout_for_address
)
from test_framework import util
from test_framework.messages import (
Expand Down Expand Up @@ -218,6 +219,7 @@ def run_test(self):
addr = addrs["mainchain_address"]
assert_equal(sidechain.decodescript(addrs["claim_script"])["type"], "witness_v0_keyhash")
txid1 = parent.sendtoaddress(addr, 24)
vout = find_vout_for_address(parent, txid1, addr)
# 10+2 confirms required to get into mempool and confirm
assert_equal(sidechain.getsidechaininfo()["pegin_confirmation_depth"], 10)
parent.generate(1)
Expand Down Expand Up @@ -278,6 +280,18 @@ def run_test(self):
raw_pegin = sidechain.createrawpegin(raw, proof)['hex']
signed_pegin = sidechain.signrawtransactionwithwallet(raw_pegin)

# Find the address that the peg-in used
outputs = []
for pegin_vout in sidechain.decoderawtransaction(raw_pegin)['vout']:
if pegin_vout['scriptPubKey']['type'] == 'witness_v0_keyhash':
outputs.append({pegin_vout['scriptPubKey']['addresses'][0]: pegin_vout['value']})
elif pegin_vout['scriptPubKey']['type'] == 'fee':
outputs.append({"fee": pegin_vout['value']})

# Check the createrawtransaction makes the same unsigned peg-in transaction
raw_pegin2 = sidechain.createrawtransaction([{"txid":txid1, "vout": vout, "pegin_bitcoin_tx": raw, "pegin_txout_proof": proof, "pegin_claim_script": addrs["claim_script"]}], outputs)
assert_equal(raw_pegin, raw_pegin2)

sample_pegin_struct = FromHex(CTransaction(), signed_pegin["hex"])
# Round-trip peg-in transaction using python serialization
assert_equal(signed_pegin["hex"], sample_pegin_struct.serialize().hex())
Expand Down
8 changes: 8 additions & 0 deletions test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ def run_test(self):
# Some Confidential-Assets-specific tests
self.run_ca_tests()

# Check that peg-ins are disallowed
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_bitcoin_tx": "00"}], [{self.nodes[0].getnewaddress(): 1}])
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_txout_proof": "00"}], [{self.nodes[0].getnewaddress(): 1}])
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].createpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_claim_script": "00"}], [{self.nodes[0].getnewaddress(): 1}])
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_bitcoin_tx": "00"}], [{self.nodes[0].getnewaddress(): 1}])
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_txout_proof": "00"}], [{self.nodes[0].getnewaddress(): 1}])
assert_raises_rpc_error(-8, 'pegin_ arguments provided but this command does not support peg-ins', self.nodes[0].walletcreatefundedpsbt, [{"txid": "0000000000000000000000000000000000000000000000000000000000000000", "vout": 0, "pegin_claim_script": "00"}], [{self.nodes[0].getnewaddress(): 1}])

# Tests added in the 0.18 rebase don't pass on Elements yet.

"""
Expand Down

0 comments on commit 5a4d611

Please sign in to comment.