Skip to content

Commit

Permalink
fix: fixed voting strategy tests and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jul 4, 2024
1 parent 28c2c68 commit 31734d8
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 35 deletions.
2 changes: 0 additions & 2 deletions packages/rs-dpp/src/voting/contender_structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use crate::document::Document;
use crate::identity::state_transition::asset_lock_proof::{Decode, Encode};
use crate::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
use crate::ProtocolError;
use platform_value::string_encoding::Encoding;
use platform_value::Identifier;
use platform_version::version::PlatformVersion;
use std::fmt;
use std::fmt::format;

pub use contender::v0::{ContenderV0, ContenderWithSerializedDocumentV0};
pub use contender::{Contender, ContenderWithSerializedDocument};
Expand Down
16 changes: 8 additions & 8 deletions packages/rs-drive-abci/src/execution/platform_events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
pub(in crate::execution) mod block_end;
/// Block fee processing
pub(in crate::execution) mod block_fee_processing;
/// Events happening what starting to process a block
pub(in crate::execution) mod block_start;
/// Update from core such as a masternode list update or quorums being updated
pub(in crate::execution) mod core_based_updates;
/// Verify the chain lock
pub(in crate::execution) mod core_chain_lock;
/// Instant lock methods
pub(in crate::execution) mod core_instant_send_lock;
/// Core subsidy
pub(in crate::execution) mod core_subsidy;
/// Epoch based methods
Expand All @@ -18,13 +24,7 @@ pub(in crate::execution) mod initialization;
pub(in crate::execution) mod protocol_upgrade;
/// State transition processing
pub(in crate::execution) mod state_transition_processing;
/// Withdrawal methods
pub(in crate::execution) mod withdrawals;
/// Events happening what starting to process a block
pub(in crate::execution) mod block_start;
/// Verify the chain lock
pub(in crate::execution) mod core_chain_lock;
/// Voting
pub(in crate::execution) mod voting;
/// Instant lock methods
pub(in crate::execution) mod core_instant_send_lock;
/// Withdrawal methods
pub(in crate::execution) mod withdrawals;
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ use crate::platform_types::platform_state::PlatformState;
use crate::rpc::core::CoreRPCLike;
use dashcore_rpc::dashcore_rpc_json::MasternodeType;
use dpp::block::block_info::BlockInfo;
use dpp::consensus::state::voting::masternode_not_found_error::MasternodeNotFoundError;
use dpp::dashcore::hashes::Hash;
use dpp::dashcore::ProTxHash;
use dpp::identifier::Identifier;
use dpp::prelude::ConsensusValidationResult;
use dpp::version::PlatformVersion;
use dpp::voting::contender_structs::FinalizedResourceVoteChoicesWithVoterInfo;
use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ mod tests {
use dpp::document::Document;
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
use dpp::util::hash::hash_double;
use dpp::util::strings::convert_to_homograph_safe_chars;
use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice::TowardsIdentity;
use drive::drive::object_size_info::DataContractResolvedInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2732,9 +2732,32 @@ mod tests {
Some(4),
false,
None,
ResultType::VoteTally,
ResultType::Documents,
platform_version,
);

assert_eq!(
(contenders.len(), abstaining, locking, finished_vote_info),
(4, None, None, None)
);

let (contenders, abstaining, locking, finished_vote_info) =
get_proved_vote_states(
&platform,
&platform_state,
&dpns_contract,
"quantum",
Some(4),
true,
None,
ResultType::Documents,
platform_version,
);

assert_eq!(
(contenders.len(), abstaining, locking, finished_vote_info),
(4, None, None, None)
);
}

// VoteTally
Expand All @@ -2751,6 +2774,29 @@ mod tests {
ResultType::VoteTally,
platform_version,
);

assert_eq!(
(contenders.len(), abstaining, locking, finished_vote_info),
(4, None, None, None)
);

let (contenders, abstaining, locking, finished_vote_info) =
get_proved_vote_states(
&platform,
&platform_state,
&dpns_contract,
"quantum",
Some(4),
true,
None,
ResultType::VoteTally,
platform_version,
);

assert_eq!(
(contenders.len(), abstaining, locking, finished_vote_info),
(4, Some(10), Some(3), None)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ impl PlatformStateV0Methods for PlatformState {
PlatformState::V0(v0) => v0.last_committed_block_id_hash(),
}
}

fn full_masternode_list_changes(&self, previous: &PlatformState) -> MasternodeListChanges {
match (self, previous) {
(PlatformState::V0(v0), PlatformState::V0(v0_previous)) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ impl PlatformStateV0Methods for PlatformStateV0 {
.unwrap_or_default()
}


fn full_masternode_list_changes(&self, previous: &PlatformStateV0) -> MasternodeListChanges {
let mut new_masternodes = Vec::new();
let mut removed_masternodes = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ mod tests {
use crate::strategy::CoreHeightIncrease::RandomCoreHeightIncrease;
use crate::strategy::{MasternodeListChangesStrategy, NetworkStrategy};
use drive_abci::config::{
ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig,
ValidatorSetConfig,
ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig,
};

use drive_abci::test::helpers::setup::TestPlatformBuilder;
Expand Down
6 changes: 3 additions & 3 deletions packages/rs-drive-abci/tests/strategy_tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ pub(crate) fn run_chain_for_strategy<'a>(
platform: &'a mut Platform<MockCoreRPCLike>,
block_count: u64,
strategy: NetworkStrategy,
mut config: PlatformConfig,
config: PlatformConfig,
seed: u64,
add_voting_keys_to_signer: &mut Option<SimpleSigner>,
) -> ChainExecutionOutcome<'a> {
// TODO: Do we want to sign instant locks or just disable verification?

let validator_quorum_count = strategy.validator_quorum_count; // In most tests 24 quorums
let chain_lock_quorum_count = strategy.chain_lock_quorum_count; // In most tests 4 quorums when not the same as validator
let instant_lock_quorum_count = strategy.instant_lock_quorum_count; // In most tests 24 quorums when not the same as validator
Expand Down Expand Up @@ -1045,7 +1045,7 @@ pub(crate) fn continue_chain_for_strategy(
proposer.pro_tx_hash.into(),
current_quorum_with_test_info,
proposed_version,
block_info.clone(),
block_info,
round,
expected_validation_errors.as_slice(),
false,
Expand Down
1 change: 0 additions & 1 deletion packages/rs-drive-abci/tests/strategy_tests/masternodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use dashcore_rpc::dashcore_rpc_json::{DMNState, MasternodeListItem, MasternodeTy
use dpp::bls_signatures::PrivateKey as BlsPrivateKey;
use dpp::identity::hash::IdentityPublicKeyHashMethodsV0;
use dpp::identity::IdentityPublicKey;
use dpp::identity::KeyType::{ECDSA_HASH160, ECDSA_SECP256K1};
use drive_abci::mimic::test_quorum::TestQuorumInfo;
use platform_version::version::PlatformVersion;
use rand::prelude::{IteratorRandom, StdRng};
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-drive-abci/tests/strategy_tests/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use drive_abci::platform_types::platform::Platform;
use drive_abci::rpc::core::MockCoreRPCLike;
use rand::prelude::{IteratorRandom, SliceRandom, StdRng};
use rand::Rng;
use strategy_tests::{KeyMaps, Strategy};
use strategy_tests::Strategy;
use strategy_tests::transitions::{create_state_transitions_for_identities, create_state_transitions_for_identities_and_proofs, instant_asset_lock_proof_fixture};
use std::borrow::Cow;
use std::collections::{BTreeMap, HashMap, HashSet};
Expand Down Expand Up @@ -391,7 +391,7 @@ impl NetworkStrategy {
if block_info.height == 1 {
if self.strategy.start_identities.number_of_identities > 0 {
let mut new_transitions = self.create_identities_state_transitions(
self.strategy.start_identities.number_of_identities.into(),
self.strategy.start_identities.number_of_identities,
signer,
rng,
instant_lock_quorums,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use drive_abci::rpc::core::MockCoreRPCLike;
use tenderdash_abci::proto::abci::ExecTxResult;

use dpp::state_transition::documents_batch_transition::accessors::DocumentsBatchTransitionAccessorsV0;
use dpp::voting::votes::resource_vote::accessors::v0::ResourceVoteGettersV0;
use dpp::voting::votes::Vote;
use drive::drive::verify::RootHash;
use drive::drive::votes::resolved::vote_polls::ResolvedVotePoll;
use drive::drive::votes::resolved::votes::resolved_resource_vote::accessors::v0::ResolvedResourceVoteGettersV0;
use drive::drive::votes::resolved::votes::ResolvedVote;
Expand Down
27 changes: 23 additions & 4 deletions packages/rs-drive-abci/tests/strategy_tests/voting_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod tests {
use dpp::identity::accessors::IdentityGettersV0;
use dpp::identity::Identity;
use dpp::platform_value::Value;
use drive_abci::config::{ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, ValidatorSetConfig};
use drive_abci::config::{ChainLockConfig, ExecutionConfig, InstantLockConfig, PlatformConfig, PlatformTestConfig};
use drive_abci::test::helpers::setup::TestPlatformBuilder;
use platform_version::version::PlatformVersion;
use rand::prelude::StdRng;
Expand All @@ -20,12 +20,11 @@ mod tests {
use dapi_grpc::platform::v0::get_contested_resource_vote_state_request::get_contested_resource_vote_state_request_v0::ResultType;
use dapi_grpc::platform::v0::get_contested_resource_vote_state_request::GetContestedResourceVoteStateRequestV0;
use dapi_grpc::platform::v0::get_contested_resource_vote_state_response::{get_contested_resource_vote_state_response_v0, GetContestedResourceVoteStateResponseV0};
use dapi_grpc::platform::v0::get_contested_resource_vote_state_response::get_contested_resource_vote_state_response_v0::{finished_vote_info, FinishedVoteInfo};
use dapi_grpc::platform::v0::get_contested_resource_vote_state_response::get_contested_resource_vote_state_response_v0::FinishedVoteInfo;
use dapi_grpc::platform::v0::get_contested_resource_vote_state_response::get_contested_resource_vote_state_response_v0::finished_vote_info::FinishedVoteOutcome;
use dpp::block::extended_block_info::v0::ExtendedBlockInfoV0Getters;
use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters;
use dpp::voting::vote_choices::resource_vote_choice::ResourceVoteChoice;
use drive::drive::config::DriveConfig;
use drive::drive::object_size_info::DataContractOwnedResolvedInfo;
use drive::drive::votes::resolved::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePollWithContractInfo;
use drive_abci::platform_types::platform_state::v0::PlatformStateV0Methods;
Expand All @@ -40,6 +39,11 @@ mod tests {
// We use the DPNS contract, and we insert two documents both with the same "name"
// This is a common scenario we should see quite often
let config = PlatformConfig {
testing_configs: PlatformTestConfig {
block_signing: false,
block_commit_signature_verification: false,
disable_instant_lock_signature_verification: true,
},
chain_lock: ChainLockConfig::default_100_67(),
instant_lock: InstantLockConfig::default_100_67(),
execution: ExecutionConfig {
Expand Down Expand Up @@ -334,6 +338,11 @@ mod tests {
// We use the DPNS contract, and we insert two documents both with the same "name"
// This is a common scenario we should see quite often
let config = PlatformConfig {
testing_configs: PlatformTestConfig {
block_signing: false,
block_commit_signature_verification: false,
disable_instant_lock_signature_verification: true,
},
chain_lock: ChainLockConfig::default_100_67(),
instant_lock: InstantLockConfig::default_100_67(),
execution: ExecutionConfig {
Expand Down Expand Up @@ -545,7 +554,7 @@ mod tests {
proposers,
validator_quorums,
current_validator_quorum_hash,
instant_lock_quorums: Default::default(),
instant_lock_quorums,
current_proposer_versions: Some(current_proposer_versions.clone()),
current_identity_nonce_counter: identity_nonce_counter,
current_identity_contract_nonce_counter: identity_contract_nonce_counter,
Expand Down Expand Up @@ -686,6 +695,11 @@ mod tests {
// We use the DPNS contract, and we insert two documents both with the same "name"
// This is a common scenario we should see quite often
let config = PlatformConfig {
testing_configs: PlatformTestConfig {
block_signing: false,
block_commit_signature_verification: false,
disable_instant_lock_signature_verification: true,
},
chain_lock: ChainLockConfig::default_100_67(),
instant_lock: InstantLockConfig::default_100_67(),
execution: ExecutionConfig {
Expand Down Expand Up @@ -1049,6 +1063,11 @@ mod tests {
// We use the DPNS contract, and we insert two documents both with the same "name"
// This is a common scenario we should see quite often
let config = PlatformConfig {
testing_configs: PlatformTestConfig {
block_signing: false,
block_commit_signature_verification: false,
disable_instant_lock_signature_verification: true,
},
chain_lock: ChainLockConfig::default_100_67(),
instant_lock: InstantLockConfig::default_100_67(),
execution: ExecutionConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl Drive {
/// # Returns
///
/// * `Result<Option<Credits>, Error>` - The balance of the Identity if successful, or an error.
#[allow(unused)]
pub(crate) fn fetch_prefunded_specialized_balance_operations(
&self,
prefunded_specialized_balance_id: [u8; 32],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::drive::verify::RootHash;
use crate::error::drive::DriveError;
use crate::query::ContractLookupFn;
use dpp::identifier::Identifier;
use std::collections::BTreeMap;

use crate::error::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::drive::Drive;
use dpp::data_contract::DataContract;
use grovedb::{GroveDb, PathQuery, SizedQuery};
use tracing::debug;

use crate::error::Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ mod v0;
use crate::drive::verify::RootHash;
use crate::error::drive::DriveError;
use dpp::prelude::TimestampMillis;
use std::collections::BTreeMap;

use crate::error::Error;

Expand Down
2 changes: 1 addition & 1 deletion packages/rs-drive/src/query/vote_poll_vote_state_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use dpp::voting::vote_info_storage::contested_document_vote_poll_stored_info::{
use dpp::voting::vote_info_storage::contested_document_vote_poll_winner_info::ContestedDocumentVotePollWinnerInfo;
use dpp::voting::vote_polls::contested_document_resource_vote_poll::ContestedDocumentResourceVotePoll;
#[cfg(feature = "server")]
use grovedb::query_result_type::{QueryResultElements, QueryResultType};
use grovedb::query_result_type::QueryResultType;
#[cfg(feature = "server")]
use grovedb::{Element, TransactionArg};
use grovedb::{PathQuery, Query, QueryItem, SizedQuery};
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk/src/mock/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl ContextProvider for GrpcContextProvider {
return Ok(Some(contract));
};
let sdk_guard = self.sdk.load();

let sdk = match sdk_guard.as_ref() {
Some(sdk) => sdk,
None => {
Expand Down

0 comments on commit 31734d8

Please sign in to comment.