def test_stake_status(mock_testerchain, token_economics, mock_staking_agent): address = mock_testerchain.etherbase_account current_period = 3 staker_info = StakerInfo(current_committed_period=current_period - 1, next_committed_period=current_period, value=0, last_committed_period=0, lock_restake_until_period=False, completed_work=0, worker_start_period=0, worker=NULL_ADDRESS, flags=bytes()) mock_staking_agent.get_current_period.return_value = current_period mock_staking_agent.get_staker_info.return_value = staker_info def make_sub_stake(value, first_locked_period, final_locked_period): return Stake(checksum_address=address, first_locked_period=first_locked_period, final_locked_period=final_locked_period, value=value, index=0, staking_agent=mock_staking_agent, economics=token_economics, validate_now=False) # Prepare unlocked sub-stake nu = NU.from_nunits(2 * token_economics.minimum_allowed_locked - 1) stake = make_sub_stake(nu, current_period - 2, current_period - 1) assert stake.status() == Stake.Status.UNLOCKED # Prepare inactive sub-stake # Update staker info and create new state stake = make_sub_stake(nu, current_period - 2, current_period - 1) staker_info = staker_info._replace(current_committed_period=current_period, next_committed_period=current_period + 1) mock_staking_agent.get_staker_info.return_value = staker_info assert stake.status() == Stake.Status.INACTIVE # Prepare locked sub-stake stake = make_sub_stake(nu, current_period - 2, current_period) assert stake.status() == Stake.Status.LOCKED # Prepare editable sub-stake stake = make_sub_stake(nu, current_period - 2, current_period + 1) assert stake.status() == Stake.Status.EDITABLE # Prepare divisible sub-stake nu = NU.from_nunits(2 * token_economics.minimum_allowed_locked) stake = make_sub_stake(nu, current_period - 2, current_period + 1) assert stake.status() == Stake.Status.DIVISIBLE
def stakeholder(current_period, mock_staking_agent, test_registry): mock_staking_agent.get_current_period.return_value = current_period staker_info = StakerInfo(current_committed_period=current_period - 1, next_committed_period=current_period, value=0, last_committed_period=0, lock_restake_until_period=False, completed_work=0, worker_start_period=0, worker=NULL_ADDRESS, flags=bytes()) mock_staking_agent.get_staker_info.return_value = staker_info return StakeHolder(registry=test_registry)
def stakeholder(current_period, mock_staking_agent, test_registry, mock_testerchain): mock_staking_agent.get_current_period.return_value = current_period staker_info = StakerInfo(current_committed_period=current_period-1, next_committed_period=current_period, value=0, last_committed_period=0, lock_restake_until_period=False, completed_work=0, worker_start_period=0, worker=NULL_ADDRESS, flags=bytes()) mock_staking_agent.get_staker_info.return_value = staker_info return StakeHolder(registry=test_registry, domain=TEMPORARY_DOMAIN, signer=Web3Signer(mock_testerchain.client))
def test_stake_sync(mock_testerchain, token_economics, mock_staking_agent): address = mock_testerchain.etherbase_account current_period = 3 staker_info = StakerInfo(current_committed_period=current_period - 1, next_committed_period=current_period, value=0, last_committed_period=0, lock_restake_until_period=False, completed_work=0, worker_start_period=0, worker=NULL_ADDRESS, flags=bytes()) mock_staking_agent.get_current_period.return_value = current_period mock_staking_agent.get_staker_info.return_value = staker_info # Prepare sub-stake nu = NU.from_nunits(2 * token_economics.minimum_allowed_locked - 1) stake = Stake(checksum_address=address, first_locked_period=current_period - 2, final_locked_period=current_period + 1, value=nu, index=0, staking_agent=mock_staking_agent, economics=token_economics, validate_now=False) assert stake.status() == Stake.Status.EDITABLE # Update locked value and sync sub_stake_info = stake.to_stake_info() nunits = 2 * token_economics.minimum_allowed_locked sub_stake_info = sub_stake_info._replace(locked_value=nunits) mock_staking_agent.get_substake_info.return_value = sub_stake_info stake.sync() assert stake.status() == Stake.Status.DIVISIBLE assert stake.value == NU.from_nunits(nunits) # Update current period and sync mock_staking_agent.get_current_period.return_value = current_period + 1 sub_stake_info = sub_stake_info._replace(locked_value=nunits) mock_staking_agent.get_substake_info.return_value = sub_stake_info stake.sync() assert stake.status() == Stake.Status.LOCKED assert stake.final_locked_period == current_period + 1 # Update final period and sync sub_stake_info = sub_stake_info._replace(last_period=current_period) mock_staking_agent.get_substake_info.return_value = sub_stake_info stake.sync() assert stake.status() == Stake.Status.UNLOCKED assert stake.final_locked_period == current_period # Update first period and sync sub_stake_info = sub_stake_info._replace(first_period=current_period) mock_staking_agent.get_substake_info.return_value = sub_stake_info with pytest.raises(Stake.StakingError): stake.sync()