def test_deterministic_superblock_selection(go_list_superblocks): from brixcoind import BrixcoinDaemon brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_conf) for item in go_list_superblocks: (go, subobj) = GovernanceObject.import_gobject_from_brixcoind(brixcoind, item) # highest hash wins if same -- so just order by hash sb = Superblock.find_highest_deterministic('542f4433e438bdd64697b8381fda1a7a9b7a111c3a4e32fad524d1821d820394') assert sb.object_hash == 'bc2834f357da7504138566727c838e6ada74d079e63b6104701f4f8eb05dae36'
def test_brixcoind(): config_text = BrixcoinConfig.slurp_config_file(config.brixcoin_conf) network = 'mainnet' is_testnet = False genesis_hash = u'0000088ffb1796ef87cc546f5f3d7d841e58eaefdd03448cc16e73c8f8bd4add' for line in config_text.split("\n"): if line.startswith('testnet=1'): network = 'testnet' is_testnet = True genesis_hash = u'0000088ffb1796ef87cc546f5f3d7d841e58eaefdd03448cc16e73c8f8bd4add' creds = BrixcoinConfig.get_rpc_creds(config_text, network) brixcoind = BrixcoinDaemon(**creds) assert brixcoind.rpc_command is not None assert hasattr(brixcoind, 'rpc_connection') # Brixcoin testnet block 0 hash == 0000088ffb1796ef87cc546f5f3d7d841e58eaefdd03448cc16e73c8f8bd4add # test commands without arguments info = brixcoind.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 brixcoind.rpc_command('getblockhash', 0) == genesis_hash
def test_deterministic_superblock_creation(go_list_proposals): import brixcoinlib import misc from brixcoind import BrixcoinDaemon brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_conf) for item in go_list_proposals: (go, subobj) = GovernanceObject.import_gobject_from_brixcoind(brixcoind, item) max_budget = 60 prop_list = Proposal.approved_and_ranked(proposal_quorum=1, next_superblock_max_budget=max_budget) # MAX_GOVERNANCE_OBJECT_DATA_SIZE defined in governance-object.h maxgovobjdatasize = 16 * 1024 sb = brixcoinlib.create_superblock(prop_list, 72000, max_budget, misc.now(), maxgovobjdatasize) assert sb.event_block_height == 72000 assert sb.payment_addresses == 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' assert sb.payment_amounts == '25.75000000|32.01000000' assert sb.proposal_hashes == 'dfd7d63979c0b62456b63d5fc5306dbec451180adee85876cbf5b28c69d1a86c|0523445762025b2e01a2cd34f1d10f4816cf26ee1796167e5b029901e5873630' assert sb.hex_hash() == 'bb3f33ccf95415c396bd09d35325dbcbc7b067010d51c7ccf772a9e839c1e414'
def test_superblock_size_limit(go_list_proposals): import brixcoinlib import misc from brixcoind import BrixcoinDaemon brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_conf) for item in go_list_proposals: (go, subobj) = GovernanceObject.import_gobject_from_brixcoind(brixcoind, item) max_budget = 60 prop_list = Proposal.approved_and_ranked(proposal_quorum=1, next_superblock_max_budget=max_budget) maxgovobjdatasize = 469 sb = brixcoinlib.create_superblock(prop_list, 72000, max_budget, misc.now(), maxgovobjdatasize) # two proposals in the list, but... assert len(prop_list) == 2 # only one should have been included in the SB, because the 2nd one is over the limit assert sb.event_block_height == 72000 assert sb.payment_addresses == 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui' assert sb.payment_amounts == '25.75000000' assert sb.proposal_hashes == 'dfd7d63979c0b62456b63d5fc5306dbec451180adee85876cbf5b28c69d1a86c' assert sb.hex_hash() == '6b8cababf797644f1d62003e4cc68c1c40a8c1873c8a68ed0fc88772ea77cc44'
def test_superblock_is_valid(superblock): from brixcoind import BrixcoinDaemon brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_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 = 'yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' superblock.payment_amounts = '5.00' assert superblock.is_valid() is True # ensure number of payment addresses matches number of payments superblock.payment_addresses = 'yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' superblock.payment_amounts = '37.00|23.24' assert superblock.is_valid() is False superblock.payment_addresses = 'yYe8KwyaUu5YswSYmB3q3ryx8XTUu9y7Ui|yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' superblock.payment_amounts = '37.00' assert superblock.is_valid() is False # ensure amounts greater than zero superblock.payment_addresses = 'yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV' 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(): brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_conf) options = process_args() # check brixcoind connectivity if not is_brixcoind_port_open(brixcoind): print( "Cannot connect to brixcoind. Please ensure brixcoind is running and the JSONRPC port is open to Sentinel." ) return # check brixcoind sync if not brixcoind.is_synced(): print( "brixcoind not synced with network! Awaiting full sync before running Sentinel." ) return # ensure valid masternode if not brixcoind.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_brixcoind_object_sync(brixcoind) if brixcoind.has_sentinel_ping: sentinel_ping(brixcoind) # auto vote network objects as valid/invalid # check_object_validity(brixcoind) # vote to delete expired proposals prune_expired_proposals(brixcoind) # create a Superblock if necessary attempt_superblock_creation(brixcoind) # schedule the next run Scheduler.schedule_next_run()
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 brixcoind import BrixcoinDaemon import brixcoinlib from decimal import Decimal brixcoind = BrixcoinDaemon.from_brixcoin_conf(config.brixcoin_conf) import misc # ============================================================================== # do stuff here pr = Proposal( name='proposal7', url='https://brixcoincentral.com/proposal7', payment_address='yTC62huR4YQEPn9AJHjnQxxreHSbgAoatV', payment_amount=39.23, start_epoch=1483250400, end_epoch=1491022800, ) # sb = Superblock( # event_block_height = 62500,