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

feat(pallet): follow psp22 standard for decrease_allowance and burn #311

Closed
wants to merge 13 commits into from

Conversation

chungquantin
Copy link
Collaborator

@chungquantin chungquantin commented Sep 27, 2024

Discussion: #300 (comment)

  • For decrease_allowance: Fungibles::decrease_allowance() saturating_sub the value, it should checked_sub and throw an error instead. Hence, we don't have to handle InsufficientAllowance on the contract side.
  • For burn: InsufficientBalance case is not returned in the burn pallet api if the value exceeds the minted value. In decrease_balance method of pallet-assets, it is also saturating_sub.

@codecov-commenter
Copy link

codecov-commenter commented Sep 27, 2024

Codecov Report

Attention: Patch coverage is 74.50980% with 13 lines in your changes missing coverage. Please review.

Project coverage is 51.52%. Comparing base (5083a46) to head (d7b5be9).

Files with missing lines Patch % Lines
pallets/api/src/fungibles/weights.rs 50.00% 13 Missing ⚠️
@@            Coverage Diff             @@
##             main     #311      +/-   ##
==========================================
+ Coverage   51.47%   51.52%   +0.05%     
==========================================
  Files          48       48              
  Lines        4894     4902       +8     
  Branches     4894     4902       +8     
==========================================
+ Hits         2519     2526       +7     
- Misses       2326     2327       +1     
  Partials       49       49              
Files with missing lines Coverage Δ
pallets/api/src/fungibles/mod.rs 92.51% <100.00%> (-0.39%) ⬇️
pallets/api/src/fungibles/tests.rs 99.69% <100.00%> (+<0.01%) ⬆️
pallets/api/src/fungibles/weights.rs 50.00% <50.00%> (ø)

Copy link
Collaborator

@Daanvdplas Daanvdplas left a comment

Choose a reason for hiding this comment

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

Unfortunately still some things to do.

  • Why are there so many changes in other files? Makes the PR very messy.
  • Would be nice to cover the changes for the integration tests here as well.
  • burn's pre-dispatch weight needs to be changed. Easiest thing to do is adding the benchmark weight for balance read function.
  • decrease_allowance needs to be re-benchmarked.

pallets/api/src/fungibles/tests.rs Outdated Show resolved Hide resolved
pallets/api/src/fungibles/tests.rs Outdated Show resolved Hide resolved
Co-authored-by: Daan van der Plas <93204684+Daanvdplas@users.noreply.github.com>
@chungquantin
Copy link
Collaborator Author

@Daanvdplas Weird things with Github commit: https://github.com/orgs/community/discussions/6814. Please ignore those empty files.

pallets/api/src/fungibles/mod.rs Show resolved Hide resolved
pop-api/integration-tests/src/fungibles/mod.rs Outdated Show resolved Hide resolved
pop-api/integration-tests/src/fungibles/mod.rs Outdated Show resolved Hide resolved
@evilrobot-01
Copy link
Collaborator

evilrobot-01 commented Oct 2, 2024

@Daanvdplas Weird things with Github commit: https://github.com/orgs/community/discussions/6814. Please ignore those empty files.

Why are the permissions changing? Can we just not revert whatever was changed so that they dont appear within the PR?

edit: I assume '100755 → 100644' shown in the git diff is the permissions change, so perhaps manually restoring the permissions to the previous should resolve. In future, please review the items being added to a commit before committing. Its better to catch these things at source than have many people review.

Copy link
Collaborator

@evilrobot-01 evilrobot-01 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, but I think the permissions should be reverted to clean up the scope of this PR. Good to merge otherwise.

Comments are only comments.

@@ -272,20 +272,28 @@ fn decrease_allowance_works() {
BadOrigin.with_weight(WeightInfo::approve(0, 0))
);
}
assets::create_mint_and_approve(owner, token, owner, value, spender, value);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes to this test demonstrate why a test per behaviour might be preferred. Such an introduction of a feat should of just had a new test added for a new behaviour, which would have been much cleaner to both write and review.

@@ -416,10 +417,17 @@ fn burn_works() {
let from = BOB;
let total_supply = value * 2;

// Check error works for `Assets::burn()`.
assert_noop!(Fungibles::burn(signed(owner), token, from, value), AssetsError::Unknown);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Whilst the assets error assertions were to ensure that errors are properly handled, which is the case on line 424, this line could have been left in.

@@ -2,7 +2,7 @@
//! Autogenerated weights for `fungibles`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 40.0.0
//! DATE: 2024-09-13, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2024-10-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well done for re-running! It might be nice to have devnet benchmarking run automatically on PRs in the future, so that changes included in the comments above the weight function signatures in terms of storage reads/writes can be checked.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Love your suggestion. Created an issue for this: #321

@chungquantin
Copy link
Collaborator Author

Created this PR #322 to substitute this PR due to the file permission changes. Did try to revert but does not work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants