From 61cee325f117a1266c119722b271ff9e8e89cdd2 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 18 Jun 2024 17:41:13 +0800 Subject: [PATCH] test: update tests --- .../src/execution/check_tx/v0/mod.rs | 14 +-- .../create_genesis_state/v0/mod.rs | 15 ++- .../state_transitions/documents_batch/mod.rs | 6 +- .../tests/strategy_tests/main.rs | 6 +- ...equest-mutable-and-can-not-be-deleted.json | 6 +- ...equest-not-mutable-and-can-be-deleted.json | 6 +- .../rs-drive/src/drive/document/insert/mod.rs | 100 +----------------- .../rs-drive/tests/deterministic_root_hash.rs | 2 +- 8 files changed, 28 insertions(+), 127 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs b/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs index e6fa1e13e84..1e362be824c 100644 --- a/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs @@ -462,7 +462,7 @@ mod tests { ) .expect("expected to process state transition"); - assert_eq!(processing_result.aggregated_fees().processing_fee, 2985330); + assert_eq!(processing_result.aggregated_fees().processing_fee, 3039820); let check_result = platform .check_tx( @@ -654,7 +654,7 @@ mod tests { // We have one invalid paid for state transition assert_eq!(processing_result.invalid_paid_count(), 1); - assert_eq!(processing_result.aggregated_fees().processing_fee, 905460); + assert_eq!(processing_result.aggregated_fees().processing_fee, 905380); let check_result = platform .check_tx( @@ -796,7 +796,7 @@ mod tests { // since a fee multiplier of 100 means 100% more of 1 (gives 2) assert_eq!( processing_result.aggregated_fees().processing_fee, - 2985330 * 2 + 3039820 * 2 ); let check_result = platform @@ -1034,7 +1034,7 @@ mod tests { ) .expect("expected to process state transition"); - assert_eq!(processing_result.aggregated_fees().processing_fee, 2985330); + assert_eq!(processing_result.aggregated_fees().processing_fee, 3039820); platform .drive @@ -1118,7 +1118,7 @@ mod tests { assert_eq!( update_processing_result.aggregated_fees().processing_fee, - 7125710 + 7351410 ); let check_result = platform @@ -1230,7 +1230,7 @@ mod tests { ) .expect("expected to process state transition"); - assert_eq!(processing_result.aggregated_fees().processing_fee, 2985330); + assert_eq!(processing_result.aggregated_fees().processing_fee, 3039820); platform .drive @@ -1350,7 +1350,7 @@ mod tests { // We have one invalid paid for state transition assert_eq!(processing_result.invalid_paid_count(), 1); - assert_eq!(processing_result.aggregated_fees().processing_fee, 1231130); + assert_eq!(processing_result.aggregated_fees().processing_fee, 1231050); let check_result = platform .check_tx( diff --git a/packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/v0/mod.rs index 73795a0aab2..006ce72067e 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/v0/mod.rs @@ -179,7 +179,11 @@ impl Platform { self.register_system_identity_operations(identity, &mut operations); } - self.register_dpns_top_level_domain_operations(&dpns_data_contract, &mut operations)?; + self.register_dpns_top_level_domain_operations( + &dpns_data_contract, + genesis_time, + &mut operations, + )?; let block_info = BlockInfo::default_with_time(genesis_time); @@ -228,6 +232,7 @@ impl Platform { fn register_dpns_top_level_domain_operations<'a>( &'a self, contract: &'a DataContract, + genesis_time: TimestampMillis, operations: &mut Vec>, ) -> Result<(), Error> { let domain = "dash"; @@ -255,8 +260,8 @@ impl Platform { properties: document_stub_properties, owner_id: contract.owner_id(), revision: None, - created_at: None, - updated_at: None, + created_at: Some(genesis_time), + updated_at: Some(genesis_time), transferred_at: None, created_at_block_height: None, updated_at_block_height: None, @@ -315,8 +320,8 @@ mod tests { assert_eq!( root_hash, [ - 162, 81, 50, 217, 246, 11, 77, 233, 231, 192, 228, 176, 197, 102, 24, 18, 160, - 5, 182, 75, 119, 174, 75, 155, 86, 92, 88, 197, 201, 60, 60, 157 + 115, 12, 128, 112, 147, 9, 54, 99, 241, 209, 128, 221, 251, 54, 5, 115, 255, + 226, 111, 160, 174, 221, 250, 250, 115, 229, 46, 223, 84, 36, 79, 52 ] ) } diff --git a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs index da5d9701619..db534f17419 100644 --- a/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs +++ b/packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/documents_batch/mod.rs @@ -779,7 +779,6 @@ mod tests { document.set("recipientKeyIndex", Value::U32(1)); document.set("senderKeyIndex", Value::U32(1)); document.set("accountReference", Value::U32(0)); - document.set("coreHeightCreatedAt", Value::U32(5)); let mut altered_document = document.clone(); @@ -1363,7 +1362,6 @@ mod tests { document.set("recipientKeyIndex", Value::U32(1)); document.set("senderKeyIndex", Value::U32(1)); document.set("accountReference", Value::U32(0)); - document.set("coreHeightCreatedAt", Value::U32(5)); let mut altered_document = document.clone(); @@ -1526,7 +1524,6 @@ mod tests { document.set("recipientKeyIndex", Value::U32(1)); document.set("senderKeyIndex", Value::U32(1)); document.set("accountReference", Value::U32(0)); - document.set("coreHeightCreatedAt", Value::U32(5)); let mut altered_document = document.clone(); @@ -1621,7 +1618,7 @@ mod tests { assert_eq!(processing_result.valid_count(), 1); - assert_eq!(processing_result.aggregated_fees().processing_fee, 9951520); + assert_eq!(processing_result.aggregated_fees().processing_fee, 9945520); } #[test] @@ -1670,7 +1667,6 @@ mod tests { document.set("recipientKeyIndex", Value::U32(1)); document.set("senderKeyIndex", Value::U32(1)); document.set("accountReference", Value::U32(0)); - document.set("coreHeightCreatedAt", Value::U32(5)); let mut altered_document = document.clone(); diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 43ea171e360..946bed45243 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -1088,7 +1088,7 @@ mod tests { .unwrap() .unwrap() ), - "3beaf287fb5fb712715e688ef3cf642e3e4042270907ebd022050b06af0cb433".to_string() + "5d622233a887daa116da2a17d61f6a8b376bc0d6af844d66fe329abdd04cc582".to_string() ) } @@ -1778,7 +1778,7 @@ mod tests { .unwrap() .unwrap() ), - "10fbe38850d752b491305b2587468788acbd6dd130272c5a8844d0da05e3a9cf".to_string() + "a5c7ad0ec71a297a3a925195c646278840fefb7574df7049da3f6110a48b1c7c".to_string() ) } @@ -1903,7 +1903,7 @@ mod tests { .unwrap() .unwrap() ), - "9ed86b1ed5d0f7a981cb0ff2f3943603a095a031c463b3389bce8a6f60e2b21e".to_string() + "eb1efa036d293b892192d38495c62cd0840ec8426bea4bb3278bed96a638f1c9".to_string() ) } diff --git a/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-mutable-and-can-not-be-deleted.json b/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-mutable-and-can-not-be-deleted.json index 1011c390f05..9506e7100e4 100644 --- a/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-mutable-and-can-not-be-deleted.json +++ b/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-mutable-and-can-not-be-deleted.json @@ -213,15 +213,11 @@ "minItems": 38, "maxItems": 102, "position": 6 - }, - "coreHeightCreatedAt": { - "type": "integer", - "minimum": 1, - "position": 7 } }, "required": [ "$createdAt", + "$createdAtCoreBlockHeight", "toUserId", "encryptedPublicKey", "senderKeyIndex", diff --git a/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-not-mutable-and-can-be-deleted.json b/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-not-mutable-and-can-be-deleted.json index bda8b4f7293..dda929cb975 100644 --- a/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-not-mutable-and-can-be-deleted.json +++ b/packages/rs-drive-abci/tests/supporting_files/contract/dashpay/dashpay-contract-contact-request-not-mutable-and-can-be-deleted.json @@ -213,15 +213,11 @@ "minItems": 38, "maxItems": 102, "position": 6 - }, - "coreHeightCreatedAt": { - "type": "integer", - "minimum": 1, - "position": 7 } }, "required": [ "$createdAt", + "$createdAtCoreBlockHeight", "toUserId", "encryptedPublicKey", "senderKeyIndex", diff --git a/packages/rs-drive/src/drive/document/insert/mod.rs b/packages/rs-drive/src/drive/document/insert/mod.rs index 03e8979c844..ef8ef8f2dee 100644 --- a/packages/rs-drive/src/drive/document/insert/mod.rs +++ b/packages/rs-drive/src/drive/document/insert/mod.rs @@ -72,6 +72,7 @@ use dpp::data_contract::conversion::cbor::DataContractCborConversionMethodsV0; #[cfg(test)] mod tests { + use chrono::{Date, NaiveDate}; use std::borrow::Cow; use std::option::Option::None; @@ -86,7 +87,7 @@ mod tests { use dpp::block::epoch::Epoch; use dpp::data_contract::accessors::v0::DataContractV0Getters; - use dpp::document::Document; + use dpp::document::{Document, DocumentV0}; use crate::drive::object_size_info::DocumentInfo::DocumentRefInfo; use crate::tests::helpers::setup::setup_drive_with_initial_state_structure; @@ -94,9 +95,11 @@ mod tests { use dpp::fee::default_costs::EpochCosts; use dpp::fee::default_costs::KnownCostItem::StorageDiskUsageCreditPerByte; use dpp::fee::fee_result::FeeResult; + use dpp::platform_value::{platform_value, BinaryData, Identifier}; use dpp::tests::fixtures::get_dpns_data_contract_fixture; use dpp::tests::json_document::json_document_to_document; use dpp::version::PlatformVersion; + use dpp::ProtocolError; #[test] fn test_add_dashpay_documents_no_transaction() { @@ -871,99 +874,4 @@ mod tests { "expected not to be able to insert document with already existing unique index", ); } - - #[test] - fn test_create_two_documents_with_the_same_index_in_different_transactions() { - let drive = setup_drive_with_initial_state_structure(); - - let db_transaction = drive.grove.start_transaction(); - - let platform_version = PlatformVersion::latest(); - - let created_contract = - get_dpns_data_contract_fixture(None, 0, platform_version.protocol_version); - - drive - .apply_contract( - created_contract.data_contract(), - BlockInfo::default(), - true, - StorageFlags::optional_default_as_cow(), - Some(&db_transaction), - platform_version, - ) - .expect("expected to apply contract successfully"); - - // Create dash TLD - - let dash_tld_cbor = hex::decode("00ac632469645820d7f2c53f46a917ab6e5b39a2d7bc260b649289453744d1e0d4f26a8d8eff37cf65247479706566646f6d61696e656c6162656c6464617368677265636f726473a17364617368416c6961734964656e74697479496458203012c19b98ec0033addb36cd64b7f510670f2a351a4304b5f6994144286efdac68246f776e6572496458203012c19b98ec0033addb36cd64b7f510670f2a351a4304b5f6994144286efdac69247265766973696f6e016a246372656174656441741b0000017f07c861586c7072656f7264657253616c745820e0b508c5a36825a206693a1f414aa13edbecf43c41e3c799ea9e737b4f9aa2266e737562646f6d61696e52756c6573a16f616c6c6f77537562646f6d61696e73f56f2464617461436f6e747261637449645820e668c659af66aee1e72c186dde7b5b7e0a1d712a09c40d5721f622bf53c531556f6e6f726d616c697a65644c6162656c6464617368781a6e6f726d616c697a6564506172656e74446f6d61696e4e616d6560").unwrap(); - let dash_tld = Document::from_cbor(&dash_tld_cbor, None, None, platform_version) - .expect("expected to get document"); - - let info = DocumentAndContractInfo { - owned_document_info: OwnedDocumentInfo { - document_info: DocumentRefInfo(( - &dash_tld, - StorageFlags::optional_default_as_cow(), - )), - owner_id: None, - }, - contract: created_contract.data_contract(), - document_type: created_contract - .data_contract() - .document_type_for_name("domain") - .expect("expected to get document type"), - }; - - drive - .add_document_for_contract( - info, - true, - BlockInfo::default(), - true, - Some(&db_transaction), - platform_version, - ) - .expect("should create dash tld"); - - drive - .grove - .commit_transaction(db_transaction) - .unwrap() - .expect("should commit transaction"); - - let db_transaction = drive.grove.start_transaction(); - - // add random TLD - - let random_tld_cbor = hex::decode("00ab632469645820655c9b5606f4ad53daea90de9c540aad656ed5fbe5fb14b40700f6f56dc793ac65247479706566646f6d61696e656c6162656c746433653966343532373963343865306261363561677265636f726473a17364617368416c6961734964656e74697479496458203012c19b98ec0033addb36cd64b7f510670f2a351a4304b5f6994144286efdac68246f776e6572496458203012c19b98ec0033addb36cd64b7f510670f2a351a4304b5f6994144286efdac69247265766973696f6e016c7072656f7264657253616c745820219353a923a29cd02c521b141f326ac0d12c362a84f1979a5de89b8dba12891b6e737562646f6d61696e52756c6573a16f616c6c6f77537562646f6d61696e73f56f2464617461436f6e747261637449645820e668c659af66aee1e72c186dde7b5b7e0a1d712a09c40d5721f622bf53c531556f6e6f726d616c697a65644c6162656c746433653966343532373963343865306261363561781a6e6f726d616c697a6564506172656e74446f6d61696e4e616d6560").unwrap(); - let _random_tld = Document::from_cbor(&random_tld_cbor, None, None, platform_version) - .expect("expected to get document"); - - let info = DocumentAndContractInfo { - owned_document_info: OwnedDocumentInfo { - document_info: DocumentRefInfo(( - &dash_tld, - StorageFlags::optional_default_as_cow(), - )), - owner_id: None, - }, - contract: created_contract.data_contract(), - document_type: created_contract - .data_contract() - .document_type_for_name("domain") - .expect("expected to get document type"), - }; - - drive - .add_document_for_contract( - info, - true, - BlockInfo::default(), - true, - Some(&db_transaction), - platform_version, - ) - .expect("should create random tld"); - } } diff --git a/packages/rs-drive/tests/deterministic_root_hash.rs b/packages/rs-drive/tests/deterministic_root_hash.rs index fa6ecc90918..b471f6a3340 100644 --- a/packages/rs-drive/tests/deterministic_root_hash.rs +++ b/packages/rs-drive/tests/deterministic_root_hash.rs @@ -446,7 +446,7 @@ fn test_root_hash_with_batches(drive: &Drive, db_transaction: &Transaction) { .unwrap() .expect("should return app hash"); - let expected_app_hash = "fa23fefadd8b0254b9e4c594f09026c070148f5de9c39ff9ea227a327761e062"; + let expected_app_hash = "1376f115e75db00aa0178b6db908b828e8ba327f24ca02098b1070508162f0b3"; assert_eq!(hex::encode(app_hash), expected_app_hash); }