Skip to content

pallet-asset: Added test cases for invalid asset value #591

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

ritankarsaha
Copy link
Contributor

This PR fixes the issue #372

Implementation Approach

This solution addresses the asset creation test by ensuring two main objectives:

  1. Proper Authorization:
    The test first creates and approves a space, then generates an authorization ID using the required inputs. This step is crucial because the asset creation function depends on a valid authorization. By correctly forming the authorization ID, the test ensures that the authorization check passes, allowing the function to proceed to validate the asset parameters.

  2. Validation of Asset Parameters:
    Once the authorization is confirmed, the asset creation function enforces rules that both the asset value and asset quantity must be greater than zero. The solution implements four distinct test cases:

  3. Overflow Simulation for Asset Value:
    An asset value is set using a wrapping addition (which simulates an overflow that effectively produces an invalid zero value).

  4. Invalid Asset Quantity:
    The test sets the asset quantity to zero, which is considered invalid.

  5. Explicit Zero Asset Value:
    The asset value is directly set to zero.

  6. Explicit Zero Asset Quantity:
    The asset quantity is directly set to zero.

Each of these cases is designed to trigger the error handling in the asset creation function, ensuring that any attempt to create an asset with invalid parameters (either value or quantity) results in a specific error.
By combining a valid authorization with multiple invalid asset scenarios, the solution guarantees that asset creation only succeeds when all input parameters are valid, thereby maintaining the integrity of the system's data.

DIscalimer

@vatsa287 For the issue #372 I had earlier raised a PR #561 where changes were requested to make the approach in compliance with the previous PRs attached to the issue.
I have modified my approach from the previous PR #561 , closed the previous PR and am raising a new one for the same with the updated code and approach in compliance with the requirements as asked.

Testing

  • All new tests can be executed using cargo test -p pallet-asset
  • Test cases validate proper error handling

Below is the attached screenshot of the test case passing in the local environment:-

Screenshot 2025-03-09 at 1 29 22 AM

@ritankarsaha
Copy link
Contributor Author

@vatsa287 For the issue #372 I had earlier raised a PR #561 where changes were requested to make the approach in compliance with the previous PRs attached to the issue.
I have modified my approach from the previous PR #561 , closed the previous PR and am raising a new one for the same with the updated code and approach in compliance with the requirements as asked.

Copy link
Member

@vatsa287 vatsa287 left a comment

Choose a reason for hiding this comment

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

LGTM.
Will be merged soon once our develop branch is stabilised with new under-development features.

@ritankarsaha
Copy link
Contributor Author

LGTM. Will be merged soon once our develop branch is stabilised with new under-development features.

Sure, thanks @vatsa287

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