diff --git a/plugins/Zeroname/updater/zeroname_updater.py b/plugins/Zeroname/updater/zeroname_updater.py index a0f21378..1700e318 100644 --- a/plugins/Zeroname/updater/zeroname_updater.py +++ b/plugins/Zeroname/updater/zeroname_updater.py @@ -14,7 +14,7 @@ def publish(): call(" ".join(command_sign_publish), shell=True) -def processNameOp(domain, value): +def processNameOp(domain, value, test=False): if not value.strip().startswith("{"): return False try: @@ -32,6 +32,9 @@ def processNameOp(domain, value): print "Invalid domain: ", domain return False + if test: + return True + if "slave" in sys.argv: print "Waiting for master update arrive" time.sleep(30) # Wait 30 sec to allow master updater @@ -61,7 +64,7 @@ def processNameOp(domain, value): return False -def processBlock(block_id): +def processBlock(block_id, test=False): print "Processing block #%s..." % block_id s = time.time() block_hash = rpc.getblockhash(block_id) @@ -75,7 +78,7 @@ def processBlock(block_id): for vout in transaction.get("vout", []): if "scriptPubKey" in vout and "nameOp" in vout["scriptPubKey"] and "name" in vout["scriptPubKey"]["nameOp"]: name_op = vout["scriptPubKey"]["nameOp"] - updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"]) + updated += processNameOp(name_op["name"].replace("d/", ""), name_op["value"], test) except Exception, err: print "Error processing tx #%s %s" % (tx, err) print "Done in %.3fs (updated %s)." % (time.time() - s, updated) @@ -140,15 +143,19 @@ if sys.platform == 'win32': # Initialize rpc connection rpc_auth, rpc_timeout = initRpc(namecoin_location + "namecoin.conf") +rpc = AuthServiceProxy(rpc_auth, timeout=rpc_timeout) +last_block = int(rpc.getinfo()["blocks"]) -if not config["lastprocessed"]: # Start processing from last block - config["lastprocessed"] = int(AuthServiceProxy(rpc_auth, timeout=rpc_timeout).getinfo()["blocks"]) +if not config["lastprocessed"]: # First startup: Start processing from last block + config["lastprocessed"] = last_block -# processBlock(223911) # Testing zeronetwork.bit -# processBlock(227052) # Testing brainwallets.bit -# processBlock(236824) # Utf8 domain name (invalid should skip) -# processBlock(236752) # Uppercase domain (invalid should skip) -# processBlock(236870) # Encoded domain (should pass) + +print "- Testing domain parsing..." +assert processBlock(223911, test=True) # Testing zeronetwork.bit +assert processBlock(227052, test=True) # Testing brainwallets.bit +assert not processBlock(236824, test=True) # Utf8 domain name (invalid should skip) +assert not processBlock(236752, test=True) # Uppercase domain (invalid should skip) +assert processBlock(236870, test=True) # Encoded domain (should pass) # sys.exit(0) while 1: