diff --git a/pallets/asset/src/tests.rs b/pallets/asset/src/tests.rs index 72541425..1be5cc87 100644 --- a/pallets/asset/src/tests.rs +++ b/pallets/asset/src/tests.rs @@ -495,3 +495,63 @@ fn asset_vc_status_change_should_succeed() { )); }); } + +#[test] +fn asset_create_should_fail_with_invalid_signature() { + let creator = DID_00; + let author = ACCOUNT_00; + let capacity = 5u64; + + let raw_space = [2u8; 256].to_vec(); + let space_digest = ::Hashing::hash(&raw_space.encode()[..]); + let space_id_digest = ::Hashing::hash( + &[&space_digest.encode()[..], &creator.encode()[..]].concat()[..], + ); + let space_id: SpaceIdOf = generate_space_id::(&space_id_digest); + + let auth_digest = ::Hashing::hash( + &[&space_id.encode()[..], &creator.encode()[..]].concat()[..], + ); + let authorization_id: Ss58Identifier = generate_authorization_id::(&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 = 10; + let asset_value = 10; + let asset_type = AssetTypeOf::MF; + + let entry = AssetInputEntryOf:: { + asset_desc, + asset_qty, + asset_type, + asset_value, + asset_tag, + asset_meta, + }; + + let digest = ::Hashing::hash(&[&entry.encode()[..]].concat()[..]); + + // Simulate an invalid signature by using a different authorization ID + let invalid_authorization_id = Ss58Identifier::create_identifier(b"invalid_signature", IdentifierType::Authorization).unwrap(); + + 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)); + + // Ensure that asset creation fails with InvalidSignature + assert_err!( + Asset::create( + DoubleOrigin(author.clone(), creator.clone()).into(), + entry, + digest, + invalid_authorization_id + ), + Error::::InvalidSignature + ); + }); +}