-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: checkpoints refactoring + tests
- Loading branch information
1 parent
946031f
commit 1161e63
Showing
8 changed files
with
226 additions
and
128 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import pytest | ||
|
||
from src.modules.csm.checkpoint import CheckpointsIterator, Checkpoint | ||
from src.modules.submodules.types import ChainConfig, FrameConfig | ||
from src.utils.web3converter import Web3Converter | ||
from tests.factory.configs import FrameConfigFactory, ChainConfigFactory | ||
|
||
|
||
@pytest.fixture | ||
def frame_config() -> FrameConfig: | ||
return FrameConfigFactory.build( | ||
epochs_per_frame=2, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def chain_config() -> ChainConfig: | ||
return ChainConfigFactory.build( | ||
slots_per_epoch=12, | ||
seconds_per_slot=3, | ||
genesis_time=0, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def converter(frame_config: FrameConfig, chain_config: ChainConfig) -> Web3Converter: | ||
return Web3Converter(chain_config, frame_config) | ||
|
||
|
||
def test_checkpoints_iterator_min_epoch_is_not_reached(converter): | ||
with pytest.raises(ValueError, match='Minimum checkpoint step is not reached yet'): | ||
CheckpointsIterator(converter, 100, 600, 109) | ||
|
||
|
||
def test_checkpoints_iterator_r_epoch_is_changed_by_finalized(converter): | ||
l_epoch = 100 | ||
r_epoch = 600 | ||
finalized_epoch = 110 | ||
expected = finalized_epoch - 1 | ||
iterator = CheckpointsIterator(converter, l_epoch, r_epoch, finalized_epoch) | ||
assert r_epoch != iterator.r_epoch, "Right border should be changed" | ||
assert iterator.r_epoch == expected, "Right border should be equal to the finalized epoch minus one" | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"l_epoch,r_epoch,finalized_epoch,expected_checkpoints", | ||
[ | ||
(0, 255, 255, [Checkpoint(3071, list(range(0, 255)))]), | ||
(15, 255, 255, [Checkpoint(3071, list(range(15, 255)))]), | ||
(15, 255, 25, [Checkpoint(311, list(range(15, 25)))]), | ||
(0, 255 * 2, 255 * 2, [Checkpoint(3071, list(range(0, 255))), Checkpoint(6131, list(range(255, 510)))]), | ||
(15, 255 * 2, 350, [Checkpoint(3251, list(range(15, 270))), Checkpoint(4211, list(range(270, 350)))]), | ||
], | ||
) | ||
def test_checkpoints_iterator_given_checkpoints(converter, l_epoch, r_epoch, finalized_epoch, expected_checkpoints): | ||
iterator = CheckpointsIterator(converter, l_epoch, r_epoch, finalized_epoch) | ||
assert iter(iterator).checkpoints == expected_checkpoints | ||
|
||
|
||
def test_checkpoints_processor(): | ||
assert True |