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 test for PeerIdTooLong and clean up code #541

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"pallets/did",
Copy link
Member

Choose a reason for hiding this comment

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

Changes made here is not required as well.

"pallets/did-name",
"pallets/identity",
"pallets/network-authorization",
"pallets/network-membership",
"pallets/network-score",
"pallets/node-authorization",
Expand Down Expand Up @@ -155,6 +156,8 @@ pallet-transaction-weight-runtime-api = { path = "runtimes/common/api/weight", d
pallet-registries = { path = "pallets/registries", default-features = false }
pallet-entries = { path = "pallets/entries", default-features = false }
pallet-schema-accounts = { path = "pallets/schema-accounts", default-features = false }
pallet-network-authorization = { path = "pallets/network-authorization" }



# substrate dependencies
Expand Down
16 changes: 16 additions & 0 deletions pallets/node-authorization/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,19 @@ fn test_generate_peer_id_invalid_utf8() {
let invalid_node_id: NodeId = vec![0xFF, 0xFE, 0xFD];
assert_err!(NodeAuthorization::generate_peer_id(&invalid_node_id), Error::<Test>::InvalidUtf8);
}

// the test to check that the PeerId not too long.
#[test]
HasanZaigam marked this conversation as resolved.
Show resolved Hide resolved
fn add_well_known_node_with_peer_id_too_long_should_fail() {
new_test_ext().execute_with(|| {
// Attempt to add a node with an excessively long peer ID
assert_noop!(
NodeAuthorization::add_well_known_node(
RuntimeOrigin::signed(1),
test_node(TEST_NODE_LEN), // Exceeds max length
15
),
Error::<Test>::PeerIdTooLong
);
});
}
2 changes: 1 addition & 1 deletion test-utils/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
interval.tick().await;

if full_nodes.iter().all(|(id, service, _, _)| full_predicate(*id, service)) {
break
break;
Copy link
Member

Choose a reason for hiding this comment

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

This change is not required as it is the last statement in the block in Rust.

}
}
};
Expand Down
Loading