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

Commit

Permalink
Merge pull request #429 from icon-project/IS-1042-fix-fee2-error-with…
Browse files Browse the repository at this point in the history
…draw-with-penalty

IS-1042 fix Fee 2.0 bug
  • Loading branch information
eunsoo-icon authored Mar 24, 2020
2 parents 84e75f0 + 9774fa2 commit 9045389
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
8 changes: 0 additions & 8 deletions iconservice/icx/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,3 @@ def _transfer(self,
context.storage.icx.put_account(context, to_account)

return True

def get_treasury_account(self, context: 'IconScoreContext') -> 'Account':
"""Returns the instance of treasury account
:param context:
:return: Account
"""
return context.storage.icx.get_account(context, context.storage.icx.fee_treasury)
8 changes: 8 additions & 0 deletions iconservice/icx/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ def get_account(self,
stake_part=stake_part,
delegation_part=delegation_part)

def get_treasury_account(self, context: 'IconScoreContext') -> 'Account':
"""Returns the instance of treasury account
:param context:
:return: Account
"""
return context.storage.icx.get_account(context, context.storage.icx.fee_treasury)

def _get_part(self, context: 'IconScoreContext',
part_class: Union[type(CoinPart), type(StakePart), type(DelegationPart)],
address: 'Address') -> Union['CoinPart', 'StakePart', 'DelegationPart']:
Expand Down
36 changes: 36 additions & 0 deletions tests/integrate_test/test_integrate_fee_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,42 @@ def test_withdraw_deposit_after_deposit(self):
tx_results: List['TransactionResult'] = self.withdraw_deposit(deposit_id=deposit_id,
score_address=self.score_address)
self.assertTrue(tx_results[0].status)
event_log = tx_results[0].event_logs[0]
self.assertEqual('DepositWithdrawn(bytes,Address,int,int)', event_log.indexed[0])
self.assertEqual(event_log.data[0], MIN_DEPOSIT_AMOUNT) # withdraw amount
self.assertEqual(event_log.data[1], 0) # penalty amount

score_info: dict = self._query_score_info(self.score_address)
self.assertNotIn('depositInfo', score_info)

def test_withdraw_deposit_with_penalty(self):
"""
Given : The SCORE is deployed, deposit once and .
When : Withdraws the deposit.
Then : Amount of availableDeposit is 0.
"""
tx_results: List['TransactionResult'] = self.deposit_icx(score_address=self.score_address,
amount=MIN_DEPOSIT_AMOUNT,
period=MIN_DEPOSIT_TERM)
deposit_id: bytes = tx_results[0].tx_hash

score_info: dict = self._query_score_info(self.score_address)
self.assertIn('depositInfo', score_info)
self.assertIn(deposit_id, map(lambda d: d['id'], score_info['depositInfo']['deposits']))

# invoke score method to use virtual step
self.score_call(from_=self._admin,
to_=self.score_address,
func_name="set_value",
params={"value": hex(100), "proportion": hex(100)})

tx_results: List['TransactionResult'] = self.withdraw_deposit(deposit_id=deposit_id,
score_address=self.score_address)
self.assertTrue(tx_results[0].status)
event_log = tx_results[0].event_logs[0]
self.assertEqual('DepositWithdrawn(bytes,Address,int,int)', event_log.indexed[0])
self.assertTrue(event_log.data[0] < MIN_DEPOSIT_AMOUNT) # withdraw amount
self.assertTrue(event_log.data[1] > 0) # penalty amount

score_info: dict = self._query_score_info(self.score_address)
self.assertNotIn('depositInfo', score_info)
Expand Down

0 comments on commit 9045389

Please sign in to comment.