Skip to content

Commit

Permalink
Change made according to the review
Browse files Browse the repository at this point in the history
  • Loading branch information
HarishKarthickS committed Apr 27, 2024
1 parent 63d1ff3 commit 3387095
Showing 1 changed file with 20 additions and 38 deletions.
58 changes: 20 additions & 38 deletions pallets/schema/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,47 +315,29 @@ fn test_schema_lookup() {
});
}

#[cfg(test)]
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(),
);
#[test]
fn test_max_encoded_schema_limit_exceeded_create() {
// Arrange
let mut mock_storage = MockStorage::new();

// Assert
assert_eq!(result.err().unwrap(), Error::<Test>::MaxEncodedSchemaLimitExceeded,);
}
// Act
let large_schema_data = vec![0u8; <Test as frame_system::Config>::MaxEncodedSchemaLength + 1];
let result =
Schema::create(Origin::signed(DID_00), large_schema_data.clone(), Default::default());

// Add similar test cases for other functions that might return the error
// Assert
assert_eq!(result.err().unwrap(), Error::<Test>::MaxEncodedSchemaLimitExceeded,);
}

#[test]
fn test_max_encoded_schema_limit_exceeded_edge_case() {
// Arrange (similar to above)
#[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());
// 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
}
// Assert
assert!(result.is_ok()); // Should not exceed limit
}

0 comments on commit 3387095

Please sign in to comment.