From 9d99ff110f3fc504ab17bf68cd14aaf740166087 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Mon, 8 Apr 2024 20:21:36 +0700 Subject: [PATCH 1/5] feat: register init contracts on second block of strategy --- Cargo.lock | 116 +++++++++--------- .../v0/v0_methods.rs | 27 ++-- packages/strategy-tests/src/lib.rs | 55 ++++++--- packages/strategy-tests/src/transitions.rs | 2 +- 4 files changed, 114 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 339360ad000..628699b2663 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -192,7 +192,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -203,7 +203,7 @@ checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -378,7 +378,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.55", + "syn 2.0.58", "which", ] @@ -509,7 +509,7 @@ dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", "syn_derive", ] @@ -658,9 +658,9 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.35" +version = "0.4.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" dependencies = [ "android-tzdata", "iana-time-zone", @@ -736,7 +736,7 @@ dependencies = [ "anstream", "anstyle", "clap_lex", - "strsim 0.11.0", + "strsim 0.11.1", ] [[package]] @@ -748,7 +748,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -997,7 +997,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1023,7 +1023,7 @@ dependencies = [ "dapi-grpc", "heck 0.4.1", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1047,7 +1047,7 @@ dependencies = [ "proc-macro2", "quote", "strsim 0.10.0", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1058,7 +1058,7 @@ checksum = "a668eda54683121533a393014d8692171709ff57a7d61f187b6e782719f8933f" dependencies = [ "darling_core", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1160,9 +1160,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -1462,7 +1462,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1753,7 +1753,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -1911,9 +1911,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.25" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fbd2820c5e49886948654ab546d0688ff24530286bdcf8fca3cefb16d4618eb" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -2476,9 +2476,9 @@ checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "metrics" @@ -2517,7 +2517,7 @@ checksum = "38b4faf00617defe497754acde3024865bc143d44a86799b24e191ecff91354f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -2717,7 +2717,7 @@ checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -2899,14 +2899,14 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -2944,7 +2944,7 @@ version = "1.0.0-dev.10" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", "virtue 0.0.14", ] @@ -2974,7 +2974,7 @@ name = "platform-value-convertible" version = "1.0.0-dev.10" dependencies = [ "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -2990,7 +2990,7 @@ version = "1.0.0-dev.10" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3118,7 +3118,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" dependencies = [ "proc-macro2", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3232,7 +3232,7 @@ dependencies = [ "prost 0.12.3", "prost-types 0.12.3", "regex", - "syn 2.0.55", + "syn 2.0.58", "tempfile", "which", ] @@ -3260,7 +3260,7 @@ dependencies = [ "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3704,9 +3704,9 @@ dependencies = [ [[package]] name = "rustls-pki-types" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "868e20fada228fefaf6b652e00cc73623d54f8171e7352c18bb281571f2d92da" +checksum = "ecd36cc4259e3e4514335c4a138c6b43171a8d61d8f5c9348f9fc7529416f247" [[package]] name = "rustls-webpki" @@ -3803,9 +3803,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.9.2" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -3816,9 +3816,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.1" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" dependencies = [ "core-foundation-sys", "libc", @@ -3879,7 +3879,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3902,7 +3902,7 @@ checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3946,7 +3946,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -3958,7 +3958,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4127,9 +4127,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" @@ -4172,7 +4172,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4203,9 +4203,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.55" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "002a1b3dbf967edfafc32655d0f377ab0bb7b994aa1d32c8cc7e9b8bf3ebb8f0" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -4221,7 +4221,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4386,7 +4386,7 @@ checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4457,9 +4457,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.36.0" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ "backtrace", "bytes", @@ -4493,7 +4493,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4654,7 +4654,7 @@ dependencies = [ "proc-macro2", "prost-build 0.12.3", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4708,7 +4708,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4982,7 +4982,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", "wasm-bindgen-shared", ] @@ -5016,7 +5016,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5317,7 +5317,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -5340,9 +5340,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.9+zstd.1.5.5" +version = "2.0.10+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e16efa8a874a0481a574084d34cc26fdb3b99627480f785888deb6386506656" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" dependencies = [ "cc", "pkg-config", 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/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index b2de4ca3531..957f467a75e 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; @@ -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,8 +1357,8 @@ 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 { + // 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.identities_inserts.frequency; if frequency.check_hit(rng) { let count = frequency.events(rng); // number of identities to create @@ -1428,23 +1430,35 @@ impl Strategy { .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 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 = 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() } diff --git a/packages/strategy-tests/src/transitions.rs b/packages/strategy-tests/src/transitions.rs index d025169c840..281860a1970 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)>, From e5b86b9cf33e3bc0e051e89cad7a91e7b0ebc091 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 9 Apr 2024 13:36:09 +0700 Subject: [PATCH 2/5] fix: rename variable --- packages/strategy-tests/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index 957f467a75e..28821f9e709 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -1435,13 +1435,13 @@ impl Strategy { .get(identity_num) .expect("Expected to find the identity in the current_identities"); - let public_key = identity.get_first_public_key_matching( + 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 = public_key.id(); + 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() From 0d74e319c30b78730f18561fd71cc3c33951e36d Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 9 Apr 2024 14:05:58 +0700 Subject: [PATCH 3/5] fix: derive Serialize for DocumentProperty --- Cargo.lock | 4 ++-- .../rs-dpp/src/data_contract/document_type/property/mod.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bf4f7747fa8..873fab2a3dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -390,7 +390,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] @@ -4198,7 +4198,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.55", + "syn 2.0.58", ] [[package]] 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, From 91e4a472711f3663fc4cb1d389c64d34c91258fe Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Tue, 9 Apr 2024 16:40:38 +0700 Subject: [PATCH 4/5] fix: add back dependency features needed in TUI --- Cargo.lock | 1 + packages/rs-dpp/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 873fab2a3dd..06abe3543eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2176,6 +2176,7 @@ checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown 0.14.3", + "serde", ] [[package]] diff --git a/packages/rs-dpp/Cargo.toml b/packages/rs-dpp/Cargo.toml index 370c6780b0c..26a56ffcc74 100644 --- a/packages/rs-dpp/Cargo.toml +++ b/packages/rs-dpp/Cargo.toml @@ -62,7 +62,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"] } [dev-dependencies] From ee01702262608c49fbeca50df00031f9b00d7f0a Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 12 Apr 2024 11:59:06 +0700 Subject: [PATCH 5/5] feat: rename contracts_with_updates to start_contracts --- .../tests/strategy_tests/chain_lock_update.rs | 4 +- .../tests/strategy_tests/core_update_tests.rs | 12 +- .../tests/strategy_tests/failures.rs | 13 +- .../tests/strategy_tests/main.rs | 146 +++++++++--------- .../tests/strategy_tests/query.rs | 12 +- .../tests/strategy_tests/strategy.rs | 14 +- .../strategy_tests/upgrade_fork_tests.rs | 28 ++-- packages/strategy-tests/src/lib.rs | 36 ++--- 8 files changed, 131 insertions(+), 134 deletions(-) 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 28821f9e709..10057af099f 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -74,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. /// @@ -102,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, } @@ -184,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; @@ -308,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, }) @@ -1359,14 +1359,14 @@ impl Strategy { // Add identities_inserts // 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.identities_inserts.frequency; + 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, @@ -1425,7 +1425,7 @@ 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 @@ -1552,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 @@ -1740,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), @@ -1763,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), };