From 385b78f3eb8c0278603f211dac23da2a418a4efc Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Sun, 29 Sep 2024 16:28:31 +0700 Subject: [PATCH] fmt --- .../v0/mod.rs | 2 +- .../v1/mod.rs | 2 +- .../tests/strategy_tests/main.rs | 11 + .../tests/strategy_tests/withdrawal_tests.rs | 247 ++++++++---------- packages/rs-drive-proof-verifier/src/types.rs | 1 - .../batch_delete_items_in_path_query/mod.rs | 1 - .../v0/mod.rs | 2 +- .../mod.rs | 2 +- packages/strategy-tests/src/lib.rs | 8 +- 9 files changed, 136 insertions(+), 140 deletions(-) diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs index ea781f33243..43eb43eea5a 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v0/mod.rs @@ -8,7 +8,6 @@ use drive::grovedb::TransactionArg; use dpp::system_data_contracts::withdrawals_contract; use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal; -use drive::config::DEFAULT_QUERY_LIMIT; use crate::platform_types::platform_state::v0::PlatformStateV0Methods; use crate::platform_types::platform_state::PlatformState; @@ -186,6 +185,7 @@ mod tests { use dpp::platform_value::platform_value; use dpp::system_data_contracts::load_system_data_contract; use dpp::version::PlatformVersion; + use drive::config::DEFAULT_QUERY_LIMIT; #[test] fn test_pooling() { diff --git a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs index da882cc1556..6d2fbad5084 100644 --- a/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs +++ b/packages/rs-drive-abci/src/execution/platform_events/withdrawals/pool_withdrawals_into_transactions_queue/v1/mod.rs @@ -8,7 +8,6 @@ use drive::grovedb::TransactionArg; use dpp::system_data_contracts::withdrawals_contract; use dpp::system_data_contracts::withdrawals_contract::v1::document_types::withdrawal; -use drive::config::DEFAULT_QUERY_LIMIT; use crate::{ error::{execution::ExecutionError, Error}, @@ -168,6 +167,7 @@ mod tests { use dpp::platform_value::platform_value; use dpp::system_data_contracts::load_system_data_contract; use dpp::version::PlatformVersion; + use drive::config::DEFAULT_QUERY_LIMIT; #[test] fn test_pooling() { diff --git a/packages/rs-drive-abci/tests/strategy_tests/main.rs b/packages/rs-drive-abci/tests/strategy_tests/main.rs index 975316a7dee..648ae05b7f2 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/main.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/main.rs @@ -47,6 +47,7 @@ mod tests { use crate::execution::{continue_chain_for_strategy, run_chain_for_strategy}; use crate::query::QueryStrategy; use crate::strategy::{FailureStrategy, MasternodeListChangesStrategy}; + use assert_matches::assert_matches; use dashcore_rpc::dashcore::hashes::Hash; use dashcore_rpc::dashcore::BlockHash; use dashcore_rpc::json::QuorumType; @@ -1248,6 +1249,16 @@ mod tests { let outcome = run_chain_for_strategy(&mut platform, 1, strategy, config, 15, &mut None); + for tx_results_per_block in outcome.state_transition_results_per_block.values() { + for (state_transition, result) in tx_results_per_block { + assert_eq!( + result.code, 0, + "state transition got code {} : {:?}", + result.code, state_transition + ); + } + } + outcome .abci_app .platform diff --git a/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs b/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs index 7b54353c191..e0c33984174 100644 --- a/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs +++ b/packages/rs-drive-abci/tests/strategy_tests/withdrawal_tests.rs @@ -1809,153 +1809,138 @@ mod tests { outcome }; - let ChainExecutionOutcome { + let outcome = continue_chain_for_strategy( abci_app, - proposers, - validator_quorums: quorums, - current_validator_quorum_hash: current_quorum_hash, - current_proposer_versions, - end_time_ms, - identity_nonce_counter, - identity_contract_nonce_counter, - instant_lock_quorums, - identities, - .. - } = { - let outcome = continue_chain_for_strategy( - abci_app, - ChainExecutionParameters { - block_start: 71, - core_height_start: 1, - block_count: 250, - proposers, - validator_quorums: quorums, - current_validator_quorum_hash: current_quorum_hash, - current_proposer_versions: Some(current_proposer_versions), - current_identity_nonce_counter: identity_nonce_counter, - current_identity_contract_nonce_counter: identity_contract_nonce_counter, - current_votes: BTreeMap::default(), - start_time_ms: GENESIS_TIME_MS, - current_time_ms: end_time_ms + 1000, - instant_lock_quorums, - current_identities: identities, - }, - continue_strategy_no_operations.clone(), - PlatformConfig { - validator_set: ValidatorSetConfig::default_100_67(), - chain_lock: ChainLockConfig::default_100_67(), - instant_lock: InstantLockConfig::default_100_67(), - execution: ExecutionConfig { - verify_sum_trees: true, + ChainExecutionParameters { + block_start: 71, + core_height_start: 1, + block_count: 250, + proposers, + validator_quorums: quorums, + current_validator_quorum_hash: current_quorum_hash, + current_proposer_versions: Some(current_proposer_versions), + current_identity_nonce_counter: identity_nonce_counter, + current_identity_contract_nonce_counter: identity_contract_nonce_counter, + current_votes: BTreeMap::default(), + start_time_ms: GENESIS_TIME_MS, + current_time_ms: end_time_ms + 1000, + instant_lock_quorums, + current_identities: identities, + }, + continue_strategy_no_operations.clone(), + PlatformConfig { + validator_set: ValidatorSetConfig::default_100_67(), + chain_lock: ChainLockConfig::default_100_67(), + instant_lock: InstantLockConfig::default_100_67(), + execution: ExecutionConfig { + verify_sum_trees: true, - ..Default::default() - }, - block_spacing_ms: hour_in_ms, - initial_protocol_version: TEST_PLATFORM_V3.protocol_version, - testing_configs: PlatformTestConfig::default_minimal_verifications(), ..Default::default() }, - StrategyRandomness::SeedEntropy(9), - ); + block_spacing_ms: hour_in_ms, + initial_protocol_version: TEST_PLATFORM_V3.protocol_version, + testing_configs: PlatformTestConfig::default_minimal_verifications(), + ..Default::default() + }, + StrategyRandomness::SeedEntropy(9), + ); - // We should have unlocked the amounts by now - let locked_amount = outcome - .abci_app - .platform - .drive - .grove_get_sum_tree_total_value( - (&get_withdrawal_root_path()).into(), - &WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, - DirectQueryType::StatefulDirectQuery, - None, - &mut vec![], - &platform_version.drive, - ) - .expect("expected to get locked amount"); + // We should have unlocked the amounts by now + let locked_amount = outcome + .abci_app + .platform + .drive + .grove_get_sum_tree_total_value( + (&get_withdrawal_root_path()).into(), + &WITHDRAWAL_TRANSACTIONS_SUM_AMOUNT_TREE_KEY, + DirectQueryType::StatefulDirectQuery, + None, + &mut vec![], + &platform_version.drive, + ) + .expect("expected to get locked amount"); - // We have nothing locked left - assert_eq!(locked_amount, 0); + // We have nothing locked left + assert_eq!(locked_amount, 0); - // Withdrawal documents with pooled status should not exist. - let withdrawal_documents_pooled = outcome - .abci_app - .platform - .drive - .fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::POOLED.into(), - DEFAULT_QUERY_LIMIT, - None, - platform_version, - ) - .unwrap(); + // Withdrawal documents with pooled status should not exist. + let withdrawal_documents_pooled = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::POOLED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); - // None are currently pooled since we have no more room - assert!(withdrawal_documents_pooled.is_empty()); + // None are currently pooled since we have no more room + assert!(withdrawal_documents_pooled.is_empty()); - // Withdrawal documents with queued status should exist. - let withdrawal_documents_queued = outcome - .abci_app - .platform - .drive - .fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::QUEUED.into(), - DEFAULT_QUERY_LIMIT, - None, - platform_version, - ) - .unwrap(); + // Withdrawal documents with queued status should exist. + let withdrawal_documents_queued = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::QUEUED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); - // Nothing is left in the queue - assert_eq!(withdrawal_documents_queued.len(), 0); + // Nothing is left in the queue + assert_eq!(withdrawal_documents_queued.len(), 0); - // Withdrawal documents with queued status should exist. - let withdrawal_documents_completed = outcome - .abci_app - .platform - .drive - .fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::COMPLETE.into(), - DEFAULT_QUERY_LIMIT, - None, - platform_version, - ) - .unwrap(); + // Withdrawal documents with queued status should exist. + let withdrawal_documents_completed = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::COMPLETE.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); - // None have completed because core didn't acknowledge them - assert_eq!(withdrawal_documents_completed.len(), 0); + // None have completed because core didn't acknowledge them + assert_eq!(withdrawal_documents_completed.len(), 0); - // Withdrawal documents with EXPIRED status should not exist yet. - let withdrawal_documents_expired = outcome - .abci_app - .platform - .drive - .fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::EXPIRED.into(), - DEFAULT_QUERY_LIMIT, - None, - platform_version, - ) - .unwrap(); + // Withdrawal documents with EXPIRED status should not exist yet. + let withdrawal_documents_expired = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::EXPIRED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); - // We have none expired yet, because the core height never went up - assert_eq!(withdrawal_documents_expired.len(), 0); + // We have none expired yet, because the core height never went up + assert_eq!(withdrawal_documents_expired.len(), 0); - // Withdrawal documents with broadcasted status should exist. - let withdrawal_documents_broadcasted = outcome - .abci_app - .platform - .drive - .fetch_oldest_withdrawal_documents_by_status( - withdrawals_contract::WithdrawalStatus::BROADCASTED.into(), - DEFAULT_QUERY_LIMIT, - None, - platform_version, - ) - .unwrap(); + // Withdrawal documents with broadcasted status should exist. + let withdrawal_documents_broadcasted = outcome + .abci_app + .platform + .drive + .fetch_oldest_withdrawal_documents_by_status( + withdrawals_contract::WithdrawalStatus::BROADCASTED.into(), + DEFAULT_QUERY_LIMIT, + None, + platform_version, + ) + .unwrap(); - assert_eq!(withdrawal_documents_broadcasted.len(), 80); - outcome - }; + assert_eq!(withdrawal_documents_broadcasted.len(), 80); } #[test] diff --git a/packages/rs-drive-proof-verifier/src/types.rs b/packages/rs-drive-proof-verifier/src/types.rs index d28ba693026..c1778ab536b 100644 --- a/packages/rs-drive-proof-verifier/src/types.rs +++ b/packages/rs-drive-proof-verifier/src/types.rs @@ -29,7 +29,6 @@ use std::collections::{BTreeMap, BTreeSet}; use dpp::block::block_info::BlockInfo; use dpp::core_types::validator_set::ValidatorSet; -use dpp::dashcore::QuorumHash; use dpp::voting::vote_info_storage::contested_document_vote_poll_winner_info::ContestedDocumentVotePollWinnerInfo; use drive::grovedb::query_result_type::Path; #[cfg(feature = "mocks")] diff --git a/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/mod.rs index e43191f4ccc..24b03094ef4 100644 --- a/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/mod.rs @@ -9,7 +9,6 @@ use crate::util::grove_operations::BatchDeleteApplyType; use dpp::version::drive_versions::DriveVersion; use grovedb::{PathQuery, TransactionArg}; -use grovedb_path::SubtreePath; impl Drive { /// Pushes multiple "delete element" operations for items in a given path based on a `PathQuery` to `drive_operations`. diff --git a/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs index b03fc91efd2..a530776986d 100644 --- a/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/batch_delete_items_in_path_query/v0/mod.rs @@ -8,7 +8,7 @@ use grovedb::batch::key_info::KeyInfo; use grovedb::batch::KeyInfoPath; use grovedb::operations::delete::DeleteOptions; use grovedb::query_result_type::QueryResultType; -use grovedb::{Element, GroveDb, PathQuery, TransactionArg}; +use grovedb::{GroveDb, PathQuery, TransactionArg}; use grovedb_storage::rocksdb_storage::RocksDbStorage; use platform_version::version::drive_versions::DriveVersion; diff --git a/packages/rs-drive/src/util/grove_operations/batch_insert_sum_item_or_add_to_if_already_exists/mod.rs b/packages/rs-drive/src/util/grove_operations/batch_insert_sum_item_or_add_to_if_already_exists/mod.rs index 83bbd76a489..bf175b75015 100644 --- a/packages/rs-drive/src/util/grove_operations/batch_insert_sum_item_or_add_to_if_already_exists/mod.rs +++ b/packages/rs-drive/src/util/grove_operations/batch_insert_sum_item_or_add_to_if_already_exists/mod.rs @@ -9,7 +9,7 @@ use crate::fees::op::LowLevelDriveOperation; use crate::util::object_size_info::PathKeyElementInfo; use dpp::version::drive_versions::DriveVersion; -use grovedb::{Element, TransactionArg}; +use grovedb::TransactionArg; impl Drive { /// Pushes an "insert sum item or add to it if the item already exists" operation to `drive_operations`. diff --git a/packages/strategy-tests/src/lib.rs b/packages/strategy-tests/src/lib.rs index 780a9ea0a44..61395d99f2a 100644 --- a/packages/strategy-tests/src/lib.rs +++ b/packages/strategy-tests/src/lib.rs @@ -45,7 +45,7 @@ use rand::prelude::StdRng; use rand::seq::{IteratorRandom, SliceRandom}; use rand::Rng; use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; -use std::ops::{Range, RangeInclusive}; +use std::ops::RangeInclusive; use bincode::{Decode, Encode}; use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters; use dpp::identifier::Identifier; @@ -53,7 +53,7 @@ use dpp::data_contract::document_type::DocumentType; use dpp::fee::Credits; use dpp::identity::accessors::IdentityGettersV0; use dpp::platform_value::{BinaryData, Bytes32, Value}; -use dpp::ProtocolError; +use dpp::{dash_to_duffs, ProtocolError}; use dpp::ProtocolError::{PlatformDeserializationError, PlatformSerializationError}; use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0; use dpp::state_transition::documents_batch_transition::document_create_transition::{DocumentCreateTransition, DocumentCreateTransitionV0}; @@ -164,7 +164,7 @@ impl Default for IdentityInsertInfo { frequency: Default::default(), start_keys: 5, extra_keys: Default::default(), - start_balance_range: 100..=100, + start_balance_range: dash_to_duffs!(1)..=dash_to_duffs!(1), } } } @@ -1863,6 +1863,7 @@ mod tests { use crate::operations::{DocumentAction, DocumentOp, Operation, OperationType}; use crate::transitions::create_state_transitions_for_identities; use crate::{StartIdentities, Strategy}; + use dpp::dash_to_duffs; use dpp::data_contract::accessors::v0::DataContractV0Getters; use dpp::data_contract::document_type::random_document::{ DocumentFieldFillSize, DocumentFieldFillType, @@ -1912,6 +1913,7 @@ mod tests { let start_identities = create_state_transitions_for_identities( vec![identity1, identity2], + &(dash_to_duffs!(1)..=dash_to_duffs!(1)), &mut simple_signer, &mut rng, platform_version,