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

Improved Tests for Schema Size Limit (Issue #312)(Adding Test max encoded schema limit exceeded to pallet/schema) #435

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
27 changes: 27 additions & 0 deletions pallets/schema/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,30 @@ fn test_schema_lookup() {
}
});
}

#[test]
fn test_max_encoded_schema_limit_exceeded_create() {
// Arrange
let mut mock_storage = MockStorage::new();

// Act
let large_schema_data = vec![0u8; <Test as frame_system::Config>::MaxEncodedSchemaLength + 1];
Copy link
Member

Choose a reason for hiding this comment

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

@HarishKarthickS I don't think this can be done, as the input is compiled to be of type BoundedVec and not just Vec, where MaxEncodedSchemaLength + 1 is impossible due to below,
pub type InputSchemaOf<T> = BoundedVec<u8, <T as Config>::MaxEncodedSchemaLength>;
but it is possible for MaxEncodedSchemaLength - 1 to take place with a BoundedVec since it will be below threshold input set limit.

let result =
Schema::create(Origin::signed(DID_00), large_schema_data.clone(), Default::default());

// Assert
assert_eq!(result.err().unwrap(), Error::<Test>::MaxEncodedSchemaLimitExceeded,);
}

#[test]
fn test_max_encoded_schema_limit_exceeded_edge_case() {
// Arrange (similar to above)

// Act
let almost_large_data = vec![0u8; <Test as frame_system::Config>::MaxEncodedSchemaLength - 1];
let result =
Schema::create(Origin::signed(DID_00), almost_large_data.clone(), Default::default());

// Assert
assert!(result.is_ok()); // Should not exceed limit
}
Loading