示例#1
0
class Testcases(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        self.lookup = Lookup(network="unittests",
                             sports_folder=os.path.join(
                                 os.path.dirname(os.path.realpath(__file__)),
                                 "bookiesports"),
                             peerplays_instance=PeerPlays(nobroadcast=True, ))

    def test_sport(self):
        self.assertIsInstance(self.lookup, dict)
        self.assertIsInstance(self.lookup.peerplays, PeerPlays)

    def test_list_sports(self):
        sports = self.lookup.list_sports()
        self.assertIsInstance(sports, list)
        for sport in sports:
            self.assertIsInstance(sport, LookupSport)
        self.assertEqual(len(sports), 2)
        self.assertIn("AmericanFootball", [x["identifier"] for x in sports])

    def test_get_sport(self):
        sport = self.lookup.get_sport("AmericanFootball")
        self.assertEqual(sport["identifier"], "AmericanFootball")
        self.assertEqual(sport["id"], sport.id)
示例#2
0
class Testcases(unittest.TestCase):
    def setUp(self):
        Lookup._clear()

    def test_sync(self):
        self.lookup = Lookup(
            network="unittests",
            sports_folder=os.path.join(
                os.path.dirname(os.path.realpath(__file__)), "bookiesports"),
            peerplays_instance=PeerPlays(nobroadcast=True),
        )
        self.assertIsInstance(self.lookup, dict)
        self.assertIsInstance(self.lookup.peerplays, PeerPlays)
        self.assertTrue(self.lookup.peerplays.nobroadcast)

        self.assertIn("sports", self.lookup.data)
        self.assertTrue(self.lookup.data["sports"])

        self.lookup.set_blocking(1)
        self.lookup.set_blocking(0)

    def test_proper_accounts(self):
        lookup = Lookup(
            network="unittests",
            sports_folder=os.path.join(
                os.path.dirname(os.path.realpath(__file__)), "bookiesports"),
            proposing_account="init0",
            approving_account="init1",
        )
        self.assertEqual(lookup.proposing_account, "init0")
        self.assertEqual(lookup.approving_account, "init1")
示例#3
0
def test(ctx, network):
    """ Sync the Entities in BookieSports with the blockchain
    """
    w = Lookup(peerplays_instance=ctx.peerplays, network=network)
    if w.is_bookiesports_in_sync():
        click.echo("In sync!")
    else:
        click.echo("NOT in sync! Needs syncing!")
示例#4
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        self.lookup = Lookup(network="unittests",
                             sports_folder=os.path.join(
                                 os.path.dirname(os.path.realpath(__file__)),
                                 "bookiesports"),
                             peerplays_instance=PeerPlays(nobroadcast=True, ))
示例#5
0
 def sync(self, chain_name):
     w = Lookup(peerplays_instance=self.get_node(),
                network=chain_name,
                proposing_account=self.getProposerAccountName(),
                approving_account=self.getProposerAccountName())
     Lookup.proposal_buffer = Node.pendingProposal
     Lookup.proposal_buffer.set_expiration(60 * 60 * 48)
     w.sync_bookiesports()
     return Node.pendingProposal
示例#6
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        Lookup(network="unittests",
               sports_folder=os.path.join(
                   os.path.dirname(os.path.realpath(__file__)),
                   "bookiesports"),
               peerplays_instance=ppy)
        self.lookup = LookupSport("AmericanFootball")
示例#7
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        Lookup._clear()
        Lookup(network="unittests",
               sports_folder=os.path.join(
                   os.path.dirname(os.path.realpath(__file__)),
                   "bookiesports"),
               peerplays_instance=PeerPlays(nobroadcast=True, ))
        self.lookup = LookupParticipants("AmericanFootball",
                                         "NFL_Teams_2017-18")
示例#8
0
    def test_sync(self):
        self.lookup = Lookup(
            network="unittests",
            sports_folder=os.path.join(
                os.path.dirname(os.path.realpath(__file__)), "bookiesports"),
            peerplays_instance=PeerPlays(nobroadcast=True),
        )
        self.assertIsInstance(self.lookup, dict)
        self.assertIsInstance(self.lookup.peerplays, PeerPlays)
        self.assertTrue(self.lookup.peerplays.nobroadcast)

        self.assertIn("sports", self.lookup.data)
        self.assertTrue(self.lookup.data["sports"])

        self.lookup.set_blocking(1)
        self.lookup.set_blocking(0)
示例#9
0
def sync(ctx, approver, proposer, network):
    """ Sync the Entities in BookieSports with the blockchain
    """
    w = Lookup(peerplays_instance=ctx.peerplays, network=network)
    if proposer:
        w.set_proposing_account(proposer)
    if approver:
        w.set_approving_account(approver)

    w.sync_bookiesports()

    broadcast = w.broadcast()
    log.info(dict(broadcast[0]))
示例#10
0
 def test_proper_accounts(self):
     lookup = Lookup(
         network="unittests",
         sports_folder=os.path.join(
             os.path.dirname(os.path.realpath(__file__)), "bookiesports"),
         proposing_account="init0",
         approving_account="init1",
     )
     self.assertEqual(lookup.proposing_account, "init0")
     self.assertEqual(lookup.approving_account, "init1")
示例#11
0
def sync(ctx, approver, proposer, network, broadcast):
    """ Sync the Entities in BookieSports with the blockchain
    """
    w = Lookup(peerplays_instance=ctx.peerplays, network=network)
    if proposer:
        w.set_proposing_account(proposer)
    if approver:
        w.set_approving_account(approver)

    w.sync_bookiesports()

    if broadcast:
        tx = w.broadcast()
        log.info(tx)
    else:
        log.info(json.dumps(Lookup.proposal_buffer.json(), indent=4))
        log.info(json.dumps(Lookup.direct_buffer.json(), indent=4))
        log.warning("Need --broadcast to broadcast!")
示例#12
0
                      nobroadcast=True,
                      num_retries=1)
config = peerplays.config

# Set defaults
peerplays.set_default_account("init0")
set_shared_peerplays_instance(peerplays)

# Ensure we are not going to transaction anythin on chain!
assert peerplays.nobroadcast

# Setup base lookup
lookup = Lookup(
    proposer="init0",
    blockchain_instance=peerplays,
    network="unittests",
    sports_folder=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               "bookiesports"),
)
lookup.set_approving_account("init0")
lookup.set_proposing_account("init0")

# ensure lookup isn't broadcasting either
assert lookup.blockchain.nobroadcast

# Storage
storage = factory.get_incident_storage("mongodbtest", purge=True)

# Incident validator
validator = IncidentValidator()
normalizer = IncidentsNormalizer(chain="unittests")
示例#13
0
 def setUp(self):
     Lookup._clear()
示例#14
0
from bookied_sync.lookup import Lookup
from bookied_sync.eventgroup import LookupEventGroup
from bookied_sync.event import LookupEvent

wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
config = dict(nobroadcast=True)
ppy = PeerPlays(
    keys=[wif],
    nobroadcast=config["nobroadcast"],
    num_retries=1,
)
set_shared_peerplays_instance(ppy)
lookup = Lookup(
    proposer="init0",
    blockchain_instance=ppy,
    network="unittests",
    sports_folder=os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               "bookiesports"),
)
assert lookup.blockchain.nobroadcast

# Setup custom Cache
BlockchainObject._cache = ObjectCache(default_expiration=60 * 60 * 1,
                                      no_overwrite=True)


def lookup_new_event():
    return LookupEvent(
        **{
            "teams": ["Miami Heat", "New Orleans Pelicans"],
            "event_group_id": "1.17.12",
示例#15
0
from bookiesports.normalize import NotNormalizableException

from .log import log
from .config import loadConfig
from . import exceptions, TRIGGERS

config = loadConfig()
peerplays = PeerPlays(
    node=config.get("node", None),
    nobroadcast=config.get("nobroadcast", False),
    num_retries=1,  # Only try once then trow an exception
)
set_shared_blockchain_instance(peerplays)
lookup = Lookup(
    proposing_account=config.get("BOOKIE_PROPOSER"),
    approving_account=config.get("BOOKIE_APPROVER"),
    blockchain_instance=peerplays,
    network=config.get("network", "beatrice"),
)


def unlock():
    """ Unlock the python-peerplays wallet so we can sign the things we are
        proposing/approving.
    """
    # We need to know the passphrase to unlock the wallet
    if "passphrase" not in config:
        err = "No 'passphrase' found in configuration!"
        log.critical(err)
        raise ValueError(err)

    if not lookup.wallet.created():
示例#16
0
 def isInSync(self, chain_name):
     Lookup.data = dict()
     w = Lookup(peerplays_instance=self.get_node(), network=chain_name)
     return w.is_bookiesports_in_sync()