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

tests.rs #406

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 28 additions & 0 deletions pallets/did/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2870,3 +2870,31 @@ fn check_invalid_signature_operation_verification() {
);
});
}

// This test case will help ensure that the InvalidDidAuthorizationCall error is properly handled in the pallet-did module
//when attempting to make an invalid DID authorization call.
#[test]
fn check_invalid_did_authorization_call() {
// Generate authentication keys for DIDs
let auth_key = get_sr25519_authentication_key(&AUTH_SEED_0);
let alice_did = get_did_identifier_from_sr25519_key(auth_key.public());

// Create a base DID creation details
let details = generate_base_did_creation_details::<Test>(alice_did, ACCOUNT_00);

// Sign the details with an invalid key
let invalid_key = get_sr25519_authentication_key(&AUTH_SEED_1); // Using a different key
let signature = invalid_key.sign(details.encode().as_ref());

new_test_ext().execute_with(|| {
// Attempt to create a DID with an invalid signature
assert_noop!(
Did::create(
RuntimeOrigin::signed(ACCOUNT_00),
Box::new(details),
did::DidSignature::from(signature)
),
did::Error::<Test>::InvalidDidAuthorizationCall
);
});
}