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

pallet-asset: Add new test case for InvalidAssetValue #520

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

Conversation

rohansen856
Copy link

Goal

This pr solves the issue: #370 , adding new test cases for checking invalid asset values in pallets/asset/src/tests.rs.

#summary

Context:

creator, author, and capacity establish the initial conditions.
The test then generates unique identifiers for both the "space" and "authorization" using hashing functions to mimic blockchain data integrity practices.

Asset Entry with Invalid Value:

The entry variable represents an asset structure, with asset_value deliberately set to -10 to simulate an invalid value scenario.
This asset entry will be used to test the error handling in the Asset::create function.
Test Execution and Assertions:

Space::create and Space::approve are called to prepare the environment, ensuring the space is created and approved before attempting asset creation.
The core test assertion is assert_err!, which confirms that calling Asset::create with the invalid asset value returns the InvalidAssetValue error as expected.

  • This structured approach not only validates error handling in the Asset::create function but also helps maintain the overall robustness of the system by preventing invalid data from being stored.

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.

I see the requirement here that Invalid Asset Value may get triggered due either from asset_qty or asset_value.
Please check for both cases.

pallets/asset/src/tests.rs Outdated Show resolved Hide resolved
@vatsa287
Copy link
Member

vatsa287 commented Nov 7, 2024

Use below for passing the rust format & add new commit.
cargo +nightly fmt --all

@vatsa287 vatsa287 changed the title enhancement: added new testcases for invalid asset values pallet-asset: Add new test case for InvalidAssetValue Nov 7, 2024
@vatsa287
Copy link
Member

@rohansen856 While at it you can also check for 0 as it only supports unsigned numbers.

@rohansen856
Copy link
Author

@vatsa287 I have added test for the following cases:
Overflow Values: Ensures asset creation fails when asset_value or asset_qty exceeds the maximum limit for their respective types.
Zero Values: Validates that asset creation fails when either asset_value or asset_qty is set to zero, as only positive, non-zero values are supported.
Negative Values: Adds validation for negative values on asset_value and asset_qty, ensuring that asset creation correctly rejects negative entries. did this a bit out of the way by passing the values like this:

let negative_value_entry = AssetInputEntryOf::<Test> {
	asset_desc: asset_desc.clone(),
	asset_qty: 10, // Valid quantity
	asset_type: asset_type.clone(),
	asset_value: (0 - 1), // Invalid (negative) asset value
	asset_tag: asset_tag.clone(),
	asset_meta: asset_meta.clone(),
};

let me know if any other changes or edge case inclusions are necessary. thank you.

@vatsa287
Copy link
Member

@rohansen856 Negative check is not required since it is handled at by the type itself.

@rohansen856
Copy link
Author

@rohansen856 Negative check is not required since it is handled at by the type itself.

thanks for the follow up. i will remove the negative check and keep just the overflow and 0 value error and make a pr.

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