Support embedded full/light node clients. (#91)

* Add support for light clients.

* Add wasm toolchain to ci.

* Fix ci tests.

* Address review comments.

* Use expect instead of unwrap.

* Purge light client chain too.

* Add README section.
This commit is contained in:
David Craven
2020-06-15 09:01:16 +02:00
committed by GitHub
parent 91203b91d3
commit 21d07c6c24
13 changed files with 544 additions and 57 deletions
+2 -4
View File
@@ -142,19 +142,17 @@ mod tests {
});
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_total_issuance() {
env_logger::try_init().ok();
let client = test_client().await;
let (client, _) = test_client().await;
let total_issuance = client.total_issuance(None).await.unwrap();
assert_ne!(total_issuance, 0);
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_state_read_free_balance() {
env_logger::try_init().ok();
let client = test_client().await;
let (client, _) = test_client().await;
let account = AccountKeyring::Alice.to_account_id();
let info = client.account(&account, None).await.unwrap();
assert_ne!(info.data.free, 0);
+37 -19
View File
@@ -42,6 +42,9 @@
#[macro_use]
extern crate substrate_subxt_proc_macro;
#[cfg(feature = "client")]
pub use substrate_subxt_client as client;
pub use sp_core;
pub use sp_runtime;
@@ -437,6 +440,7 @@ impl codec::Encode for Encoded {
#[cfg(test)]
mod tests {
use super::*;
use sp_core::{
storage::{
well_known_keys,
@@ -448,24 +452,44 @@ mod tests {
AccountKeyring,
Ed25519Keyring,
};
use substrate_subxt_client::{
DatabaseConfig,
Role,
SubxtClient,
SubxtClientConfig,
};
use tempdir::TempDir;
use super::*;
pub(crate) async fn test_client() -> Client<crate::DefaultNodeRuntime> {
ClientBuilder::new()
pub(crate) async fn test_client() -> (Client<crate::NodeTemplateRuntime>, TempDir) {
let tmp = TempDir::new("subxt-").expect("failed to create tempdir");
let config = SubxtClientConfig {
impl_name: "substrate-subxt-full-client",
impl_version: "0.0.1",
author: "substrate subxt",
copyright_start_year: 2020,
db: DatabaseConfig::RocksDb {
path: tmp.path().into(),
cache_size: 128,
},
builder: node_template::service::new_full,
chain_spec: node_template::chain_spec::development_config(),
role: Role::Authority(AccountKeyring::Alice),
};
let client = ClientBuilder::new()
.set_client(SubxtClient::new(config).expect("Error creating subxt client"))
.build()
.await
.expect("Error creating client")
.expect("Error creating client");
(client, tmp)
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_tx_transfer_balance() {
env_logger::try_init().ok();
let mut signer = PairSigner::new(AccountKeyring::Alice.pair());
let dest = AccountKeyring::Bob.to_account_id().into();
let client = test_client().await;
let (client, _) = test_client().await;
let nonce = client
.account(&AccountKeyring::Alice.to_account_id(), None)
.await
@@ -498,24 +522,21 @@ mod tests {
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_getting_hash() {
let client = test_client().await;
let (client, _) = test_client().await;
client.block_hash(None).await.unwrap();
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_getting_block() {
let client = test_client().await;
let (client, _) = test_client().await;
let block_hash = client.block_hash(None).await.unwrap();
client.block(block_hash).await.unwrap();
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_getting_read_proof() {
let client = test_client().await;
let (client, _) = test_client().await;
let block_hash = client.block_hash(None).await.unwrap();
client
.read_proof(
@@ -530,29 +551,26 @@ mod tests {
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_chain_subscribe_blocks() {
let client = test_client().await;
let (client, _) = test_client().await;
let mut blocks = client.subscribe_blocks().await.unwrap();
blocks.next().await;
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_chain_subscribe_finalized_blocks() {
let client = test_client().await;
let (client, _) = test_client().await;
let mut blocks = client.subscribe_finalized_blocks().await.unwrap();
blocks.next().await;
}
#[async_std::test]
#[ignore] // requires locally running substrate node
async fn test_create_raw_payload() {
let signer_pair = Ed25519Keyring::Alice.pair();
let signer_account_id = Ed25519Keyring::Alice.to_account_id();
let dest = AccountKeyring::Bob.to_account_id().into();
let client = test_client().await;
let (client, _) = test_client().await;
// create raw payload with AccoundId and sign it
let raw_payload = client
+25
View File
@@ -61,6 +61,31 @@ impl Balances for DefaultNodeRuntime {
impl Contracts for DefaultNodeRuntime {}
/// Concrete type definitions compatible with the node template.
///
/// # Note
///
/// Main difference is `type Address = AccountId`.
/// Also the contracts module is not part of the node template runtime.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct NodeTemplateRuntime;
impl System for NodeTemplateRuntime {
type Index = u32;
type BlockNumber = u32;
type Hash = sp_core::H256;
type Hashing = BlakeTwo256;
type AccountId = <<MultiSignature as Verify>::Signer as IdentifyAccount>::AccountId;
type Address = Self::AccountId;
type Header = Header<Self::BlockNumber, BlakeTwo256>;
type Extrinsic = OpaqueExtrinsic;
type AccountData = AccountData<<Self as Balances>::Balance>;
}
impl Balances for NodeTemplateRuntime {
type Balance = u128;
}
/// Concrete type definitions compatible with those for kusama, v0.7
///
/// # Note