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)
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
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_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