Skip to content

refactor: rename validate to full_validation #1845

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

Merged
merged 1 commit into from
May 13, 2024
Merged
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
10 changes: 6 additions & 4 deletions packages/rs-dpp/src/data_contract/conversion/cbor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl DataContractCborConversionMethodsV0 for DataContract {
fn from_cbor_with_id(
cbor_bytes: impl AsRef<[u8]>,
contract_id: Option<Identifier>,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
match platform_version
Expand All @@ -23,7 +23,7 @@ impl DataContractCborConversionMethodsV0 for DataContract {
0 => Ok(DataContractV0::from_cbor_with_id(
cbor_bytes,
contract_id,
validate,
full_validation,
platform_version,
)?
.into()),
Expand All @@ -37,15 +37,17 @@ impl DataContractCborConversionMethodsV0 for DataContract {

fn from_cbor(
cbor_bytes: impl AsRef<[u8]>,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
match platform_version
.dpp
.contract_versions
.contract_structure_version
{
0 => Ok(DataContractV0::from_cbor(cbor_bytes, validate, platform_version)?.into()),
0 => Ok(
DataContractV0::from_cbor(cbor_bytes, full_validation, platform_version)?.into(),
),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContract::from_cbor".to_string(),
known_versions: vec![0],
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-dpp/src/data_contract/conversion/cbor/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pub trait DataContractCborConversionMethodsV0 {
fn from_cbor_with_id(
cbor_bytes: impl AsRef<[u8]>,
contract_id: Option<Identifier>,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Self: Sized;
fn from_cbor(
cbor_bytes: impl AsRef<[u8]>,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Expand Down
6 changes: 4 additions & 2 deletions packages/rs-dpp/src/data_contract/conversion/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_json::Value as JsonValue;
impl DataContractJsonConversionMethodsV0 for DataContract {
fn from_json(
json_value: JsonValue,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Expand All @@ -21,7 +21,9 @@ impl DataContractJsonConversionMethodsV0 for DataContract {
.contract_versions
.contract_structure_version
{
0 => Ok(DataContractV0::from_json(json_value, validate, platform_version)?.into()),
0 => Ok(
DataContractV0::from_json(json_value, full_validation, platform_version)?.into(),
),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContract::from_json_object".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_json::Value as JsonValue;
pub trait DataContractJsonConversionMethodsV0 {
fn from_json(
json_value: JsonValue,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Expand Down
6 changes: 4 additions & 2 deletions packages/rs-dpp/src/data_contract/conversion/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@ use platform_value::Value;
impl DataContractValueConversionMethodsV0 for DataContract {
fn from_value(
raw_object: Value,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
match platform_version
.dpp
.contract_versions
.contract_structure_version
{
0 => Ok(DataContractV0::from_value(raw_object, validate, platform_version)?.into()),
0 => Ok(
DataContractV0::from_value(raw_object, full_validation, platform_version)?.into(),
),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContract::from_object".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use platform_value::Value;
pub trait DataContractValueConversionMethodsV0 {
fn from_value(
raw_object: Value,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Expand Down
15 changes: 9 additions & 6 deletions packages/rs-dpp/src/data_contract/created_data_contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl PlatformSerializableWithPlatformVersion for CreatedDataContract {
impl PlatformDeserializableWithPotentialValidationFromVersionedStructure for CreatedDataContract {
fn versioned_deserialize(
data: &[u8],
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError>
where
Expand All @@ -104,7 +104,7 @@ impl PlatformDeserializableWithPotentialValidationFromVersionedStructure for Cre
created_data_contract_in_serialization_format.data_contract_and_identity_nonce_owned();
let data_contract = DataContract::try_from_platform_versioned(
data_contract_in_serialization_format,
validate,
full_validation,
&mut vec![],
platform_version,
)?;
Expand Down Expand Up @@ -198,17 +198,20 @@ impl CreatedDataContract {
#[cfg(feature = "data-contract-value-conversion")]
pub fn from_object(
raw_object: Value,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
match platform_version
.dpp
.contract_versions
.created_data_contract_structure
{
0 => Ok(
CreatedDataContractV0::from_object(raw_object, validate, platform_version)?.into(),
),
0 => Ok(CreatedDataContractV0::from_object(
raw_object,
full_validation,
platform_version,
)?
.into()),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "CreatedDataContract::from_object".to_string(),
known_versions: vec![0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl CreatedDataContractV0 {
#[cfg(feature = "data-contract-value-conversion")]
pub fn from_object(
raw_object: Value,
validate: bool,
full_validation: bool,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
let mut raw_map = raw_object
Expand All @@ -48,7 +48,7 @@ impl CreatedDataContractV0 {
.map_err(ProtocolError::ValueError)?;

let data_contract =
DataContract::from_value(raw_data_contract, validate, platform_version)?;
DataContract::from_value(raw_data_contract, full_validation, platform_version)?;

Ok(Self {
data_contract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl DocumentType {
documents_keep_history_contract_default: bool,
documents_mutable_contract_default: bool,
documents_can_be_deleted_contract_default: bool,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<BTreeMap<String, DocumentType>, ProtocolError> {
Expand All @@ -58,7 +58,7 @@ impl DocumentType {
documents_keep_history_contract_default,
documents_mutable_contract_default,
documents_can_be_deleted_contract_default,
validate,
full_validation,
validation_operations,
platform_version,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl DocumentTypeV0 {
documents_keep_history_contract_default: bool,
documents_mutable_contract_default: bool,
documents_can_be_deleted_contract_default: bool,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<BTreeMap<String, DocumentType>, ProtocolError> {
Expand All @@ -43,7 +43,7 @@ impl DocumentTypeV0 {
documents_keep_history_contract_default,
documents_mutable_contract_default,
documents_can_be_deleted_contract_default,
validate,
full_validation,
validation_operations,
platform_version,
)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ impl DocumentType {
default_keeps_history: bool,
default_mutability: bool,
default_can_be_deleted: bool,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
Expand All @@ -36,7 +36,7 @@ impl DocumentType {
default_keeps_history,
default_mutability,
default_can_be_deleted,
validate,
full_validation,
validation_operations,
platform_version,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl DocumentTypeV0 {
default_keeps_history: bool,
default_mutability: bool,
default_can_be_deleted: bool,
validate: bool, // we don't need to validate if loaded from state
full_validation: bool, // we don't need to validate if loaded from state
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<Self, ProtocolError> {
Expand All @@ -123,7 +123,7 @@ impl DocumentTypeV0 {
)?;

#[cfg(not(feature = "validation"))]
if validate {
if full_validation {
// TODO we are silently dropping this error when we shouldn't be
// but returning this error causes tests to fail; investigate more.
ProtocolError::CorruptedCodeExecution(
Expand All @@ -135,7 +135,7 @@ impl DocumentTypeV0 {
let json_schema_validator = StatelessJsonSchemaLazyValidator::new();

#[cfg(feature = "validation")]
if validate {
if full_validation {
// Make sure a document type name is compliant
if !name
.chars()
Expand Down Expand Up @@ -265,7 +265,7 @@ impl DocumentTypeV0 {
.unwrap_or_default();

#[cfg(feature = "validation")]
if validate {
if full_validation {
validation_operations.push(
ProtocolValidationOperation::DocumentTypeSchemaPropertyValidation(
property_values.values().len() as u64,
Expand Down Expand Up @@ -347,7 +347,7 @@ impl DocumentTypeV0 {
.map_err(consensus_or_protocol_data_contract_error)?;

#[cfg(feature = "validation")]
if validate {
if full_validation {
validation_operations.push(
ProtocolValidationOperation::DocumentTypeSchemaIndexValidation(
index.properties.len() as u64,
Expand Down Expand Up @@ -500,7 +500,7 @@ impl DocumentTypeV0 {
.unwrap_or(SecurityLevel::HIGH);

#[cfg(feature = "validation")]
if validate && security_level_requirement == SecurityLevel::MASTER {
if full_validation && security_level_requirement == SecurityLevel::MASTER {
return Err(ConsensusError::BasicError(
BasicError::InvalidDocumentTypeRequiredSecurityLevelError(
InvalidDocumentTypeRequiredSecurityLevelError::new(
Expand Down
12 changes: 7 additions & 5 deletions packages/rs-dpp/src/data_contract/factory/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,20 @@ impl DataContractFactoryV0 {
pub fn create_from_object(
&self,
data_contract_object: Value,
validate: bool,
full_validation: bool,
) -> Result<DataContract, ProtocolError> {
let platform_version = PlatformVersion::get(self.protocol_version)?;
match platform_version
.dpp
.contract_versions
.contract_structure_version
{
0 => Ok(
DataContractV0::from_value(data_contract_object, validate, platform_version)?
.into(),
),
0 => Ok(DataContractV0::from_value(
data_contract_object,
full_validation,
platform_version,
)?
.into()),
version => Err(ProtocolError::UnknownVersionMismatch {
method: "DataContractFactoryV0::create_from_object".to_string(),
known_versions: vec![0],
Expand Down
19 changes: 11 additions & 8 deletions packages/rs-dpp/src/data_contract/methods/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ impl DataContractSchemaMethodsV0 for DataContract {
&mut self,
schemas: BTreeMap<DocumentName, Value>,
defs: Option<BTreeMap<DefinitionName, Value>>,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError> {
match self {
DataContract::V0(v0) => v0.set_document_schemas(
schemas,
defs,
validate,
full_validation,
validation_operations,
platform_version,
),
Expand All @@ -33,15 +33,15 @@ impl DataContractSchemaMethodsV0 for DataContract {
&mut self,
name: &str,
schema: Value,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError> {
match self {
DataContract::V0(v0) => v0.set_document_schema(
name,
schema,
validate,
full_validation,
validation_operations,
platform_version,
),
Expand All @@ -63,14 +63,17 @@ impl DataContractSchemaMethodsV0 for DataContract {
fn set_schema_defs(
&mut self,
defs: Option<BTreeMap<DefinitionName, Value>>,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError> {
match self {
DataContract::V0(v0) => {
v0.set_schema_defs(defs, validate, validation_operations, platform_version)
}
DataContract::V0(v0) => v0.set_schema_defs(
defs,
full_validation,
validation_operations,
platform_version,
),
}
}
}
6 changes: 3 additions & 3 deletions packages/rs-dpp/src/data_contract/methods/schema/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub trait DataContractSchemaMethodsV0 {
&mut self,
schemas: BTreeMap<DocumentName, Value>,
defs: Option<BTreeMap<DefinitionName, Value>>,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError>;
Expand All @@ -19,7 +19,7 @@ pub trait DataContractSchemaMethodsV0 {
&mut self,
name: &str,
schema: Value,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError>;
Expand All @@ -29,7 +29,7 @@ pub trait DataContractSchemaMethodsV0 {
fn set_schema_defs(
&mut self,
defs: Option<BTreeMap<DefinitionName, Value>>,
validate: bool,
full_validation: bool,
validation_operations: &mut Vec<ProtocolValidationOperation>,
platform_version: &PlatformVersion,
) -> Result<(), ProtocolError>;
Expand Down
Loading
Loading