Skip to content

Commit

Permalink
Added test cases for InvalidAssetType
Browse files Browse the repository at this point in the history
  • Loading branch information
sanika181 committed Dec 5, 2024
1 parent 058fcee commit f44ca3a
Showing 1 changed file with 99 additions and 0 deletions.
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
);
});
}

0 comments on commit f44ca3a

Please sign in to comment.