def test_account(self): account1 = Account() self.assertIsNotNone(account1) self.assertIsNone(account1.address) self.assertTrue(account1.icx == 0) self.assertFalse(account1.locked) self.assertFalse(account1.c_rep) account1.address = create_address() account1.deposit(100) self.assertEqual(100, account1.icx) account1.withdraw(100) self.assertEqual(0, account1.icx) # wrong value self.assertRaises(InvalidParamsException, account1.deposit, -10) # 0 transfer is possible old = account1.icx account1.deposit(0) self.assertEqual(old, account1.icx) self.assertRaises(InvalidParamsException, account1.withdraw, -11234) self.assertRaises(OutOfBalanceException, account1.withdraw, 1) old = account1.icx account1.withdraw(0) self.assertEqual(old, account1.icx)
def test_get_put_account(self): context = self.context account = Account() account.address = create_address(AddressPrefix.EOA) account.deposit(10**19) self.storage.put_account(context, account.address, account) account2 = self.storage.get_account(context, account.address) self.assertEqual(account, account2)
def test_get_put_account(self): context = self.context account = Account() account.deposit(10**19) for address in self.addresses: account.address = address self.storage.put_account(context, account.address, account) account2 = self.storage.get_account(context, account.address) self.assertEqual(account, account2)
def test_account_for_stake_rev_multiple_unstake1(self): address: 'Address' = create_address() context: 'IconScoreContext' = Mock(spec=IconScoreContext) unstake_slot_max = 10 context.configure_mock(unstake_slot_max=unstake_slot_max) context.configure_mock(revision=Revision.MULTIPLE_UNSTAKE.value) coin_part: 'CoinPart' = CoinPart() stake_part: 'StakePart' = StakePart() account = Account(address, 0, Revision.MULTIPLE_UNSTAKE.value, coin_part=coin_part, stake_part=stake_part) balance = 1000 account.deposit(balance) stake1 = 500 unstake_block_height = 0 remain_balance = balance - stake1 account.set_stake(context, stake1, 0) self.assertEqual(stake1, account.stake) self.assertEqual(0, account.unstake) self.assertEqual(unstake_block_height, account.unstake_block_height) self.assertEqual(remain_balance, account.balance) stake2 = 100 block_height = 10 unstake = stake1 - stake2 remain_balance = balance - stake1 account.set_stake(context, stake2, block_height) expected_unstake_info = [[unstake, block_height]] self.assertEqual(stake2, account.stake) self.assertEqual(0, account.unstake) self.assertEqual(0, account.unstake_block_height) self.assertEqual(expected_unstake_info, account.unstakes_info) self.assertEqual(remain_balance, account.balance) stake3 = 600 block_height = 15 account.set_stake(context, stake3, block_height) expected_unstake_info = [] expected_balance = 400 self.assertEqual(stake3, account.stake) self.assertEqual(expected_unstake_info, account.unstakes_info) self.assertEqual(expected_balance, account.balance)
def test_account_for_unstake_slot_max_case_1(self): address: 'Address' = create_address() context: 'IconScoreContext' = Mock(spec=IconScoreContext) unstake_slot_max = 10 context.configure_mock(unstake_slot_max=unstake_slot_max) context.configure_mock(revision=Revision.MULTIPLE_UNSTAKE.value) coin_part: 'CoinPart' = CoinPart() stake_part: 'StakePart' = StakePart() account = Account(address, 0, Revision.MULTIPLE_UNSTAKE.value, coin_part=coin_part, stake_part=stake_part) balance = 2000 account.deposit(balance) stake = 2000 unstake_block_height = 0 remain_balance = balance - stake account.set_stake(context, stake, 0) self.assertEqual(stake, account.stake) self.assertEqual(0, account.unstake) self.assertEqual(unstake_block_height, account.unstake_block_height) self.assertEqual(remain_balance, account.balance) unstake = 1 total_unstake = 0 expected_unstake_info = [] for i in range(unstake_slot_max): expected_unstake_info.append([unstake, unstake_slot_max + i]) stake -= unstake total_unstake += unstake account.set_stake(context, account.stake - unstake, unstake_slot_max + i) self.assertEqual(stake, account.stake) self.assertEqual(total_unstake, account.stake_part.total_unstake) self.assertEqual(remain_balance, account.balance) self.assertEqual(expected_unstake_info, account.unstakes_info) last_unstake = 100 account.set_stake(context, account.stake - last_unstake, unstake_slot_max + 2) expected_unstake_info[-1] = [101, unstake_slot_max * 2 - 1] self.assertEqual(expected_unstake_info, account.unstakes_info)
def test_account_for_stake(self): address: 'Address' = create_address() context: 'IconScoreContext' = IconScoreContext() coin_part: 'CoinPart' = CoinPart() stake_part: 'StakePart' = StakePart() account = Account(address, 0, Revision.IISS.value, coin_part=coin_part, stake_part=stake_part) balance = 1000 account.deposit(balance) stake1 = 500 unstake_block_height = 0 remain_balance = balance - stake1 account.set_stake(context, stake1, 0) self.assertEqual(stake1, account.stake) self.assertEqual(0, account.unstake) self.assertEqual(unstake_block_height, account.unstake_block_height) self.assertEqual(remain_balance, account.balance) stake2 = 100 block_height = 10 unstake = stake1 - stake2 remain_balance = balance - stake1 account.set_stake(context, stake2, block_height) self.assertEqual(stake2, account.stake) self.assertEqual(unstake, account.unstake) self.assertEqual(block_height, account.unstake_block_height) self.assertEqual(remain_balance, account.balance) remain_balance = remain_balance + unstake account._current_block_height += 11 account.normalize(Revision.IISS.value) self.assertEqual(remain_balance, account.balance)
def test_account_from_bytes_to_bytes(self): account = Account() data = account.to_bytes() self.assertEqual(bytes(account), data) self.assertTrue(isinstance(data, bytes)) self.assertEqual(36, len(data)) account2 = Account.from_bytes(data) self.assertFalse(account2.locked) self.assertFalse(account2.c_rep) self.assertEqual(AccountType.GENERAL, account2.type) self.assertEqual(0, account2.icx) account.type = AccountType.GENESIS account.locked = True account.c_rep = True account.deposit(1024) account3 = Account.from_bytes(account.to_bytes()) self.assertTrue(account3.locked) self.assertTrue(account3.c_rep) self.assertEqual(AccountType.GENESIS, account3.type) self.assertEqual(1024, account3.icx)