Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Jul 4, 2024
1 parent ed7d1b6 commit 199cfb7
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/rs-platform-version/src/version/fee/data_contract/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,35 @@ impl PartialEq for FeeDataContractValidationVersion {
== other.document_type_unique_index_per_property_fee
}
}

#[cfg(test)]
mod tests {
use super::FeeDataContractValidationVersion;

#[test]
// If this test failed, then a new field was added in FeeDataContractValidationVersion. And the corresponding eq needs to be updated as well
fn test_fee_data_contract_validation_fees_version_equality() {
let version1 = FeeDataContractValidationVersion {
document_type_base_fee: 1,
document_type_size_fee: 2,
document_type_per_property_fee: 3,
document_type_base_non_unique_index_fee: 4,
document_type_non_unique_index_per_property_fee: 5,
document_type_base_unique_index_fee: 6,
document_type_unique_index_per_property_fee: 7,
};

let version2 = FeeDataContractValidationVersion {
document_type_base_fee: 1,
document_type_size_fee: 2,
document_type_per_property_fee: 3,
document_type_base_non_unique_index_fee: 4,
document_type_non_unique_index_per_property_fee: 5,
document_type_base_unique_index_fee: 6,
document_type_unique_index_per_property_fee: 7,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "FeeDataContractValidationVersion equality test failed. If a field was added or removed, update the Eq implementation.");
}
}
28 changes: 28 additions & 0 deletions packages/rs-platform-version/src/version/fee/hashing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ impl PartialEq for FeeHashingVersion {
&& self.single_sha256_base == other.single_sha256_base
}
}

#[cfg(test)]
mod tests {
use super::FeeHashingVersion;

#[test]
// If this test failed, then a new field was added in FeeHashingVersion. And the corresponding eq needs to be updated as well
fn test_fee_hashing_version_equality() {
let version1 = FeeHashingVersion {
single_sha256_base: 1,
blake3_base: 2,
sha256_ripe_md160_base: 3,
sha256_per_block: 4,
blake3_per_block: 5,
};

let version2 = FeeHashingVersion {
single_sha256_base: 1,
blake3_base: 2,
sha256_ripe_md160_base: 3,
sha256_per_block: 4,
blake3_per_block: 5,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "FeeHashingVersion equality test failed. If a field was added or removed, update the Eq implementation.");
}
}
30 changes: 30 additions & 0 deletions packages/rs-platform-version/src/version/fee/processing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,33 @@ impl PartialEq for FeeProcessingVersion {
&& self.validate_key_structure == other.validate_key_structure
}
}

#[cfg(test)]
mod tests {
use super::FeeProcessingVersion;

#[test]
// If this test failed, then a new field was added in FeeProcessingVersion. And the corresponding eq needs to be updated as well
fn test_fee_processing_version_equality() {
let version1 = FeeProcessingVersion {
fetch_identity_balance_processing_cost: 1,
fetch_identity_revision_processing_cost: 2,
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
};

let version2 = FeeProcessingVersion {
fetch_identity_balance_processing_cost: 1,
fetch_identity_revision_processing_cost: 2,
fetch_identity_balance_and_revision_processing_cost: 3,
fetch_identity_cost_per_look_up_key_by_id: 4,
fetch_single_identity_key_processing_cost: 5,
validate_key_structure: 6,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "FeeProcessingVersion equality test failed. If a field was added or removed, update the Eq implementation.");
}
}
28 changes: 28 additions & 0 deletions packages/rs-platform-version/src/version/fee/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ impl PartialEq for FeeSignatureVersion {
&& self.verify_signature_eddsa25519_hash160 == other.verify_signature_eddsa25519_hash160
}
}

#[cfg(test)]
mod tests {
use super::FeeSignatureVersion;

#[test]
// If this test failed, then a new field was added in FeeSignatureVersion. And the corresponding eq needs to be updated as well
fn test_fee_signature_version_equality() {
let version1 = FeeSignatureVersion {
verify_signature_ecdsa_secp256k1: 1,
verify_signature_bls12_381: 2,
verify_signature_ecdsa_hash160: 3,
verify_signature_bip13_script_hash: 4,
verify_signature_eddsa25519_hash160: 5,
};

let version2 = FeeSignatureVersion {
verify_signature_ecdsa_secp256k1: 1,
verify_signature_bls12_381: 2,
verify_signature_ecdsa_hash160: 3,
verify_signature_bip13_script_hash: 4,
verify_signature_eddsa25519_hash160: 5,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "FeeSignatureVersion equality test failed. If a field was added or removed, update the Eq implementation.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,33 @@ impl PartialEq for StateTransitionMinFees {
&& self.contract_update == other.contract_update
}
}

#[cfg(test)]
mod tests {
use super::StateTransitionMinFees;

#[test]
// If this test failed, then a new field was added in StateTransitionMinFees. And the corresponding eq needs to be updated as well
fn test_fee_state_transition_min_fees_version_equality() {
let version1 = StateTransitionMinFees {
credit_transfer: 1,
credit_withdrawal: 2,
identity_update: 3,
document_batch_sub_transition: 4,
contract_create: 5,
contract_update: 6,
};

let version2 = StateTransitionMinFees {
credit_transfer: 1,
credit_withdrawal: 2,
identity_update: 3,
document_batch_sub_transition: 4,
contract_create: 5,
contract_update: 6,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "StateTransitionMinFees equality test failed. If a field was added or removed, update the Eq implementation.");
}
}
28 changes: 28 additions & 0 deletions packages/rs-platform-version/src/version/fee/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ impl PartialEq for FeeStorageVersion {
&& self.storage_seek_cost == other.storage_seek_cost
}
}

#[cfg(test)]
mod tests {
use super::FeeStorageVersion;

#[test]
// If this test failed, then a new field was added in FeeProcessingVersion. And the corresponding eq needs to be updated as well
fn test_fee_storage_version_equality() {
let version1 = FeeStorageVersion {
storage_disk_usage_credit_per_byte: 1,
storage_processing_credit_per_byte: 2,
storage_load_credit_per_byte: 3,
non_storage_load_credit_per_byte: 4,
storage_seek_cost: 5,
};

let version2 = FeeStorageVersion {
storage_disk_usage_credit_per_byte: 1,
storage_processing_credit_per_byte: 2,
storage_load_credit_per_byte: 3,
non_storage_load_credit_per_byte: 4,
storage_seek_cost: 5,
};

// This assertion will check if all fields are considered in the equality comparison
assert_eq!(version1, version2, "FeeStorageVersion equality test failed. If a field was added or removed, update the Eq implementation.");
}
}

0 comments on commit 199cfb7

Please sign in to comment.