diff --git a/Cargo.lock b/Cargo.lock index a8482a4d788..2d3cbc966e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -53,9 +53,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -197,9 +197,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", @@ -686,7 +686,7 @@ dependencies = [ "num-traits", "serde", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -1447,9 +1447,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "enum-map" @@ -2264,9 +2264,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "685a7d121ee3f65ae4fddd72b25a04bb36b6af81bc0828f7d5434c0fe60fa3a2" dependencies = [ "libc", ] @@ -2371,7 +2371,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -2679,9 +2679,9 @@ dependencies = [ [[package]] name = "num" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +checksum = "3135b08af27d103b0a51f2ae0f8632117b7b185ccf931445affa8df530576a41" dependencies = [ "num-bigint", "num-complex", @@ -4361,9 +4361,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.35" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef89ece63debf11bc32d1ed8d078ac870cbeb44da02afb02a9ff135ae7ca0582" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", @@ -4547,7 +4547,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow 0.6.5", + "winnow 0.6.6", ] [[package]] @@ -5087,7 +5087,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -5105,7 +5105,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -5125,17 +5125,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -5146,9 +5147,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -5158,9 +5159,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -5170,9 +5171,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -5182,9 +5189,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -5194,9 +5201,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -5206,9 +5213,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -5218,9 +5225,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" @@ -5233,9 +5240,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "f0c976aaaa0e1f90dbb21e9587cdaf1d9679a1cde8875c0d6bd83ab96a208352" dependencies = [ "memchr", ] diff --git a/packages/rs-dpp/Cargo.toml b/packages/rs-dpp/Cargo.toml index 7c39d54dea0..71b5809e396 100644 --- a/packages/rs-dpp/Cargo.toml +++ b/packages/rs-dpp/Cargo.toml @@ -60,7 +60,7 @@ ed25519-dalek = { version = "2.0.0-rc.2", features = ["rand_core"], optional = t nohash-hasher = "0.2.0" rust_decimal = "1.29.1" rust_decimal_macros = "1.29.1" -indexmap = { version = "2.0.2"} +indexmap = { version = "2.0.2", features = ["serde"] } strum = { version = "0.25.0", features = ["derive"] } json-schema-compatibility-validator = { path = '../rs-json-schema-compatibility-validator' } diff --git a/packages/rs-dpp/src/data_contract/document_type/property/mod.rs b/packages/rs-dpp/src/data_contract/document_type/property/mod.rs index cfe1b52e403..c544bfd62bd 100644 --- a/packages/rs-dpp/src/data_contract/document_type/property/mod.rs +++ b/packages/rs-dpp/src/data_contract/document_type/property/mod.rs @@ -15,20 +15,21 @@ use platform_value::Value; use rand::distributions::{Alphanumeric, Standard}; use rand::rngs::StdRng; use rand::Rng; +use serde::Serialize; pub mod array; // This struct will be changed in future to support more validation logic and serialization // It will become versioned and it will be introduced by a new document type version // @append_only -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Serialize)] pub struct DocumentProperty { pub property_type: DocumentPropertyType, pub required: bool, } // @append_only -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Clone, Serialize)] pub enum DocumentPropertyType { ///Todo decompose integer Integer, diff --git a/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_create_transition/v0/v0_methods.rs b/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_create_transition/v0/v0_methods.rs index ddf987f5a5e..ca6fe4e1480 100644 --- a/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_create_transition/v0/v0_methods.rs +++ b/packages/rs-dpp/src/state_transition/state_transitions/contract/data_contract_create_transition/v0/v0_methods.rs @@ -46,15 +46,24 @@ impl DataContractCreateTransitionMethodsV0 for DataContractCreateTransitionV0 { let mut state_transition: StateTransition = transition.into(); let value = state_transition.signable_bytes()?; - let public_key = - identity - .loaded_public_keys - .get(&key_id) - .ok_or(ProtocolError::NonConsensusError( - NonConsensusError::StateTransitionCreationError( - "public key did not exist".to_string(), - ), - ))?; + // The public key ids don't always match the keys in the map, so we need to do this. + let matching_key = identity + .loaded_public_keys + .iter() + .find_map(|(&key, public_key)| { + if public_key.id() == key_id { + Some(key) + } else { + None + } + }) + .expect("No matching public key id found in the map"); + + let public_key = identity.loaded_public_keys.get(&matching_key).ok_or( + ProtocolError::NonConsensusError(NonConsensusError::StateTransitionCreationError( + "public key did not exist".to_string(), + )), + )?; let security_level_requirements = state_transition.security_level_requirement().ok_or( ProtocolError::CorruptedCodeExecution( diff --git a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs index 56c1c8df753..f80ec3645de 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/chain_lock_update.rs @@ -16,10 +16,10 @@ mod tests { // simple case where quorums do not change let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs index 88a439f29f5..4c892673123 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/core_update_tests.rs @@ -15,10 +15,10 @@ mod tests { fn run_chain_random_bans() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -113,10 +113,10 @@ mod tests { fn run_chain_random_removals() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -197,10 +197,10 @@ mod tests { fn run_chain_random_bans_and_unbans() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/failures.rs b/packages/rs-drive-abci/tests/strategy_tests/failures.rs index d7d7eb9ccc1..c1fe8150951 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/failures.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/failures.rs @@ -41,13 +41,10 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![( - contract, - Some(BTreeMap::from([(3, contract_update_1)])), - )], + start_contracts: vec![(contract, Some(BTreeMap::from([(3, contract_update_1)])))], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -104,7 +101,7 @@ mod tests { outcome .strategy .strategy - .contracts_with_updates + .start_contracts .first() .unwrap() .0 @@ -125,10 +122,10 @@ mod tests { fn run_chain_block_failure_on_genesis_block_correctly_fixes_itself() { let mut strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index b98b88de9d2..3ca8b0768e2 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -121,10 +121,10 @@ mod tests { fn run_chain_nothing_happening() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -165,10 +165,10 @@ mod tests { fn run_chain_block_signing() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -210,10 +210,10 @@ mod tests { fn run_chain_stop_and_restart() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -336,10 +336,10 @@ mod tests { fn run_chain_stop_and_restart_multiround() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -469,10 +469,10 @@ mod tests { let platform_version = PlatformVersion::latest(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -534,10 +534,10 @@ mod tests { fn run_chain_core_height_randomly_increasing() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -582,10 +582,10 @@ mod tests { fn run_chain_core_height_randomly_increasing_with_epoch_change() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -638,10 +638,10 @@ mod tests { fn run_chain_core_height_randomly_increasing_with_quick_epoch_change() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -699,10 +699,10 @@ mod tests { let platform_version = PlatformVersion::latest(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, }, @@ -772,10 +772,10 @@ mod tests { fn run_chain_core_height_randomly_increasing_with_quorum_updates_new_proposers() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -835,10 +835,10 @@ mod tests { fn run_chain_core_height_randomly_increasing_with_quorum_updates_changing_proposers() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -901,10 +901,10 @@ mod tests { fn run_chain_core_height_randomly_increasing_with_quorum_updates_updating_proposers() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -994,10 +994,10 @@ mod tests { // drive_abci::logging::Loggers::default().try_install().ok(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1052,10 +1052,10 @@ mod tests { fn run_chain_insert_one_new_identity_per_block_with_epoch_change() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1134,10 +1134,10 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(contract, None)], + start_contracts: vec![(contract, None)], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1188,7 +1188,7 @@ mod tests { outcome .strategy .strategy - .contracts_with_updates + .start_contracts .first() .unwrap() .0 @@ -1209,7 +1209,7 @@ mod tests { fn run_chain_insert_one_new_identity_and_many_big_contracts() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![Operation { op_type: OperationType::ContractCreate( RandomDocumentTypeParameters { @@ -1255,7 +1255,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1333,7 +1333,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![( + start_contracts: vec![( contract, Some(BTreeMap::from([ (3, contract_update_1), @@ -1342,7 +1342,7 @@ mod tests { )], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1393,7 +1393,7 @@ mod tests { outcome .strategy .strategy - .contracts_with_updates + .start_contracts .first() .unwrap() .0 @@ -1437,7 +1437,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![Operation { op_type: OperationType::Document(document_op), frequency: Frequency { @@ -1446,7 +1446,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1517,7 +1517,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![Operation { op_type: OperationType::Document(document_op), frequency: Frequency { @@ -1526,7 +1526,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1616,7 +1616,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -1634,7 +1634,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1724,7 +1724,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -1742,7 +1742,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1847,7 +1847,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -1865,7 +1865,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -1972,7 +1972,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -1990,7 +1990,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -2086,7 +2086,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -2104,7 +2104,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -2200,7 +2200,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -2218,7 +2218,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..30, chance_per_block: None, @@ -2322,7 +2322,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![(created_contract, None)], + start_contracts: vec![(created_contract, None)], operations: vec![ Operation { op_type: OperationType::Document(document_insertion_op), @@ -2347,7 +2347,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..6, chance_per_block: None, @@ -2411,7 +2411,7 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![Operation { op_type: OperationType::IdentityTopUp, frequency: Frequency { @@ -2420,7 +2420,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -2487,7 +2487,7 @@ mod tests { fn run_chain_update_identities_add_keys() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![Operation { op_type: OperationType::IdentityUpdate( IdentityUpdateOp::IdentityUpdateAddKeys(3), @@ -2498,7 +2498,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -2572,7 +2572,7 @@ mod tests { let platform_version = PlatformVersion::latest(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![Operation { op_type: OperationType::IdentityUpdate( IdentityUpdateOp::IdentityUpdateDisableKey(3), @@ -2583,7 +2583,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -2658,7 +2658,7 @@ mod tests { let platform_version = PlatformVersion::latest(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![ Operation { op_type: OperationType::IdentityTopUp, @@ -2676,7 +2676,7 @@ mod tests { }, ], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 1..2, chance_per_block: None, @@ -3237,10 +3237,10 @@ mod tests { fn run_chain_rotation_is_deterministic_1_block() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { //we do this to create some paying transactions frequency: Frequency { times_per_block_range: 1..2, @@ -3402,10 +3402,10 @@ mod tests { fn run_chain_heavy_rotation_deterministic_before_payout() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { //we do this to create some paying transactions frequency: Frequency { times_per_block_range: 1..2, @@ -3538,10 +3538,10 @@ mod tests { ) { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { //we do this to create some paying transactions frequency: Frequency { times_per_block_range: 1..2, @@ -3675,10 +3675,10 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -3800,7 +3800,7 @@ mod tests { fn run_chain_transfer_between_identities() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![Operation { op_type: OperationType::IdentityTransfer, frequency: Frequency { @@ -3809,7 +3809,7 @@ mod tests { }, }], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { //we do this to create some paying transactions frequency: Frequency { times_per_block_range: 6..10, @@ -3882,7 +3882,7 @@ mod tests { fn run_transactions_exceeding_max_block_size() { let strategy = NetworkStrategy { strategy: Strategy { - identities_inserts: IdentityInsertInfo { + identity_inserts: IdentityInsertInfo { frequency: Frequency { times_per_block_range: 5..6, chance_per_block: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/query.rs b/packages/rs-drive-abci/tests/strategy_tests/query.rs index bd68dfbbf23..b25ac5ad02e 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/query.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/query.rs @@ -369,10 +369,10 @@ mod tests { fn run_chain_query_epoch_info() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -467,10 +467,10 @@ mod tests { fn run_chain_query_epoch_info_latest() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -566,10 +566,10 @@ mod tests { fn run_chain_prove_epoch_info() { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, diff --git a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs index 8359379df37..cd9ccdd195f 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/strategy.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/strategy.rs @@ -370,21 +370,21 @@ impl NetworkStrategy { if block_info.height == 1 && self.strategy.start_identities.number_of_identities > 0 { let mut new_transitions = NetworkStrategy::create_identities_state_transitions( self.strategy.start_identities.number_of_identities.into(), - self.strategy.identities_inserts.start_keys as KeyID, - &self.strategy.identities_inserts.extra_keys, + self.strategy.identity_inserts.start_keys as KeyID, + &self.strategy.identity_inserts.extra_keys, signer, rng, platform_version, ); state_transitions.append(&mut new_transitions); } - let frequency = &self.strategy.identities_inserts.frequency; + let frequency = &self.strategy.identity_inserts.frequency; if frequency.check_hit(rng) { let count = frequency.events(rng); let mut new_transitions = NetworkStrategy::create_identities_state_transitions( count, - self.strategy.identities_inserts.start_keys as KeyID, - &self.strategy.identities_inserts.extra_keys, + self.strategy.identity_inserts.start_keys as KeyID, + &self.strategy.identity_inserts.extra_keys, signer, rng, platform_version, @@ -403,7 +403,7 @@ impl NetworkStrategy { platform_version: &PlatformVersion, ) -> Vec { self.strategy - .contracts_with_updates + .start_contracts .iter_mut() .map(|(created_contract, contract_updates)| { let identity_num = rng.gen_range(0..current_identities.len()); @@ -474,7 +474,7 @@ impl NetworkStrategy { platform_version: &PlatformVersion, ) -> Vec { self.strategy - .contracts_with_updates + .start_contracts .iter_mut() .filter_map(|(_, contract_updates)| { let Some(contract_updates) = contract_updates else { diff --git a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs index 353d098a8b8..7b588734515 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/upgrade_fork_tests.rs @@ -38,10 +38,10 @@ mod tests { let platform_version = PlatformVersion::first(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -281,10 +281,10 @@ mod tests { let platform_version = PlatformVersion::first(); let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, }, @@ -675,10 +675,10 @@ mod tests { .spawn(|| { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -908,10 +908,10 @@ mod tests { .spawn(|| { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -1069,10 +1069,10 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -1233,10 +1233,10 @@ mod tests { .spawn(|| { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, @@ -1349,10 +1349,10 @@ mod tests { let strategy = NetworkStrategy { strategy: Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![], start_identities: StartIdentities::default(), - identities_inserts: IdentityInsertInfo::default(), + identity_inserts: IdentityInsertInfo::default(), identity_contract_nonce_gaps: None, signer: None, diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index b2de4ca3531..10057af099f 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -23,6 +23,7 @@ use dpp::data_contract::document_type::v0::DocumentTypeV0; use dpp::data_contract::{DataContract, DataContractFactory}; use dpp::document::{Document, DocumentV0Getters}; +use dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0; use dpp::identity::state_transition::asset_lock_proof::AssetLockProof; use dpp::identity::{Identity, KeyID, KeyType, PartialIdentity, Purpose, SecurityLevel}; use dpp::platform_value::string_encoding::Encoding; @@ -73,13 +74,13 @@ pub type KeyMaps = BTreeMap>>; /// The strategy allows for the specification of initial conditions, such as contracts to be created and identities to be registered, as well as dynamic actions that unfold over the simulation's lifespan, including contract updates and identity transactions. This versatile structure supports a broad spectrum of blockchain-related activities, from simple transfer operations to complex contract lifecycle management. /// /// # Fields -/// - `contracts_with_updates`: Maps each created data contract to potential updates, enabling the simulation of contract evolution. Each tuple consists of a `CreatedDataContract` and an optional mapping of block heights to subsequent contract versions, facilitating time-sensitive contract transformations. +/// - `start_identities`: Specifies identities to be established at the simulation's outset, including their initial attributes and balances. This setup allows for immediate participation of these identities in the blockchain's simulated activities. +/// +/// - `start_contracts`: Maps each created data contract to potential updates, enabling the simulation of contract evolution. Each tuple consists of a `CreatedDataContract` and an optional mapping of block heights to subsequent contract versions, facilitating time-sensitive contract transformations. /// /// - `operations`: Enumerates discrete operations to be executed within the strategy. These operations represent individual actions or sequences of actions, such as document manipulations, identity updates, or contract interactions, each contributing to the overarching simulation narrative. /// -/// - `start_identities`: Specifies identities to be established at the simulation's outset, including their initial attributes and balances. This setup allows for immediate participation of these identities in the blockchain's simulated activities. -/// -/// - `identities_inserts`: Controls the stochastic introduction of new identities into the simulation, based on a defined frequency distribution. This field allows the strategy to dynamically expand the set of participants, reflecting organic growth or specific testing requirements. +/// - `identity_inserts`: Controls the stochastic introduction of new identities into the simulation, based on a defined frequency distribution. This field allows the strategy to dynamically expand the set of participants, reflecting organic growth or specific testing requirements. /// /// - `identity_contract_nonce_gaps`: Optionally defines intervals at which nonce values for identities and contracts may be artificially incremented, introducing realistic entropy or testing specific edge cases. /// @@ -101,13 +102,13 @@ pub type KeyMaps = BTreeMap>>; /// It's imperative to maintain coherence among the specified operations, identities, and contracts within the `Strategy` to ensure the simulated scenarios accurately reflect intended behaviors or test conditions. Discrepancies or inconsistencies may result in unexpected outcomes or hinder the simulation's effectiveness in achieving its objectives. #[derive(Clone, Debug, PartialEq, Default)] pub struct Strategy { - pub contracts_with_updates: Vec<( + pub start_identities: StartIdentities, + pub start_contracts: Vec<( CreatedDataContract, Option>, )>, pub operations: Vec, - pub start_identities: StartIdentities, - pub identities_inserts: IdentityInsertInfo, + pub identity_inserts: IdentityInsertInfo, pub identity_contract_nonce_gaps: Option, pub signer: Option, } @@ -183,10 +184,10 @@ impl PlatformSerializableWithPlatformVersion for Strategy { platform_version: &PlatformVersion, ) -> Result, ProtocolError> { let Strategy { - contracts_with_updates, + start_contracts: contracts_with_updates, operations, start_identities, - identities_inserts, + identity_inserts: identities_inserts, identity_contract_nonce_gaps, signer, } = self; @@ -307,10 +308,10 @@ impl PlatformDeserializableWithPotentialValidationFromVersionedStructure for Str .collect::, ProtocolError>>()?; Ok(Strategy { - contracts_with_updates, + start_contracts: contracts_with_updates, operations, start_identities, - identities_inserts, + identity_inserts: identities_inserts, identity_contract_nonce_gaps, signer, }) @@ -399,6 +400,7 @@ impl Strategy { let mut finalize_block_operations = vec![]; // Get identity state transitions + // Start identities are done on the 1st block, identity inserts are done on 3rd+ blocks let identity_state_transitions = match self.identity_state_transitions_for_block( block_info, self.start_identities.starting_balances, @@ -419,8 +421,8 @@ impl Strategy { let (identities, mut state_transitions): (Vec, Vec) = identity_state_transitions.into_iter().unzip(); - // Add initial contracts for contracts_with_updates on first block of strategy - if block_info.height == config.start_block_height { + // Add initial contracts for contracts_with_updates on 2nd block of strategy + if block_info.height == config.start_block_height + 1 { let mut contract_state_transitions = self.initial_contract_state_transitions( current_identities, identity_nonce_counter, @@ -429,8 +431,8 @@ impl Strategy { platform_version, ); state_transitions.append(&mut contract_state_transitions); - } else { - // Do operations and contract updates after the first block + } else if block_info.height > config.start_block_height + 1 { + // Do operations and contract updates after the first two blocks let (mut operations_state_transitions, mut add_to_finalize_block_operations) = self .operations_based_transitions( document_query_callback, @@ -1191,7 +1193,7 @@ impl Strategy { let public_key = identity .get_first_public_key_matching( Purpose::AUTHENTICATION, - HashSet::from([SecurityLevel::CRITICAL]), + HashSet::from([SecurityLevel::HIGH, SecurityLevel::CRITICAL]), HashSet::from([KeyType::ECDSA_SECP256K1]), ) .expect("Expected to get identity public key in ContractCreate"); @@ -1355,16 +1357,16 @@ impl Strategy { } // Add identities_inserts - // Don't do this on first block because we need to skip utxo refresh - if block_info.height > config.start_block_height { - let frequency = &self.identities_inserts.frequency; + // Don't do this on first two blocks (per design but also we need to skip utxo refresh) + if block_info.height > config.start_block_height + 1 { + let frequency = &self.identity_inserts.frequency; if frequency.check_hit(rng) { let count = frequency.events(rng); // number of identities to create let mut new_transitions = crate::transitions::create_identities_state_transitions( count, - self.identities_inserts.start_keys as KeyID, - &self.identities_inserts.extra_keys, + self.identity_inserts.start_keys as KeyID, + &self.identity_inserts.extra_keys, 200000, // 0.002 dash signer, rng, @@ -1423,28 +1425,40 @@ impl Strategy { ) -> Vec { let mut id_mapping = HashMap::new(); // Maps old IDs to new IDs - self.contracts_with_updates + self.start_contracts .iter_mut() .map(|(created_contract, contract_updates)| { // Select a random identity from current_identities to be the contract owner let identity_num = rng.gen_range(0..current_identities.len()); + let identity = current_identities .get(identity_num) - .unwrap() - .clone() - .into_partial_identity_info(); + .expect("Expected to find the identity in the current_identities"); + + let identity_public_key = identity.get_first_public_key_matching( + Purpose::AUTHENTICATION, + HashSet::from([SecurityLevel::HIGH, SecurityLevel::CRITICAL]), + HashSet::from([KeyType::ECDSA_SECP256K1]), + ) + .expect("Expected to get identity public key in initial_contract_state_transitions"); + let key_id = identity_public_key.id(); + + let partial_identity = identity.clone().into_partial_identity_info(); + let partial_identity_public_key = partial_identity.loaded_public_keys.values() + .find(|&public_key| public_key.id() == key_id) + .expect("No public key with matching id found"); let contract = created_contract.data_contract_mut(); // Get and bump the identity nonce - let identity_nonce = identity_nonce_counter.entry(identity.id).or_default(); + let identity_nonce = identity_nonce_counter.entry(partial_identity.id).or_default(); *identity_nonce += 1; // Set the contract ID and owner ID with the random identity - contract.set_owner_id(identity.id); + contract.set_owner_id(partial_identity.id); let old_id = contract.id(); let new_id = - DataContract::generate_data_contract_id_v0(identity.id, *identity_nonce); + DataContract::generate_data_contract_id_v0(partial_identity.id, *identity_nonce); contract.set_id(new_id); id_mapping.insert(old_id, new_id); // Store the mapping @@ -1473,16 +1487,21 @@ impl Strategy { } } - DataContractCreateTransition::new_from_data_contract( + match DataContractCreateTransition::new_from_data_contract( contract.clone(), *identity_nonce, - &identity, - 2, + &partial_identity, + partial_identity_public_key.id(), signer, platform_version, None, - ) - .expect("expected to create a create state transition from a data contract") + ) { + Ok(transition) => transition, + Err(e) => { + tracing::error!("Error creating DataContractCreateTransition: {e}"); + panic!(); + } + } }) .collect() } @@ -1533,7 +1552,7 @@ impl Strategy { ) -> Vec { // Collect updates let updates: Vec<_> = self - .contracts_with_updates + .start_contracts .iter() .flat_map(|(_, contract_updates_option)| { contract_updates_option @@ -1721,7 +1740,7 @@ mod tests { }; let strategy = Strategy { - contracts_with_updates: vec![], + start_contracts: vec![], operations: vec![ Operation { op_type: OperationType::Document(document_op_1), @@ -1744,7 +1763,7 @@ mod tests { starting_balances: 100_000_000, extra_keys: BTreeMap::new(), }, - identities_inserts: Default::default(), + identity_inserts: Default::default(), identity_contract_nonce_gaps: None, signer: Some(simple_signer), }; diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index 1eb97d3b811..94c36f5cbe0 100644 --- a/packages/strategy-tests/src/transitions.rs +++ b/packages/strategy-tests/src/transitions.rs @@ -634,7 +634,7 @@ pub fn create_identities_state_transitions( count: u16, key_count: KeyID, extra_keys: &KeyMaps, - balance: u64, + _balance: u64, signer: &mut SimpleSigner, rng: &mut StdRng, asset_lock_proofs: &mut Vec<(AssetLockProof, PrivateKey)>,