Exemple #1
0
    def p_compare_conviction_and_threshold(params, step, sL, s, **kwargs):
        """
        This policy simply goes through the Proposals to see if their thresholds
        are smaller than their gathered conviction
        """
        network = s["network"]
        funding_pool = s["funding_pool"]
        token_supply = s["token_supply"]

        proposals_w_enough_conviction = []
        proposals = get_proposals(network, status=ProposalStatus.CANDIDATE)
        for idx, proposal in proposals:
            total_conviction = calc_total_conviction(network, idx)
            proposal.conviction = total_conviction
            res = proposal.has_enough_conviction(
                funding_pool, token_supply, params["max_proposal_request"])

            if params.get("debug"):
                print(
                    "ProposalFunding: Proposal {} has {} conviction, and needs {} to pass"
                    .format(idx, proposal.conviction, proposal.trigger))
            if res:
                proposals_w_enough_conviction.append(idx)

        return {
            "proposal_idxs_with_enough_conviction":
            proposals_w_enough_conviction
        }
    def test_calc_total_conviction(self):
        """
        Ensure that the function reports the correct sum of conviction from all
        support edges.
        """
        self.network = setup_support_edges(self.network)
        ans = calc_total_conviction(self.network, 1)
        self.assertEqual(ans, 0)

        support_edges = get_edges_by_type(self.network, "support")

        # Every support edge gets a conviction value. Since there are 5
        # Participants and 5 Proposals, this should result in a sum of 5
        # conviction for each Proposal.
        for u, v in support_edges:
            self.network.edges[u, v]["conviction"] = 1

        for i in [1, 3, 5, 7, 9]:
            ans = calc_total_conviction(self.network, i)
            self.assertEqual(ans, 5)