def test_deterministic_superblock_selection(go_list_superblocks): from pyrkd import PyrkDaemon pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) for item in go_list_superblocks: (go, subobj) = GovernanceObject.import_gobject_from_pyrkd(pyrkd, item) # highest hash wins if same -- so just order by hash sb = Superblock.find_highest_deterministic( '542f4433e438bdd64697b8381fda1a7a9b7a111c3a4e32fad524d1821d820394')
def test_approved_and_ranked(go_list_proposals): from pyrkd import PyrkDaemon pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) for item in go_list_proposals: (go, subobj) = GovernanceObject.import_gobject_from_pyrkd(pyrkd, item) prop_list = Proposal.approved_and_ranked(proposal_quorum=1, next_superblock_max_budget=60) #assert prop_list[0].object_hash == u'dfd7d63979c0b62456b63d5fc5306dbec451180adee85876cbf5b28c69d1a86c' #assert prop_list[1].object_hash == u'0523445762025b2e01a2cd34f1d10f4816cf26ee1796167e5b029901e5873630' print prop_list
def test_deterministic_superblock_creation(go_list_proposals): import pyrklib import misc from pyrkd import PyrkDaemon pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) for item in go_list_proposals: (go, subobj) = GovernanceObject.import_gobject_from_pyrkd(pyrkd, item) max_budget = 60 prop_list = Proposal.approved_and_ranked( proposal_quorum=1, next_superblock_max_budget=max_budget) print prop_list sb = pyrklib.create_superblock(prop_list, 72000, max_budget, misc.now())
def test_pyrkd(): config_text = PyrkConfig.slurp_config_file(config.pyrk_conf) network = 'mainnet' is_testnet = False genesis_hash = u'0x973814a07c1ae4f3af90372952c9b9709901a95df1d0ea54bd1b3bd6feff5b89' for line in config_text.split("\n"): if line.startswith('testnet=1'): network = 'testnet' is_testnet = True genesis_hash = u'0x6015f9422d514ebd62d28c48b7faf86738680091d38ecb2c9bc2381b9325c13a' creds = PyrkConfig.get_rpc_creds(config_text, network) pyrkd = PyrkDaemon(**creds) assert pyrkd.rpc_command is not None assert hasattr(pyrkd, 'rpc_connection') # Pyrk testnet block 0 hash == 0x6015f9422d514ebd62d28c48b7faf86738680091d38ecb2c9bc2381b9325c13a # test commands without arguments info = pyrkd.rpc_command('getinfo') info_keys = [ 'blocks', 'connections', 'difficulty', 'errors', 'protocolversion', 'proxy', 'testnet', 'timeoffset', 'version', ] for key in info_keys: assert key in info assert info['testnet'] is is_testnet # test commands with args assert pyrkd.rpc_command('getblockhash', 0) == genesis_hash
# -*- coding: utf-8 -*- import pdb from pprint import pprint import re import sys import os sys.path.append( os.path.normpath(os.path.join(os.path.dirname(__file__), '../lib'))) import config from models import Superblock, Proposal, GovernanceObject, Setting, Signal, Vote, Outcome from models import VoteSignals, VoteOutcomes from peewee import PeeweeException # , OperationalError, IntegrityError from pyrkd import PyrkDaemon import pyrklib from decimal import Decimal pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) import misc # ============================================================================== # do stuff here pr = Proposal( name='proposal7', url='https://pyrkcentral.com/proposal7', payment_address='PK6qz8xFz5EYLy1wxD2v1xmpFHPK5yQCgh', payment_amount=42.42, start_epoch=1590230222, end_epoch=1600230222, ) # sb = Superblock( # event_block_height = 62500,
def test_superblock_is_valid(superblock): from pyrkd import PyrkDaemon pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) orig = Superblock(**superblock.get_dict()) # make a copy # original as-is should be valid assert orig.is_valid() is True # mess with payment amounts superblock.payment_amounts = '7|yyzx' assert superblock.is_valid() is False superblock.payment_amounts = '7,|yzx' assert superblock.is_valid() is False superblock.payment_amounts = '7|8' assert superblock.is_valid() is True superblock.payment_amounts = ' 7|8' assert superblock.is_valid() is False superblock.payment_amounts = '7|8 ' assert superblock.is_valid() is False superblock.payment_amounts = ' 7|8 ' assert superblock.is_valid() is False # reset superblock = Superblock(**orig.get_dict()) assert superblock.is_valid() is True # mess with payment addresses superblock.payment_addresses = 'yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV|1234 Anywhere ST, Chicago, USA' assert superblock.is_valid() is False # leading spaces in payment addresses superblock.payment_addresses = ' yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' superblock.payment_amounts = '5.00' assert superblock.is_valid() is False # trailing spaces in payment addresses superblock.payment_addresses = 'yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV ' superblock.payment_amounts = '5.00' assert superblock.is_valid() is False # leading & trailing spaces in payment addresses superblock.payment_addresses = ' yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV ' superblock.payment_amounts = '5.00' assert superblock.is_valid() is False # single payment addr/amt is ok superblock.payment_addresses = 'nGSspKw2vnGQMvX3BiRLNSCD21MVXbCcwt' superblock.payment_amounts = '5.00' assert superblock.is_valid() is True # ensure number of payment addresses matches number of payments superblock.payment_addresses = 'nGSspKw2vnGQMvX3BiRLNSCD21MVXbCcwt' superblock.payment_amounts = '37.00|23.24' assert superblock.is_valid() is False superblock.payment_addresses = 'nFr5So8SVuREU8bghTF4eZewiMuKaZ4M2t|nGSspKw2vnGQMvX3BiRLNSCD21MVXbCcwt' superblock.payment_amounts = '37.00' assert superblock.is_valid() is False # ensure amounts greater than zero superblock.payment_addresses = 'nGSspKw2vnGQMvX3BiRLNSCD21MVXbCcwt' superblock.payment_amounts = '-37.00' assert superblock.is_valid() is False # reset superblock = Superblock(**orig.get_dict()) assert superblock.is_valid() is True # mess with proposal hashes superblock.proposal_hashes = '7|yyzx' assert superblock.is_valid() is False superblock.proposal_hashes = '7,|yyzx' assert superblock.is_valid() is False superblock.proposal_hashes = '0|1' assert superblock.is_valid() is False superblock.proposal_hashes = '0000000000000000000000000000000000000000000000000000000000000000|1111111111111111111111111111111111111111111111111111111111111111' assert superblock.is_valid() is True # reset superblock = Superblock(**orig.get_dict()) assert superblock.is_valid() is True
def main(): pyrkd = PyrkDaemon.from_pyrk_conf(config.pyrk_conf) options = process_args() # check pyrkd connectivity if not is_pyrkd_port_open(pyrkd): print( "Cannot connect to pyrkd. Please ensure pyrkd is running and the JSONRPC port is open to Sentinel." ) return # check pyrkd sync if not pyrkd.is_synced(): print( "pyrkd not synced with network! Awaiting full sync before running Sentinel." ) return # ensure valid masternode if not pyrkd.is_masternode(): print("Invalid Masternode Status, cannot continue.") return # register a handler if SENTINEL_DEBUG is set if os.environ.get('SENTINEL_DEBUG', None): import logging logger = logging.getLogger('peewee') logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) if options.bypass: # bypassing scheduler, remove the scheduled event printdbg("--bypass-schedule option used, clearing schedule") Scheduler.clear_schedule() if not Scheduler.is_run_time(): printdbg("Not yet time for an object sync/vote, moving on.") return if not options.bypass: # delay to account for cron minute sync Scheduler.delay() # running now, so remove the scheduled event Scheduler.clear_schedule() # ======================================================================== # general flow: # ======================================================================== # # load "gobject list" rpc command data, sync objects into internal database perform_pyrkd_object_sync(pyrkd) if pyrkd.has_sentinel_ping: sentinel_ping(pyrkd) # auto vote network objects as valid/invalid # check_object_validity(pyrkd) # vote to delete expired proposals prune_expired_proposals(pyrkd) # create a Superblock if necessary attempt_superblock_creation(pyrkd) # schedule the next run Scheduler.schedule_next_run()