-
Notifications
You must be signed in to change notification settings - Fork 53
test(dpp): restore ~60 commented-out/ignored tests #3122
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
base: v3.1-dev
Are you sure you want to change the base?
Changes from all commits
b89ee50
8ca16bf
aa7ad1c
cd85514
5ab0af8
85ba7cd
f42d3c7
a1ba1b7
b30d0ff
ea12ed9
002718e
e2ee8c3
e2cf13e
bdb24bf
5d7c830
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,11 @@ pub use traversal_validator::*; | |
| #[cfg(test)] | ||
| mod test { | ||
| use super::*; | ||
| use crate::consensus::basic::data_contract::IncompatibleRe2PatternError; | ||
| use crate::consensus::basic::json_schema_compilation_error::JsonSchemaCompilationError; | ||
| use crate::consensus::basic::BasicError; | ||
| use crate::consensus::codes::ErrorWithCode; | ||
| use crate::consensus::ConsensusError; | ||
| use assert_matches::assert_matches; | ||
| use platform_value::{platform_value, Value}; | ||
| use platform_version::version::PlatformVersion; | ||
|
|
||
|
|
@@ -17,9 +18,100 @@ mod test { | |
| .try_init(); | ||
| } | ||
|
|
||
| #[ignore] | ||
| // ---------------------------------------------------------------- | ||
| // Test-only sub-validator callbacks. | ||
| // | ||
| // IMPORTANT: The helpers below are NOT production validators and | ||
| // are NOT wired into document-type validation. Production | ||
| // document-type schema validation does not use `traversal_validator` | ||
| // at all — it relies on `validate_max_depth`, JSON Schema meta-schema | ||
| // validation, and `json_schema_validator.compile()`. | ||
| // | ||
| // These callbacks exist solely as fixtures to exercise the | ||
| // `traversal_validator` mechanism: they prove that traversal walks | ||
| // every map/array node, invokes each provided sub-validator with the | ||
| // expected `(path, key, parent, value)` arguments, and that any | ||
| // `ConsensusError`s a callback adds (or `ProtocolError`s it returns) | ||
| // are propagated correctly. They happen to be shaped after legacy | ||
| // validators (byteArray-with-items, regex compatibility) only because | ||
| // those produce well-known consensus error variants that are | ||
| // convenient to assert on; do not read the assertions below as | ||
| // coverage of the corresponding production validation rules. | ||
| // ---------------------------------------------------------------- | ||
|
|
||
| /// Test callback fixture: when traversal visits a map that contains | ||
| /// `"byteArray"` alongside `"items"` or `"prefixItems"`, emit a | ||
| /// `JsonSchemaCompilationError`. Used purely to verify the traversal | ||
| /// mechanism propagates consensus errors added by callbacks; this is | ||
| /// not the production byteArray-vs-items rule. | ||
| fn test_callback_flag_byte_array_with_items( | ||
| path: &str, | ||
| key: &str, | ||
| parent: &Value, | ||
| _value: &Value, | ||
| result: &mut crate::validation::SimpleConsensusValidationResult, | ||
| _platform_version: &PlatformVersion, | ||
| ) -> Result<(), crate::ProtocolError> { | ||
| if key != "byteArray" { | ||
| return Ok(()); | ||
| } | ||
| let Value::Map(parent_map) = parent else { | ||
| return Ok(()); | ||
| }; | ||
| let has_items = parent_map.iter().any( | ||
| |(k, _)| matches!(k.to_str(), Ok(name) if name == "items" || name == "prefixItems"), | ||
| ); | ||
| if has_items { | ||
| let message = format!( | ||
| "invalid path: '{}': byteArray cannot be used with `items` or `prefixItems`", | ||
| path | ||
| ); | ||
| result.add_error(ConsensusError::BasicError( | ||
| BasicError::JsonSchemaCompilationError(JsonSchemaCompilationError::new(message)), | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Test callback fixture: when traversal visits a `"pattern"` string | ||
| /// that fails to compile under Rust's `regex` crate (which, like | ||
| /// Re2, rejects lookarounds), emit an `IncompatibleRe2PatternError`. | ||
| /// Used purely to verify the traversal mechanism propagates | ||
| /// consensus errors added by callbacks; this is not the production | ||
| /// pattern-validation rule. | ||
| fn test_callback_flag_invalid_regex_pattern( | ||
| path: &str, | ||
| key: &str, | ||
| _parent: &Value, | ||
| value: &Value, | ||
| result: &mut crate::validation::SimpleConsensusValidationResult, | ||
| _platform_version: &PlatformVersion, | ||
| ) -> Result<(), crate::ProtocolError> { | ||
| if key != "pattern" { | ||
| return Ok(()); | ||
| } | ||
| let Value::Text(pattern) = value else { | ||
| return Ok(()); | ||
| }; | ||
| if let Err(err) = regex::Regex::new(pattern) { | ||
| result.add_error(ConsensusError::BasicError( | ||
| BasicError::IncompatibleRe2PatternError(IncompatibleRe2PatternError::new( | ||
| pattern.clone(), | ||
| path.to_string(), | ||
| err.to_string(), | ||
| )), | ||
| )); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
Comment on lines
+21
to
+106
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Recursive-schema rejection tests now exercise test-local mirrors, not production validation The restored byteArray/regex rejection tests define source: ['codex-general'] 🤖 Fix this with AI agents |
||
|
|
||
| #[test] | ||
| fn should_return_error_if_bytes_array_parent_contains_items_or_prefix_items() { | ||
| fn traversal_propagates_byte_array_callback_errors_for_each_offending_parent() { | ||
| // Verifies traversal-mechanism behavior only: that the test | ||
| // callback is invoked at every map node and that each | ||
| // ConsensusError it adds reaches the result. Does not assert | ||
| // anything about production document-type byteArray validation, | ||
| // which does not run through traversal_validator. | ||
| let schema: Value = platform_value!( | ||
| { | ||
| "type": "object", | ||
|
|
@@ -36,25 +128,31 @@ mod test { | |
| "additionalProperties": false, | ||
| } | ||
| ); | ||
| let mut result = traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to succeed"); | ||
| let mut result = traversal_validator( | ||
| &schema, | ||
| &[test_callback_flag_byte_array_with_items], | ||
| PlatformVersion::first(), | ||
| ) | ||
| .expect("expected traversal validator to succeed"); | ||
| assert_eq!(2, result.errors.len()); | ||
| let first_error = get_basic_error(result.errors.pop().unwrap()); | ||
| let second_error = get_basic_error(result.errors.pop().unwrap()); | ||
|
|
||
| assert_matches!( | ||
| assert!(matches!( | ||
| first_error, | ||
| BasicError::JsonSchemaCompilationError(msg) if msg.compilation_error().starts_with("invalid path: '/properties/bar': byteArray cannot") | ||
| ); | ||
| assert_matches!( | ||
| BasicError::JsonSchemaCompilationError(msg) if msg.compilation_error().starts_with("invalid path: '/properties/bar': byteArray cannot"), | ||
| )); | ||
| assert!(matches!( | ||
| second_error, | ||
| BasicError::JsonSchemaCompilationError(msg) if msg.compilation_error().starts_with("invalid path: '/properties': byteArray cannot") | ||
| ); | ||
| BasicError::JsonSchemaCompilationError(msg) if msg.compilation_error().starts_with("invalid path: '/properties': byteArray cannot"), | ||
| )); | ||
| } | ||
|
|
||
| #[ignore] | ||
| #[test] | ||
| fn should_return_valid_result() { | ||
| fn traversal_pattern_callback_adds_no_errors_for_compilable_regex() { | ||
| // Traversal-mechanism check only: verifies the test callback | ||
| // returns no errors when every visited "pattern" compiles. | ||
| // Not a production pattern-validation assertion. | ||
| let schema: Value = platform_value!( | ||
| { | ||
| "type": "object", | ||
|
|
@@ -69,63 +167,79 @@ mod test { | |
| "additionalProperties": false, | ||
| } | ||
| ); | ||
| assert!(traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to succeed") | ||
| .is_valid()); | ||
| assert!(traversal_validator( | ||
| &schema, | ||
| &[test_callback_flag_invalid_regex_pattern], | ||
| PlatformVersion::first() | ||
| ) | ||
| .expect("expected traversal validator to succeed") | ||
| .is_valid()); | ||
| } | ||
|
|
||
| #[ignore] | ||
| #[test] | ||
| fn should_return_invalid_result() { | ||
| fn traversal_propagates_pattern_callback_error_for_top_level_uncompilable_regex() { | ||
| // Traversal-mechanism check only: confirms the IncompatibleRe2 | ||
| // ConsensusError that the test callback emits propagates with | ||
| // the correct path/pattern. Production document-type schema | ||
| // validation does not invoke traversal_validator. | ||
| let unsafe_pattern = "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$"; | ||
| let schema: Value = platform_value!({ | ||
| "type": "object", | ||
| "properties": { | ||
| "foo": { "type": "integer" }, | ||
| "bar": { | ||
| "type": "string", | ||
| "pattern": "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$", | ||
| "pattern": unsafe_pattern, | ||
| }, | ||
| }, | ||
| "required": ["foo"], | ||
| "additionalProperties": false, | ||
|
|
||
| }); | ||
| let result = traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to succeed"); | ||
| let result = traversal_validator( | ||
| &schema, | ||
| &[test_callback_flag_invalid_regex_pattern], | ||
| PlatformVersion::first(), | ||
| ) | ||
| .expect("expected traversal validator to succeed"); | ||
| let consensus_error = result.errors.first().expect("the error should be returned"); | ||
|
|
||
| match consensus_error { | ||
| ConsensusError::BasicError(BasicError::IncompatibleRe2PatternError(err)) => { | ||
| assert_eq!(err.path(), "/properties/bar".to_string()); | ||
| assert_eq!( | ||
| err.pattern(), | ||
| "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$".to_string() | ||
| ); | ||
| assert_eq!(err.pattern(), unsafe_pattern.to_string()); | ||
| assert_eq!(consensus_error.code(), 10202); | ||
| } | ||
| _ => panic!("Expected error to be IncompatibleRe2PatternError"), | ||
| } | ||
| } | ||
|
|
||
| #[ignore] | ||
| #[test] | ||
| fn should_be_valid_complex_for_complex_schema() { | ||
| fn traversal_with_no_validators_visits_complex_schema_without_errors() { | ||
| let schema = get_document_schema(); | ||
|
|
||
| assert!(traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to exist for first protocol version") | ||
| .is_valid()) | ||
| } | ||
|
|
||
| #[ignore] | ||
| #[test] | ||
| fn invalid_result_for_array_of_object() { | ||
| fn traversal_propagates_pattern_callback_error_inside_array_items_object() { | ||
| // Traversal-mechanism check only: confirms traversal descends | ||
| // into `items` of an array-of-object schema and that the test | ||
| // callback's ConsensusError carries the expected path. | ||
| // Not a production pattern-validation assertion. | ||
| let unsafe_pattern = "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$"; | ||
| let mut schema = get_document_schema(); | ||
| schema["properties"]["arrayOfObject"]["items"]["properties"]["simple"]["pattern"] = | ||
| platform_value!("^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$"); | ||
|
|
||
| let result = traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to exist for first protocol version"); | ||
| platform_value!(unsafe_pattern); | ||
|
|
||
| let result = traversal_validator( | ||
| &schema, | ||
| &[test_callback_flag_invalid_regex_pattern], | ||
| PlatformVersion::first(), | ||
| ) | ||
| .expect("expected traversal validator to exist for first protocol version"); | ||
| let consensus_error = result.errors.first().expect("the error should be returned"); | ||
|
|
||
| match consensus_error { | ||
|
|
@@ -134,25 +248,30 @@ mod test { | |
| err.path(), | ||
| "/properties/arrayOfObject/items/properties/simple".to_string() | ||
| ); | ||
| assert_eq!( | ||
| err.pattern(), | ||
| "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$".to_string() | ||
| ); | ||
| assert_eq!(err.pattern(), unsafe_pattern.to_string()); | ||
| assert_eq!(consensus_error.code(), 10202); | ||
| } | ||
| _ => panic!("Expected error to be IncompatibleRe2PatternError"), | ||
| } | ||
| } | ||
|
|
||
| #[ignore] | ||
| #[test] | ||
| fn invalid_result_for_array_of_objects() { | ||
| fn traversal_propagates_pattern_callback_error_inside_array_items_tuple() { | ||
| // Traversal-mechanism check only: confirms traversal descends | ||
| // into the indexed entries of a tuple-form `items` array and | ||
| // that the path passed to the test callback includes the | ||
| // numeric index. Not a production pattern-validation assertion. | ||
| let unsafe_pattern = "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$"; | ||
| let mut schema = get_document_schema(); | ||
| schema["properties"]["arrayOfObjects"]["items"][0]["properties"]["simple"]["pattern"] = | ||
| platform_value!("^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$"); | ||
|
|
||
| let result = traversal_validator(&schema, &[], PlatformVersion::first()) | ||
| .expect("expected traversal validator to exist for first protocol version"); | ||
| platform_value!(unsafe_pattern); | ||
|
|
||
| let result = traversal_validator( | ||
| &schema, | ||
| &[test_callback_flag_invalid_regex_pattern], | ||
| PlatformVersion::first(), | ||
| ) | ||
| .expect("expected traversal validator to exist for first protocol version"); | ||
| let consensus_error = result.errors.first().expect("the error should be returned"); | ||
|
|
||
| match consensus_error { | ||
|
|
@@ -161,16 +280,20 @@ mod test { | |
| err.path(), | ||
| "/properties/arrayOfObjects/items/[0]/properties/simple".to_string() | ||
| ); | ||
| assert_eq!( | ||
| err.pattern(), | ||
| "^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$".to_string() | ||
| ); | ||
| assert_eq!(err.pattern(), unsafe_pattern.to_string()); | ||
| assert_eq!(consensus_error.code(), 10202); | ||
| } | ||
| _ => panic!("Expected error to be IncompatibleRe2PatternError"), | ||
| } | ||
| } | ||
|
|
||
| fn get_basic_error(error: ConsensusError) -> BasicError { | ||
| if let ConsensusError::BasicError(err) = error { | ||
| return err; | ||
| } | ||
| panic!("the error: {:?} isn't a BasicError", error) | ||
| } | ||
|
Comment on lines
108
to
295
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Several un-ignored validator tests now assert the opposite of what their names describe Four tests were brought back from source: ['claude'] 🤖 Fix this with AI agents
Comment on lines
108
to
295
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Suggestion: Restored traversal_validator tests no longer assert original error variants The original commented-out versions of source: ['claude'] 🤖 Fix this with AI agents |
||
|
|
||
| fn get_document_schema() -> Value { | ||
| platform_value!({ | ||
| "properties": { | ||
|
|
@@ -251,13 +374,6 @@ mod test { | |
| }) | ||
| } | ||
|
|
||
| fn get_basic_error(error: ConsensusError) -> BasicError { | ||
| if let ConsensusError::BasicError(err) = error { | ||
| return err; | ||
| } | ||
| panic!("the error: {:?} isn't a BasicError", error) | ||
| } | ||
|
|
||
| // ================================================================ | ||
| // New tests that actually run (not #[ignore]'d) to cover the | ||
| // traversal_validator_v0 traversal logic. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: The restored recursive-schema rejection tests exercise test-local validator copies rather than production validation
The restored tests now define
byte_array_has_no_items_as_parent_validatorandpattern_is_valid_regex_validatorinside the test module, and the in-file comment explicitly says the original production modules were removed and these helpers exist only to preserve the historical assertions. A repository search shows these validators do not exist anywhere outside this test file. That means the named rejection cases no longer protect production byte-array or regex validation behavior; they only verify thattraversal_validatorinvokes arbitrary callbacks and propagates the constructed consensus errors. That is useful traversal coverage, but it is narrower than the test names and comments imply.source: ['claude']
🤖 Fix this with AI agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on the scope here. I did not reintroduce removed production validator modules just to satisfy these tests; those validators no longer exist outside this test file. I kept the traversal/error-propagation coverage test-local and only made small clarity adjustments around the surrounding traversal-only cases, while fixing the other actionable findings (toolchain churn, duplicate constant, and fixed external JSON fixture coverage).