Skip to content

Conversation

@johnny423
Copy link
Owner

No description provided.

@Elialka
Copy link
Collaborator

Elialka commented Jan 19, 2023

@johnny423 Where do you suggest placing a test for this function?
Should we add a more elaborate end to end test case as well?

@Elialka Elialka changed the title support nip_2 support nip_22 Jan 21, 2023
Copy link
Owner Author

@johnny423 johnny423 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, please run scripts/format-imports.sh before pushing again (I should add setup for pre-commit but Im lazy 😓 )

return dispatcher


async def _attempt_timestamp(event_builder, timestamps: list[int], should_save: bool):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really understand what the function is doing with the attempt_timestamp. can we rename it?

nip_22_config = nips_config.nip_22
if not nip_22_config:
return
current_time = time.time()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fun part about not working with a method that uses the actual time it to test it specifically without having the whole dispatcher

Comment on lines +190 to +214
def test_timestamp_validation(self):
good_timestamps_params = [
(1500, 2000, (-600, 0)),
(1700, 2000, (-600, -200)),
(190000, 100000, (80000, 100000)),
(250000, 100000, (-600, 500000)),
(100000, 100000, (0, 1)),
(101, 100, (-600, 500000)),
(8000, 100000, None),
]
bad_timestamps_params = [
(1300, 2000, (-600, 0)),
(1900, 2000, (-600, -200)),
(150000, 100000, (80000, 100000)),
(9999999, 100000, (-600, 500000)),
(100001, 100000, (0, 1)),
(151, 100, (-600, 50)),
]
for param_list, expected in [
(good_timestamps_params, True),
(bad_timestamps_params, False)
]:
for param_instance in param_list:
result = is_creation_time_valid(*param_instance)
assert result == expected
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first - you probably want to use parameterize here :)
second - its a bit hard to read like that, anyway to improve readability?


@pytest.mark.asyncio
async def test_legal_timestamp(self, event_builder):
nip_22_config = nips_config.nip_22
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this test work based on configuration?

await repo.delete(keys_to_delete)


def is_creation_time_valid(event_creation_time: int, current_time: float, nip_22_config: tuple[int, int]) -> bool:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a docstring?

if nips_config.nip_9 and event.kind == EventKind.EventDeletion: # type: ignore
await _handle_delete_event(repo, event)

if not is_creation_time_valid(event.created_at, time.time(), nips_config.nip_22):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the validation should happen before the delete

@Elialka Elialka force-pushed the feature/support_nip_22 branch from 6736792 to 473c19b Compare February 25, 2023 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants