Skip to content

Commit

Permalink
Merge a2a0a83 into merged_master (Elements PR ElementsProject#738)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoelstra committed Nov 9, 2020
2 parents 7b30a0c + a2a0a83 commit 12af427
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
connect_nodes,
disconnect_nodes,
get_auth_cookie,
get_datadir_path,
rpc_port,
Expand Down Expand Up @@ -542,6 +541,8 @@ def run_test(self):
# Watch the address so we can get tx without txindex
parent.importaddress(mainchain_addr)
claim_block = parent.generatetoaddress(50, mainchain_addr)[0]
for node_group in self.node_groups:
self.sync_all(node_group)
block_coinbase = parent.getblock(claim_block, 2)["tx"][0]
claim_txid = block_coinbase["txid"]
claim_tx = block_coinbase["hex"]
Expand All @@ -557,11 +558,15 @@ def run_test(self):

# 50 more blocks to allow wallet to make it succeed by relay and consensus
parent.generatetoaddress(50, parent.getnewaddress())
for node_group in self.node_groups:
self.sync_all(node_group)
# Wallet still doesn't want to for 2 more confirms
assert_equal(sidechain.createrawpegin(claim_tx, claim_proof)["mature"], False)
# But we can just shoot it off
claim_txid = sidechain.sendrawtransaction(signed_pegin)
sidechain.generatetoaddress(1, sidechain.getnewaddress())
for node_group in self.node_groups:
self.sync_all(node_group)
assert_equal(sidechain.gettransaction(claim_txid)["confirmations"], 1)

# Test a confidential pegin.
Expand All @@ -573,6 +578,22 @@ def run_test(self):
txid_fund = parent.sendtoaddress(pegin_addr, 10)
# 10+2 confirms required to get into mempool and confirm
parent.generate(11)
for node_group in self.node_groups:
self.sync_all(node_group)
proof = parent.gettxoutproof([txid_fund])
assert_equal(sidechain.gettransaction(claim_txid)["confirmations"], 1)

# Test a confidential pegin.
print("Performing a confidential pegin.")
# start pegin
pegin_addrs = sidechain.getpeginaddress()
assert_equal(sidechain.decodescript(pegin_addrs["claim_script"])["type"], "witness_v0_keyhash")
pegin_addr = addrs["mainchain_address"]
txid_fund = parent.sendtoaddress(pegin_addr, 10)
# 10+2 confirms required to get into mempool and confirm
parent.generate(11)
for node_group in self.node_groups:
self.sync_all(node_group)
proof = parent.gettxoutproof([txid_fund])
raw = parent.gettransaction(txid_fund)["hex"]
raw_pegin = sidechain.createrawpegin(raw, proof)['hex']
Expand All @@ -583,6 +604,9 @@ def run_test(self):
blind_addr = sidechain.getnewaddress("", "blech32")
sidechain.sendtoaddress(blind_addr, 15)
sidechain.generate(6)
# Make sure sidechain2 knows about the same input
for node_group in self.node_groups:
self.sync_all(node_group)
unspent = [u for u in sidechain.listunspent(6, 6) if u["amount"] == 15][0]
assert(unspent["spendable"])
assert("amountcommitment" in unspent)
Expand Down Expand Up @@ -619,23 +643,14 @@ def run_test(self):
assert(final_decoded["vout"][1]["commitmentnonce_fully_valid"])
assert("value" in final_decoded["vout"][2])
assert("asset" in final_decoded["vout"][2])
# check that it is accepted in the mempool
# check that it is accepted in either mempool
accepted = sidechain.testmempoolaccept([pegin_signed["hex"]])[0]
if not accepted["allowed"]:
raise Exception(accepted["reject-reason"])
accepted = sidechain2.testmempoolaccept([pegin_signed["hex"]])[0]
if not accepted["allowed"]:
raise Exception(accepted["reject-reason"])
print("Blinded transaction looks ok!") # need this print to distinguish failures in for loop
# check if they get mined; since we're trying to mine two double spends, disconnect the nodes
disconnect_nodes(sidechain, 3)
disconnect_nodes(sidechain2, 2)
txid1 = sidechain.sendrawtransaction(pegin_signed1["hex"])
blocks = sidechain.generate(3)
assert_equal(sidechain.getrawtransaction(txid1, True, blocks[0])["confirmations"], 3)
txid2 = sidechain2.sendrawtransaction(pegin_signed2["hex"])
blocks = sidechain2.generate(3)
assert_equal(sidechain2.getrawtransaction(txid2, True, blocks[0])["confirmations"], 3)
# reconnect in case we extend the test
connect_nodes(self.nodes[2], 3)
sidechain.generate(10)

print('Success!')

Expand Down

0 comments on commit 12af427

Please sign in to comment.