Merge branch 'master' into aj/update-substrate-crates

This commit is contained in:
Andrew Jones
2022-11-14 11:45:57 +00:00
24 changed files with 168 additions and 76 deletions
@@ -101,12 +101,12 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> {
let alice_account_addr = subxt::dynamic::storage(
"System",
"Account",
vec![Value::from_bytes(&alice.account_id())],
vec![Value::from_bytes(alice.account_id())],
);
let bob_account_addr = subxt::dynamic::storage(
"System",
"Account",
vec![Value::from_bytes(&bob.account_id())],
vec![Value::from_bytes(bob.account_id())],
);
let alice_pre = api
@@ -122,7 +122,7 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> {
"Balances",
"transfer",
vec![
Value::unnamed_variant("Id", vec![Value::from_bytes(&bob.account_id())]),
Value::unnamed_variant("Id", vec![Value::from_bytes(bob.account_id())]),
Value::u128(10_000u128),
],
);
@@ -145,11 +145,11 @@ async fn tx_dynamic_transfer() -> Result<(), subxt::Error> {
let expected_fields = Composite::Named(vec![
(
"from".into(),
Value::unnamed_composite(vec![Value::from_bytes(&alice.account_id())]),
Value::unnamed_composite(vec![Value::from_bytes(alice.account_id())]),
),
(
"to".into(),
Value::unnamed_composite(vec![Value::from_bytes(&bob.account_id())]),
Value::unnamed_composite(vec![Value::from_bytes(bob.account_id())]),
),
("amount".into(), Value::u128(10_000)),
]);
@@ -242,7 +242,7 @@ async fn storage_current_era() -> Result<(), Error> {
async fn storage_era_reward_points() -> Result<(), Error> {
let ctx = test_context().await;
let api = ctx.client();
let reward_points_addr = node_runtime::storage().staking().eras_reward_points(&0);
let reward_points_addr = node_runtime::storage().staking().eras_reward_points(0);
let current_era_result = api.storage().fetch(&reward_points_addr, None).await;
assert!(current_era_result.is_ok());
+1 -1
View File
@@ -72,7 +72,7 @@ async fn storage_n_mapish_key_is_properly_created() -> Result<(), subxt::Error>
bytes.extend(&sp_core::twox_128("KeyOwner".as_bytes())[..]);
// twox64_concat a *tuple* of the args expected:
let suffix = (KeyTypeId([1, 2, 3, 4]), vec![5u8, 6, 7, 8]).encode();
bytes.extend(&sp_core::twox_64(&suffix));
bytes.extend(sp_core::twox_64(&suffix));
bytes.extend(&suffix);
bytes
};
+1 -1
View File
@@ -13,4 +13,4 @@ subxt = { path = "../../subxt" }
sp-core = { version = "6.0.0", git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.33", package = "sp-core", default-features = false }
tokio = { version = "1.8", features = ["macros", "rt-multi-thread"] }
which = "4.2.2"
jsonrpsee = { version = "0.15.1", features = ["async-client", "client-ws-transport"] }
jsonrpsee = { version = "0.16.0", features = ["async-client", "client-ws-transport"] }
+5 -2
View File
@@ -60,7 +60,7 @@ async fn run() {
// Thus, the connection might get rejected a few times.
use client::ClientT;
let res = match client::build(&format!("ws://localhost:{}", port)).await {
Ok(c) => c.request("state_getMetadata", None).await,
Ok(c) => c.request("state_getMetadata", client::rpc_params![]).await,
Err(e) => Err(e),
};
@@ -174,7 +174,10 @@ mod client {
},
};
pub use jsonrpsee::core::client::ClientT;
pub use jsonrpsee::core::{
client::ClientT,
rpc_params,
};
/// Build WS RPC client from URL
pub async fn build(url: &str) -> Result<Client, Error> {
+11
View File
@@ -0,0 +1,11 @@
[package]
name = "wasm-test"
version = "0.1.0"
edition = "2021"
[dev-dependencies]
wasm-bindgen-test = "0.3.24"
tracing-wasm = "0.2.1"
console_error_panic_hook = "0.1.7"
serde_json = "1.0.57"
subxt = { path = "../../subxt", default-features = false, features = ["jsonrpsee-web"] }
+26
View File
@@ -0,0 +1,26 @@
#![cfg(target_arch = "wasm32")]
use subxt::config::PolkadotConfig;
use wasm_bindgen_test::*;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
/// Run the tests by `$ wasm-pack test --firefox --headless`
fn init_tracing() {
console_error_panic_hook::set_once();
tracing_wasm::set_as_global_default();
}
#[wasm_bindgen_test]
async fn wasm_ws_transport_works() {
init_tracing();
let client =
subxt::client::OnlineClient::<PolkadotConfig>::from_url("ws://127.0.0.1:9944")
.await
.unwrap();
let chain = client.rpc().system_chain().await.unwrap();
assert_eq!(&chain, "Development");
}