Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate zero amount in a defined activity #180

Conversation

joseguru
Copy link

This PR addresses the issue #176 . This has been done by updating the validate_activity function

  • updated validate_activity to disallow zero values.
  • Throws a validation error when amount_msat is 0 on a defined activity

@joseguru joseguru marked this pull request as ready for review April 18, 2024 15:28
Copy link

@Anyitechs Anyitechs left a comment

Choose a reason for hiding this comment

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

Good job on the PR @joseguru. Left a few feedbacks on having a descriptive error message, fixing the lint error and maybe having the zero amount validation after the source and destination node validation, if it makes sense to you.

cc: @carlaKC

// lets validate the amount_msats to be greater than zero
if payment_flow.amount_msat==0 {
return Err(LightningError::ValidationError(
"Expected amount_msat should be greater than zero.".to_string(),

Choose a reason for hiding this comment

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

I think the error message here can be more descriptive, because some users may find this hard to understand at first.

Suggested change
"Expected amount_msat should be greater than zero.".to_string(),
""We do not allow defined activity amount_msat with zero values".to_string(),

@@ -475,6 +475,12 @@ impl Simulation {
}

for payment_flow in self.activity.iter() {
// lets validate the amount_msats to be greater than zero
if payment_flow.amount_msat==0 {

Choose a reason for hiding this comment

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

This needs proper formatting. The contributing guide recommends running a make check command to check for lint errors and adhering to the linter suggestions made by clippy.

@@ -475,6 +475,12 @@ impl Simulation {
}

for payment_flow in self.activity.iter() {
// lets validate the amount_msats to be greater than zero
if payment_flow.amount_msat==0 {

Choose a reason for hiding this comment

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

nit: I think having the zero amount validation after the source and destination nodes validation makes more sense because the payment amount_msat is coming from a valid source node to a valid destination node.

Copy link
Author

Choose a reason for hiding this comment

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

@Anyitechs. I see. This makes sense

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Agree with @Anyitechs's review here. It would be very nice to include some test coverage for validate_activity with this PR as well. We've been quite shocking with tests so far in the project's existence, but that's certainly something we want to change.

@joseguru
Copy link
Author

Hello @carlaKC we were having a chat with @Anyitechs on the where to place test files. The current implementation has tests written on each file , for example defined_activity.rs has tests written on it.
Can these tests files be separated to a tests directory then have individual test file for each implementation?

@carlaKC
Copy link
Contributor

carlaKC commented May 6, 2024

Hello @carlaKC we were having a chat with @Anyitechs on the where to place test files. The current implementation has tests written on each file , for example defined_activity.rs has tests written on it. Can these tests files be separated to a tests directory then have individual test file for each implementation?

We're following the rust convention of including tests in the same file in a different module - I don't really see a compelling reason to move them into another file?

@carlaKC
Copy link
Contributor

carlaKC commented May 24, 2024

Closing due to inactivity, please feel free to re-open if you've got time to pick this up again.

@carlaKC carlaKC closed this May 24, 2024
@joseguru
Copy link
Author

joseguru commented May 25, 2024

Hi @carlaKC Been working on it on the side . Been trying to work on mocking a Simulation as per your instructions. So its work in progress

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