except JSONRPCException as e: assert ( "Given claim_script does not match the given Bitcoin transaction." in e.error["message"]) pass # 12 confirms allows in mempool bitcoin.generate(1) # Should succeed via wallet lookup for address match, and when given pegtxid1 = sidechain.claimpegin(raw, proof) # 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"] == 6: print("Peg-in is confirmed: Success!") else: raise Exception("Peg-in confirmation has failed.") # Look at pegin fields decoded = sidechain.decoderawtransaction(tx1["hex"]) assert decoded["vin"][0]["is_pegin"] == True assert len(decoded["vin"][0]["pegin_witness"]) > 0 # 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.")
timeout = 20 # Should succeed via wallet lookup for address match pegtxid = sidechain.claimpegin(raw, proof) 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) while sidechain.getblockcount() != sidechain2.getblockcount(): time.sleep(1) timeout -= 1 if timeout == 0: raise Exception("Blocks are not propagating.") tx = sidechain.gettransaction(pegtxid) if "confirmations" in tx and tx["confirmations"] > 0: print("Peg-in is confirmed: Success!") else: raise Exception("Peg-in confirmation has failed.") except JSONRPCException as e: print("Pegging testing failed, aborting:") print(e.error) except Exception as e: print("Pegging testing failed, aborting:") print(e) print("Stopping daemons and cleaning up") bitcoin.stop()