Skip to content

Commit

Permalink
Fixes: #318 Add test cases for PresentationDigestAlreadyAnchored error (
Browse files Browse the repository at this point in the history
#542)

Signed-off-by: Vaibhav <[email protected]>
  • Loading branch information
Vaibhavsahu2810 authored Jan 2, 2025
1 parent b634cde commit 6fa1f04
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions pallets/statement/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,3 +1296,66 @@ fn nonexistent_presentation_should_fail() {
);
});
}

#[test]
fn adding_duplicate_presentation_should_fail() {
let creator = DID_00;
let author = ACCOUNT_00;
let capacity = 5u64;
let statement = [77u8; 32];
let statement_digest = <Test as frame_system::Config>::Hashing::hash(&statement[..]);

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 statement_id_digest = <Test as frame_system::Config>::Hashing::hash(
&[&statement_digest.encode()[..], &space_id.encode()[..], &creator.encode()[..]].concat()[..],
);
let statement_id: StatementIdOf = generate_statement_id::<Test>(&statement_id_digest);
let presentation = [88u8; 32];
let presentation_digest = <Test as frame_system::Config>::Hashing::hash(&presentation[..]);
let presentation_type = PresentationTypeOf::Other;

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_ok!(Statement::register(
DoubleOrigin(author.clone(), creator.clone()).into(),
statement_digest,
authorization_id.clone(),
None
));
assert_ok!(Statement::add_presentation(
DoubleOrigin(author.clone(), creator.clone()).into(),
statement_id.clone(), // Use the generated statement_id
presentation_digest,
presentation_type,
authorization_id.clone(),
));

assert_err!(
Statement::add_presentation(
DoubleOrigin(author, creator).into(),
statement_id, // Use the generated statement_id
presentation_digest,
presentation_type,
authorization_id,
),
Error::<Test>::PresentationDigestAlreadyAnchored
);
});
}

0 comments on commit 6fa1f04

Please sign in to comment.