Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

IS-1206: Improvement unstake integrate test. #517

Merged
merged 1 commit into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions iconservice/prep/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ def _on_term_ended(self, context: 'IconScoreContext') -> Tuple[dict, 'Term']:
main_preps: List['Address'] = [prep.address for prep in self.term.main_preps]
else:
# first term
new_preps: List['PRep'] = context.preps.get_preps(start_index=0,
size=context.main_prep_count)
new_preps: List['PRep'] = context.preps.get_preps(
start_index=0,
size=context.main_prep_count
)
main_preps: List['Address'] = [prep.address for prep in new_preps]

context.storage.meta.put_last_main_preps(context, main_preps)
Expand Down
302 changes: 232 additions & 70 deletions tests/integrate_test/iiss/decentralized/test_iiss_unstake.py

Large diffs are not rendered by default.

49 changes: 29 additions & 20 deletions tests/integrate_test/iiss/decentralized/test_preps.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,10 @@ def test_set_governance_variables3(self):
self.assertEqual(int(False), tx_results[1].status)

def test_weighted_average_of_irep(self):
self.distribute_icx(accounts=self._accounts[:2] + self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2],
init_balance=1 * ICX_IN_LOOP)
self.distribute_icx(
accounts=self._accounts[:2] + self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2],
init_balance=2 * ICX_IN_LOOP
)

tx_list = []
for account in self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2]:
Expand Down Expand Up @@ -295,32 +297,39 @@ def test_sync_end_block_height_of_calc_and_term(self):
self.assertEqual(response['nextCalculation'], response['nextPRepTerm'])

def test_register_prep_apply_terms_irep(self):
self.distribute_icx(accounts=self._accounts[:2] + self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2],
init_balance=1 * ICX_IN_LOOP)
self.distribute_icx(
accounts=self._accounts[:2] + self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2],
init_balance=2 * ICX_IN_LOOP)

tx_list = []
for account in self._accounts[PREP_MAIN_PREPS:PREP_MAIN_PREPS + 2]:
tx = self.create_set_stake_tx(from_=account,
value=3)
tx = self.create_set_stake_tx(
from_=account,
value=3
)
tx_list.append(tx)
self.process_confirm_block_tx(tx_list)

delegation1: int = 1
tx1: dict = self.create_set_delegation_tx(from_=self._accounts[PREP_MAIN_PREPS],
origin_delegations=[
(
self._accounts[0],
delegation1
)
])
tx1: dict = self.create_set_delegation_tx(
from_=self._accounts[PREP_MAIN_PREPS],
origin_delegations=[
(
self._accounts[0],
delegation1
)
]
)
delegation2: int = 3
tx2: dict = self.create_set_delegation_tx(from_=self._accounts[PREP_MAIN_PREPS + 1],
origin_delegations=[
(
self._accounts[1],
delegation2
)
])
tx2: dict = self.create_set_delegation_tx(
from_=self._accounts[PREP_MAIN_PREPS + 1],
origin_delegations=[
(
self._accounts[1],
delegation2
)
]
)
self.process_confirm_block_tx([tx1, tx2])

irep1: int = IISS_INITIAL_IREP * 12 // 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_prep_set_node_address_check_generator(self):
self.set_revision(Revision.DIVIDE_NODE_ADDRESS.value)

self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
init_balance=1 * ICX_IN_LOOP)
init_balance=2 * ICX_IN_LOOP)

# 0 start change node_address
account: 'EOAAccount' = self._accounts[0]
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_prep_set_node_address_check_votes(self):
self.set_revision(Revision.DIVIDE_NODE_ADDRESS.value)

self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
init_balance=1 * ICX_IN_LOOP)
init_balance=2 * ICX_IN_LOOP)

# 0 start change node_key
account: 'EOAAccount' = self._accounts[1]
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_scenario2(self):
self.set_revision(Revision.DIVIDE_NODE_ADDRESS.value)

self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
init_balance=1 * ICX_IN_LOOP)
init_balance=2 * ICX_IN_LOOP)

# PRepA: 0
prep_a: 'EOAAccount' = self._accounts[0]
Expand Down Expand Up @@ -302,7 +302,7 @@ def test_scenario3(self):
self.set_revision(Revision.DIVIDE_NODE_ADDRESS.value)

self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
init_balance=1 * ICX_IN_LOOP)
init_balance=2 * ICX_IN_LOOP)

# PRepA: 0
# PRepB: 1
Expand Down Expand Up @@ -544,7 +544,7 @@ def test_change_node_prep2(self):
self.set_revision(Revision.DIVIDE_NODE_ADDRESS.value)

self.distribute_icx(accounts=self._accounts[:PREP_MAIN_PREPS],
init_balance=1 * ICX_IN_LOOP)
init_balance=2 * ICX_IN_LOOP)

# PRepA: 0
# PRepB: 1
Expand Down
19 changes: 13 additions & 6 deletions tests/integrate_test/iiss/test_iiss_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from iconservice.prep import PRepMethod
from iconservice.prep.data import Term
from iconservice.utils import icx_to_loop
from tests.integrate_test.test_integrate_base import TestIntegrateBase, TOTAL_SUPPLY, DEFAULT_STEP_LIMIT
from tests.integrate_test.test_integrate_base import TestIntegrateBase, TOTAL_SUPPLY, MINIMUM_STEP_LIMIT

if TYPE_CHECKING:
from iconservice.base.block import Block
Expand Down Expand Up @@ -57,7 +57,7 @@ def make_blocks(self,
to: int,
prev_block_generator: Optional['Address'] = None,
prev_block_validators: Optional[List['Address']] = None,
prev_block_votes: Optional[List[Tuple['Address', int]]] = None)\
prev_block_votes: Optional[List[Tuple['Address', int]]] = None) \
-> List[List['TransactionResult']]:
block_height = self._block_height
tx_results: List[List['TransactionResult']] = []
Expand Down Expand Up @@ -586,18 +586,25 @@ def init_decentralized(self, network_proposal: bool = False, clear: bool = True)

tx_list: list = []
step_price: int = self.get_step_price()
fee: int = DEFAULT_STEP_LIMIT * step_price
fee: int = 100_000 * step_price

for account in self._accounts:
balance: int = self.get_balance(account)

if balance - fee > 0:
tx: dict = self.create_transfer_icx_tx(from_=account,
to_=self._admin,
value=balance - fee)
tx: dict = self.create_transfer_icx_tx(
from_=account,
to_=self._admin,
value=balance - fee,
step_limit=100_000
)
tx_list.append(tx)
self.process_confirm_block_tx(tx_list)

def init_inv(self):
self.set_revision(revision=Revision.OPTIMIZE_DIRTY_PREP_UPDATE.value)
self.update_governance(version="1_1_0", expected_status=True, root_path="sample_builtin_for_tests")

@staticmethod
def get_debug_term() -> 'Term':
return IconScoreContext.engine.prep.term
Expand Down
10 changes: 5 additions & 5 deletions tests/integrate_test/iiss/test_inv_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _get_step_price(self):
func_name="getStepPrice")

def _set_step_price(self, step_price: int, is_migrated: bool):
func_name = "set_step_price" if is_migrated else "setStepPrice"
func_name = "setStepPrice"
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name=func_name,
Expand All @@ -63,7 +63,7 @@ def _is_in_score_black_list(self, address: 'Address'):
params={"address": str(address)})

def _add_to_score_black_list(self, address: 'Address', is_migrated: bool):
func_name = "add_to_score_black_list" if is_migrated else "addToScoreBlackList"
func_name = "addToScoreBlackList"
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name=func_name,
Expand Down Expand Up @@ -99,7 +99,7 @@ def _get_step_costs(self):
func_name="getStepCosts")

def _set_step_costs(self, step_type: str, cost: int, is_migrated: bool):
func_name = "set_step_cost" if is_migrated else "setStepCost"
func_name = "setStepCost"
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name=func_name,
Expand All @@ -116,7 +116,7 @@ def _get_max_step_limit(self, context_type: str):
})

def _set_max_step_limit(self, context_type: str, value: int, is_migrated: bool):
func_name = "set_max_step_limit" if is_migrated else "setMaxStepLimit"
func_name = "setMaxStepLimit"
self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name=func_name,
Expand All @@ -131,7 +131,7 @@ def _get_revision(self):

# Override
def _set_revision(self, revision: int, is_migrated: bool):
func_name = "set_revision" if is_migrated else "setRevision"
func_name = "setRevision"
return self.score_call(from_=self._admin,
to_=GOVERNANCE_SCORE_ADDRESS,
func_name=func_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ def _set_step_price(self, value: str):

# ========== for debug ==========
@external
def set_revision(self, code: str, name: str):
def setRevision(self, code: str, name: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -811,10 +811,11 @@ def set_revision(self, code: str, name: str):

self.set_icon_network_value(IconNetworkValueType.REVISION_CODE, code)
self.set_icon_network_value(IconNetworkValueType.REVISION_NAME, name)
self.apply_revision_change(code)
self.RevisionChanged(code, name)

@external
def set_step_price(self, stepPrice: str):
def setStepPrice(self, stepPrice: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -824,7 +825,7 @@ def set_step_price(self, stepPrice: str):
self.StepPriceChanged(step_price)

@external
def set_max_step_limit(self, contextType: str, value: str):
def setMaxStepLimit(self, contextType: str, value: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -835,7 +836,7 @@ def set_max_step_limit(self, contextType: str, value: str):
self.set_icon_network_value(IconNetworkValueType.MAX_STEP_LIMITS, max_step_limits)

@external
def set_step_cost(self, stepType: str, cost: str):
def setStepCost(self, stepType: str, cost: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -846,13 +847,13 @@ def set_step_cost(self, stepType: str, cost: str):
self.set_icon_network_value(IconNetworkValueType.STEP_COSTS, step_costs)

@external
def add_to_score_black_list(self, address: 'Address'):
def addToScoreBlackList(self, address: 'Address'):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')
self._addToScoreBlackList(address)

@external
def malicious_score(self, address: str, type: str):
def maliciousScore(self, address: str, type: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -864,7 +865,7 @@ def malicious_score(self, address: str, type: str):
self._removeFromScoreBlackList(converted_address)

@external
def disqualify_prep(self, address: str):
def disqualifyPrep(self, address: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ def _set_step_price(self, value: str):

# ========== for debug ==========
@external
def set_revision(self, code: str, name: str):
def setRevision(self, code: str, name: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -787,7 +787,7 @@ def set_revision(self, code: str, name: str):
self.RevisionChanged(code, name)

@external
def set_step_price(self, stepPrice: str):
def setStepPrice(self, stepPrice: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -797,7 +797,7 @@ def set_step_price(self, stepPrice: str):
self.StepPriceChanged(step_price)

@external
def set_max_step_limit(self, contextType: str, value: str):
def setMaxStepLimit(self, contextType: str, value: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -808,7 +808,7 @@ def set_max_step_limit(self, contextType: str, value: str):
self.set_icon_network_value(IconNetworkValueType.MAX_STEP_LIMITS, max_step_limits)

@external
def set_step_cost(self, stepType: str, cost: str):
def setStepCost(self, stepType: str, cost: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -819,13 +819,13 @@ def set_step_cost(self, stepType: str, cost: str):
self.set_icon_network_value(IconNetworkValueType.STEP_COSTS, step_costs)

@external
def add_to_score_black_list(self, address: 'Address'):
def addToScoreBlackList(self, address: 'Address'):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')
self._addToScoreBlackList(address)

@external
def malicious_score(self, address: str, type: str):
def maliciousScore(self, address: str, type: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand All @@ -837,7 +837,7 @@ def malicious_score(self, address: str, type: str):
self._removeFromScoreBlackList(converted_address)

@external
def disqualify_prep(self, address: str):
def disqualifyPrep(self, address: str):
if self.msg.sender != self.owner:
revert('Invalid sender: not owner')

Expand Down
3 changes: 1 addition & 2 deletions tests/integrate_test/test_integrate_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ def set_revision(self,
revision: int,
expected_status: bool = True,
with_np: bool = False) -> List['TransactionResult']:
response = self.get_revision()
if not with_np:
# update revision value only
self.score_call(from_=self._admin,
Expand Down Expand Up @@ -889,7 +888,7 @@ def withdraw_deposit(self,
return self.process_confirm_block_tx([tx], expected_status)

def register_proposal(self,
from_: 'Address',
from_: Union['EOAAccount', 'Address'],
title: str,
description: str,
type_: int,
Expand Down