Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import subprocess
import json
from bitcoinrpc.authproxy import AuthServiceProxy
import time
# Change this to lbrycrd binary location
LBRYCRD_BIN_LOCATION = 'src/lbrycrdd'
lbrycrd_rpc_user = 'test'
lbrycrd_rpc_pw = 'test'
lbrycrd_rpc_ip = '127.0.0.1'
lbrycrd_rpc_port = '8332'
def run_command(cmd):
"""given shell command, returns communication tuple of stdout and stderr"""
#p=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p=subprocess.Popen(cmd, shell=True)
return p.communicate()
def get_lbrycrd():
return AuthServiceProxy("http://{}:{}@{}:{}".format(lbrycrd_rpc_user, lbrycrd_rpc_pw,
lbrycrd_rpc_ip, lbrycrd_rpc_port),timeout=60*20)
# clean up regtest folder
run_command('rm -rf ~/.lbrycrd/regtest')
run_command('{} -regtest -daemon'.format(LBRYCRD_BIN_LOCATION))
lbrycrd = get_lbrycrd()
time.sleep(6)
print("Generating initial blcoks")
out = lbrycrd.generate(300)
claim_txid = lbrycrd.claimname('test','0000',0.1)
print("Claim named:{}".format(claim_txid))
out = lbrycrd.generate(1)
block_hash = out[-1]
print("Generated block hash:{}".format(block_hash))
lbrycrd.stop()
print("Killed lbrycrdd")
time.sleep(6)
run_command('{} -regtest -daemon'.format(LBRYCRD_BIN_LOCATION))
time.sleep(6)
print("Started lbrycrdd again")
lbrycrd = get_lbrycrd()
out = lbrycrd.invalidateblock(block_hash)
print("Invalidating block:{}".format(out))
lbrycrd.generate(1)
print("Generated blocks again")
print("Stopping regtest")
run_command('pkill lbrycrdd')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment