From 38446ab76f09fcc6e85860085ea25a46f58dd554 Mon Sep 17 00:00:00 2001 From: leeheonseung Date: Fri, 4 Sep 2020 15:24:13 +0900 Subject: [PATCH] Improvement unstake integrate test. --- iconservice/prep/engine.py | 6 +- .../iiss/decentralized/test_iiss_unstake.py | 302 ++++++++++++++---- .../iiss/decentralized/test_preps.py | 49 +-- .../test_preps_divide_node_address.py | 10 +- tests/integrate_test/iiss/test_iiss_base.py | 19 +- .../integrate_test/iiss/test_inv_migration.py | 10 +- .../1_1_0/governance/governance.py | 15 +- .../governance/governance.py | 14 +- tests/integrate_test/test_integrate_base.py | 3 +- 9 files changed, 304 insertions(+), 124 deletions(-) diff --git a/iconservice/prep/engine.py b/iconservice/prep/engine.py index 700261e5f..aaf7f7d44 100644 --- a/iconservice/prep/engine.py +++ b/iconservice/prep/engine.py @@ -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) diff --git a/tests/integrate_test/iiss/decentralized/test_iiss_unstake.py b/tests/integrate_test/iiss/decentralized/test_iiss_unstake.py index 46849bcd4..ca2f315b2 100644 --- a/tests/integrate_test/iiss/decentralized/test_iiss_unstake.py +++ b/tests/integrate_test/iiss/decentralized/test_iiss_unstake.py @@ -24,7 +24,8 @@ from iconservice.icon_constant import Revision, ICX_IN_LOOP, ConfigKey from iconservice.icx.coin_part import CoinPart, CoinPartFlag from iconservice.icx.stake_part import StakePart -from iconservice.icx.unstake_patcher import UnstakePatcher, Target, INVALID_EXPIRED_UNSTAKES_FILENAME +from iconservice.icx.unstake_patcher import INVALID_EXPIRED_UNSTAKES_FILENAME +from iconservice.icx.unstake_patcher import UnstakePatcher, Target from tests.integrate_test.iiss.test_iiss_base import TestIISSBase if TYPE_CHECKING: @@ -53,10 +54,8 @@ def _test_unstake_balance( expected_expired_unstake_cnt: int, expected_last_balance: int ): - self.update_governance() - - # set Revision REV_IISS - self.set_revision(Revision.IISS.value) + self.init_decentralized() + self.init_inv() # gain 10 icx balance: int = 10 * ICX_IN_LOOP @@ -72,7 +71,7 @@ def _test_unstake_balance( from_=self._accounts[0], value=stake ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance: int = balance - stake - fee response: int = self.get_balance(self._accounts[0]) self.assertEqual(expected_balance, response) @@ -92,12 +91,12 @@ def _test_unstake_balance( expected_res = { "stake": stake - 1 * ICX_IN_LOOP * 6, "unstakes": [ - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 25, "remainingBlocks": first_remaining_blocks}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 26, "remainingBlocks": first_remaining_blocks+1}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 27, "remainingBlocks": first_remaining_blocks+2}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 28, "remainingBlocks": first_remaining_blocks+3}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 29, "remainingBlocks": first_remaining_blocks+4}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 30, "remainingBlocks": first_remaining_blocks+5}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 70, "remainingBlocks": first_remaining_blocks}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 71, "remainingBlocks": first_remaining_blocks+1}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 72, "remainingBlocks": first_remaining_blocks+2}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 73, "remainingBlocks": first_remaining_blocks+3}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 74, "remainingBlocks": first_remaining_blocks+4}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 75, "remainingBlocks": first_remaining_blocks+5}, ] } self.assertEqual(expected_res, actual_res) @@ -111,11 +110,11 @@ def _test_unstake_balance( expected_res = { "stake": stake - 1 * ICX_IN_LOOP * 6, "unstakes": [ - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 26, "remainingBlocks": 0}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 27, "remainingBlocks": 1}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 28, "remainingBlocks": 2}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 29, "remainingBlocks": 3}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 30, "remainingBlocks": 4}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 71, "remainingBlocks": 0}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 72, "remainingBlocks": 1}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 73, "remainingBlocks": 2}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 74, "remainingBlocks": 3}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 75, "remainingBlocks": 4}, ] } self.assertEqual(res, expected_res) @@ -126,15 +125,15 @@ def _test_unstake_balance( expected_res = { "stake": stake - 1 * ICX_IN_LOOP * 6, "unstakes": [ - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 27, "remainingBlocks": 0}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 28, "remainingBlocks": 1}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 29, "remainingBlocks": 2}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 30, "remainingBlocks": 3}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 72, "remainingBlocks": 0}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 73, "remainingBlocks": 1}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 74, "remainingBlocks": 2}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 75, "remainingBlocks": 3}, ] } self.assertEqual(res, expected_res) - estimate_fee = tx_results[0].step_used * tx_results[0].step_price + estimate_fee = tx_results[1].step_used * tx_results[1].step_price # 2nd expired unstake self.make_empty_blocks(1) @@ -143,9 +142,9 @@ def _test_unstake_balance( expected_res = { "stake": stake - 1 * ICX_IN_LOOP * 6, "unstakes": [ - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 28, "remainingBlocks": 0}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 29, "remainingBlocks": 1}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 30, "remainingBlocks": 2}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 73, "remainingBlocks": 0}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 74, "remainingBlocks": 1}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 75, "remainingBlocks": 2}, ] } self.assertEqual(res, expected_res) @@ -168,8 +167,8 @@ def _test_unstake_balance( expected_res = { "stake": stake - 1 * ICX_IN_LOOP * 6, "unstakes": [ - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 29, "remainingBlocks": 0}, - {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 30, "remainingBlocks": 1}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 74, "remainingBlocks": 0}, + {"unstake": 1 * ICX_IN_LOOP, "unstakeBlockHeight": 75, "remainingBlocks": 1}, ] } self.assertEqual(res, expected_res) @@ -194,8 +193,10 @@ def _setup( unstake_count: int = 1, account_count: int = 1 ) -> list: - self.update_governance() + self.init_decentralized() + self.init_inv() self.set_revision(Revision.MULTIPLE_UNSTAKE.value) + # gain 150 icx self.distribute_icx( accounts=self._accounts[:account_count], @@ -215,7 +216,7 @@ def _setup( tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) for i in range(account_count): - fee = tx_results[i].step_used * tx_results[i].step_price + fee = tx_results[i+1].step_used * tx_results[i+1].step_price expected_balance = self._accounts[i].balance - stake - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) self._accounts[i].balance = expected_balance @@ -233,7 +234,7 @@ def _setup( tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) for j in range(account_count): - fee = tx_results[j].step_used * tx_results[j].step_price + fee = tx_results[j+1].step_used * tx_results[j+1].step_price expected_balance = self._accounts[i].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[j])) self._accounts[i].balance = expected_balance @@ -246,7 +247,7 @@ def _setup( tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) for i in range(account_count): - fee = tx_results[i].step_used * tx_results[i].step_price + fee = tx_results[i+1].step_used * tx_results[i+1].step_price expected_balance = self._accounts[i].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) self._accounts[i].balance = expected_balance @@ -280,7 +281,7 @@ def test_expired_icx_case1(self): expired_icx = stake transfer_value = 10 * ICX_IN_LOOP tx_results = self.transfer_icx(self._accounts[0], self._accounts[1], transfer_value) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price transfer_fee: int = fee account0_unstakes_info = unstakes_info_per_account[0] expired_unstake = ( @@ -305,7 +306,7 @@ def test_expired_icx_case1(self): from_=self._accounts[0], value=stake ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price # Balance | Stake | UnStake | Expired_icx # 210 icx | 30 icx | 0 icx | 0 icx expected_balance = self._accounts[0].balance - stake - fee + expired_icx @@ -349,7 +350,7 @@ def test_multiple_expired_icx(self): self._accounts[1], transfer_value ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price account0_unstakes_info = unstakes_info_per_account[0] expired_unstake1 = ( account0_unstakes_info[0]["unstake"], @@ -381,7 +382,7 @@ def test_multiple_expired_icx(self): self._accounts[1], transfer_value ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price transfer_fee: int = fee account0_unstakes_info = unstakes_info_per_account[0] expired_unstake1 = ( @@ -408,7 +409,7 @@ def test_multiple_expired_icx(self): from_=self._accounts[0], value=stake ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price # Balance | Stake | UnStake | Expired_icx # 200 icx | 30 icx | 0 icx | 0 icx expected_balance = self._accounts[0].balance - stake - fee + expired_icx @@ -456,7 +457,7 @@ def set_delegation(): ) ] ) - _fee = _tx_results[0].step_used * _tx_results[0].step_price + _fee = _tx_results[1].step_used * _tx_results[1].step_price _expected_balance = self._accounts[0].balance - _fee + expired_icx self.assertEqual(_expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = _expected_balance @@ -509,7 +510,7 @@ def set_delegation(): ] ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -532,7 +533,7 @@ def test_expired_icx_case2_2_transfer_icx(self): # transfer icx 10 transfer_value = 10 * ICX_IN_LOOP tx_results = self.transfer_icx(self._accounts[0], self._accounts[1], transfer_value) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price transfer_fee: int = fee account0_unstakes_info = unstakes_info_per_account[0] expired_unstake = ( @@ -556,7 +557,7 @@ def set_delegation(): ) ] ) - _fee = _tx_results[0].step_used * _tx_results[0].step_price + _fee = _tx_results[1].step_used * _tx_results[1].step_price expected_balance = self._accounts[0].balance - _fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -672,7 +673,169 @@ def test_fix_bug_rev11_all_success(self): tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) for i in range(account_count): - fee = tx_results[i].step_used * tx_results[i].step_price + fee = tx_results[i+1].step_used * tx_results[i+1].step_price + expected_balance = self._accounts[i].balance - fee + expired_icx + self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) + + # check expired_icx 1 + account0_unstakes_info = unstakes_info_per_account[0] + expired_unstake = ( + account0_unstakes_info[0]["unstake"], + account0_unstakes_info[0]["unstakeBlockHeight"] + ) + expired_unstakes_info = [expired_unstake] + self._check_expired_icx( + expired_icx=expired_icx, + expired_unstakes_info=expired_unstakes_info, + account_count=account_count + ) + + src: list = [] + for i in range(account_count): + db_info: dict = self._get_account_info(self._accounts[0]) + stake_part: 'StakePart' = db_info["stake"] + data: dict = { + "address": str(self._accounts[i].address), + "total_unstake": stake_part._stake + stake_part._total_unstake(), + "old_unstake_format": False, + "unstakes": [ + [ + stake_part._unstakes_info[0][0], + stake_part._unstakes_info[0][1] + ], + ] + } + src.append(data) + + targets: List[Target] = [Target.from_dict(i) for i in src] + patcher = UnstakePatcher(targets=targets) + + with patch.object(UnstakePatcher, 'from_path') as from_path_mock: + from_path_mock.return_value = patcher + + self.set_revision(Revision.FIX_BALANCE_BUG.value) + self._check_expired_icx_release(account_count=account_count) + + # Retry + # sync balance + for i in range(account_count): + self._accounts[i].balance = self.get_balance(self._accounts[i]) + + # set stake + tx_list = [] + for i in range(account_count): + tx = self.create_set_stake_tx(from_=self._accounts[i], value=stake) + tx_list.append(tx) + tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) + + for i in range(account_count): + fee = tx_results[i+1].step_used * tx_results[i+1].step_price + expected_balance = self._accounts[i].balance - stake - fee + self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) + self._accounts[i].balance = expected_balance + # Balance | Stake | UnStake | Expired_icx + # 50 icx | 100 icx | 0 icx | 0 icx + + # unstake (unstake_count - 1) times + tx_list = [] + unstake = stake // 1 + for i in range(1-1): + for j in range(account_count): + unstake_value = (i+1) * unstake + tx = self.create_set_stake_tx(from_=self._accounts[j], value=stake - unstake_value) + tx_list.append(tx) + tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) + + for j in range(account_count): + fee = tx_results[j+1].step_used * tx_results[j+1].step_price + expected_balance = self._accounts[i].balance - fee + self.assertEqual(expected_balance, self.get_balance(self._accounts[j])) + self._accounts[i].balance = expected_balance + + # unstake all staked value + tx_list = [] + for i in range(account_count): + tx = self.create_set_stake_tx(from_=self._accounts[i], value=0) + tx_list.append(tx) + tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) + + for i in range(account_count): + fee = tx_results[i+1].step_used * tx_results[i+1].step_price + expected_balance = self._accounts[i].balance - fee + self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) + self._accounts[i].balance = expected_balance + + # Balance | Stake | UnStake | Expired_icx + # 50 icx | 0 icx | 100 icx | 0 icx + + # wait expire unstake + remaining_blocks = 0 + + rets = [] + for i in range(account_count): + unstakes_info: list = self.get_stake(self._accounts[0]).get("unstakes") + rets.append(unstakes_info) + unstake_info = unstakes_info[-1] + remaining_blocks = unstake_info["remainingBlocks"] + self.make_empty_blocks(remaining_blocks + 1) + + # delegation + expired_icx: int = stake + tx_list = [] + for i in range(account_count): + tx = self.create_set_delegation_tx( + from_=self._accounts[i], + origin_delegations=[ + ( + self._accounts[i], + 0 + ) + ] + ) + tx_list.append(tx) + tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) + + for i in range(account_count): + fee = tx_results[i+1].step_used * tx_results[i+1].step_price + expected_balance = self._accounts[i].balance - fee + expired_icx + self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) + + # check expired_icx 1 + account0_unstakes_info = unstakes_info_per_account[0] + expired_unstake = ( + account0_unstakes_info[0]["unstake"], + account0_unstakes_info[0]["unstakeBlockHeight"] + ) + self._check_expired_icx_release(account_count=account_count) + + def test_fix_bug_rev11_all_success2(self): + account_count: int = 5 + initial_balance: int = 150 * ICX_IN_LOOP + stake: int = 100 * ICX_IN_LOOP + unstakes_info_per_account: list = self._setup( + init_balance=initial_balance, + stake=stake, + account_count=account_count + ) + + # delegation + expired_icx: int = stake + tx_list = [] + for i in range(account_count): + tx = self.create_set_delegation_tx( + from_=self._accounts[i], + origin_delegations=[ + ( + self._accounts[i], + 0 + ) + ] + ) + tx_list.append(tx) + tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) + + for i in range(account_count): + fee = tx_results[i+1].step_used * tx_results[i+1].step_price expected_balance = self._accounts[i].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) @@ -742,7 +905,7 @@ def test_fix_bug_rev11_all_fail(self): tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=tx_list) for i in range(account_count): - fee = tx_results[i].step_used * tx_results[i].step_price + fee = tx_results[i+1].step_used * tx_results[i+1].step_price expected_balance = self._accounts[i].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[i])) @@ -795,8 +958,8 @@ def tearDown(self): os.remove(report_path) def test_old_format1(self): - self.update_governance() - self.set_revision(Revision.MULTIPLE_UNSTAKE.value - 1) + self.init_decentralized() + self.init_inv() init_balance: int = 150 * ICX_IN_LOOP stake: int = 100 * ICX_IN_LOOP @@ -814,7 +977,7 @@ def test_old_format1(self): expired_icx: int = stake tx = self.create_set_stake_tx(from_=self._accounts[0], value=stake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - stake - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -825,7 +988,7 @@ def test_old_format1(self): # unstake all staked value tx = self.create_set_stake_tx(from_=self._accounts[0], value=0) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -857,7 +1020,7 @@ def test_old_format1(self): ) ] ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -894,8 +1057,8 @@ def test_old_format1(self): self._check_unstake_patch() def test_new_format(self): - self.update_governance() - self.set_revision(Revision.MULTIPLE_UNSTAKE.value - 1) + self.init_decentralized() + self.init_inv() init_balance: int = 150 * ICX_IN_LOOP stake: int = 100 * ICX_IN_LOOP @@ -913,7 +1076,7 @@ def test_new_format(self): expired_icx: int = stake tx = self.create_set_stake_tx(from_=self._accounts[0], value=stake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - stake - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -926,7 +1089,7 @@ def test_new_format(self): # unstake all staked value tx = self.create_set_stake_tx(from_=self._accounts[0], value=0) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -956,7 +1119,7 @@ def test_new_format(self): ) ] ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -992,8 +1155,8 @@ def test_new_format(self): self._check_unstake_patch() def test_new_format_multi_1_of_2_expired(self): - self.update_governance() - self.set_revision(Revision.MULTIPLE_UNSTAKE.value - 1) + self.init_decentralized() + self.init_inv() init_balance: int = 150 * ICX_IN_LOOP stake: int = 100 * ICX_IN_LOOP @@ -1011,7 +1174,7 @@ def test_new_format_multi_1_of_2_expired(self): expired_icx: int = stake // 2 tx = self.create_set_stake_tx(from_=self._accounts[0], value=stake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - stake - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1025,7 +1188,7 @@ def test_new_format_multi_1_of_2_expired(self): unstake = stake // 2 tx = self.create_set_stake_tx(from_=self._accounts[0], value=unstake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1036,7 +1199,7 @@ def test_new_format_multi_1_of_2_expired(self): # unstake the rest of staked value tx = self.create_set_stake_tx(from_=self._accounts[0], value=0) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1071,7 +1234,7 @@ def test_new_format_multi_1_of_2_expired(self): ) ] ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1110,8 +1273,8 @@ def test_new_format_multi_1_of_2_expired(self): self._check_unstake_patch() def test_new_format_multi_2_of_2_expired(self): - self.update_governance() - self.set_revision(Revision.MULTIPLE_UNSTAKE.value - 1) + self.init_decentralized() + self.init_inv() init_balance: int = 150 * ICX_IN_LOOP stake: int = 100 * ICX_IN_LOOP @@ -1129,7 +1292,7 @@ def test_new_format_multi_2_of_2_expired(self): expired_icx: int = stake tx = self.create_set_stake_tx(from_=self._accounts[0], value=stake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - stake - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1143,7 +1306,7 @@ def test_new_format_multi_2_of_2_expired(self): unstake = stake // 2 tx = self.create_set_stake_tx(from_=self._accounts[0], value=unstake) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1151,7 +1314,7 @@ def test_new_format_multi_2_of_2_expired(self): # unstake the rest of staked value tx = self.create_set_stake_tx(from_=self._accounts[0], value=0) tx_results: List['TransactionResult'] = self.process_confirm_block_tx(tx_list=[tx]) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1184,7 +1347,7 @@ def test_new_format_multi_2_of_2_expired(self): ) ] ) - fee = tx_results[0].step_used * tx_results[0].step_price + fee = tx_results[1].step_used * tx_results[1].step_price expected_balance = self._accounts[0].balance - fee + expired_icx self.assertEqual(expected_balance, self.get_balance(self._accounts[0])) self._accounts[0].balance = expected_balance @@ -1256,14 +1419,13 @@ class TestIISSUnStakePatcher(TestIISSBase): PATH = os.path.join(os.path.dirname(__file__), "./invalid_expired_unstakes/test.json") def _make_init_config(self) -> dict: - return { - ConfigKey.INVALID_EXPIRED_UNSTAKES_PATH: self.PATH - } + config: dict = super()._make_init_config() + config[ConfigKey.INVALID_EXPIRED_UNSTAKES_PATH] = self.PATH + return config def test_loader(self): - self.update_governance() - self.set_revision(Revision.IISS.value) - self.set_revision(Revision.DECENTRALIZATION.value) + self.init_decentralized() + self.init_inv() self.set_revision(Revision.FIX_BALANCE_BUG.value) expected_data: dict = { diff --git a/tests/integrate_test/iiss/decentralized/test_preps.py b/tests/integrate_test/iiss/decentralized/test_preps.py index 4f41a417b..ffda6b5c8 100644 --- a/tests/integrate_test/iiss/decentralized/test_preps.py +++ b/tests/integrate_test/iiss/decentralized/test_preps.py @@ -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]: @@ -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 diff --git a/tests/integrate_test/iiss/decentralized/test_preps_divide_node_address.py b/tests/integrate_test/iiss/decentralized/test_preps_divide_node_address.py index 239da14ef..67acaf0c3 100644 --- a/tests/integrate_test/iiss/decentralized/test_preps_divide_node_address.py +++ b/tests/integrate_test/iiss/decentralized/test_preps_divide_node_address.py @@ -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] @@ -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] @@ -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] @@ -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 @@ -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 diff --git a/tests/integrate_test/iiss/test_iiss_base.py b/tests/integrate_test/iiss/test_iiss_base.py index ab55f4f72..ea442a015 100644 --- a/tests/integrate_test/iiss/test_iiss_base.py +++ b/tests/integrate_test/iiss/test_iiss_base.py @@ -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 @@ -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']] = [] @@ -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 diff --git a/tests/integrate_test/iiss/test_inv_migration.py b/tests/integrate_test/iiss/test_inv_migration.py index f41f5887e..9019084c6 100644 --- a/tests/integrate_test/iiss/test_inv_migration.py +++ b/tests/integrate_test/iiss/test_inv_migration.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0/governance/governance.py b/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0/governance/governance.py index dbef6b88f..a9c43fcf5 100644 --- a/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0/governance/governance.py +++ b/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0/governance/governance.py @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0_change_the_value_of_invs_on_migrations/governance/governance.py b/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0_change_the_value_of_invs_on_migrations/governance/governance.py index ff26db312..d9452fde6 100644 --- a/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0_change_the_value_of_invs_on_migrations/governance/governance.py +++ b/tests/integrate_test/samples/sample_builtin_for_tests/1_1_0_change_the_value_of_invs_on_migrations/governance/governance.py @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/tests/integrate_test/test_integrate_base.py b/tests/integrate_test/test_integrate_base.py index 75b7c40cf..93e1dfe65 100644 --- a/tests/integrate_test/test_integrate_base.py +++ b/tests/integrate_test/test_integrate_base.py @@ -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, @@ -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,