Skip to content

Commit

Permalink
[smoke-test] Add comprehensive rosetta block & balance test
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario committed Aug 15, 2022
1 parent 734c6e1 commit 3858a0c
Show file tree
Hide file tree
Showing 2 changed files with 368 additions and 283 deletions.
27 changes: 24 additions & 3 deletions crates/aptos-rest-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pub use types::{Account, Resource};
use crate::aptos::{AptosVersion, Balance};
use anyhow::{anyhow, Result};
use aptos_api_types::{
mime_types::BCS_SIGNED_TRANSACTION as BCS_CONTENT_TYPE, AptosError, Block, BlockInfo,
HexEncodedBytes, VersionedEvent,
mime_types::BCS_SIGNED_TRANSACTION as BCS_CONTENT_TYPE, AptosError, Block, HexEncodedBytes,
VersionedEvent,
};
use aptos_crypto::HashValue;
use aptos_types::{
Expand Down Expand Up @@ -120,6 +120,27 @@ impl Client {
})
}

pub async fn get_account_balance_at_version(
&self,
address: AccountAddress,
version: u64,
) -> Result<Response<Balance>> {
let resp = self
.get_account_resource_at_version(
address,
"0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
version,
)
.await?;
resp.and_then(|resource| {
if let Some(res) = resource {
Ok(serde_json::from_value::<Balance>(res.data)?)
} else {
Err(anyhow!("No data returned"))
}
})
}

pub async fn get_index(&self) -> Result<Response<IndexResponse>> {
self.get(self.build_path("")?).await
}
Expand Down Expand Up @@ -299,7 +320,7 @@ impl Client {
version: u64,
) -> Result<Response<Vec<Resource>>> {
let url = self.build_path(&format!(
"accounts/{}/resources?version={}",
"accounts/{}/resources?ledger_version={}",
address, version
))?;

Expand Down
Loading

0 comments on commit 3858a0c

Please sign in to comment.