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
4 changes: 4 additions & 0 deletions packages/rs-sdk/src/mock/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ impl MockDashPlatformSdk {
self.load_expectation::<proto::GetDataContractsRequest>(filename)
.await?
}
"GetDataContractHistoryRequest" => {
self.load_expectation::<proto::GetDataContractHistoryRequest>(filename)
.await?
}
"IdentityRequest" => self.load_expectation::<IdentityRequest>(filename).await?,
"GetIdentityRequest" => {
self.load_expectation::<proto::GetIdentityRequest>(filename)
Expand Down
4 changes: 4 additions & 0 deletions packages/rs-sdk/src/platform/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ impl Fetch for drive_proof_verifier::types::IdentityBalanceAndRevision {
type Request = platform_proto::GetIdentityBalanceAndRevisionRequest;
}

impl Fetch for drive_proof_verifier::types::DataContractHistory {
type Request = platform_proto::GetDataContractHistoryRequest;
}

impl Fetch for ExtendedEpochInfo {
type Request = platform_proto::GetEpochsInfoRequest;
}
21 changes: 21 additions & 0 deletions packages/rs-sdk/src/platform/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,27 @@ impl Query<proto::GetDataContractsRequest> for Vec<Identifier> {
}
}

impl Query<proto::GetDataContractHistoryRequest> for LimitQuery<(Identifier, u64)> {
fn query(self, prove: bool) -> Result<proto::GetDataContractHistoryRequest, Error> {
if !prove {
unimplemented!("queries without proofs are not supported yet");
}
let (id, start_at_ms) = self.query;

Ok(proto::GetDataContractHistoryRequest {
version: Some(proto::get_data_contract_history_request::Version::V0(
proto::get_data_contract_history_request::GetDataContractHistoryRequestV0 {
id: id.to_vec(),
limit: self.limit,
offset: None,
start_at_ms,
prove,
},
)),
})
}
}

impl Query<proto::GetIdentityKeysRequest> for Identifier {
/// Get all keys for an identity with provided identifier.
fn query(self, prove: bool) -> Result<proto::GetIdentityKeysRequest, Error> {
Expand Down
32 changes: 31 additions & 1 deletion packages/rs-sdk/tests/fetch/data_contract.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use super::config::Config;
use dash_sdk::platform::{Fetch, FetchMany};
use dash_sdk::platform::{Fetch, FetchMany, LimitQuery};
use dpp::data_contract::accessors::v0::DataContractV0Getters;
use dpp::platform_value::string_encoding::Encoding;
use dpp::prelude::{DataContract, Identifier};
use drive_proof_verifier::types::DataContractHistory;

/// Given some dummy data contract ID, when I fetch data contract, I get None because it doesn't exist.
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
Expand Down Expand Up @@ -88,3 +91,30 @@ async fn test_data_contracts_2_nx() {
"proof of non-existence 2 failed"
);
}

// This test currently supports offline mode only.
// It needs Data Contract with `keep_history` set to true, which is not available in the network
// by default and has to be created manually.
// At the moment tests in rs-sdk do not provide Core Wallet signer, and unable to create
// identities and data contracts.
// The contract for this test was pre-created with
// `packages/platform-test-suite/test/functional/platform/DataContract.spec.js`
// and stored as a test vector for offline testing only.
#[cfg(not(feature = "network-testing"))]
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_data_contract_history_read() {
let cfg = Config::new();
let id = Identifier::from_string(
"3c71ba2d0b655ac3d231c4411d3c3fad43451d3f48213537ff9da331b24e5dea",
Comment thread
lklimek marked this conversation as resolved.
Encoding::Hex,
)
.unwrap();

let sdk = cfg.setup_api("test_data_contract_history_read").await;

let result = DataContractHistory::fetch(&sdk, LimitQuery::from((id, 10))).await;

assert!(matches!(result, Ok(Some(_))), "result: {:?}", result);
let (_, contract) = result.unwrap().unwrap().pop_first().unwrap();
assert_eq!(contract.id(), id);
}
Empty file.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[134,90,211,2,159,204,117,201,202,79,41,171,146,86,115,171,247,117,185,147,133,32,111,139,93,126,226,86,104,239,140,58,90,36,89,121,41,96,244,146,48,229,249,80,185,69,142,129]