From fc5c7b8cc586417336b79521a0e29ce495678206 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Sun, 19 May 2024 14:19:00 +0200 Subject: [PATCH 1/2] feat: implement mempool document counter in strategy tests --- .../document_type/random_document.rs | 2 +- packages/strategy-tests/src/lib.rs | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/rs-dpp/src/data_contract/document_type/random_document.rs b/packages/rs-dpp/src/data_contract/document_type/random_document.rs index 9c91f4f7f50..e64256540ee 100644 --- a/packages/rs-dpp/src/data_contract/document_type/random_document.rs +++ b/packages/rs-dpp/src/data_contract/document_type/random_document.rs @@ -307,7 +307,7 @@ impl CreateRandomDocument for DocumentType { document_field_fill_size, rng, platform_version, - ), // Add more cases as necessary for other variants + ), } } } diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index d8a0182c027..1ef2191ca66 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -394,6 +394,7 @@ impl Strategy { signer: &mut SimpleSigner, identity_nonce_counter: &mut BTreeMap, contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>, + mempool_document_counter: BTreeMap<(Identifier, Identifier), u64>, rng: &mut StdRng, config: &StrategyConfig, platform_version: &PlatformVersion, @@ -449,6 +450,7 @@ impl Strategy { signer, identity_nonce_counter, contract_nonce_counter, + mempool_document_counter, rng, platform_version, ); @@ -541,6 +543,7 @@ impl Strategy { signer: &mut SimpleSigner, identity_nonce_counter: &mut BTreeMap, contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>, + mempool_document_counter: BTreeMap<(Identifier, Identifier), u64>, rng: &mut StdRng, platform_version: &PlatformVersion, ) -> (Vec, Vec) { @@ -566,11 +569,24 @@ impl Strategy { document_type, contract, }) => { + // Get the first 3 identities who are eligible to submit documents for this contract + let first_3_eligible_identities: Vec = current_identities + .iter() + .filter(|identity| { + mempool_document_counter + .get(&(identity.id(), contract.id())) + .unwrap_or(&0) + < &24u64 + }) + .take(3) + .cloned() + .collect(); + // TO-DO: these documents should be created according to the data contract's validation rules let documents = document_type .random_documents_with_params( count as u32, - current_identities, + &first_3_eligible_identities, Some(block_info.time_ms), Some(block_info.height), Some(block_info.core_height), From f15725b27512f026238a7bb3d13695836a306a89 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Mon, 20 May 2024 13:04:43 +0200 Subject: [PATCH 2/2] change to 10 eligible identities and add warning if there are 0 --- packages/strategy-tests/src/lib.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index 1ef2191ca66..35505244727 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -569,8 +569,8 @@ impl Strategy { document_type, contract, }) => { - // Get the first 3 identities who are eligible to submit documents for this contract - let first_3_eligible_identities: Vec = current_identities + // Get the first 10 identities who are eligible to submit documents for this contract + let first_10_eligible_identities: Vec = current_identities .iter() .filter(|identity| { mempool_document_counter @@ -578,15 +578,22 @@ impl Strategy { .unwrap_or(&0) < &24u64 }) - .take(3) + .take(10) .cloned() .collect(); + if first_10_eligible_identities.len() == 0 { + tracing::warn!( + "No eligible identities to submit a document to contract {}", + contract.id().to_string(Encoding::Base64) + ); + } + // TO-DO: these documents should be created according to the data contract's validation rules let documents = document_type .random_documents_with_params( count as u32, - &first_3_eligible_identities, + &first_10_eligible_identities, Some(block_info.time_ms), Some(block_info.height), Some(block_info.core_height),