Skip to content

Commit

Permalink
fix(drive): more than one key was returned when expecting only one re…
Browse files Browse the repository at this point in the history
…sult (#2421)
  • Loading branch information
shumkov authored Jan 14, 2025
1 parent be5cd6d commit 4ee57a6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/rs-drive-abci/src/abci/handler/check_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ where
let handler_error = HandlerError::Internal(error.to_string());

if tracing::enabled!(tracing::Level::ERROR) {
let st_hash = hex::encode(hash_single(tx));
let st_hash = hex::encode(hash_single(&tx));

tracing::error!(
?error,
st = hex::encode(tx),
st_hash,
check_tx_mode = r#type,
"Failed to check state transition ({}): {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,66 @@ impl IdentityCreditWithdrawalTransitionAction {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::util::test_helpers::setup::setup_drive_with_initial_state_structure;
use dpp::identity::accessors::IdentityGettersV0;
use dpp::identity::{Identity, IdentityPublicKey};
use dpp::state_transition::identity_credit_withdrawal_transition::v1::IdentityCreditWithdrawalTransitionV1;

#[test]
fn test_try_from_identity_credit_withdrawal_without_address_and_multiple_transfer_keys() {
let drive = setup_drive_with_initial_state_structure(None);

let platform_version = PlatformVersion::latest();

let mut identity = Identity::random_identity(1, Some(64), &platform_version)
.expect("create random identity");

let (transfer_key1, _) =
IdentityPublicKey::random_masternode_transfer_key(2, Some(64), &platform_version)
.expect("create random masternode transfer key");
let (transfer_key2, _) =
IdentityPublicKey::random_masternode_transfer_key(3, Some(64), &platform_version)
.expect("create random masternode transfer key");

identity.add_public_keys([transfer_key1, transfer_key2]);

let identity_id = identity.id();

drive
.add_new_identity(
identity,
true,
&BlockInfo::default(),
true,
None,
platform_version,
)
.expect("create new identity");

let transition =
IdentityCreditWithdrawalTransition::V1(IdentityCreditWithdrawalTransitionV1 {
identity_id,
nonce: 0,
amount: 0,
core_fee_per_byte: 0,
pooling: Default::default(),
output_script: None,
user_fee_increase: 0,
signature_public_key_id: 0,
signature: Default::default(),
});

IdentityCreditWithdrawalTransitionAction::try_from_identity_credit_withdrawal(
&drive,
None,
&transition,
&BlockInfo::default(),
platform_version,
)
.expect("create action");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl IdentityCreditWithdrawalTransitionActionV0 {
let key_request = IdentityKeysRequest {
identity_id: identity_credit_withdrawal.identity_id.to_buffer(),
request_type: KeyRequestType::RecentWithdrawalKeys,
limit: None,
limit: Some(1),
offset: None,
};
let key: Option<IdentityPublicKey> =
Expand Down Expand Up @@ -177,7 +177,7 @@ impl IdentityCreditWithdrawalTransitionActionV0 {
let withdrawal_document = DocumentV0 {
id: document_id,
owner_id: identity_credit_withdrawal.identity_id,
properties: document_data.into_btree_string_map().unwrap(),
properties: document_data.into_btree_string_map()?,
revision: Some(1),
created_at: Some(block_info.time_ms),
updated_at: Some(block_info.time_ms),
Expand Down

0 comments on commit 4ee57a6

Please sign in to comment.