pallet-asset: Added test cases for invalid asset value #591
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the issue #372
Implementation Approach
This solution addresses the asset creation test by ensuring two main objectives:
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.
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:
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).
Invalid Asset Quantity:
The test sets the asset quantity to zero, which is considered invalid.
Explicit Zero Asset Value:
The asset value is directly set to zero.
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
Below is the attached screenshot of the test case passing in the local environment:-