Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make system properties an arbitrary JSON object, plus CI fixes #349

Merged
merged 8 commits into from
Dec 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
9 changes: 8 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ impl<T: Config> Client<T> {
&self.metadata
}

/// Returns the system properties
/// Returns the properties defined in the chain spec as a JSON object.
///
/// # Note
///
/// Some chains use this to define common properties such as `token_decimals` and `token_symbol`
/// required for UIs, but this is merely a convention. So it is up to the library user to
/// deserialize the JSON into the appropriate type or otherwise extract the properties defined
/// in the target chain's spec.
pub fn properties(&self) -> &SystemProperties {
&self.properties
}
Expand Down
13 changes: 2 additions & 11 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,8 @@ impl From<u32> for BlockNumber {
}
}

/// System properties for a Substrate-based runtime
#[derive(serde::Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default)]
#[serde(rename_all = "camelCase")]
pub struct SystemProperties {
/// The address format
pub ss58_format: u8,
/// The number of digits after the decimal point in the native token
pub token_decimals: u8,
/// The symbol of the native token
pub token_symbol: String,
}
/// Arbitrary properties defined in the chain spec as a JSON object.
pub type SystemProperties = serde_json::Map<String, serde_json::Value>;

/// Possible transaction status events.
///
Expand Down
23 changes: 3 additions & 20 deletions tests/integration/frame/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,17 @@
// along with subxt. If not, see <http://www.gnu.org/licenses/>.

use crate::test_context;
use std::time::{
SystemTime,
UNIX_EPOCH,
};

#[async_std::test]
async fn storage_get_current_timestamp() {
let sys_timestamp = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64;
let cxt = test_context().await;

// wait until blocks are produced to get the timestamp
let mut sub = cxt.client().rpc().subscribe_blocks().await.unwrap();
let block_hash = loop {
if let Ok(Some(block)) = sub.next().await {
break block.hash()
}
};

let timestamp = cxt
.api
.storage()
.timestamp()
.now(Some(block_hash))
.await
.unwrap();
.now(None)
.await;

assert!(timestamp > sys_timestamp)
assert!(timestamp.is_ok())
}