From 5a4d61169b5c8605c13353b4d3bc5c6c73e58743 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 15 Oct 2019 15:22:17 -0400 Subject: [PATCH] Test raw transaction peg-in --- test/functional/feature_fedpeg.py | 14 ++++++++++++++ test/functional/rpc_psbt.py | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/test/functional/feature_fedpeg.py b/test/functional/feature_fedpeg.py index 55d5495135..19e9f2b598 100755 --- a/test/functional/feature_fedpeg.py +++ b/test/functional/feature_fedpeg.py @@ -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 ( @@ -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) @@ -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()) diff --git a/test/functional/rpc_psbt.py b/test/functional/rpc_psbt.py index 7a0f9f6d0f..25ea4d9f52 100755 --- a/test/functional/rpc_psbt.py +++ b/test/functional/rpc_psbt.py @@ -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. """