Skip to content

Conversation

@JiyaGupta-cs
Copy link
Contributor

@JiyaGupta-cs JiyaGupta-cs commented Sep 13, 2024

Fixes #301

Description

This pull request adds test coverage for the ReferenceIdentifierNotFound error in the pallet-network-score module.

Changes Made

Added a new test case to assert the correct return of the ReferenceIdentifierNotFound error in various calls across the pallet-network-score.
Ensured that all functions which can return this error are validated, either individually or collectively in a single test.

Implementation Details

Followed the structure and approach of existing test cases
Tests were run and verified using cargo test -p pallet-network-score test

Screenshots

dhiway

@zeel991
Copy link
Contributor

zeel991 commented Sep 14, 2024

Hey @JiyaGupta-cs , you can go to the src folder of network-score pallet and run the command

rustfmt tests.rs

To pass the rustfmt github action

@JiyaGupta-cs
Copy link
Contributor Author

@zeel991 I have done rustfmt for tests.rs now
Please review it again

@zeel991
Copy link
Contributor

zeel991 commented Sep 15, 2024

hey @JiyaGupta-cs , In the revise rating function , you are trying to return ReferenceNotDebitIdentifier rather than ReferenceIdentifierNotfound error .
To return ReferenceIdentifierNotfound , try registering and revoking the ratings and then remove the identifier created from the digest id of revoke rating function , then try revising the rating , you will get the correct error

println!("Revise rating result: {:?}", result);

// Check for the correct error
assert_err!(result, Error::<Test>::ReferenceNotDebitIdentifier);
Copy link
Contributor

Choose a reason for hiding this comment

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

Change the error returned to ReferenceIdentifierNotFound

message_id.clone(),
authorization_id.clone(),
));

Copy link
Contributor

Choose a reason for hiding this comment

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

Refer the revise_rating_with_existing_rating_identifier_should_fail() method in the tests.rs file to correctly call the revoke_rating function

@JiyaGupta-cs
Copy link
Contributor Author

@zeel991 Now. I have fixed all the errors as mentioned
I have successfully registered the rating and revoked the rating , and then removed message id, then removed the identifier from the RatingEntries storage to trigger the ReferenceIdentifierFotFound error while revising the rating

Comment on lines +699 to +700
let auth_digest = <Test as frame_system::Config>::Hashing::hash(
&[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..],
Copy link
Contributor

Choose a reason for hiding this comment

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

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
		&[&space_id.encode()[..], &creator.encode()[..]].concat()[..],
	);

Correct this declaration of auth_digest , or else it will give AuthorizationNotFound Error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In all other functions too

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
		&[&space_id.encode()[..], &creator.encode()[..], &creator.encode()[..]].concat()[..],
	);

this is used

on using the below snippet does not meet the requirements

let auth_digest = <Test as frame_system::Config>::Hashing::hash(
		&[&space_id.encode()[..], &creator.encode()[..]].concat()[..],
	);

Copy link
Contributor

Choose a reason for hiding this comment

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

where is the first code snippet used elsewhere , I got this

Screenshot 2024-09-16 210759

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sir my test is running fine, because if we give only two requirements as mentioned by you , the length would be short then it would give error. but the snippet which I have used is running error-free

Copy link
Contributor

Choose a reason for hiding this comment

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

Sir my test is running fine, because if we give only two requirements as mentioned by you , the length would be short then it would give error. but the snippet which I have used is running error-free

Sir my test is running fine, because if we give only two requirements as mentioned by you , the length would be short then it would give error. but the snippet which I have used is running error-free

Sir my test is running fine, because if we give only two requirements as mentioned by you , the length would be short then it would give error. but the snippet which I have used is running error-free

Can you run this command and check if the tests are running error-free

cargo test --release --locked --features=runtime-benchmarks --no-fail-fast --verbose --color always -p pallet-network-score --lib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

by this command also its working fine
Screenshot -
image

Copy link
Collaborator

@vatsa287 vatsa287 left a comment

Choose a reason for hiding this comment

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

lib.rs changes are not required for this test change.

Copy link
Collaborator

@vatsa287 vatsa287 left a comment

Choose a reason for hiding this comment

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

Rebase your branch with develop:latest to avoid conflicts. As changes have been made into this file recently.

@JiyaGupta-cs
Copy link
Contributor Author

@zeel991 @vatsa287
I have removed the changes of lib.rs
And the tests are working error-free

image

@zeel991
Copy link
Contributor

zeel991 commented Sep 16, 2024

@zeel991 @vatsa287 I have removed the changes of lib.rs And the tests are working error-free

image

Interesting , it seems your test is working on linux , but throws error on windows , @vatsa287 can you look into this please

@JiyaGupta-cs
Copy link
Contributor Author

JiyaGupta-cs commented Sep 16, 2024

@zeel991 @vatsa287 I have removed the changes of lib.rs And the tests are working error-free
image

Interesting , it seems your test is working on linux , but throws error on windows , @vatsa287 can you look into this please

Sir it's the last day for the PR to get merged in Augtoberfest in C4GT @zeel991 @vatsa287

Copy link
Collaborator

@vatsa287 vatsa287 left a comment

Choose a reason for hiding this comment

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

LGTM

@vatsa287 vatsa287 requested a review from amarts September 17, 2024 09:08
@JiyaGupta-cs
Copy link
Contributor Author

@amarts Please review and merge the PR

@amarts amarts merged commit 2be737e into dhiway:develop Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C4GT] Network-Score: Add tests for ReferenceIdentifierNotFound

4 participants