Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement mempool document counter in strategy tests #1848

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
shumkov marked this conversation as resolved.
Show resolved Hide resolved
.iter()
.filter(|identity| {
mempool_document_counter
.get(&(identity.id(), contract.id()))
.unwrap_or(&0)
shumkov marked this conversation as resolved.
Show resolved Hide resolved
< &24u64
})
.take(10)
.cloned()
shumkov marked this conversation as resolved.
Show resolved Hide resolved
.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
Loading