addr = bitcoin.getnewaddress() # First, blackhole all 21M bitcoin that already exist(and test subtractfrom) assert(sidechain.getwalletinfo()["balance"]["bitcoin"] == 21000000) sidechain.sendtomainchain(addr, 21000000, True) assert("bitcoin" not in sidechain.getwalletinfo()["balance"]) sidechain.generate(101) addrs = sidechain.getpeginaddress() txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24) # 10+2 confirms required to get into mempool and confirm bitcoin.generate(1) time.sleep(2) proof = bitcoin.gettxoutproof([txid1]) raw = bitcoin.getrawtransaction(txid1) print("Attempting peg-in") # First attempt fails the consensus check but gives useful result try: pegtxid = sidechain.claimpegin(raw, proof) raise Exception("Peg-in should not be mature enough yet, need another block.") except JSONRPCException as e: assert("Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"]) pass # Second attempt simply doesn't hit mempool bar bitcoin.generate(10) try: pegtxid = sidechain.claimpegin(raw, proof) raise Exception("Peg-in should not be mature enough yet, need another block.")
sidechain2 = AuthServiceProxy("http://*****:*****@127.0.0.1:" + str(sidechain2_port)) print("Daemons started, making blocks to get funds") bitcoin.generate(101) sidechain.generate(101) addr = bitcoin.getnewaddress() addrs = sidechain.getpeginaddress() txid1 = bitcoin.sendtoaddress(addrs["mainchain_address"], 24) # 10+2 confirms required to get into mempool and confirm bitcoin.generate(11) time.sleep(2) proof = bitcoin.gettxoutproof([txid1]) raw = bitcoin.getrawtransaction(txid1) print("Attempting peg-in") try: pegtxid = sidechain.claimpegin(raw, proof) raise Exception( "Peg-in should not mature enough yet, need another block.") except JSONRPCException as e: assert ( "Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"]) pass # Should fail due to non-matching wallet address try: pegtxid = sidechain.claimpegin(raw, proof, sidechain.getnewaddress())
assert (sidechain.getwalletinfo()["balance"]["bitcoin"] == 21000000) sidechain.sendtomainchain(20999998, True) assert (sidechain.getwalletinfo()["balance"]["bitcoin"] == 2) sidechain.generate(101) getpeginaddr_res = sidechain.getpeginaddress() addr = getpeginaddr_res["mainchain_address"] claim_script = getpeginaddr_res["claim_script"] assert (addr == sidechain.tweakfedpegscript(claim_script)["address"]) txid1 = bitcoin.sendtoaddress(addr, 24) # 10+2 confirms required to get into mempool and confirm bitcoin.generate(9) time.sleep(2) proof = bitcoin.gettxoutproof([txid1]) raw = bitcoin.getrawtransaction(txid1) print("Attempting peg-in") # Fails consensus level depth check and wallet gives right message try: pegtxid = sidechain.claimpegin(raw, proof) raise Exception( "Peg-in should not mature enough yet, need another block.") except JSONRPCException as e: assert ( "Peg-in Bitcoin transaction needs more confirmations to be sent." in e.error["message"]) pass bitcoin.generate(2) # Fails mempool limit check, gives right message try: