Beispiel #1
0
def test_constructor():
    pub_ss = PublisherStrategy()
    agent = PublisherAgent("pub1", USD=1.0, OCEAN=2.0, pub_ss=pub_ss)
    assert agent.USD() == 1.0
    assert agent.OCEAN() == 2.0
    assert id(agent.pub_ss) == id(pub_ss)
    assert agent.pub_ss.s_between_create == pub_ss.s_between_create

    assert agent._s_since_create == 0
    assert agent._s_since_unstake == 0
    assert agent._s_since_sellDT == 0

    assert agent.pools == []
def test_createPoolAgent():
    state = MockState()
    assert len(state.agents) == 0

    pub_agent = PublisherAgent("pub1", USD=0.0, OCEAN=1000.0)
    state.addAgent(pub_agent)
    assert len(state.agents) == 1
    assert len(state.agents.filterToPool()) == 0

    pool_agent = pub_agent._createPoolAgent(state)
    assert len(state.agents) == 2
    assert len(state.agents.filterToPool()) == 1
    pool_agent2 = state.agents[pool_agent.name]
    assert isinstance(pool_agent2, PoolAgent)
Beispiel #3
0
def test_createPoolAgent(is_malicious):
    state = MockState()
    assert len(state.agents) == 0

    pub_ss = PublisherStrategy(is_malicious=is_malicious)
    pub_agent = PublisherAgent(name="a", USD=0.0, OCEAN=1000.0, pub_ss=pub_ss)

    state.addAgent(pub_agent)
    assert len(state.agents) == 1
    assert len(state.agents.filterToPool()) == 0

    pool_agent = pub_agent._createPoolAgent(state)
    assert len(state.agents) == 2
    assert len(state.agents.filterToPool()) == 1
    pool_agent2 = state.agents[pool_agent.name]
    assert isinstance(pool_agent2, PoolAgent)
def test_unstakeOCEAN():
    state = MockState()
    pub_agent = PublisherAgent("pub1", USD=0.0, OCEAN=1000.0)

    state.addAgent(pub_agent)
    assert len(state.agents.filterByNonzeroStake(pub_agent)) == 0
    assert pub_agent._doUnstakeOCEAN(state) == False

    pool_agent = pub_agent._createPoolAgent(state)
    assert len(state.agents.filterByNonzeroStake(pub_agent)) == 1
    assert pub_agent._doUnstakeOCEAN(state) == False

    pub_agent._s_since_unstake += pub_agent._s_between_unstake  #force unstake
    assert pub_agent._doUnstakeOCEAN(state) == True

    BPT_before = pub_agent.BPT(pool_agent.pool)
    pub_agent._unstakeOCEAN(state)
    BPT_after = pub_agent.BPT(pool_agent.pool)
    assert BPT_after == (1.0 - 0.10) * BPT_before
Beispiel #5
0
def test_unstakeOCEANsomewhere(is_malicious):
    state = MockState()

    pub_ss = PublisherStrategy(is_malicious=is_malicious)
    pub_agent = PublisherAgent(name="a", USD=0.0, OCEAN=1000.0, pub_ss=pub_ss)

    state.addAgent(pub_agent)
    assert len(state.agents.filterByNonzeroStake(pub_agent)) == 0
    assert not pub_agent._doUnstakeOCEAN(state)

    pool_agent = pub_agent._createPoolAgent(state)
    assert len(state.agents.filterByNonzeroStake(pub_agent)) == 1
    assert not pub_agent._doUnstakeOCEAN(state)

    pub_agent._s_since_unstake += pub_agent.pub_ss.s_between_unstake  # force unstake
    pub_agent._s_since_create += pub_agent.pub_ss.s_wait_to_rug  # ""
    assert pub_agent._doUnstakeOCEAN(state)

    BPT_before = pub_agent.BPT(pool_agent.pool)
    pub_agent._unstakeOCEANsomewhere(state)
    BPT_after = pub_agent.BPT(pool_agent.pool)
    assert BPT_after == (1.0 - PERCENT_UNSTAKE) * BPT_before
def test_doCreatePool():
    agent = PublisherAgent("agent1", USD=0.0, OCEAN=0.0)
    c = agent._doCreatePool()
    assert c in [False, True]
 def _createPublisherAgent(self, state) -> PublisherAgent:
     name = 'foo'  #FIXME
     USD = 0.0  #FIXME magic number
     OCEAN = 1000.0  #FIXME magic number
     new_agent = PublisherAgent(name=name, USD=USD, OCEAN=OCEAN)
     new_agents.add(new_agent)
Beispiel #8
0
 def _createPublisherAgent(self, state) -> None:  # pylint: disable=no-self-use
     name = "foo_publisher"
     USD = 0.0  # magic number
     OCEAN = 1000.0  # magic number
     new_agent = PublisherAgent(name=name, USD=USD, OCEAN=OCEAN)
     state.addAgent(new_agent)
Beispiel #9
0
    def __init__(self, ss=None):
        # initialize self.tick, ss, agents, kpis
        super().__init__(ss)

        # now, fill in actual values for ss, agents, kpis
        if self.ss is None:
            self.ss = SimStrategy()
        ss = self.ss  # for convenience as we go forward

        # wire up the circuit
        new_agents: Set[AgentBase.AgentBase] = set()

        pub_ss = PublisherStrategy(
            DT_init=self.ss.publisher_DT_init,
            DT_stake=self.ss.publisher_DT_stake,
            pool_weight_DT=self.ss.publisher_pool_weight_DT,
            pool_weight_OCEAN=self.ss.publisher_pool_weight_OCEAN,
            s_between_create=self.ss.publisher_s_between_create,
            s_between_unstake=self.ss.publisher_s_between_unstake,
            s_between_sellDT=self.ss.publisher_s_between_sellDT,
            is_malicious=False,
        )
        new_agents.add(
            PublisherAgent(
                name="publisher",
                USD=0.0,
                OCEAN=self.ss.publisher_init_OCEAN,
                pub_ss=pub_ss,
            ))

        new_agents.add(
            DataconsumerAgent(
                name="consumer",
                USD=0.0,
                OCEAN=self.ss.consumer_init_OCEAN,
                s_between_buys=self.ss.consumer_s_between_buys,
                profit_margin_on_consume=self.ss.
                consumer_profit_margin_on_consume,
            ))

        new_agents.add(
            StakerspeculatorAgent(
                name="stakerSpeculator",
                USD=0.0,
                OCEAN=self.ss.staker_init_OCEAN,
                s_between_speculates=self.ss.staker_s_between_speculates,
            ))

        new_agents.add(
            SpeculatorAgent(
                name="speculator",
                USD=0.0,
                OCEAN=self.ss.speculator_init_OCEAN,
                s_between_speculates=self.ss.speculator_s_between_speculates,
            ))

        mal_pub_ss = PublisherStrategy(
            DT_init=self.ss.mal_DT_init,
            DT_stake=self.ss.mal_DT_stake,
            pool_weight_DT=self.ss.mal_pool_weight_DT,
            pool_weight_OCEAN=self.ss.mal_pool_weight_OCEAN,
            s_between_create=self.ss.mal_s_between_create,
            s_between_unstake=self.ss.mal_s_between_unstake,
            s_between_sellDT=self.ss.mal_s_between_sellDT,
            is_malicious=True,
            s_wait_to_rug=self.ss.mal_s_wait_to_rug,
            s_rug_time=self.ss.mal_s_rug_time,
        )
        new_agents.add(
            PublisherAgent(
                name="maliciousPublisher",
                USD=0.0,
                OCEAN=self.ss.mal_init_OCEAN,
                pub_ss=mal_pub_ss,
            ))

        for agent in new_agents:
            self.agents[agent.name] = agent

        # kpis is defined in this netlist module
        self.kpis = KPIs(self.ss.time_step)

        # pools that were rug-pulled by a malicious publisher. Some agents
        # watch for 'state.rugged_pools' and act accordingly.
        self.rugged_pools: List[str] = []
Beispiel #10
0
def test_doCreatePool(is_malicious):
    pub_ss = PublisherStrategy(is_malicious=is_malicious)
    agent = PublisherAgent(name="a", USD=0.0, OCEAN=1000.0, pub_ss=pub_ss)
    c = agent._doCreatePool()
    assert c in [False, True]
Beispiel #11
0
def test_sellDTsomewhere(is_malicious):
    state = MockState()

    pub_ss = PublisherStrategy(is_malicious=is_malicious)
    pub_agent = PublisherAgent(name="a", USD=0.0, OCEAN=1000.0, pub_ss=pub_ss)

    state.addAgent(pub_agent)
    assert len(state.agents.filterByNonzeroStake(pub_agent)) == 0
    assert not pub_agent._doSellDT(state)

    pool_agent = pub_agent._createPoolAgent(state)
    assert len(pub_agent._DTsWithNonzeroBalance(state)) == 1
    assert not pub_agent._doSellDT(state)

    pub_agent._s_since_sellDT += pub_agent.pub_ss.s_between_sellDT  # force sell
    pub_agent._s_since_create += pub_agent.pub_ss.s_wait_to_rug  # ""
    assert pub_agent._doSellDT(state)

    DT_before = pub_agent.DT(pool_agent.datatoken)
    perc_sell = 0.01
    pub_agent._sellDTsomewhere(state, perc_sell=perc_sell)
    DT_after = pub_agent.DT(pool_agent.datatoken)
    assert DT_after == (1.0 - perc_sell) * DT_before