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

✅ Comprehensive settlement tests #304

Merged
merged 1 commit into from
Jun 11, 2024

Conversation

JuaniRios
Copy link
Contributor

@JuaniRios JuaniRios commented May 24, 2024

What?

  • Test more logic branches of the code

How?

@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 7e49ee7 to 10a1837 Compare May 24, 2024 14:10
@JuaniRios JuaniRios changed the title Comprehensive settlement tests ✅ Comprehensive settlement tests May 24, 2024
@JuaniRios JuaniRios self-assigned this May 27, 2024
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch 5 times, most recently from a3d19e5 to 3583f0d Compare May 28, 2024 12:32
@JuaniRios JuaniRios requested review from lrazovic and vstam1 May 28, 2024 12:36
@JuaniRios JuaniRios marked this pull request as ready for review May 28, 2024 12:36
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 3583f0d to f49022b Compare May 28, 2024 13:55
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from c6646cc to 49ac770 Compare May 28, 2024 14:35
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from f49022b to a31bf79 Compare May 28, 2024 14:35
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 49ac770 to c16590e Compare May 29, 2024 10:08
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from a31bf79 to 9bc9a93 Compare May 29, 2024 10:08
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from c16590e to 10e938a Compare May 29, 2024 11:29
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 9bc9a93 to f2d4599 Compare May 29, 2024 11:29
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 10e938a to 5d12e2f Compare May 29, 2024 12:01
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from f2d4599 to 9225bf5 Compare May 29, 2024 12:01
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 5d12e2f to 089dd93 Compare May 29, 2024 12:26
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 9225bf5 to 1943662 Compare May 29, 2024 12:26
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 089dd93 to b022520 Compare May 29, 2024 12:42
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 1943662 to 120b60e Compare May 29, 2024 12:42
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from b022520 to 0166950 Compare May 31, 2024 09:36
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 120b60e to e19e097 Compare May 31, 2024 09:36
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 0166950 to 0980858 Compare June 3, 2024 13:23
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 0980858 to 94159d0 Compare June 3, 2024 14:15
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from e19e097 to a10f42e Compare June 3, 2024 14:16
@JuaniRios JuaniRios force-pushed the 05-22-comprehensive_funding_end_tests branch from 94159d0 to fe2d5dd Compare June 3, 2024 14:41
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from a10f42e to 4cedfa5 Compare June 3, 2024 14:42
Base automatically changed from 05-22-comprehensive_funding_end_tests to main June 3, 2024 16:04
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 4cedfa5 to c87ef41 Compare June 4, 2024 09:32
Copy link
Collaborator

@vstam1 vstam1 left a comment

Choose a reason for hiding this comment

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

Think its a good initial testing setup. I have left a few comments and do have some comments in general:

  1. We have quite a lot of code duplication (settlement for successful + failed project for each type 95% of that code is the same). I know that you are more of the clear distinction between tests and don't mind code duplication, but I think it would be great if we could somehow dedup the tests at least a bit.
  2. I think in certain situations we could get away with less code for the "setup" part of the tests. So instead of going step for step we could create a finished project with as input our specific bids, contributions or evaluations, correct? I think this would make the tests also clearer where there is a clear "setup" part and a clear "this is what we are testing" part.
  3. I think we are over asserting a bit in certain situations. For example in the settle_failed_bids part, we assert for the two bids that the ct amount is 0 before and after settlement. I think we can already skip the one before in this situation. We also assert the issuer balance == 0 at each step before and after, but I think a single assert for issuer balance == 0 at the end is sufficient. This makes the code easier to read and the assertions more clear.

pallets/funding/src/tests/6_funding_end.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/7_settlement.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/7_settlement.rs Show resolved Hide resolved
pallets/funding/src/tests/7_settlement.rs Show resolved Hide resolved
pallets/funding/src/tests/7_settlement.rs Show resolved Hide resolved
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch 2 times, most recently from faf7c81 to 46c142d Compare June 11, 2024 09:41
@JuaniRios JuaniRios requested a review from vstam1 June 11, 2024 10:31
@JuaniRios JuaniRios force-pushed the 05-24-comprehensive_settlement_tests branch from 46c142d to 9ae047e Compare June 11, 2024 10:49
@JuaniRios
Copy link
Contributor Author

Think its a good initial testing setup. I have left a few comments and do have some comments in general:

  1. We have quite a lot of code duplication (settlement for successful + failed project for each type 95% of that code is the same). I know that you are more of the clear distinction between tests and don't mind code duplication, but I think it would be great if we could somehow dedup the tests at least a bit.
  2. I think in certain situations we could get away with less code for the "setup" part of the tests. So instead of going step for step we could create a finished project with as input our specific bids, contributions or evaluations, correct? I think this would make the tests also clearer where there is a clear "setup" part and a clear "this is what we are testing" part.
  3. I think we are over asserting a bit in certain situations. For example in the settle_failed_bids part, we assert for the two bids that the ct amount is 0 before and after settlement. I think we can already skip the one before in this situation. We also assert the issuer balance == 0 at each step before and after, but I think a single assert for issuer balance == 0 at the end is sufficient. This makes the code easier to read and the assertions more clear.
  1. I addressed your specific comments, but I guess you mean that the same refactor can be applied in multiple places right?
  2. Where possible I can fix that, but in most places we cannot because the instantiator only works when specific conditions apply, like for example all bids are accepted. We can in the future extend the instantiator to accept more cases and reduce the size of these functions.
  3. I prefer over-asserting than under-asserting. For the case of asserting the same thing over several logic steps, I think it's preferable since we are making sure only specific changes are done, and not anything else by accident. But I'm happy to look at any specific cases you have in mind, like the one for removing the accountData, which I thought was ok to remove

@JuaniRios
Copy link
Contributor Author

@vstam1 A lot of repetition comes from the fact that 2 participations have different multipliers, and so have a different checking logic. And I think introducing a loop doesn't make sense there. I commented this in one of the inner comments you left

Copy link
Contributor Author

JuaniRios commented Jun 11, 2024

Merge activity

@JuaniRios JuaniRios merged commit e1de2ce into main Jun 11, 2024
@JuaniRios JuaniRios deleted the 05-24-comprehensive_settlement_tests branch June 11, 2024 14:37
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.

2 participants