Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/rs-dpp/src/document/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ mod tests {
use super::*;
use crate::data_contract::document_type::random_document::CreateRandomDocument;
use crate::data_contract::extra::common::json_document_to_cbor;
use regex::Regex;

#[test]
fn test_serialization() {
Expand Down Expand Up @@ -504,6 +505,9 @@ mod tests {
let document = document_type.random_document(Some(3333));

let document_string = format!("{}", document);
assert_eq!(document_string.as_str(), "id:2vq574DjKi7ZD8kJ6dMHxT5wu6ZKD2bW5xKAyKAGW7qZ owner_id:ChTEGXJcpyknkADUC5s6tAzvPqVG7x6Lo1Nr5mFtj2mk created_at:2027-09-24 14:16:54 updated_at:2030-06-20 21:52:44 avatarUrl:string RD1DbW18RuyblDX7hxB3[...(1936)] displayName:string jALmlamgYbnlKUkT1 publicMessage:string oyGtAOjibsOvx9OUjxVO[...(110)] ")

let pattern = r#"id:45ZNwGcxeMpLpYmiVEKKBKXbZfinrhjZLkau1GWizPFX owner_id:2vq574DjKi7ZD8kJ6dMHxT5wu6ZKD2bW5xKAyKAGW7qZ created_at:(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) updated_at:(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) avatarUrl:string y8RD1DbW18RuyblDX7hx\[...\(670\)\] displayName:string SvAQrzsslj0ESc15GQB publicMessage:string ccpKt9ckWftHIEKdBlas\[...\(36\)\] .*"#;
let re = Regex::new(pattern).unwrap();
assert!(re.is_match(document_string.as_str()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ pub fn get_security_level_requirement(v: &JsonValue, default: SecurityLevel) ->

#[cfg(test)]
mod test {
use itertools::Itertools;
use std::sync::Arc;

use platform_value::Bytes32;
Expand Down Expand Up @@ -595,13 +596,10 @@ mod test {
)])
.expect("batch transition should be created");

assert_eq!(
&SecurityLevel::MEDIUM,
batch_transition
.get_security_level_requirement()
.first()
.unwrap()
);
assert!(batch_transition
.get_security_level_requirement()
.iter()
.contains(&SecurityLevel::MEDIUM));

let batch_transition = document_factory
.create_state_transition(vec![(
Expand All @@ -613,13 +611,10 @@ mod test {
)])
.expect("batch transition should be created");

assert_eq!(
&SecurityLevel::MASTER,
batch_transition
.get_security_level_requirement()
.first()
.unwrap()
);
assert!(batch_transition
.get_security_level_requirement()
.iter()
.contains(&SecurityLevel::MASTER));

let batch_transition = document_factory
.create_state_transition(vec![(
Expand All @@ -628,13 +623,10 @@ mod test {
)])
.expect("batch transition should be created");

assert_eq!(
&SecurityLevel::HIGH,
batch_transition
.get_security_level_requirement()
.first()
.unwrap()
);
assert!(batch_transition
.get_security_level_requirement()
.iter()
.contains(&SecurityLevel::HIGH));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ impl From<MissingMasterPublicKeyError> for ConsensusError {
}

#[cfg(test)]
impl From<TestConsensusError> for ConsensusError {
fn from(error: TestConsensusError) -> Self {
impl From<basic::TestConsensusError> for ConsensusError {
fn from(error: basic::TestConsensusError) -> Self {
Self::TestConsensusError(error)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod test {
state_repository_for_apply
.expect_add_to_identity_balance()
.times(1)
.with(eq(identity_id), eq(90000000), always())
.with(eq(identity_id), eq(100000000000), always())
.returning(|_, _, _| Ok(()));

state_repository_for_apply
Expand All @@ -125,7 +125,7 @@ mod test {
state_repository_for_apply
.expect_add_to_system_credits()
.times(1)
.with(eq(90000000), always())
.with(eq(100000000000), always())
.returning(|_, _| Ok(()));

state_repository_for_apply
Expand Down Expand Up @@ -164,7 +164,7 @@ mod test {
state_repository_for_apply
.expect_add_to_identity_balance()
.times(1)
.with(eq(identity_id), eq(90000000), always())
.with(eq(identity_id), eq(100000000000), always())
.returning(|_, _, _| Ok(()));

state_repository_for_apply
Expand All @@ -176,7 +176,7 @@ mod test {
state_repository_for_apply
.expect_add_to_system_credits()
.times(1)
.with(eq(90000000 - 5), always())
.with(eq(100000000000 - 5), always())
.returning(|_, _| Ok(()));

state_repository_for_apply
Expand Down Expand Up @@ -215,7 +215,7 @@ mod test {
state_repository_for_apply
.expect_add_to_identity_balance()
.times(1)
.with(eq(identity_id), eq(90000000), always())
.with(eq(identity_id), eq(100000000000), always())
.returning(|_, _, _| Ok(()));

state_repository_for_apply
Expand All @@ -227,7 +227,7 @@ mod test {
state_repository_for_apply
.expect_add_to_system_credits()
.times(1)
.with(eq(90000000), always())
.with(eq(100000000000), always())
.returning(|_, _| Ok(()));

state_repository_for_apply
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ pub fn get_compressed_public_ec_key(private_key: &[u8]) -> Result<[u8; 33], Prot
mod test {
use chrono::Utc;
use platform_value::{BinaryData, Value};
use rand::rngs::StdRng;
use rand::SeedableRng;
use serde::{Deserialize, Serialize};
use serde_json::json;
use std::convert::TryInto;
use std::vec;

use crate::document::DocumentsBatchTransition;
use crate::state_transition::state_transition_execution_context::StateTransitionExecutionContext;
use crate::ProtocolError::InvalidSignaturePublicKeySecurityLevelError;
use crate::{
assert_error_contains,
identity::{KeyID, SecurityLevel},
Expand Down Expand Up @@ -318,17 +321,16 @@ mod test {
fn get_test_keys() -> Keys {
let secp = dashcore::secp256k1::Secp256k1::new();
let mut rng = dashcore::secp256k1::rand::thread_rng();
let mut std_rng = StdRng::seed_from_u64(99999);
let (private_key, public_key) = secp.generate_keypair(&mut rng);

let public_key_id = 1;
let ec_private_key_bytes = private_key.secret_bytes();
let ec_public_compressed_bytes = public_key.serialize();
let ec_public_uncompressed_bytes = public_key.serialize_uncompressed();

let mut buffer = [0u8; 32];
let _ = getrandom::getrandom(&mut buffer);
let bls_private = bls_signatures::PrivateKey::from_bytes(buffer.as_slice(), false)
.expect("expected private key");
let bls_private =
bls_signatures::PrivateKey::generate_dash(&mut std_rng).expect("expected private key");
let bls_public = bls_private
.g1_element()
.expect("expected to make public key");
Expand Down Expand Up @@ -488,9 +490,9 @@ mod test {
.sign(&keys.identity_public_key, &keys.ec_private, &bls)
.unwrap_err();
match sign_error {
ProtocolError::PublicKeySecurityLevelNotMetError(err) => {
InvalidSignaturePublicKeySecurityLevelError(err) => {
assert_eq!(SecurityLevel::MEDIUM, err.public_key_security_level());
assert_eq!(SecurityLevel::HIGH, err.required_security_level());
assert_eq!(vec![SecurityLevel::HIGH], err.allowed_key_security_levels());
}
error => {
panic!("invalid error type: {}", error)
Expand Down
13 changes: 10 additions & 3 deletions packages/rs-dpp/src/state_transition/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ mod tests {
use crate::document::document_transition::Action;
use crate::document::DocumentsBatchTransition;
use crate::identity::core_script::CoreScript;
use crate::identity::state_transition::asset_lock_proof::AssetLockProof;
use crate::identity::state_transition::identity_create_transition::IdentityCreateTransition;
use crate::identity::state_transition::identity_credit_withdrawal_transition::{
IdentityCreditWithdrawalTransition, Pooling,
Expand All @@ -56,7 +57,7 @@ mod tests {
};
use crate::tests::fixtures::{
get_data_contract_fixture, get_document_transitions_fixture,
get_documents_fixture_with_owner_id_from_contract,
get_documents_fixture_with_owner_id_from_contract, raw_instant_asset_lock_proof_fixture,
};
use crate::version::LATEST_VERSION;
use crate::{NativeBlsModule, ProtocolError};
Expand All @@ -67,7 +68,10 @@ mod tests {

#[test]
fn identity_create_transition_ser_de() {
let identity = Identity::random_identity(5, Some(5));
let mut identity = Identity::random_identity(5, Some(5));
let asset_lock_proof = raw_instant_asset_lock_proof_fixture(None);
identity.set_asset_lock_proof(AssetLockProof::Instant(asset_lock_proof));

let identity_create_transition: IdentityCreateTransition = identity
.try_into()
.expect("expected to make an identity create transition");
Expand All @@ -80,7 +84,10 @@ mod tests {

#[test]
fn identity_topup_transition_ser_de() {
let identity = Identity::random_identity(5, Some(5));
let mut identity = Identity::random_identity(5, Some(5));
let asset_lock_proof = raw_instant_asset_lock_proof_fixture(None);
identity.set_asset_lock_proof(AssetLockProof::Instant(asset_lock_proof));

let identity_topup_transition = IdentityTopUpTransition {
asset_lock_proof: identity
.asset_lock_proof
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2446,40 +2446,6 @@ mod indices {
}
}

#[test]
fn should_return_invalid_result_if_unique_compound_index_contains_both_required_and_optional_properties(
) {
let TestData {
mut raw_data_contract,
data_contract_validator,
..
} = setup_test();

if let Some(Value::Array(arr)) = raw_data_contract
.get_optional_mut_value_at_path("documents.optionalUniqueIndexedDocument.required")
.expect("expected to get optional value at path")
{
arr.pop();
}

let result = data_contract_validator
.validate(&raw_data_contract)
.expect("validation result should be returned");
let error = result.errors.get(0).expect("the error should be present");
let index_error = get_index_error(error);

assert_eq!(1010, index_error.get_code());
match index_error {
IndexError::InvalidCompoundIndexError(err) => {
assert_eq!(
err.document_type(),
"optionalUniqueIndexedDocument".to_string()
);
}
_ => panic!("Expected InvalidCompoundIndexError, got {}", index_error),
}
}

#[test]
fn should_have_valid_property_names() {
let TestData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ mod from_raw_object {
assert_eq!(public_key.key_type, KeyType::BLS12_381);
assert_eq!(
vec![
111, 89, 76, 223, 228, 50, 201, 143, 165, 74, 149, 193, 215, 143, 217, 170, 49,
108, 229, 150
41, 182, 195, 61, 168, 53, 154, 177, 166, 144, 85, 113, 1, 53, 136, 83, 16, 114,
51, 82
],
public_key.hash().unwrap()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ fn to_object() {
{

"id" : 3u32,
"type": 0u8,
"purpose" : 0u8,
"securityLevel" : 0u8,
"type": 0u8,
"data" :BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
"readOnly" : false,
"data" :BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
"signature" : BinaryData::new(vec![0u8;65])
}
],
Expand All @@ -176,11 +176,11 @@ fn to_object_with_signature_skipped() {
{

"id" : 3u32,
"type": 0u8,
"purpose" : 0u8,
"securityLevel" : 0u8,
"type": 0u8,
"data" :BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
"readOnly" : false,
"data" :BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
}
],
"disablePublicKeys" : [0u32],
Expand Down Expand Up @@ -208,11 +208,11 @@ fn to_json() {
{

"id" : 3u32,
"type": 0u8,
"purpose" : 0u8,
"securityLevel" : 0u8,
"type": 0u8,
"data" : BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
"readOnly" : false,
"data" : BinaryData::new(base64::decode("AkVuTKyF3YgKLAQlLEtaUL2HTditwGILfWUVqjzYnIgH").unwrap()),
"signature" : BinaryData::new(vec![0;65]),
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,6 @@ pub fn should_return_invalid_result_if_bls12_381_public_key_is_invalid() {
//assert_eq!(error.validation_error(), TypeError);
assert_eq!(
error.validation_error().as_ref().unwrap().message(),
"Group decode error"
"Given G1 non-infinity element must start with 0b10"
);
}