def fixture_data():
    peerplays.clear()
    BettingMarkets.clear_cache()
    Rules.clear_cache()
    BettingMarketGroups.clear_cache()
    Proposals.clear_cache()
    Witnesses.clear_cache()
    Events.clear_cache()
    EventGroups.clear_cache()
    Sports.clear_cache()

    with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid:
        data = yaml.safe_load(fid)

    [Account(x) for x in data.get("accounts", [])]
    [Account(x).store(x, "name") for x in data.get("accounts", [])]
    Witnesses.cache_objects([Witness(x) for x in data.get("witnesses", [])])
    Sports.cache_objects([Sport(x) for x in data.get("sports", [])])
    EventGroups.cache_objects(
        [EventGroup(x) for x in data.get("eventgroups", [])])
    Events.cache_objects([Event(x) for x in data.get("events", [])])
    BettingMarketGroups.cache_objects(
        [BettingMarketGroup(x) for x in data.get("bettingmarketgroups", [])])
    BettingMarkets.cache_objects(
        [BettingMarket(x) for x in data.get("bettingmarkets", [])])
    Rules.cache_objects([Rule(x) for x in data.get("rules", [])])
    [Bet(x) for x in data.get("bets", [])]

    proposals = []
    for proposal in data.get("proposals", []):
        ops = list()
        for _op in proposal["operations"]:
            for opName, op in _op.items():
                ops.append([operations[opName], op])
        # Proposal!
        proposal_id = proposal["proposal_id"]
        proposal_data = {
            "available_active_approvals": [],
            "available_key_approvals": [],
            "available_owner_approvals": [],
            "expiration_time": "2018-05-29T10:23:13",
            "id": proposal_id,
            "proposed_transaction": {
                "expiration": "2018-05-29T10:23:13",
                "extensions": [],
                "operations": ops,
                "ref_block_num": 0,
                "ref_block_prefix": 0,
            },
            "proposer": "1.2.7",
            "required_active_approvals": ["1.2.1"],
            "required_owner_approvals": [],
        }
        proposals.append(Proposal(proposal_data))

    Proposals.cache_objects(proposals, "1.2.1")
    Proposals.cache_objects(proposals, "witness-account")
Beispiel #2
0
    def test_evg(self):
        EventGroups("1.20.0")
        EventGroups("1.20.0")

        Sports()
        Sports()

        Events("1.21.12")
        Events("1.21.12")

        BettingMarketGroups("1.22.12")
        BettingMarketGroups("1.22.12")

        BettingMarkets("1.24.241")
        BettingMarkets("1.24.241")
Beispiel #3
0
 def test_lists(self):
     self.assertIsInstance(Sports(), list)
     self.assertIsInstance(EventGroups("1.20.2"), list)
     self.assertIsInstance(Events("1.21.2"), list)
     self.assertIsInstance(BettingMarketGroups("1.22.2"), list)
     self.assertIsInstance(Rules(), list)
     self.assertIsInstance(BettingMarkets("1.24.2"), list)
Beispiel #4
0
 def get_onchain_bmgs(self):
     """ Returns a list of BettingMarketGroups of the event that already
         exist on the Blockchain
     """
     if not self.event:
         self.event = self.getEvent()
         if not self.event:
             return []
     return BettingMarketGroups(self.event.id)
Beispiel #5
0
 def getBettingMarketGroups(self, eventId):
     if not eventId:
         raise NonScalableRequest
     try:
         return BettingMarketGroups(
             eventId,
             peerplays_instance=self.get_node()).bettingmarketgroups
     except Exception as ex:
         raise NodeException(
             "BettingMarketGroup could not be loaded: {}".format(
                 self._get_exception_message(ex)))
    def find_id(self, **kwargs):
        """ Try to find an id for the object of the  lookup on the
            blockchain

            .. note:: This only checks if a sport exists with the same name in
                       **ENGLISH**!
        """
        # In case the parent is a proposal, we won't
        # be able to find an id for a child
        parent_id = self.parent.get_id(skip_proposals=False)
        if not self.valid_object_id(parent_id):
            return

        bmgs = BettingMarketGroups(self.parent_id,
                                   peerplays_instance=self.peerplays)

        find_id_search = kwargs.get(
            "find_id_search",
            [
                # We compare only the 'eng' content by default
                comparators.cmp_description("en"),
                comparators.cmp_asset()
            ],
        )

        for bmg in bmgs:
            if all([
                    # compare by using 'all' the funcs in find_id_search
                    func(self, bmg) for func in find_id_search
            ]):
                """ This is special!

                    Since we allow fuzzy logic for matching dynamic parameters, we
                    need to pass back the dynamic parameter in case we found a
                    object on chain or as a proposal that matches our criteria
                    here.

                """
                if self.is_dynamic(bmg):
                    self.set_dynamic(bmg)
                return bmg["id"]