Skip to content

Commit c30a1bf

Browse files
committed
refactor(sdk): remove 5 redundant document nonce-masking tests
All 6 document_*_sign_masks_nonce tests tested the same underlying behavior (Sdk::get_identity_contract_nonce masks out-of-bounds bits). Keep one representative test, remove the other 5. Also removes dead second assert that was always true (result was Ok) and unused test_document_for_create helper.
1 parent b8e5813 commit c30a1bf

1 file changed

Lines changed: 6 additions & 260 deletions

File tree

  • packages/rs-sdk/src/platform/documents/transitions

packages/rs-sdk/src/platform/documents/transitions/tests.rs

Lines changed: 6 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use super::create::DocumentCreateTransitionBuilder;
21
use super::delete::DocumentDeleteTransitionBuilder;
3-
use super::purchase::DocumentPurchaseTransitionBuilder;
4-
use super::replace::DocumentReplaceTransitionBuilder;
5-
use super::set_price::DocumentSetPriceTransitionBuilder;
6-
use super::transfer::DocumentTransferTransitionBuilder;
72
use crate::{Error, Sdk, SdkBuilder};
83
use dpp::address_funds::AddressWitness;
94
use dpp::data_contract::accessors::v0::DataContractV0Getters;
@@ -136,35 +131,6 @@ fn test_document(owner_id: Identifier) -> Document {
136131
})
137132
}
138133

139-
fn test_document_for_create(
140-
data_contract_id: &Identifier,
141-
document_type_name: &str,
142-
owner_id: Identifier,
143-
entropy: [u8; 32],
144-
) -> Document {
145-
Document::V0(DocumentV0 {
146-
id: Document::generate_document_id_v0(
147-
data_contract_id,
148-
&owner_id,
149-
document_type_name,
150-
&entropy,
151-
),
152-
owner_id,
153-
properties: Default::default(),
154-
revision: None,
155-
created_at: None,
156-
updated_at: None,
157-
transferred_at: None,
158-
created_at_block_height: None,
159-
updated_at_block_height: None,
160-
transferred_at_block_height: None,
161-
created_at_core_block_height: None,
162-
updated_at_core_block_height: None,
163-
transferred_at_core_block_height: None,
164-
creator_id: None,
165-
})
166-
}
167-
168134
fn validate_transition_like_builder(state_transition: &StateTransition) -> Result<(), Error> {
169135
let platform_version = dpp::version::PlatformVersion::latest();
170136
let validation_result = match state_transition {
@@ -363,10 +329,11 @@ async fn new_mock_sdk_with_contract_nonce(
363329
}
364330

365331
#[tokio::test]
366-
async fn document_delete_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
367-
// Document builders always create exactly one transition and obtain nonce through
368-
// `Sdk::get_identity_contract_nonce`, which masks out-of-bounds bits.
369-
// This makes `validate_base_structure` nonce-out-of-bounds errors unreachable here.
332+
async fn document_builder_sign_masks_nonce_so_out_of_bounds_is_unreachable() {
333+
// Document builders obtain nonce through `Sdk::get_identity_contract_nonce`,
334+
// which masks out-of-bounds bits. This makes `validate_base_structure`
335+
// nonce-out-of-bounds errors unreachable through the builder API.
336+
// One test suffices since all document builders use the same SDK nonce path.
370337
let document_type_name = "testDoc";
371338
let data_contract = test_data_contract(document_type_name);
372339
let owner_id = Identifier::random();
@@ -391,228 +358,7 @@ async fn document_delete_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_v
391358

392359
assert!(
393360
result.is_ok(),
394-
"unexpected error while signing document delete transition: {:?}",
395-
result.err()
396-
);
397-
398-
assert!(
399-
!matches!(
400-
result,
401-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
402-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
403-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
404-
))
405-
),
406-
"nonce out-of-bounds should be unreachable via document builders"
407-
);
408-
}
409-
410-
#[tokio::test]
411-
async fn document_create_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
412-
let document_type_name = "testDoc";
413-
let data_contract = test_data_contract(document_type_name);
414-
let owner_id = Identifier::random();
415-
let entropy = [11; 32];
416-
let document =
417-
test_document_for_create(&data_contract.id(), document_type_name, owner_id, entropy);
418-
let sdk = new_mock_sdk_with_contract_nonce(owner_id, data_contract.id(), 1_u64 << 50).await;
419-
420-
let builder = DocumentCreateTransitionBuilder::new(
421-
Arc::clone(&data_contract),
422-
document_type_name.to_string(),
423-
document,
424-
entropy,
425-
);
426-
427-
let result = builder
428-
.sign(
429-
&sdk,
430-
&test_identity_public_key(),
431-
&TestSigner,
432-
dpp::version::PlatformVersion::latest(),
433-
)
434-
.await;
435-
436-
assert!(
437-
result.is_ok(),
438-
"unexpected error while signing document create transition: {:?}",
439-
result.err()
440-
);
441-
442-
assert!(
443-
!matches!(
444-
result,
445-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
446-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
447-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
448-
))
449-
),
450-
"nonce out-of-bounds should be unreachable via document builders"
451-
);
452-
}
453-
454-
#[tokio::test]
455-
async fn document_replace_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
456-
let document_type_name = "testDoc";
457-
let data_contract = test_data_contract(document_type_name);
458-
let owner_id = Identifier::random();
459-
let sdk = new_mock_sdk_with_contract_nonce(owner_id, data_contract.id(), 1_u64 << 50).await;
460-
461-
let builder = DocumentReplaceTransitionBuilder::new(
462-
Arc::clone(&data_contract),
463-
document_type_name.to_string(),
464-
test_document(owner_id),
465-
);
466-
467-
let result = builder
468-
.sign(
469-
&sdk,
470-
&test_identity_public_key(),
471-
&TestSigner,
472-
dpp::version::PlatformVersion::latest(),
473-
)
474-
.await;
475-
476-
assert!(
477-
result.is_ok(),
478-
"unexpected error while signing document replace transition: {:?}",
479-
result.err()
480-
);
481-
482-
assert!(
483-
!matches!(
484-
result,
485-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
486-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
487-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
488-
))
489-
),
490-
"nonce out-of-bounds should be unreachable via document builders"
491-
);
492-
}
493-
494-
#[tokio::test]
495-
async fn document_purchase_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
496-
let document_type_name = "testDoc";
497-
let data_contract = test_data_contract(document_type_name);
498-
let owner_id = Identifier::random();
499-
let purchaser_id = Identifier::random();
500-
let sdk = new_mock_sdk_with_contract_nonce(purchaser_id, data_contract.id(), 1_u64 << 50).await;
501-
502-
let builder = DocumentPurchaseTransitionBuilder::new(
503-
Arc::clone(&data_contract),
504-
document_type_name.to_string(),
505-
test_document(owner_id),
506-
purchaser_id,
507-
100,
508-
);
509-
510-
let result = builder
511-
.sign(
512-
&sdk,
513-
&test_identity_public_key(),
514-
&TestSigner,
515-
dpp::version::PlatformVersion::latest(),
516-
)
517-
.await;
518-
519-
assert!(
520-
result.is_ok(),
521-
"unexpected error while signing document purchase transition: {:?}",
522-
result.err()
523-
);
524-
525-
assert!(
526-
!matches!(
527-
result,
528-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
529-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
530-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
531-
))
532-
),
533-
"nonce out-of-bounds should be unreachable via document builders"
534-
);
535-
}
536-
537-
#[tokio::test]
538-
async fn document_set_price_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
539-
let document_type_name = "testDoc";
540-
let data_contract = test_data_contract(document_type_name);
541-
let owner_id = Identifier::random();
542-
let sdk = new_mock_sdk_with_contract_nonce(owner_id, data_contract.id(), 1_u64 << 50).await;
543-
544-
let builder = DocumentSetPriceTransitionBuilder::new(
545-
Arc::clone(&data_contract),
546-
document_type_name.to_string(),
547-
test_document(owner_id),
548-
123,
549-
);
550-
551-
let result = builder
552-
.sign(
553-
&sdk,
554-
&test_identity_public_key(),
555-
&TestSigner,
556-
dpp::version::PlatformVersion::latest(),
557-
)
558-
.await;
559-
560-
assert!(
561-
result.is_ok(),
562-
"unexpected error while signing document set_price transition: {:?}",
361+
"SDK should mask nonce internally; got error: {:?}",
563362
result.err()
564363
);
565-
566-
assert!(
567-
!matches!(
568-
result,
569-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
570-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
571-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
572-
))
573-
),
574-
"nonce out-of-bounds should be unreachable via document builders"
575-
);
576-
}
577-
578-
#[tokio::test]
579-
async fn document_transfer_sign_masks_nonce_and_does_not_hit_nonce_out_of_bounds_validation() {
580-
let document_type_name = "testDoc";
581-
let data_contract = test_data_contract(document_type_name);
582-
let owner_id = Identifier::random();
583-
let recipient_id = Identifier::random();
584-
let sdk = new_mock_sdk_with_contract_nonce(owner_id, data_contract.id(), 1_u64 << 50).await;
585-
586-
let builder = DocumentTransferTransitionBuilder::new(
587-
Arc::clone(&data_contract),
588-
document_type_name.to_string(),
589-
test_document(owner_id),
590-
recipient_id,
591-
);
592-
593-
let result = builder
594-
.sign(
595-
&sdk,
596-
&test_identity_public_key(),
597-
&TestSigner,
598-
dpp::version::PlatformVersion::latest(),
599-
)
600-
.await;
601-
602-
assert!(
603-
result.is_ok(),
604-
"unexpected error while signing document transfer transition: {:?}",
605-
result.err()
606-
);
607-
608-
assert!(
609-
!matches!(
610-
result,
611-
Err(Error::Protocol(ProtocolError::ConsensusError(consensus_error)))
612-
if matches!(*consensus_error, dpp::consensus::ConsensusError::BasicError(
613-
dpp::consensus::basic::BasicError::NonceOutOfBoundsError(_)
614-
))
615-
),
616-
"nonce out-of-bounds should be unreachable via document builders"
617-
);
618364
}

0 commit comments

Comments
 (0)