Skip to content

Commit

Permalink
basic functional test for peg-in reorgs in sidechain
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Nov 6, 2017
1 parent 4aad513 commit d4d00da
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions qa/rpc-tests/pegging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
print(sys.argv[1])
print(sys.argv[2])

# Sync mempool, make a block, sync blocks
def sync_all(sidechain, sidechain2):
timeout = 20
while len(sidechain.getrawmempool()) != len(sidechain2.getrawmempool()):
time.sleep(1)
timeout -= 1
if timeout == 0:
raise Exception("Peg-in has failed to propagate.")
sidechain2.generate(1)
block = sidechain2.generate(1)
while sidechain.getblockcount() != sidechain2.getblockcount():
time.sleep(1)
timeout -= 1
if timeout == 0:
raise Exception("Blocks are not propagating.")
return block

fedpeg_key="cPxqWyf1HDGpGFH1dnfjz8HbiWxvwG8WXyetbuAiw4thKXUdXLpR"
fedpeg_pubkey="512103dff4923d778550cc13ce0d887d737553b4b58f4e8e886507fc39f5e447b2186451ae"
Expand Down Expand Up @@ -156,19 +158,32 @@ def sync_all(sidechain, sidechain2):

# 12 confirms allows in mempool
bitcoin.generate(1)

# Should succeed via wallet lookup for address match, and when given
pegtxid1 = sidechain.claimpegin(raw, proof)

sync_all(sidechain, sidechain2)
# Will invalidate the block that confirms this transaction later
blockhash = sync_all(sidechain, sidechain2)
sidechain.generate(5)

tx1 = sidechain.gettransaction(pegtxid1)

if "confirmations" in tx1 and tx1["confirmations"] > 0:
if "confirmations" in tx1 and tx1["confirmations"] == 6:
print("Peg-in is confirmed: Success!")
else:
raise Exception("Peg-in confirmation has failed.")

# Quick reorg checks of pegs
sidechain.invalidateblock(blockhash[0])
if sidechain.gettransaction(pegtxid1)["confirmations"] != 0:
raise Exception("Peg-in didn't unconfirm after invalidateblock call.")
# Re-enters block
sidechain.generate(1)
if sidechain.gettransaction(pegtxid1)["confirmations"] != 1:
raise Exception("Peg-in should have one confirm on side block.")
sidechain.reconsiderblock(blockhash[0])
if sidechain.gettransaction(pegtxid1)["confirmations"] != 6:
raise Exception("Peg-in should be back to 6 confirms.")

# Do many claims in mempool
n_claims = 100

Expand All @@ -192,8 +207,6 @@ def sync_all(sidechain, sidechain2):
if "confirmations" not in tx or tx["confirmations"] == 0:
raise Exception("Peg-in confirmation has failed.")

# TODO test reorgs, conflicting peg-ins

print("Success!")

except JSONRPCException as e:
Expand Down

0 comments on commit d4d00da

Please sign in to comment.