Skip to content

Commit

Permalink
feat: implement mempool document counter in strategy tests (#1848)
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldelucia authored May 21, 2024
2 parents 3e163aa + f15725b commit 74f552f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl CreateRandomDocument for DocumentType {
document_field_fill_size,
rng,
platform_version,
), // Add more cases as necessary for other variants
),
}
}
}
Expand Down
25 changes: 24 additions & 1 deletion packages/strategy-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ impl Strategy {
signer: &mut SimpleSigner,
identity_nonce_counter: &mut BTreeMap<Identifier, u64>,
contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>,
mempool_document_counter: BTreeMap<(Identifier, Identifier), u64>,
rng: &mut StdRng,
config: &StrategyConfig,
platform_version: &PlatformVersion,
Expand Down Expand Up @@ -449,6 +450,7 @@ impl Strategy {
signer,
identity_nonce_counter,
contract_nonce_counter,
mempool_document_counter,
rng,
platform_version,
);
Expand Down Expand Up @@ -541,6 +543,7 @@ impl Strategy {
signer: &mut SimpleSigner,
identity_nonce_counter: &mut BTreeMap<Identifier, u64>,
contract_nonce_counter: &mut BTreeMap<(Identifier, Identifier), u64>,
mempool_document_counter: BTreeMap<(Identifier, Identifier), u64>,
rng: &mut StdRng,
platform_version: &PlatformVersion,
) -> (Vec<StateTransition>, Vec<FinalizeBlockOperation>) {
Expand All @@ -566,11 +569,31 @@ impl Strategy {
document_type,
contract,
}) => {
// Get the first 10 identities who are eligible to submit documents for this contract
let first_10_eligible_identities: Vec<Identity> = current_identities
.iter()
.filter(|identity| {
mempool_document_counter
.get(&(identity.id(), contract.id()))
.unwrap_or(&0)
< &24u64
})
.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,
current_identities,
&first_10_eligible_identities,
Some(block_info.time_ms),
Some(block_info.height),
Some(block_info.core_height),
Expand Down

0 comments on commit 74f552f

Please sign in to comment.