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

Add tests for InvalidSignature #418

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
60 changes: 60 additions & 0 deletions pallets/asset/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <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()[..]].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 = 10;
let asset_value = 10;
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()[..]);

// 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::<Test>::InvalidSignature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amarts Currently InvalidSignature is not being used/checked in Asset pallet, but it is part of error enum list. Should we either implement it in asset(which I feel is not required) or remove it from error enum list.

);
});
}
Loading