Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jun 18, 2024
1 parent 51cfb3d commit 61cee32
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 127 deletions.
14 changes: 7 additions & 7 deletions packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1118,7 +1118,7 @@ mod tests {

assert_eq!(
update_processing_result.aggregated_fees().processing_fee,
7125710
7351410
);

let check_result = platform
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ impl<C> Platform<C> {
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);

Expand Down Expand Up @@ -228,6 +232,7 @@ impl<C> Platform<C> {
fn register_dpns_top_level_domain_operations<'a>(
&'a self,
contract: &'a DataContract,
genesis_time: TimestampMillis,
operations: &mut Vec<DriveOperation<'a>>,
) -> Result<(), Error> {
let domain = "dash";
Expand Down Expand Up @@ -255,8 +260,8 @@ impl<C> Platform<C> {
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,
Expand Down Expand Up @@ -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
]
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ mod tests {
.unwrap()
.unwrap()
),
"3beaf287fb5fb712715e688ef3cf642e3e4042270907ebd022050b06af0cb433".to_string()
"5d622233a887daa116da2a17d61f6a8b376bc0d6af844d66fe329abdd04cc582".to_string()
)
}

Expand Down Expand Up @@ -1778,7 +1778,7 @@ mod tests {
.unwrap()
.unwrap()
),
"10fbe38850d752b491305b2587468788acbd6dd130272c5a8844d0da05e3a9cf".to_string()
"a5c7ad0ec71a297a3a925195c646278840fefb7574df7049da3f6110a48b1c7c".to_string()
)
}

Expand Down Expand Up @@ -1903,7 +1903,7 @@ mod tests {
.unwrap()
.unwrap()
),
"9ed86b1ed5d0f7a981cb0ff2f3943603a095a031c463b3389bce8a6f60e2b21e".to_string()
"eb1efa036d293b892192d38495c62cd0840ec8426bea4bb3278bed96a638f1c9".to_string()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,11 @@
"minItems": 38,
"maxItems": 102,
"position": 6
},
"coreHeightCreatedAt": {
"type": "integer",
"minimum": 1,
"position": 7
}
},
"required": [
"$createdAt",
"$createdAtCoreBlockHeight",
"toUserId",
"encryptedPublicKey",
"senderKeyIndex",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,11 @@
"minItems": 38,
"maxItems": 102,
"position": 6
},
"coreHeightCreatedAt": {
"type": "integer",
"minimum": 1,
"position": 7
}
},
"required": [
"$createdAt",
"$createdAtCoreBlockHeight",
"toUserId",
"encryptedPublicKey",
"senderKeyIndex",
Expand Down
100 changes: 4 additions & 96 deletions packages/rs-drive/src/drive/document/insert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -86,17 +87,19 @@ 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;
use dpp::document::serialization_traits::DocumentCborMethodsV0;
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() {
Expand Down Expand Up @@ -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");
}
}
2 changes: 1 addition & 1 deletion packages/rs-drive/tests/deterministic_root_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 61cee32

Please sign in to comment.