Ejemplo n.º 1
0
    def test_p_participant_decides_if_he_wants_to_exit(self):
        participants = get_participants(self.network)
        for i, participant in participants:
            participant.sentiment = 0.1

        self.params["probability_func"] = always
        ans = ParticipantExits.p_participant_decides_if_he_wants_to_exit(
            self.params, 0, 0, self.default_state)

        self.assertEqual(len(ans["defectors"]), 2)
Ejemplo n.º 2
0
    def test_p_participant_decides_if_he_wants_to_exit(self):
        participants = get_participants(self.network)
        for i, participant in participants:
            participant.sentiment = 0.1

        with patch("entities.probability") as p:
            p.return_value = True
            ans = ParticipantExits.p_participant_decides_if_he_wants_to_exit(
                self.params, 0, 0, self.default_state)

            self.assertEqual(len(ans["defectors"]), 4)
Ejemplo n.º 3
0
    def test_su_burn_exiters_tokens(self):
        policy_output = {
            "defectors": {
                1: {
                    "sentiment": 0.1,
                    "holdings": 10000,
                },
                2: {
                    "sentiment": 0.1,
                    "holdings": 10000,
                }
            }
        }
        old_collateral_pool = self.commons._collateral_pool
        old_token_supply = self.commons._token_supply
        _, n_commons = ParticipantExits.su_burn_exiters_tokens(
            self.params, 0, 0, self.default_state, policy_output)

        self.assertNotEqual(old_collateral_pool, n_commons._collateral_pool)
        self.assertNotEqual(old_token_supply, n_commons._token_supply)
Ejemplo n.º 4
0
    def test_su_remove_participants_from_network(self):
        policy_output = {
            "defectors": {
                1: {
                    "sentiment": 0.1,
                    "holdings": 10000,
                },
                2: {
                    "sentiment": 0.1,
                    "holdings": 10000,
                }
            }
        }

        _, n_network = ParticipantExits.su_remove_participants_from_network(
            self.params, 0, 0, self.default_state, policy_output)

        with self.assertRaises(nx.NetworkXError):
            n_network.remove_node(1)
            n_network.remove_node(2)
Ejemplo n.º 5
0
    def test_su_update_sentiment_when_proposal_becomes_active(self):
        """
        Because this policy depends on a policy passthrough from a previous
        partial state update block, it does not use _input, but
        s["policy_output"]
        """
        policy_output_passthru = {
            "proposal_idxs_with_enough_conviction": [4, 5]
        }

        # Let's say Participant 2 owns Proposal 4, Participant 3 owns Proposal 5
        self.network.nodes[2]["item"].sentiment = 0.4
        self.network.nodes[3]["item"].sentiment = 0.6
        self.network.edges[2, 4]["affinity"] = 1
        self.network.edges[3, 5]["affinity"] = 1

        self.default_state["policy_output"] = policy_output_passthru
        _, n_network = ParticipantExits.su_update_sentiment_when_proposal_becomes_active(
            self.params, 0, 0, self.default_state, {})

        self.assertEqual(n_network.nodes[2]["item"].sentiment, 0.9)
        self.assertEqual(n_network.nodes[3]["item"].sentiment, 1)
Ejemplo n.º 6
0
    def test_su_update_sentiment_when_proposal_becomes_failed_or_completed(
            self):
        """
        Because this policy depends on a policy passthrough from a previous
        partial state update block, it does not use _input, but
        s["policy_output"]
        """
        policy_output_passthru = {"failed": [4], "succeeded": [5]}

        # Let's say Participant 2 owns Proposal 4, Participant 3 owns Proposal 5 and have staked on Proposal 4
        participant_2_sentiment = 0.5
        participant_3_sentiment = 0.7
        self.network.nodes[2]["item"].sentiment = participant_2_sentiment
        self.network.nodes[3]["item"].sentiment = participant_3_sentiment
        self.network.edges[2, 4]["support"] = self.network.edges[
            2, 4]["support"]._replace(affinity=1, is_author=1)
        self.network.edges[3, 4]["support"] = self.network.edges[
            3, 4]["support"]._replace(tokens=1)
        self.network.edges[2, 5]["support"] = self.network.edges[
            2, 5]["support"]._replace(tokens=0)
        self.network.edges[3, 5]["support"] = self.network.edges[
            3, 5]["support"]._replace(affinity=1, is_author=1)

        self.default_state["policy_output"] = policy_output_passthru
        _, n_network = ParticipantExits.su_update_sentiment_when_proposal_becomes_failed_or_completed(
            self.params, 0, 0, self.default_state, {})

        new_sentiment_2 = (participant_2_sentiment +
                           1 * config.sentiment_bonus_proposal_becomes_failed)
        new_sentiment_3 = (
            participant_3_sentiment +
            (self.network.edges[3, 4]["support"].affinity *
             config.sentiment_bonus_proposal_becomes_failed)) + (
                 1 * config.sentiment_bonus_proposal_becomes_completed)
        self.assertEqual(n_network.nodes[2]["item"].sentiment, new_sentiment_2)
        self.assertEqual(n_network.nodes[3]["item"].sentiment, new_sentiment_3)