bitcoin2_rpccookie = f.readline() bitcoin = AuthServiceProxy("http://*****:*****@127.0.0.1:"+str(bitcoin_port)) bitcoin2 = AuthServiceProxy("http://"+ bitcoin2_rpccookie +"@127.0.0.1:"+str(bitcoin2_port)) sidechain = AuthServiceProxy("http://*****:*****@127.0.0.1:"+str(sidechain_port)) 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() # 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:
bitcoin = AuthServiceProxy("http://*****:*****@127.0.0.1:" + str(bitcoin_port)) sidechain = AuthServiceProxy("http://*****:*****@127.0.0.1:" + str(sidechain_port)) 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() # Lockup some funds to unlock later sidechain.sendtomainchain(addr, 50) sidechain.generate(101) addrs = sidechain.getpeginaddress() txid = bitcoin.sendtoaddress(addrs["mainchain_address"], 49) bitcoin.generate(10) proof = bitcoin.gettxoutproof([txid]) raw = bitcoin.getrawtransaction(txid) print("Attempting peg-in") # Should fail due to non-matching address try: pegtxid = sidechain.claimpegin(raw, proof, sidechain.getnewaddress()) raise Exception("Peg-in with non-matching address should fail.") except JSONRPCException:
sidechain.generate(101) sidechain2.getwalletinfo() addr = bitcoin.getnewaddress() # Activate PAK wallet to allow peg out testing sidechain.importprivkey( "cUyokiFagFZQpUwwh5Qjsp6jAjRX77tUAWP8kznhCtWyXBWm1gip") pakstuff = sidechain.initpegoutwallet( "tpubDAenfwNu5GyCJWv8oqRAckdKMSUoZjgVF5p8WvQwHQeXjDhAHmGrPa4a4y2Fn7HF2nfCLefJanHV3ny1UY25MRVogizB2zRUdAo7Tr9XAjm", 0, "038a2ab87e8d3d9eb2dbd3aa9911e16541bd8d42a13d29584fb25c6272e9ac23ea") # First, blackhole almost all 21M bitcoin that already exist(and test subtractfrom) 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)