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 community round tests (518) #229

Merged
merged 47 commits into from
Apr 22, 2024

Conversation

JuaniRios
Copy link
Contributor

@JuaniRios JuaniRios commented Apr 11, 2024

What?

  • Found and fixed critical bug in the price calculation
  • Wrote and modified tests to cover more paths and make code clearer

How?

  • PLMC and Funding asset returns only happen when they are higher than ED. Also wap is taken as min_price when wap is lower than min_price. This can happen due to rounding errors when bucket is increased only by rejected bids.

Testing?

cargo test --features runtime-benchmarks

Anything else?

check https://linear.app/polimec/issue/PLMC-502/community for documentation on all paths covered

@JuaniRios JuaniRios marked this pull request as draft April 11, 2024 11:19
@JuaniRios JuaniRios changed the title Feature/plmc 518 comprehensive community round tests ✅ Comprehensive community round tests (518) Apr 15, 2024
@JuaniRios
Copy link
Contributor Author

@JuaniRios JuaniRios marked this pull request as ready for review April 17, 2024 10:17
@JuaniRios JuaniRios requested review from lrazovic and vstam1 April 17, 2024 10:18
@JuaniRios JuaniRios mentioned this pull request Apr 17, 2024
@JuaniRios JuaniRios mentioned this pull request Apr 17, 2024
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.

Good first changes! Did an review on tests, but will do another on maybe missing paths.

pallets/funding/src/tests/3_auction.rs Outdated Show resolved Hide resolved
pallets/funding/src/functions.rs Outdated Show resolved Hide resolved
pallets/funding/src/functions.rs Outdated Show resolved Hide resolved
Comment on lines +2047 to +2054
if plmc_bond_returned > T::ExistentialDeposit::get() {
T::NativeCurrency::release(
&HoldReason::Participation(project_id).into(),
&bid.bidder,
plmc_bond_returned,
Precision::Exact,
)?;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why does a release of a hold fail? We are not actually sending tokens, right? Just releasing tokens that are already in the users account?

Copy link
Collaborator

Choose a reason for hiding this comment

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

As far as I understand from a quick test, its not possible to hold funds if it would put your free balance under ED. So I think this situation should in theory not happen. Lets say we have 100 tokens with ED = 1:

  • We hold 100. -> Error
  • We hold 90 -> transfer_allow_death(10) -> Error.
    So balance should always contain at least ED free tokens in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CleanShot 2024-04-19 at 16.00.55.png

This is the logic for placing a hold. It is called with Protect and Force.
The case for erroring out when there's no ED left after hold is when there is only 1 provider. And if I understand correctly, we could in the future introduce pallets that provide for the existence of the account, making it possible for it to live without an ED.

Therefore I prefer to be safe and do a check before releasing so we don't halt the whole project. I don't think most people will be getting a return below ED anyway, and if they do they shouldn't mind it not being returned.

@lrazovic any thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CleanShot 2024-04-19 at 16.04.25.png

For reference here is the logic for releasing an asset. It always checks the amount free + the released amount will be bigger than ED.

Copy link
Member

Choose a reason for hiding this comment

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

From: paritytech/substrate#12951

"... may be replaced with fungible::hold::Mutate::release, however the returned Result must be handled and the inner of Ok has the opposite meaning (i.e. it is the amount released, rather than the amount not released, if any)."

So I don't think that release is infallible. Now I throw the question back at you: is this the best way to handle this possible failure? If yes, then we can resolve the comment.

Tagging also @joepetrowski who maybe has some extra input on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it fails due to ED, we can cover it. If it fails for some other reason we probably don't want to continue the project transition because it's unexpected behavior and we should fix it and then force run the community start.

So I think we can resolve as is

pallets/funding/src/tests/4_community.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Show resolved Hide resolved
@JuaniRios JuaniRios requested a review from vstam1 April 19, 2024 16:10
…rehensive-community-round-tests

# Conflicts:
#	pallets/funding/src/functions.rs
#	pallets/funding/src/instantiator.rs
#	pallets/funding/src/tests/3_auction.rs
#	pallets/funding/src/tests/4_community.rs
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.

Looks good for a couple of last things

pallets/funding/src/tests/4_community.rs Show resolved Hide resolved
pallets/funding/src/tests/4_community.rs Outdated Show resolved Hide resolved
pallets/funding/src/tests/misc.rs Outdated Show resolved Hide resolved
@JuaniRios JuaniRios merged commit 0e3d28e into main Apr 22, 2024
@JuaniRios JuaniRios deleted the feature/plmc-518-comprehensive-community-round-tests branch April 22, 2024 12:11
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