Skip to content

Commit

Permalink
fix!: refresh references on identity key re-enable/disable (#2047)
Browse files Browse the repository at this point in the history
Co-authored-by: Quantum Explorer <[email protected]>
  • Loading branch information
ogabrielides and QuantumExplorer authored Aug 13, 2024
1 parent 4161564 commit eb6857b
Show file tree
Hide file tree
Showing 26 changed files with 756 additions and 29 deletions.
8 changes: 4 additions & 4 deletions packages/rs-dpp/src/identity/identity_public_key/purpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ impl std::fmt::Display for Purpose {

impl Purpose {
/// The full range of purposes
pub fn full_range() -> [Purpose; 4] {
[AUTHENTICATION, ENCRYPTION, DECRYPTION, TRANSFER]
pub fn full_range() -> [Purpose; 5] {
[AUTHENTICATION, ENCRYPTION, DECRYPTION, TRANSFER, VOTING]
}
/// Just the authentication and withdraw purposes
pub fn authentication_and_transfer() -> [Purpose; 2] {
[AUTHENTICATION, TRANSFER]
pub fn searchable_purposes() -> [Purpose; 3] {
[AUTHENTICATION, TRANSFER, VOTING]
}
/// Just the encryption and decryption purposes
pub fn encryption_decryption() -> [Purpose; 2] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ mod tests {

assert_eq!(processing_result.valid_count(), 1);

assert_eq!(processing_result.aggregated_fees().processing_fee, 1823240);
assert_eq!(processing_result.aggregated_fees().processing_fee, 1871240);

platform
.drive
Expand All @@ -324,7 +324,7 @@ mod tests {
.expect("expected to get identity balance")
.expect("expected there to be an identity balance for this identity");

assert_eq!(identity_balance, 99916906760);
assert_eq!(identity_balance, 99913915760);
}

#[test]
Expand Down Expand Up @@ -531,7 +531,7 @@ mod tests {

assert_eq!(processing_result.valid_count(), 1);

assert_eq!(processing_result.aggregated_fees().processing_fee, 2098900);
assert_eq!(processing_result.aggregated_fees().processing_fee, 2146900);

platform
.drive
Expand All @@ -546,7 +546,7 @@ mod tests {
.expect("expected to get identity balance")
.expect("expected there to be an identity balance for this identity");

assert_eq!(identity_balance, 99912301400); // The identity balance is smaller than if there hadn't been any issue
assert_eq!(identity_balance, 99909310400); // The identity balance is smaller than if there hadn't been any issue
}

#[test]
Expand Down Expand Up @@ -1235,7 +1235,7 @@ mod tests {

assert_eq!(processing_result.valid_count(), 1);

assert_eq!(processing_result.aggregated_fees().processing_fee, 2098900);
assert_eq!(processing_result.aggregated_fees().processing_fee, 2146900);

platform
.drive
Expand All @@ -1250,6 +1250,6 @@ mod tests {
.expect("expected to get identity balance")
.expect("expected there to be an identity balance for this identity");

assert_eq!(identity_balance, 99912301400); // The identity balance is smaller than if there hadn't been any issue
assert_eq!(identity_balance, 99909310400); // The identity balance is smaller than if there hadn't been any issue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,102 @@ impl StateTransitionStateValidationV0 for IdentityUpdateTransition {
}
}
}

#[cfg(test)]
mod tests {
use crate::config::{PlatformConfig, PlatformTestConfig};
use crate::execution::validation::state_transition::tests::setup_identity_return_master_key;
use crate::test::helpers::setup::TestPlatformBuilder;
use dpp::block::block_info::BlockInfo;
use dpp::dash_to_credits;
use dpp::identity::accessors::IdentityGettersV0;
use dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
use dpp::identity::signer::Signer;
use dpp::serialization::{PlatformSerializable, Signable};
use dpp::state_transition::identity_update_transition::v0::IdentityUpdateTransitionV0;
use dpp::state_transition::identity_update_transition::IdentityUpdateTransition;
use dpp::state_transition::StateTransition;
use platform_version::version::PlatformVersion;

#[test]
fn test_identity_update_that_disables_a_key() {
let platform_config = PlatformConfig {
testing_configs: PlatformTestConfig {
disable_instant_lock_signature_verification: true,
..Default::default()
},
..Default::default()
};

let platform_version = PlatformVersion::latest();

let mut platform = TestPlatformBuilder::new()
.with_config(platform_config)
.build_with_mock_rpc()
.set_genesis_state();

let (identity, signer, key) =
setup_identity_return_master_key(&mut platform, 958, dash_to_credits!(0.1));

let platform_state = platform.state.load();

let update_transition: IdentityUpdateTransition = IdentityUpdateTransitionV0 {
identity_id: identity.id(),
revision: 1,
nonce: 1,
add_public_keys: vec![],
disable_public_keys: vec![1],
user_fee_increase: 0,
signature_public_key_id: key.id(),
signature: Default::default(),
}
.into();

let mut update_transition: StateTransition = update_transition.into();

let data = update_transition
.signable_bytes()
.expect("expected signable bytes");
update_transition.set_signature(
signer
.sign(&key, data.as_slice())
.expect("expected to sign"),
);

let update_transition_bytes = update_transition
.serialize_to_bytes()
.expect("expected to serialize");

let transaction = platform.drive.grove.start_transaction();

let processing_result = platform
.platform
.process_raw_state_transitions(
&vec![update_transition_bytes.clone()],
&platform_state,
&BlockInfo::default(),
&transaction,
platform_version,
true,
None,
)
.expect("expected to process state transition");

assert_eq!(processing_result.valid_count(), 1);

platform
.drive
.grove
.commit_transaction(transaction)
.unwrap()
.expect("expected to commit");

let issues = platform
.drive
.grove
.visualize_verify_grovedb(true, &platform_version.drive.grove_version)
.expect("expected to have no issues");

assert_eq!(issues.len(), 0);
}
}
8 changes: 4 additions & 4 deletions packages/rs-drive-abci/tests/strategy_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ mod tests {
.expect("expected to fetch balances")
.expect("expected to have an identity to get balance from");

assert_eq!(balance, 99867003200)
assert_eq!(balance, 99864012200)
}

#[test]
Expand Down Expand Up @@ -1194,7 +1194,7 @@ mod tests {
.unwrap()
.unwrap()
),
"4f4fc212d1d0c631b985a29544a24fbe6f7ffdd9e8d69a69d2da173dea567945".to_string()
"d12cc15405f4a810c239539f06fe6eee9f2b2d1ad49055a5ca55882b5842baa4".to_string()
)
}

Expand Down Expand Up @@ -1915,7 +1915,7 @@ mod tests {
.unwrap()
.unwrap()
),
"cdb5dc16b1e774c0fc777f1b7ffa16b652ba5a80ad8329d75accf30b19f97dd8".to_string()
"48cfe777a90adbe975bfab264e7a2a0951c93386ef81f17bfe6640ad1251feda".to_string()
)
}

Expand Down Expand Up @@ -2050,7 +2050,7 @@ mod tests {
.unwrap()
.unwrap()
),
"f7422a9297c1c2b903dac3873f31604f6268e69498e06c658c2948093efb4368".to_string()
"3319167d723776fdb8dab32dd9d360d098a47e7f496b7b4c24419b4edbac5f77".to_string()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use platform_version::version::PlatformVersion;
use std::collections::BTreeMap;

mod add_potential_contract_info_for_contract_bounded_key;
mod refresh_potential_contract_info_key_references;

pub enum IdentityDataContractKeyApplyInfo {
/// The root_id is either a contract id or an owner id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::drive::Drive;
use crate::error::drive::DriveError;
use crate::error::Error;
use crate::fees::op::LowLevelDriveOperation;
use dpp::block::epoch::Epoch;
use dpp::identity::IdentityPublicKey;
use grovedb::batch::KeyInfoPath;
use grovedb::{EstimatedLayerInformation, TransactionArg};
use platform_version::version::PlatformVersion;
use std::collections::HashMap;

mod v0;

impl Drive {
/// Adds potential contract information for a contract-bounded key.
///
/// This function considers the contract bounds associated with an identity key and forms the operations needed to process the contract information.
///
/// # Arguments
///
/// * `identity_id` - An array of bytes representing the identity id.
/// * `identity_key` - A reference to the `IdentityPublicKey` associated with the contract.
/// * `epoch` - The current epoch.
/// * `estimated_costs_only_with_layer_info` - A mutable reference to an optional `HashMap` that may contain estimated layer information.
/// * `transaction` - The transaction arguments.
/// * `drive_operations` - A mutable reference to a vector of `LowLevelDriveOperation` objects.
/// * `platform_version` - A reference to the platform version information.
///
/// # Returns
///
/// * `Result<(), Error>` - If successful, returns unit (`()`). If an error occurs during the operation, returns an `Error`.
///
/// # Errors
///
/// This function may return an `Error` if the operation creation process fails or if the platform version does not match any of the implemented method versions.
pub(crate) fn refresh_potential_contract_info_key_references(
&self,
identity_id: [u8; 32],
identity_key: &IdentityPublicKey,
epoch: &Epoch,
estimated_costs_only_with_layer_info: &mut Option<
HashMap<KeyInfoPath, EstimatedLayerInformation>,
>,
transaction: TransactionArg,
drive_operations: &mut Vec<LowLevelDriveOperation>,
platform_version: &PlatformVersion,
) -> Result<(), Error> {
match platform_version
.drive
.methods
.identity
.contract_info
.refresh_potential_contract_info_key_references
{
0 => self.refresh_potential_contract_info_key_references_v0(
identity_id,
identity_key,
epoch,
estimated_costs_only_with_layer_info,
transaction,
drive_operations,
platform_version,
),
version => Err(Error::Drive(DriveError::UnknownVersionMismatch {
method: "refresh_potential_contract_info_key_references".to_string(),
known_versions: vec![0],
received: version,
})),
}
}
}
Loading

0 comments on commit eb6857b

Please sign in to comment.