-
Notifications
You must be signed in to change notification settings - Fork 121
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
Added tests for Invalid Asset Type. Fixes #374 #548
base: develop
Are you sure you want to change the base?
Conversation
@ritankarsaha This approach doesn't solve the problem as you have created a new type INVALID and in your tests you generate an error by creating INVALID type and then checking for the same |
@JiyaGupta-cs i am trying to create invalid entry by having invalid type However, the invalid type seems to be automatically converted into AssetTypeOf::MF. This results in the assertion for assert_err not matching as expected. This is the output I am receiving:- ---- tests::asset_create_should_fail_with_invalid_asset_type stdout ----
Invalid type being tested: AssetTypeOf::MF
thread 'tests::asset_create_should_fail_with_invalid_asset_type' panicked at pallets/asset/src/tests.rs:2887:9:
assertion `left == right` failed
left: Ok(())
right: Err(Module(ModuleError { index: 2, error: [7, 0, 0, 0], message: Some("InvalidAssetType") })) My initial approach to the code was:- new_test_ext().execute_with(|| {
assert_ok!(Space::create(
DoubleOrigin(author.clone(), creator.clone()).into(),
space_digest
));
assert_ok!(Space::approve(RawOrigin::Root.into(), space_id, capacity));
let invalid_entry = AssetInputEntryOf::<Test> {
asset_desc: BoundedVec::try_from([72u8; 10].to_vec()).unwrap(),
asset_tag: BoundedVec::try_from([72u8; 10].to_vec()).unwrap(),
asset_meta: BoundedVec::try_from([72u8; 10].to_vec()).unwrap(),
asset_qty: 10,
asset_value: 10,
asset_type: unsafe { std::mem::transmute(3u8) },
};
println!("Invalid type being tested: {:?}", invalid_entry.asset_type);
let invalid_digest = <Test as frame_system::Config>::Hashing::hash(
&[
&invalid_entry.encode()[..],
&[0u8; 32].to_vec()[..],
]
.concat()[..],
);
assert_err!(
Asset::create(
DoubleOrigin(author, creator).into(),
invalid_entry,
invalid_digest,
authorization_id
),
Error::<Test>::InvalidAssetType
);
}); @JiyaGupta-cs @vatsa287 any suggestions for this? |
@vatsa287 is this implementation correct? Or do i need to make certain changes in this PR? |
@vatsa287 does this PR require any more changes? |
@ritankarsaha This might be a better approach IMO. Please refer below and add a different new commit. |
Sure @vatsa287 |
Fixes #374
This PR introduces a new unit test,
asset_create_should_fail_with_invalid_asset_type
, to verify that the Asset::create function fails as expected when provided with an invalid asset type.The test attempts to create the asset using the invalid entry and checks that the
Asset::create function
returns the expectedError::<Test>::InvalidAssetType
. This ensures the system rejects invalid asset types correctly.The test has passed as well, as shown in the screenshot.