Example #1
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 #2
0
    def test_normalize(self, revision, block_height, unstakes_info,
                       expected_expired_unstake, expected_unstakes_info,
                       expected_dirty):
        stake = random.randint(0, 100)

        stake_part = StakePart(stake=stake,
                               unstakes_info=copy.deepcopy(unstakes_info))
        expired_unstake = stake_part.normalize(block_height, revision)
        assert expired_unstake == expected_expired_unstake
        assert stake_part.unstakes_info == expected_unstakes_info
        assert stake_part.is_dirty() == expected_dirty
Example #3
0
    def test_set_unstakes_info(self, unstakes_info, new_total_unstake,
                               unstake_block_height, expected_unstakes_info):
        old_total_unsake: int = sum(
            info[0] for info in unstakes_info) if unstakes_info else 0
        assert new_total_unstake != old_total_unsake

        stake = random.randint(0, 100)
        slot_max = 3
        revision = Revision.FIX_UNSTAKE_BUG.value
        block_height = 500

        stake_part = StakePart(stake=stake, unstakes_info=unstakes_info)
        stake_part.normalize(block_height, revision)

        unstake_delta: int = new_total_unstake - old_total_unsake
        stake_part.set_unstakes_info(unstake_block_height, new_total_unstake,
                                     slot_max)
        assert stake_part.is_dirty()
        assert stake_part.stake == stake - unstake_delta
        assert stake_part.unstakes_info == expected_unstakes_info
        assert stake_part.total_unstake == new_total_unstake
        assert stake_part.total_stake == stake_part.stake + stake_part.total_unstake
Example #4
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