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 2 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
45 changes: 45 additions & 0 deletions pallets/schema/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,48 @@ fn test_schema_lookup() {
}
});
}

#[cfg(test)]
HarishKarthickS marked this conversation as resolved.
Show resolved Hide resolved
mod tests {
// This module contains unit tests for the `pallet/schema` module.
// Unit tests are isolated tests that focus on the functionality of a single module
// and are typically run during development and testing to ensure the module
// behaves as expected.
// The `#[cfg(test)]` attribute ensures this module is only compiled when the
// `test` feature is enabled.
use super::*;
use mock::MockStorage; // Assuming you have a mock for storage

#[test]
fn test_max_encoded_schema_limit_exceeded_create() {
// Arrange
let mut mock_storage = MockStorage::new();
const MAX_SCHEMA_SIZE: usize = 1024; // Replace with the actual value

// Act
let large_schema_data = vec![0u8; MAX_SCHEMA_SIZE + 1];
let result = Schema::create(
Origin::signed(DID_00), // Replace with appropriate origin type
large_schema_data.clone(),
Default::default(),
);

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

// Add similar test cases for other functions that might return the error

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

// Act
let almost_large_data = vec![0u8; MAX_SCHEMA_SIZE - 1];
let result =
Schema::create(Origin::signed(DID_00), almost_large_data.clone(), Default::default());

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