mirror of https://github.com/nucypher/nucypher.git
Apply suggestions from code review #1652
Co-Authored-By: Derek Pierre <derek.pierre@gmail.com>pull/1652/head
parent
ab0bad144e
commit
030eda725f
|
@ -21,6 +21,4 @@ MULTISIG_CONTRACT_NAME = 'MultiSig'
|
|||
ETH_ADDRESS_BYTE_LENGTH = 20
|
||||
ETH_ADDRESS_STR_LENGTH = 40
|
||||
|
||||
|
||||
# Solidity
|
||||
SOLIDITY_MAX_UINT16 = 65535
|
||||
MAX_UINT16 = 65535
|
||||
|
|
|
@ -19,7 +19,7 @@ import click
|
|||
from web3 import Web3
|
||||
|
||||
from nucypher.blockchain.eth.actors import StakeHolder
|
||||
from nucypher.blockchain.eth.constants import SOLIDITY_MAX_UINT16
|
||||
from nucypher.blockchain.eth.constants import MAX_UINT16
|
||||
from nucypher.blockchain.eth.interfaces import BlockchainInterfaceFactory
|
||||
from nucypher.blockchain.eth.registry import IndividualAllocationRegistry
|
||||
from nucypher.blockchain.eth.token import NU, StakeList
|
||||
|
@ -459,7 +459,7 @@ def create(general_config, transacting_staker_options, config_file, force, value
|
|||
if not lock_periods:
|
||||
min_locktime = STAKEHOLDER.economics.minimum_locked_periods
|
||||
default_locktime = STAKEHOLDER.economics.maximum_rewarded_periods
|
||||
max_locktime = SOLIDITY_MAX_UINT16 - STAKEHOLDER.staking_agent.get_current_period()
|
||||
max_locktime = MAX_UINT16 - STAKEHOLDER.staking_agent.get_current_period()
|
||||
prompt = f"Enter stake duration ({min_locktime} - {max_locktime})"
|
||||
lock_periods = click.prompt(prompt, type=stake_duration_range, default=default_locktime)
|
||||
|
||||
|
@ -653,7 +653,7 @@ def divide(general_config, transacting_staker_options, config_file, force, value
|
|||
|
||||
# Duration
|
||||
if not lock_periods:
|
||||
max_extension = SOLIDITY_MAX_UINT16 - current_stake.final_locked_period
|
||||
max_extension = MAX_UINT16 - current_stake.final_locked_period
|
||||
divide_extension_range = click.IntRange(min=1, max=max_extension, clamp=False)
|
||||
extension = click.prompt(f"Enter number of periods to extend (1 - {max_extension})",
|
||||
type=divide_extension_range)
|
||||
|
@ -732,7 +732,7 @@ def prolong(general_config, transacting_staker_options, config_file, force, lock
|
|||
|
||||
# Interactive
|
||||
if not lock_periods:
|
||||
max_extension = SOLIDITY_MAX_UINT16 - current_stake.final_locked_period
|
||||
max_extension = MAX_UINT16 - current_stake.final_locked_period
|
||||
# +1 because current period excluded
|
||||
min_extension = economics.minimum_locked_periods - current_stake.periods_remaining + 1
|
||||
if min_extension < 1:
|
||||
|
|
|
@ -523,7 +523,7 @@ def paint_staged_stake_division(emitter,
|
|||
target_value,
|
||||
extension):
|
||||
new_end_period = original_stake.final_locked_period + extension
|
||||
new_duration_periods = new_end_period - original_stake.first_locked_period
|
||||
new_duration_periods = new_end_period - original_stake.first_locked_period + 1
|
||||
staking_address = original_stake.staker_address
|
||||
|
||||
division_message = f"""
|
||||
|
@ -537,7 +537,7 @@ Staking address: {staking_address}
|
|||
stake_value=target_value,
|
||||
lock_periods=new_duration_periods,
|
||||
start_period=original_stake.first_locked_period,
|
||||
unlock_period=new_end_period,
|
||||
unlock_period=new_end_period + 1,
|
||||
division_message=division_message)
|
||||
|
||||
|
||||
|
|
|
@ -848,12 +848,12 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
assert sub_stake == escrow.functions.getLockedTokens(staker, duration).call(), "Sub-stake is already unlocked"
|
||||
assert 0 == escrow.functions.getLockedTokens(staker, duration + 1).call(), "Sub-stake is still locked"
|
||||
|
||||
def check_events(value: bool, length: int):
|
||||
def check_events(wind_down: bool, length: int):
|
||||
events = wind_down_log.get_all_entries()
|
||||
assert len(events) == length
|
||||
event_args = events[-1]['args']
|
||||
assert staker == event_args['staker'] == staker
|
||||
assert event_args['windDown'] == value
|
||||
assert event_args['windDown'] == wind_down
|
||||
|
||||
tx = token.functions.transfer(staker, 2 * sub_stake).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -891,7 +891,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
tx = escrow.functions.setWindDown(True).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.stakerInfo(staker).call()[WIND_DOWN_FIELD]
|
||||
check_events(value=True, length=1)
|
||||
check_events(wind_down=True, length=1)
|
||||
|
||||
# Enabling wind-down will affect duration only after next confirm activity
|
||||
check_last_period()
|
||||
|
@ -913,7 +913,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
assert not escrow.functions.stakerInfo(staker).call()[WIND_DOWN_FIELD]
|
||||
|
||||
check_events(value=False, length=2)
|
||||
check_events(wind_down=False, length=2)
|
||||
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
|
@ -927,7 +927,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
tx = escrow.functions.setWindDown(True).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.stakerInfo(staker).call()[WIND_DOWN_FIELD]
|
||||
check_events(value=True, length=3)
|
||||
check_events(wind_down=True, length=3)
|
||||
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
|
|
Loading…
Reference in New Issue