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