Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
20aee21
Remove TypeSegmenter and dynclone dependency
ascjones Sep 29, 2021
3de2815
Publicly expose Rpc mod
ascjones Sep 29, 2021
c5ef0fa
Unused import warnings
ascjones Sep 29, 2021
b2f0ddf
Add getter for runtime metadata
ascjones Sep 29, 2021
e8256e0
Add pallet and event indices for raw events
ascjones Sep 29, 2021
d0dda23
Add is_call and is_event convenience trait functions
ascjones Oct 1, 2021
6198ac2
Add missing docs
ascjones Oct 4, 2021
cbbf0e1
Refactor tests crate
ascjones Oct 4, 2021
76d7b11
Restore remaining client tests
ascjones Oct 4, 2021
c86a9ce
Fmt
ascjones Oct 4, 2021
d439722
Fix warnings
ascjones Oct 4, 2021
997d6b7
Restore get_mod as test helper and fmt
ascjones Oct 4, 2021
44ec197
Use client references for api calls
ascjones Oct 4, 2021
950845f
Fix api usages with methods
ascjones Oct 4, 2021
3cb4000
Use Bytes for RawEvent debug
ascjones Oct 4, 2021
602f62b
Update metadata
ascjones Oct 5, 2021
4d1de1b
Restoring some Balances tests
ascjones Oct 5, 2021
384f88e
Populate runtime storage metadata
ascjones Oct 5, 2021
b340bc2
Restore balances lock test
ascjones Oct 5, 2021
f1b7b85
Restore Balances error test
ascjones Oct 5, 2021
ec90ecc
Fmt
ascjones Oct 5, 2021
e4907d4
Restore transfer subscription API
ascjones Oct 5, 2021
bab2aef
Staking test
ascjones Oct 5, 2021
696ee63
Restore another staking test
ascjones Oct 5, 2021
560ceb5
Restore another staking test
ascjones Oct 5, 2021
c5915b9
Restore another staking test
ascjones Oct 5, 2021
5e9b7d2
Partially restore chill_works_for_controller_only staking test
ascjones Oct 5, 2021
34e1da5
Fix fetching Optional storage entries
ascjones Oct 6, 2021
442fe24
Restore staking bond test
ascjones Oct 6, 2021
35a3141
Restore remaining staking tests
ascjones Oct 6, 2021
83af04e
Fmt
ascjones Oct 6, 2021
b95ce3d
Restore sudo tests
ascjones Oct 6, 2021
79355d3
Add some system tests
ascjones Oct 6, 2021
5e7b7e7
Fmt
ascjones Oct 6, 2021
368ec3b
Resolve some todos
ascjones Oct 6, 2021
f819cb6
Remove pass through rpc methods on Client, expose via rpc() getter
ascjones Oct 6, 2021
903b153
Remove more rpc pass through methods
ascjones Oct 6, 2021
d984dd5
Remove submit tx pass through rpc methods
ascjones Oct 6, 2021
a9d1e8f
Add some comments to SubmittableExtrinsic methods
ascjones Oct 7, 2021
ccb1491
Construct the runtime api from the client
ascjones Oct 7, 2021
ffc1a3c
Fmt
ascjones Oct 7, 2021
f46c944
Use From trait instead of new for AccountData query
ascjones Oct 8, 2021
f834035
Rename subxt_proc_macro crate to subxt_macro
ascjones Oct 12, 2021
fc80bb0
Fix AccountData From impl
ascjones Oct 12, 2021
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
Prev Previous commit
Next Next commit
Restore get_mod as test helper and fmt
  • Loading branch information
ascjones committed Oct 4, 2021
commit 997d6b77d7c9ffa6d20f0cc949132d0d3c17ace2
70 changes: 42 additions & 28 deletions proc-macro/src/generate_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,20 @@ mod tests {
const MOD_PATH: &'static [&'static str] =
&["chameleon_core", "generate_types", "tests"];

fn get_mod<'a>(
module: &'a Module,
path_segs: &[&'static str],
) -> Option<&'a Module<'a>> {
let (mod_name, rest) = path_segs.split_first()?;
let mod_ident = Ident::new(mod_name, Span::call_site());
let module = module.children.get(&mod_ident)?;
if rest.is_empty() {
Some(module)
} else {
get_mod(module, rest)
}
}

#[test]
fn generate_struct_with_primitives() {
#[allow(unused)]
Expand All @@ -717,9 +731,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -758,9 +772,9 @@ mod tests {
registry.register_type(&meta_type::<Parent>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -798,9 +812,9 @@ mod tests {
registry.register_type(&meta_type::<Parent>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -833,9 +847,9 @@ mod tests {
registry.register_type(&meta_type::<E>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -866,9 +880,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -898,9 +912,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -935,9 +949,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -970,9 +984,9 @@ mod tests {
registry.register_type(&meta_type::<E>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1003,9 +1017,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1042,9 +1056,9 @@ mod tests {
registry.register_type(&meta_type::<Bar>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1085,9 +1099,9 @@ mod tests {
registry.register_type(&meta_type::<Bar<bool>>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1132,9 +1146,9 @@ mod tests {
registry.register_type(&meta_type::<S>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1180,9 +1194,9 @@ mod tests {
registry.register_type(&meta_type::<UnnamedFields<bool, bool>>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down Expand Up @@ -1235,9 +1249,9 @@ mod tests {
registry.register_type(&meta_type::<modules::c::Foo>());
let portable_types: PortableRegistry = registry.into();

let type_gen = TypeGenerator::new(&portable_types, "root");
let type_gen = TypeGenerator::new(&portable_types, "root", Default::default());
let types = type_gen.generate_types_mod();
let tests_mod = types.get_mod(MOD_PATH).unwrap();
let tests_mod = get_mod(&types, MOD_PATH).unwrap();

assert_eq!(
tests_mod.into_token_stream().to_string(),
Expand Down
12 changes: 10 additions & 2 deletions tests/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use crate::{runtime::node_runtime::system, test_node_process, test_node_process_with};
use crate::{
runtime::node_runtime::system,
test_node_process,
test_node_process_with,
};

use sp_core::storage::{
well_known_keys,
Expand Down Expand Up @@ -104,7 +108,11 @@ async fn fetch_keys() {
async fn test_iter() {
let node_process = test_node_process().await;
let client = node_process.client();
let mut iter = client.storage().iter::<system::storage::Account>(None).await.unwrap();
let mut iter = client
.storage()
.iter::<system::storage::Account>(None)
.await
.unwrap();
let mut i = 0;
while let Some(_) = iter.next().await.unwrap() {
i += 1;
Expand Down
8 changes: 3 additions & 5 deletions tests/src/frame/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ use crate::{
TestRuntime,
};
use sp_keyring::AccountKeyring;
use subxt::{
extrinsic::{
PairSigner,
Signer,
},
use subxt::extrinsic::{
PairSigner,
Signer,
};

#[async_std::test]
Expand Down
23 changes: 19 additions & 4 deletions tests/src/frame/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ use crate::{
};
use sp_core::sr25519::Pair;
use sp_runtime::MultiAddress;
use subxt::{Client, Error, ExtrinsicSuccess, PairSigner, Runtime, StorageEntry};
use subxt::{
Client,
Error,
ExtrinsicSuccess,
PairSigner,
Runtime,
StorageEntry,
};

struct ContractsTestContext {
cxt: TestContext,
Expand Down Expand Up @@ -177,14 +184,22 @@ async fn tx_call() {
// assert!(contract_info.is_ok());

let contract_info_of = storage::ContractInfoOf(contract.clone());
let storage_entry_key = <storage::ContractInfoOf as StorageEntry>::key(&contract_info_of);
let storage_entry_key =
<storage::ContractInfoOf as StorageEntry>::key(&contract_info_of);
let final_key = storage_entry_key.final_key::<storage::ContractInfoOf>();
println!("contract_info_key key {:?}", hex::encode(&final_key.0));

let res = ctx.client().storage().fetch_raw(final_key, None).await.unwrap();
let res = ctx
.client()
.storage()
.fetch_raw(final_key, None)
.await
.unwrap();
println!("Result {:?}", res);

let keys = ctx.client().storage()
let keys = ctx
.client()
.storage()
.fetch_keys::<storage::ContractInfoOf>(5, None, None)
.await
.unwrap()
Expand Down
5 changes: 4 additions & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ mod client;
#[cfg(test)]
mod frame;

pub use runtime::{
node_runtime,
TestRuntime,
};
pub use utils::*;
pub use runtime::{TestRuntime, node_runtime};
6 changes: 5 additions & 1 deletion tests/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

use sp_runtime::traits::BlakeTwo256;
use subxt::{Runtime, StorageEntry, subxt};
use subxt::{
subxt,
Runtime,
StorageEntry,
};

#[subxt(runtime_metadata_path = "node_runtime.scale")]
pub mod node_runtime {
Expand Down
12 changes: 9 additions & 3 deletions tests/src/utils/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

pub use crate::{
TestNodeProcess, TestRuntime, node_runtime,
node_runtime,
TestNodeProcess,
TestRuntime,
};

use sp_keyring::AccountKeyring;
Expand Down Expand Up @@ -55,5 +57,9 @@ pub async fn test_context() -> TestContext {
let node_proc = test_node_process_with(AccountKeyring::Alice).await;
let client = node_proc.client().clone();
let api = node_runtime::RuntimeApi::<TestRuntime>::new(client.clone());
TestContext { node_proc, api, client }
}
TestContext {
node_proc,
api,
client,
}
}
4 changes: 2 additions & 2 deletions tests/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with substrate-subxt. If not, see <http://www.gnu.org/licenses/>.

mod node_proc;
mod context;
mod node_proc;

pub use context::*;
pub use node_proc::TestNodeProcess;
pub use context::*;