Example #1
0
    def test_stake_part_set_unstake_update(self):
        part = StakePart()
        part.set_complete(True)

        stake = 100
        block_height = 10
        part.add_stake(100)
        unstake = stake
        part.set_unstake(block_height, unstake)

        self.assertEqual(0, part.stake)
        self.assertEqual(stake, part.unstake)
        self.assertEqual(block_height, part.unstake_block_height)
        self.assertTrue(
            part.is_set(BasePartState.DIRTY | BasePartState.COMPLETE))

        block_height += block_height
        unstake = 10
        part.set_unstake(block_height, unstake)
        self.assertEqual(stake - unstake, part.stake)
        self.assertEqual(unstake, part.unstake)
        self.assertEqual(block_height, part.unstake_block_height)
        self.assertTrue(
            part.is_set(BasePartState.DIRTY | BasePartState.COMPLETE))

        refund_unstake = part.normalize(block_height + 1, Revision.IISS.value)
        self.assertEqual(unstake, refund_unstake)
Example #2
0
    def test_is_removable_v1(self, unstake_patcher, index, unstakes_info,
                             result):
        stake_part = StakePart(0, 0, 0, unstakes_info)
        stake_part.set_complete(True)
        target = unstake_patcher._targets[index]

        assert unstake_patcher._is_removable_v1(stake_part, target) == result
Example #3
0
    def test_is_removable_v0(self, unstake_patcher, index, unstake,
                             unstake_block_height, result):
        stake_part = StakePart(0, unstake, unstake_block_height)
        stake_part.set_complete(True)
        target = unstake_patcher._targets[index]

        assert unstake_patcher._is_removable_v0(stake_part, target) == result
Example #4
0
    def test_stake_part_add_stake(self):
        part = StakePart()
        part.set_complete(True)

        stake = 100
        part.add_stake(100)
        self.assertEqual(stake, part.stake)
        self.assertTrue(
            part.is_set(BasePartState.DIRTY | BasePartState.COMPLETE))
Example #5
0
    def test_account_stake(self):
        value: int = 0
        stake_part = StakePart(stake=value)
        stake_part.set_complete(True)
        account = Account(create_address(), 0, stake_part=stake_part)
        self.assertEqual(value, account.stake)

        value: int = 100
        stake_part = StakePart(stake=value)
        stake_part.set_complete(True)
        account = Account(create_address(), 0, stake_part=stake_part)
        self.assertEqual(value, account.stake)
Example #6
0
    def test_account_unstake_block_height(self):
        value: int = 0
        stake_part = StakePart(unstake_block_height=value)
        stake_part.set_complete(True)
        account = Account(create_address(), 0, stake_part=stake_part)
        self.assertEqual(0, account.unstake_block_height)

        value: int = 300
        stake_part = StakePart(unstake_block_height=value)
        stake_part.set_complete(True)
        account = Account(create_address(), 0, stake_part=stake_part)
        self.assertEqual(value, account.unstake_block_height)
Example #7
0
    def test_account_unstakes_info(self):
        value: int = 0
        stake_part = StakePart(unstake=value)
        stake_part.set_complete(True)
        account = Account(create_address(),
                          0,
                          Revision.MULTIPLE_UNSTAKE.value,
                          stake_part=stake_part)
        self.assertEqual([], account.unstakes_info)

        info = [(10, 1), (20, 5)]
        stake_part = StakePart(unstakes_info=info)
        stake_part.set_complete(True)
        account = Account(create_address(),
                          0,
                          Revision.MULTIPLE_UNSTAKE.value,
                          stake_part=stake_part)
        self.assertEqual(info, account.unstakes_info)
Example #8
0
    def test_account_unstake(self):
        value: int = 0
        stake_part = StakePart(unstake=value)
        stake_part.set_complete(True)
        account = Account(create_address(),
                          0,
                          Revision.IISS.value,
                          stake_part=stake_part)
        self.assertEqual(0, account.unstake)

        value: int = 200
        stake_part = StakePart(unstake=value)
        stake_part.set_complete(True)
        account = Account(create_address(),
                          0,
                          Revision.IISS.value,
                          stake_part=stake_part)
        self.assertEqual(value, account.unstake)
Example #9
0
    def test_remove_invalid_expired_unstakes_v0(self, unstake_patcher, index,
                                                unstake, unstake_block_height):
        stake = random.randint(0, 1000)
        stake_part = StakePart(stake, unstake, unstake_block_height)
        stake_part.set_complete(True)
        target = unstake_patcher._targets[index]

        assert stake_part.stake == stake
        assert stake_part.unstake == unstake
        assert stake_part.unstake_block_height == unstake_block_height
        assert not stake_part.is_dirty()

        stake_part = unstake_patcher._remove_invalid_expired_unstakes_v0(
            stake_part, target)
        assert stake_part.is_dirty()
        assert len(stake_part.unstakes_info) == 0
        assert stake_part.stake == stake
        assert stake_part.unstake == 0
        assert stake_part.unstake_block_height == 0
Example #10
0
 def test_stake_part_update_multiple_unstake(self):
     stake: int = 5
     block_height = 3
     unstake_info1 = [10, 1]
     unstake_info2 = [20, 2]
     unstake_info3 = [40, 3]
     unstake_info4 = [30, 5]
     unstake_info5 = [100, 5]
     unstakes_info = [
         unstake_info1, unstake_info2, unstake_info3, unstake_info4,
         unstake_info5
     ]
     part = StakePart(stake=stake, unstakes_info=unstakes_info)
     part.set_complete(True)
     part.normalize(block_height, Revision.MULTIPLE_UNSTAKE.value)
     self.assertEqual(stake, part.stake)
     self.assertEqual(0, part.unstake)
     self.assertEqual(0, part.unstake_block_height)
     expected_info = [[40, 3], [30, 5], [100, 5]]
     self.assertEqual(expected_info, part.unstakes_info)
Example #11
0
    def test_remove_invalid_expired_unstakes_v1(self, unstake_patcher,
                                                unstakes_info, index):
        stake = random.randint(0, 1000)
        stake_part = StakePart(stake, 0, 0, copy.deepcopy(unstakes_info))
        stake_part.set_complete(True)
        target = unstake_patcher._targets[index]

        stake_part = unstake_patcher._remove_invalid_expired_unstakes_v1(
            stake_part, target)
        assert stake_part.is_dirty()
        assert stake_part.stake == stake
        assert stake_part.unstake == 0
        assert stake_part.unstake_block_height == 0

        size = len(stake_part.unstakes_info)
        target_size = len(target.unstakes)
        assert size == len(unstakes_info) - target_size

        for i in range(size):
            index = target_size + i
            assert stake_part.unstakes_info[i] == unstakes_info[index]
            assert stake_part.total_unstake == unstakes_info[index][0]
            assert stake_part.total_stake == unstakes_info[index][0] + stake
Example #12
0
 def test_stake_part_total_unstake2(self):
     unstakes_info = [(10, 1), (20, 1)]
     part = StakePart(unstakes_info=unstakes_info)
     part.set_complete(True)
     self.assertEqual(30, part.total_unstake)
Example #13
0
 def test_stake_part_stake(self):
     part = StakePart()
     part.set_complete(True)
     self.assertEqual(0, part.stake)
Example #14
0
 def test_stake_part_voting_weight(self):
     stake = 10
     part = StakePart(stake=stake)
     part.set_complete(True)
     self.assertEqual(stake, part.voting_weight)
Example #15
0
 def test_stake_part_unstake_block_height(self):
     unstake_block_height = 10
     part = StakePart(unstake_block_height=unstake_block_height)
     part.set_complete(True)
     self.assertEqual(unstake_block_height, part.unstake_block_height)
Example #16
0
 def test_stake_part_total_unstake(self):
     unstake = 10
     part = StakePart(unstake=10)
     part.set_complete(True)
     self.assertEqual(unstake, part.total_unstake)
Example #17
0
 def test_stake_part_unstakes_info(self):
     unstakes_info = [(10, 1), (10, 2)]
     part = StakePart(unstakes_info=unstakes_info)
     part.set_complete(True)
     self.assertEqual(unstakes_info, part.unstakes_info)
Example #18
0
 def test_stake_part_total_stake_multiple_unstake(self):
     stake = 10
     unstakes_info = [(10, 1), (10, 2)]
     part = StakePart(stake=stake, unstakes_info=unstakes_info)
     part.set_complete(True)
     self.assertEqual(stake + 20, part.total_stake)
Example #19
0
 def test_stake_part_total_stake(self):
     stake = 10
     unstake = 20
     part = StakePart(stake=stake, unstake=unstake)
     part.set_complete(True)
     self.assertEqual(stake + unstake, part.total_stake)