From 24dfd12bd3adad94f421848a9b1385d2989ee8bd Mon Sep 17 00:00:00 2001
From: Paulo <paulo.rmartins@gmail.com>
Date: Thu, 14 Oct 2021 23:23:27 +0100
Subject: [PATCH] fix metadata constants

---
 src/metadata.rs             |  6 +++++-
 tests/src/frame/balances.rs | 15 +++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/metadata.rs b/src/metadata.rs
index 0ab94e8476..7272add1a9 100644
--- a/src/metadata.rs
+++ b/src/metadata.rs
@@ -279,12 +279,16 @@ impl TryFrom<RuntimeMetadataPrefixed> for Metadata {
                         .collect()
                 });
 
+                let constants = pallet.constants.iter().map(|constant| 
+                    (constant.name.clone(), constant.clone()))
+                    .collect();
+
                 let pallet_metadata = PalletMetadata {
                     index: pallet.index,
                     name: pallet.name.to_string(),
                     calls,
                     storage,
-                    constants: Default::default(), // todo: [AJ] constants
+                    constants,
                 };
 
                 Ok((pallet.name.to_string(), pallet_metadata))
diff --git a/tests/src/frame/balances.rs b/tests/src/frame/balances.rs
index a14a12e1df..f55e7bf300 100644
--- a/tests/src/frame/balances.rs
+++ b/tests/src/frame/balances.rs
@@ -218,3 +218,18 @@ async fn transfer_subscription() {
         balances::events::Transfer(alice.account_id().clone(), bob.clone(), 10_000,)
     );
 }
+
+#[async_std::test]
+async fn constant_existential_deposit() {
+    let cxt = test_context().await;
+    let balances_metadata = cxt
+        .client()
+        .metadata()
+        .pallet("Balances").unwrap();
+    let constant_metadata = balances_metadata
+        .constant("ExistentialDeposit")
+        .unwrap();
+    let existential_deposit = u128::decode(&mut &constant_metadata.value[..])
+        .unwrap();
+    assert_eq!(existential_deposit, 10_000_000_000);
+}
\ No newline at end of file