dhiway / cord

CORD - Enterprise Blockchain Framework
https://cord.network
GNU General Public License v3.0
161 stars 112 forks source link

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

Open rohansen856 opened 2 weeks ago

rohansen856 commented 2 weeks ago

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.

vatsa287 commented 2 weeks ago

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

vatsa287 commented 1 week ago

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

rohansen856 commented 1 week ago

@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 commented 1 week ago

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

rohansen856 commented 1 week ago

@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.