Skip to content

Commit

Permalink
sui-graphql-client: cleanup of Option<Page> and add tests back (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-mysten authored Nov 11, 2024
1 parent 0db436f commit 5ee3ec1
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions crates/sui-graphql-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ impl Client {
pagination_filter: PaginationFilter,
after_version: Option<u64>,
before_version: Option<u64>,
) -> Result<Option<Page<MovePackage>>, Error> {
) -> Result<Page<MovePackage>, Error> {
let (after, before, first, last) = self.pagination_filter(pagination_filter).await;
let operation = PackageVersionsQuery::build(PackageVersionsArgs {
address,
Expand Down Expand Up @@ -1250,9 +1250,9 @@ impl Client {
Error::msg(format!("Cannot decode bcs bytes into MovePackage: {e}"))
})?;

Ok(Some(Page::new(page_info, packages)))
Ok(Page::new(page_info, packages))
} else {
Ok(None)
Ok(Page::new_empty())
}
}

Expand Down Expand Up @@ -1317,7 +1317,7 @@ impl Client {
last: Option<i32>,
after_checkpoint: Option<u64>,
before_checkpoint: Option<u64>,
) -> Result<Option<Page<MovePackage>>, Error> {
) -> Result<Page<MovePackage>, Error> {
if first.is_some() && last.is_some() {
return Err(Error::msg("Cannot specify both first and last"));
}
Expand Down Expand Up @@ -1360,9 +1360,9 @@ impl Client {
Error::msg(format!("Cannot decode bcs bytes into MovePackage: {e}"))
})?;

Ok(Some(Page::new(page_info, packages)))
Ok(Page::new(page_info, packages))
} else {
Ok(None)
Ok(Page::new_empty())
}
}

Expand Down Expand Up @@ -1869,7 +1869,6 @@ mod tests {
}

#[tokio::test]
#[ignore] // schema was updated, but the service has not been released with the new schema
async fn test_events_query() {
let client = test_client();
let events = client.events(None, PaginationFilter::default()).await;
Expand All @@ -1887,7 +1886,6 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_objects_query() {
let client = test_client();
let objects = client.objects(None, PaginationFilter::default()).await;
Expand All @@ -1900,7 +1898,6 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_object_query() {
let client = test_client();
let object = client.object("0x5".parse().unwrap(), None).await;
Expand Down Expand Up @@ -1964,7 +1961,6 @@ mod tests {
}

#[tokio::test]
#[ignore]
async fn test_transactions_query() {
let client = test_client();
let transactions = client.transactions(None, PaginationFilter::default()).await;
Expand Down Expand Up @@ -1996,7 +1992,6 @@ mod tests {

// This needs the tx builder to be able to be tested properly
#[tokio::test]
#[ignore]
async fn test_dry_run() {
let client = Client::new_testnet();
// this tx bytes works on testnet
Expand Down Expand Up @@ -2077,7 +2072,18 @@ mod tests {
async fn test_package() {
let client = test_client();
let package = client.package("0x2".parse().unwrap(), None).await;
assert!(package.is_ok());
assert!(
package.is_ok(),
"Package query failed for {} network. Error: {}",
client.rpc_server(),
package.unwrap_err()
);

assert!(
package.unwrap().is_some(),
"Package query returned None for {} network",
client.rpc_server()
);
}

#[tokio::test]
Expand All @@ -2098,10 +2104,15 @@ mod tests {
client.rpc_server(),
package.unwrap_err()
);

assert!(
package.unwrap().is_some(),
"Latest package for 0x2 query returned None for {} network",
client.rpc_server()
);
}

#[tokio::test]
#[ignore] // TIMES OUT FOR NOW
async fn test_packages_query() {
let client = test_client();
let packages = client.packages(None, None, None, None, None, None).await;
Expand All @@ -2111,5 +2122,11 @@ mod tests {
client.rpc_server(),
packages.unwrap_err()
);

assert!(
!packages.unwrap().is_empty(),
"Packages query returned no data for {} network",
client.rpc_server()
);
}
}

0 comments on commit 5ee3ec1

Please sign in to comment.