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
8 changes: 8 additions & 0 deletions packages/dashpay-contract/schema/v2/dashpay.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
"maxItems": 21,
"description": "Platform address in storage form (type byte 0x00 P2PKH / 0x01 P2SH followed by the 20-byte HASH160, i.e. RIPEMD160 of SHA256, of the public key or redeem script) for public payments. The type byte is consensus-enforced by a data trigger.",
"position": 6
},
"shieldedAddress": {
"type": "array",
"byteArray": true,
"minItems": 43,
"maxItems": 43,
"description": "Raw Orchard receiving address: 11-byte diversifier followed by 32-byte diversified transmission key. Clients validate before payment; wallets should use a dedicated tip account.",
"position": 7
}
},
"minProperties": 1,
Expand Down
3 changes: 2 additions & 1 deletion packages/dashpay-contract/src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use serde_json::Value;

// Document-type name and property constants live in `crate::v1::document_types`;
// v2 does not change any names v1 defined, it only adds the optional
// `corePaymentAddress` / `platformPaymentAddress` properties to `profile`.
// `corePaymentAddress`, `platformPaymentAddress`, and `shieldedAddress`
// properties to `profile`.

pub fn load_documents_schemas() -> Result<Value, Error> {
serde_json::from_str(include_str!("../../schema/v2/dashpay.schema.json"))
Expand Down
25 changes: 15 additions & 10 deletions packages/rs-drive-abci/src/execution/check_tx/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,9 @@ mod tests {

assert_eq!(
processing_result.aggregated_fees().processing_fee,
// from protocol version 14 the contract's version item is stored beside the contract
24002877830
// from protocol version 14 the contract's version item is stored beside the contract,
// and the larger DashPay v2 schema adds byte-billed contract bytes
24002988740
);

let check_result = platform
Expand Down Expand Up @@ -1353,8 +1354,9 @@ mod tests {
// Plus we have 24_000_000_000 in base costs
assert_eq!(
processing_result.aggregated_fees().processing_fee,
// from protocol version 14 the contract's version item is stored beside the contract
24005755660
// from protocol version 14 the contract's version item is stored beside the contract,
// and the larger DashPay v2 schema adds byte-billed contract bytes
24005977480
);

let check_result = platform
Expand Down Expand Up @@ -1829,8 +1831,9 @@ mod tests {

assert_eq!(
processing_result.aggregated_fees().processing_fee,
// from protocol version 14 the contract's version item is stored beside the contract
24002877830
// from protocol version 14 the contract's version item is stored beside the contract,
// and the larger DashPay v2 schema adds byte-billed contract bytes
24002988740
);

platform
Expand Down Expand Up @@ -1917,8 +1920,9 @@ mod tests {

assert_eq!(
update_processing_result.aggregated_fees().processing_fee,
// from protocol version 14 the contract's version item is stored beside the contract
27002932650
// from protocol version 14 the contract's version item is stored beside the contract,
// and the larger DashPay v2 schema adds byte-billed contract bytes
27003059940
);

let check_result = platform
Expand Down Expand Up @@ -2506,8 +2510,9 @@ mod tests {

assert_eq!(
processing_result.aggregated_fees().processing_fee,
// from protocol version 14 the contract's version item is stored beside the contract
24002877830
// from protocol version 14 the contract's version item is stored beside the contract,
// and the larger DashPay v2 schema adds byte-billed contract bytes
24002988740
);

platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,8 @@ mod tests {
"profile must not carry platformPaymentAddress before transition_to_version_14"
);

assert!(!pre_profile.iter().any(|p| p == "shieldedAddress"));

let result = platform.transition_to_version_14(&block_info, &transaction, platform_version);
assert!(result.is_ok(), "transition failed: {:?}", result.err());

Expand Down Expand Up @@ -1177,6 +1179,7 @@ mod tests {
profile.iter().any(|p| p == "platformPaymentAddress"),
"profile must carry platformPaymentAddress after transition_to_version_14"
);
assert!(profile.iter().any(|p| p == "shieldedAddress"));
}

/// Reads the `status` enum of the stored withdrawals contract's `withdrawal` document
Expand Down Expand Up @@ -1387,7 +1390,11 @@ mod tests {
.keys()
.cloned()
.collect::<Vec<_>>();
for field in ["corePaymentAddress", "platformPaymentAddress"] {
for field in [
"corePaymentAddress",
"platformPaymentAddress",
"shieldedAddress",
] {
assert!(
!pre_profile_properties.iter().any(|p| p == field),
"profile must not carry {field} before the upgrade"
Expand Down Expand Up @@ -1439,7 +1446,11 @@ mod tests {
.keys()
.cloned()
.collect::<Vec<_>>();
for field in ["corePaymentAddress", "platformPaymentAddress"] {
for field in [
"corePaymentAddress",
"platformPaymentAddress",
"shieldedAddress",
] {
assert!(
post_profile_properties.iter().any(|p| p == field),
"profile must carry {field} after the upgrade"
Expand Down Expand Up @@ -2816,3 +2827,47 @@ mod tests {
);
}
}

#[cfg(test)]
mod shielded_profile_schema_tests {
use dpp::data_contract::validate_document::DataContractDocumentValidationMethodsV0;
use dpp::platform_value::{platform_value, Value};
use dpp::system_data_contracts::{load_system_data_contract, SystemDataContract};
use dpp::version::PlatformVersion;

#[test]
fn should_validate_shielded_profile_address_boundaries() {
for version in [13, 14] {
let pv = PlatformVersion::get(version).unwrap();
let contract = load_system_data_contract(SystemDataContract::Dashpay, pv).unwrap();
for length in [0, 42, 43, 44] {
let properties =
platform_value!({ "shieldedAddress": Value::Bytes(vec![0; length]) });
let result = contract
.validate_document_properties("profile", properties, pv)
.unwrap();
assert_eq!(
result.is_valid(),
version == 14 && length == 43,
"protocol {version}, address length {length}: {result:?}"
);
}
let result = contract
.validate_document_properties(
"profile",
platform_value!({"shieldedAddress": "not bytes"}),
pv,
)
.unwrap();
assert!(!result.is_valid());
let legacy = contract
.validate_document_properties(
"profile",
platform_value!({"displayName": "Alice"}),
pv,
)
.unwrap();
assert!(legacy.is_valid());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ mod deletion_tests {
PlatformVersion::latest().protocol_version,
// v14: the deleted document carries the contract-version stamp
// (one stored byte, five estimated), shifting processing costs
1700360, // +740 per document write from protocol version 14: the contract's version item is one more node to rehash
// Protocol version 14 adds +740 per document write (the contract's version
// item is one more node to rehash) and the larger DashPay v2 schema
// increases byte-billed contract-tree reads.
1721520,
)
.await;
}
Expand Down
Loading
Loading