Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::data_contract::serialized_version::property_names;
use crate::version::PlatformVersion;
use crate::ProtocolError;
use platform_value::Value;

pub const DATA_CONTRACT_IDENTIFIER_FIELDS_V0: [&str; 2] =
[property_names::ID, property_names::OWNER_ID];

pub trait DataContractValueConversionMethodsV0 {
fn from_value(
raw_object: Value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,13 +840,14 @@ mod tests {
let config = DataContractConfig::default_for_version(platform_version)
.expect("should create a default config");

let result = DocumentTypeV0::try_from_schema(
let result = DocumentTypeV1::try_from_schema(
Identifier::new([1; 32]),
1,
config.version(),
"invalid name",
schema.clone(),
None,
&BTreeMap::new(),
&config,
true,
&mut vec![],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pub use traversal_validator::*;
#[cfg(test)]
mod test {
use super::*;
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;

Expand All @@ -17,7 +13,6 @@ mod test {
.try_init();
}

#[ignore]
#[test]
fn should_return_error_if_bytes_array_parent_contains_items_or_prefix_items() {
let schema: Value = platform_value!(
Expand All @@ -36,23 +31,11 @@ mod test {
"additionalProperties": false,
}
);
let mut result = traversal_validator(&schema, &[], 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!(
first_error,
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")
);
assert!(traversal_validator(&schema, &[], PlatformVersion::first())
.expect("expected traversal validator to succeed")
.is_valid());
}

#[ignore]
#[test]
fn should_return_valid_result() {
let schema: Value = platform_value!(
Expand All @@ -74,7 +57,6 @@ mod test {
.is_valid());
}

#[ignore]
#[test]
fn should_return_invalid_result() {
let schema: Value = platform_value!({
Expand All @@ -90,24 +72,11 @@ mod test {
"additionalProperties": false,

});
let result = traversal_validator(&schema, &[], 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!(consensus_error.code(), 10202);
}
_ => panic!("Expected error to be IncompatibleRe2PatternError"),
}
assert!(traversal_validator(&schema, &[], PlatformVersion::first())
.expect("expected traversal validator to succeed")
.is_valid());
}

#[ignore]
#[test]
fn should_be_valid_complex_for_complex_schema() {
let schema = get_document_schema();
Expand All @@ -117,58 +86,26 @@ mod test {
.is_valid())
}

#[ignore]
#[test]
fn invalid_result_for_array_of_object() {
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");
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/arrayOfObject/items/properties/simple".to_string()
);
assert_eq!(
err.pattern(),
"^((?!-|_)[a-zA-Z0-9-_]{0,62}[a-zA-Z0-9])$".to_string()
);
assert_eq!(consensus_error.code(), 10202);
}
_ => panic!("Expected error to be IncompatibleRe2PatternError"),
}
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_objects() {
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");
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/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!(consensus_error.code(), 10202);
}
_ => panic!("Expected error to be IncompatibleRe2PatternError"),
}
assert!(traversal_validator(&schema, &[], PlatformVersion::first())
.expect("expected traversal validator to exist for first protocol version")
.is_valid());
}

fn get_document_schema() -> Value {
Expand Down Expand Up @@ -250,11 +187,4 @@ 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)
}
}
Loading
Loading