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

Added test cases for InvalidAssetValue #529

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions pallets/asset/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2839,3 +2839,102 @@ fn asset_vc_status_change_with_wrong_asset_id_should_fail() {
);
});
}

#[test]
fn asset_create_should_fail_for_invalid_asset_value() {
let creator = DID_00;
let author = ACCOUNT_00;
let capacity = 5u64;

let raw_space = [2u8; 256].to_vec();
let space_digest = <Test as frame_system::Config>::Hashing::hash(&raw_space.encode()[..]);
let space_id_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_digest.encode()[..], &creator.encode()[..]].concat()[..],
);
let space_id: SpaceIdOf = generate_space_id::<Test>(&space_id_digest);

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..],
);
let authorization_id: Ss58Identifier = generate_authorization_id::<Test>(&auth_digest);

let asset_desc = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_tag = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_meta = BoundedVec::try_from([72u8; 10].to_vec()).unwrap();
let asset_qty = 0; // Invalid quantity
let asset_value = 0; // Invalid value
let asset_type = AssetTypeOf::MF;

let entry = AssetInputEntryOf::<Test> {
asset_desc,
asset_qty,
asset_type,
asset_value,
asset_tag,
asset_meta,
};

let digest = <Test as frame_system::Config>::Hashing::hash(&[&entry.encode()[..]].concat()[..]);

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));

assert_err!(
Asset::create(
DoubleOrigin(author.clone(), creator.clone()).into(),
entry,
digest,
authorization_id
),
Error::<Test>::InvalidAssetValue
);
});
}

#[test]
fn asset_vc_create_should_fail_for_invalid_asset_value() {
let creator = DID_00;
let author = ACCOUNT_00;
let capacity = 5u64;

let raw_space = [2u8; 256].to_vec();
let space_digest = <Test as frame_system::Config>::Hashing::hash(&raw_space.encode()[..]);
let space_id_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_digest.encode()[..], &creator.encode()[..]].concat()[..],
);
let space_id: SpaceIdOf = generate_space_id::<Test>(&space_id_digest);

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..],
);
let authorization_id: Ss58Identifier = generate_authorization_id::<Test>(&auth_digest);

let asset_qty = 0; // Invalid quantity

let digest = <Test as frame_system::Config>::Hashing::hash(&[&asset_qty.encode()[..]].concat()[..]);

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));

assert_err!(
Asset::vc_create(
DoubleOrigin(author.clone(), creator.clone()).into(),
asset_qty,
digest,
authorization_id
),
Error::<Test>::InvalidAssetQty
);
});
}

Loading