Skip to content

Commit

Permalink
more work on strategy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumExplorer committed Jan 13, 2025
1 parent 999a432 commit 184d1e3
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,49 +745,51 @@ fn insert_values_nested(

let field_type = match type_value {
"integer" => {
let minimum = inner_properties.get_optional_integer::<i64>(property_names::MINIMUM)?;
let maximum = inner_properties.get_optional_integer::<i64>(property_names::MAXIMUM)?;

match (minimum, maximum) {
(Some(min), Some(max)) => {
if min >= 0 {
if max <= u8::MAX as i64 {
DocumentPropertyType::U8
} else if max <= u16::MAX as i64 {
DocumentPropertyType::U16
} else if max <= u32::MAX as i64 {
DocumentPropertyType::U32
} else {
DocumentPropertyType::U64
}
} else {
if min >= i8::MIN as i64 && max <= i8::MAX as i64 {
DocumentPropertyType::I8
} else if min >= i16::MIN as i64 && max <= i16::MAX as i64 {
DocumentPropertyType::I16
} else if min >= i32::MIN as i64 && max <= i32::MAX as i64 {
DocumentPropertyType::I32
} else {
DocumentPropertyType::I64
}
}
}
(Some(min), None) => {
if min >= 0 {
DocumentPropertyType::U64
} else {
DocumentPropertyType::I64
}
}
(None, Some(max)) => {
if max >= 0 {
DocumentPropertyType::U64
} else {
DocumentPropertyType::I64
}
}
(None, None) => DocumentPropertyType::I64,
}
DocumentPropertyType::I64
// todo: we might want to do the following in the future (must be versioned)
// let minimum = inner_properties.get_optional_integer::<i64>(property_names::MINIMUM)?;
// let maximum = inner_properties.get_optional_integer::<i64>(property_names::MAXIMUM)?;
//
// match (minimum, maximum) {
// (Some(min), Some(max)) => {
// if min >= 0 {
// if max <= u8::MAX as i64 {
// DocumentPropertyType::U8
// } else if max <= u16::MAX as i64 {
// DocumentPropertyType::U16
// } else if max <= u32::MAX as i64 {
// DocumentPropertyType::U32
// } else {
// DocumentPropertyType::U64
// }
// } else {
// if min >= i8::MIN as i64 && max <= i8::MAX as i64 {
// DocumentPropertyType::I8
// } else if min >= i16::MIN as i64 && max <= i16::MAX as i64 {
// DocumentPropertyType::I16
// } else if min >= i32::MIN as i64 && max <= i32::MAX as i64 {
// DocumentPropertyType::I32
// } else {
// DocumentPropertyType::I64
// }
// }
// }
// (Some(min), None) => {
// if min >= 0 {
// DocumentPropertyType::U64
// } else {
// DocumentPropertyType::I64
// }
// }
// (None, Some(max)) => {
// if max >= 0 {
// DocumentPropertyType::U64
// } else {
// DocumentPropertyType::I64
// }
// }
// (None, None) => DocumentPropertyType::I64,
// }
}
"number" => DocumentPropertyType::F64,
"string" => DocumentPropertyType::String(StringPropertySizes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10776,7 +10776,7 @@ mod tests {
let (identity, signer, key) =
setup_identity(&mut platform, rng.gen(), dash_to_credits!(0.5));

let (identity_2, signer2, key2) =
let (identity_2, _, _) =
setup_identity(&mut platform, rng.gen(), dash_to_credits!(0.5));

let (contract, token_id) = create_token_contract_with_owner_identity(
Expand Down Expand Up @@ -11889,7 +11889,7 @@ mod tests {

let platform_state = platform.state.load();

let (identity, signer, key) =
let (identity, _, _) =
setup_identity(&mut platform, rng.gen(), dash_to_credits!(0.5));

let (identity_2, signer2, key2) =
Expand Down Expand Up @@ -12508,7 +12508,6 @@ mod tests {
platform_version,
)
.expect("expected to fetch token balance");
let expected_amount = 100000 - 1337;
assert_eq!(token_balance, Some(100000));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ mod tests {

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

assert_eq!(processing_result.aggregated_fees().processing_fee, 1913100);
assert_eq!(processing_result.aggregated_fees().processing_fee, 1919540);

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

assert_eq!(identity_balance, 99913873900);
assert_eq!(identity_balance, 99913867460);
}

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

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

assert_eq!(processing_result.aggregated_fees().processing_fee, 2188760);
assert_eq!(processing_result.aggregated_fees().processing_fee, 2195200);

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

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

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

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

assert_eq!(processing_result.aggregated_fees().processing_fee, 2188760);
assert_eq!(processing_result.aggregated_fees().processing_fee, 2195200);

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

assert_eq!(identity_balance, 99909268540); // The identity balance is smaller than if there hadn't been any issue
assert_eq!(identity_balance, 99909262100); // 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 @@ -359,7 +359,7 @@ mod tests {

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

assert_eq!(processing_result.aggregated_fees().processing_fee, 582400);
assert_eq!(processing_result.aggregated_fees().processing_fee, 588840);

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

assert_eq!(identity_balance, 149993612600); // about 0.5 Dash starting balance + 1 Dash asset lock top up
assert_eq!(identity_balance, 149993606160); // about 0.5 Dash starting balance + 1 Dash asset lock top up
}
}
89 changes: 88 additions & 1 deletion packages/rs-drive-abci/tests/strategy_tests/strategy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ use dpp::state_transition::batch_transition::document_create_transition::{
};
use dpp::state_transition::batch_transition::token_base_transition::v0::TokenBaseTransitionV0;
use dpp::state_transition::batch_transition::token_mint_transition::TokenMintTransitionV0;
use dpp::state_transition::batch_transition::token_transfer_transition::TokenTransferTransitionV0;
use dpp::state_transition::batch_transition::{
BatchTransition, BatchTransitionV0, BatchTransitionV1, TokenMintTransition,
TokenTransferTransition,
};
use dpp::state_transition::data_contract_create_transition::methods::v0::DataContractCreateTransitionMethodsV0;
use dpp::state_transition::data_contract_update_transition::methods::DataContractUpdateTransitionMethodsV0;
Expand Down Expand Up @@ -1455,7 +1457,7 @@ impl NetworkStrategy {
let token_mint_transition: TokenMintTransition = TokenMintTransitionV0 {
base: TokenBaseTransitionV0 {
identity_contract_nonce: *identity_contract_nonce,
token_contract_position: 0,
token_contract_position: *token_pos,
data_contract_id: contract.id(),
token_id: *token_id,
using_group_info: None,
Expand Down Expand Up @@ -1498,6 +1500,91 @@ impl NetworkStrategy {

operations.push(batch_transition);
}
OperationType::Token(TokenOp {
contract,
token_id,
token_pos,
use_identity_with_id,
action:
TokenEvent::Transfer(
recipient,
public_note,
shared_encrypted_note,
private_encrypted_note,
amount,
),
}) if current_identities.len() > 1 => {
let operation_owner_id = if let Some(identity_id) = use_identity_with_id {
*identity_id
} else {
let random_index = rng.gen_range(0..current_identities.len());
current_identities[random_index].id()
};

let request = IdentityKeysRequest {
identity_id: operation_owner_id.to_buffer(),
request_type: KeyRequestType::SpecificKeys(vec![1]),
limit: Some(1),
offset: None,
};
let identity = platform
.drive
.fetch_identity_balance_with_keys(request, None, platform_version)
.expect("expected to be able to get identity")
.expect("expected to get an identity for token mint operation");
let identity_contract_nonce = contract_nonce_counter
.entry((operation_owner_id, contract.id()))
.or_default();
*identity_contract_nonce += 1;
let token_transfer_transition: TokenTransferTransition =
TokenTransferTransitionV0 {
base: TokenBaseTransitionV0 {
identity_contract_nonce: *identity_contract_nonce,
token_contract_position: *token_pos,
data_contract_id: contract.id(),
token_id: *token_id,
using_group_info: None,
}
.into(),
amount: *amount,
recipient_id: *recipient,
public_note: public_note.clone(),
shared_encrypted_note: shared_encrypted_note.clone(),
private_encrypted_note: private_encrypted_note.clone(),
}
.into();

let batch_transition: BatchTransition = BatchTransitionV1 {
owner_id: identity.id,
transitions: vec![BatchedTransition::Token(
token_transfer_transition.into(),
)],
user_fee_increase: 0,
signature_public_key_id: 0,
signature: BinaryData::default(),
}
.into();

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

let identity_public_key = identity
.loaded_public_keys
.values()
.next()
.expect("expected a key");

batch_transition
.sign_external(
identity_public_key,
signer,
Some(|_data_contract_id, _document_type_name| {
Ok(SecurityLevel::HIGH)
}),
)
.expect("expected to sign");

operations.push(batch_transition);
}
_ => {}
}
}
Expand Down
Loading

0 comments on commit 184d1e3

Please sign in to comment.