Skip to content

Commit 2dcd559

Browse files
authored
Add test for invalid UTF8 (#508)
* fix the testcase * change assert_noop to assert_err * Fix fmt issue
1 parent 828770a commit 2dcd559

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pallets/node-authorization/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ pub mod pallet {
150150
}
151151

152152
#[pallet::error]
153+
#[derive(PartialEq)]
153154
pub enum Error<T> {
154155
/// The Node identifier is too long.
155156
NodeIdTooLong,

pallets/node-authorization/src/tests.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
2323
use super::*;
2424
use crate::mock::*;
25-
use frame_support::{assert_noop, assert_ok};
25+
use frame_support::{assert_err, assert_noop, assert_ok};
2626
use sp_runtime::traits::BadOrigin;
2727

2828
#[test]
@@ -453,3 +453,9 @@ fn adding_already_connected_connection_should_fail() {
453453
);
454454
});
455455
}
456+
457+
#[test]
458+
fn test_generate_peer_id_invalid_utf8() {
459+
let invalid_node_id: NodeId = vec![0xFF, 0xFE, 0xFD];
460+
assert_err!(NodeAuthorization::generate_peer_id(&invalid_node_id), Error::<Test>::InvalidUtf8);
461+
}

0 commit comments

Comments
 (0)