speed up ui tests. (#944)

* speed up ui tests by reducing number of pallets

* add small and tiny versions of polkadot metadata

* change drop implementation fix test

* rust yml add nextest and merge tests

* 2

* 3

* 4

* 5

* 6

* add script for generating files

* Upgrade to `syn 2.0` (#875)

* WIP updating to syn 2.0.0

* WIP darling compat

* Update darling and syn workspace deps

* NestedMeta::parse_meta_list

* Rename attribute keyword type property to path

* Fmt

* Update more type to path

* Unused darling

* Cargo.lock

* Add missing syn features

* Metadata V15: Generate Runtime APIs (#918)

* Update frame-metadata to v15.1.0

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Enable V15 unstable metadata in frame-metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Move validation hashing to dedicated file

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Use sp-metadata-ir from substrate to work with metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Revert using sp-metadata-ir in favor of conversion to v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Convert v14 to v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Use v15 for validation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Use v15 for codegen

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata/bench: Use v15

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust to v15 metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Adjust testing

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Improve documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* force CI

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Fetch metadata at version

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* artifacts: Update polkadot.scale from commit 6dc9e84dde2

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Fetch V15 using the new API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Add runtime API interface

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Hash runtime API metadata for validation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Extract runtime API metadata wrapper from subxt::Metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Adjust hashing cache to reflect root+item keys

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* rpc: Add raw state_call API method

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime_api: Add payload with static and dynamic variants

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Allow payloads to call into the runtime

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Add example to make a runtime API call both static and dynamic

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Simplify client fetching

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Address feedback and fallback to old API if needed

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime_api: Make mutability conditional on input params

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Regenerate polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Retain only pallets without runtime API info

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Retry via `Metadata_metadata` without conversion

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* payload: Remove `Decode` and change validation fn

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* metadata: Retain runtime API types

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Runtime APIs documentation based on flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update examples/examples/custom_metadata_url.rs

Co-authored-by: James Wilson <james@jsdw.me>

* Update artifacts from polkadot-a6cfdb16e9

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update polkadot.rs with polkadot-a6cfdb16e9

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Generate input structures for runtime API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* runtime_api: Remove the static paylaod and use single impl

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* examples: Fetch account nonce

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Adjust build script to fetch latest metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Check account nonce from runtime API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Fix doc generation for runtime types

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Rename `inputs` runtime calls module to `types`

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Generate Calls structs inside the types module

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Check Alice account nonce before submitting the tx

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Add metadata version option flag supporting v14 and unstable

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Specify version to fetch

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Fallback to fetching latest stable metadata

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* subxt: Add unstable-metadata feature to fetch the latest

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* RuntimeVersion with Latest and Version(u32)

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update polkadot.rs

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Adjust fetch_metadata to inspect version list

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* testing: Adjust metadata to metadata_legacy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* events: Adjust docs to use metadata_legacy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* have a pass over fetch_metadata

* cargo fmt

* Option<String> when fetch metadata via latest API

* clippy

* fmt

* cli: Use the MetadataVersion from codegen

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Specify latest as default for MetadataVersion

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Remove version from metadata and use the one from file_or_url

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Fix clippy

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* codegen: Decode metadata independently for different RPC calls

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: James Wilson <james@jsdw.me>

* add small and tiny versions of polkadot metadata

* add script for generating files

* new metadata

* Runtime APIs; don't ask for validation hash anywhere except new_static (#947)

* remove validation hash where not wanted

* .into()

* fix example

* cargo fmt

* Subxt Guide (#890)

* WIP Starting to write book; extrinsics first pass done

* cargo fmt

* Ongoing work; events, constants, wip blocks

* at_latest() and wip blocks

* remove need to import parity-scale-codec crate with Subxt for macro to work

* More docs; expanding on setup guide and finish pass of main sections

* Tidy and remove example section for now

* format book lines to 100chars

* Fix example code

* cargo fmt

* cargo fmt

* fix example

* Fix typos

* fix broken doc links, pub mods

* Update Subxt macro docs

* can't link to Subxt here

* move macro docs to Subxt to make linking better and fix example code

* note on macro about docs

* cargo fmt

* document the no_default_derives macro feature

* Address feedback and remove redundant text

* address review comments; minor tweaks

* WIP add Runtime calls to book

* Improve Runtime API docs

* expose thing we forgot to expose and doc link fixes

* use new metadata files in book

* use mtadata full in docs

* regenerate polkadot.rs

* use small metadata in a couple of places

* Update scripts/artifacts.sh

Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: Andrew Jones <ascjones@gmail.com>
Co-authored-by: Alexandru Vasile <60601340+lexnv@users.noreply.github.com>
Co-authored-by: James Wilson <james@jsdw.me>
Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
Tadeo Hepperle
2023-05-12 11:27:24 +02:00
committed by GitHub
parent bb394156a2
commit 6087dc0002
38 changed files with 891 additions and 565 deletions
+173 -263
View File
@@ -1,306 +1,216 @@
name: Rust
on:
push:
# Run jobs when commits are pushed to
# master or release-like branches:
branches:
- master
pull_request:
# Run jobs for any external PR that wants
# to merge to master, too:
branches:
- master
push:
# Run jobs when commits are pushed to
# master or release-like branches:
branches:
- master
pull_request:
# Run jobs for any external PR that wants
# to merge to master, too:
branches:
- master
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
# TODO: Currently pointing at latest substrate; is there a suitable binary we can pin to here?
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:stretch/latest/substrate/substrate
CARGO_TERM_COLOR: always
# TODO: Currently pointing at latest substrate; is there a suitable binary we can pin to here?
SUBSTRATE_URL: https://releases.parity.io/substrate/x86_64-debian:stretch/latest/substrate/substrate
jobs:
build:
name: Cargo check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
build:
name: Cargo check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Install cargo-hack
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-hack
version: 0.5
- name: Install cargo-hack
uses: baptiste0928/cargo-install@v2
with:
crate: cargo-hack
version: 0.5
- name: Cargo check
run: cargo hack --exclude-all-features --each-feature check --all-targets --workspace
- name: Cargo check
run: cargo hack --exclude-all-features --each-feature check --all-targets --workspace
fmt:
name: Cargo fmt
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
fmt:
name: Cargo fmt
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Install Rust nightly toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Cargo fmt
uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check
- name: Cargo fmt
uses: actions-rs/cargo@v1.0.3
with:
command: fmt
args: --all -- --check
docs:
name: Check documentation
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
docs:
name: Check documentation and run doc tests
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Check internal documentation links
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items
- name: Check internal documentation links
run: RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc -vv --workspace --no-deps --document-private-items
- name: Run cargo test on documentation
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --doc
- name: Run cargo test on documentation
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --doc
test-docs:
name: "Test: docs"
runs-on: ubuntu-latest-8-cores
steps:
- name: Checkout sources
uses: actions/checkout@v3
nonwasm_tests:
name: "Test non-wasm"
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Run tests
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --doc
- name: Install cargo-nextest
run: cargo install cargo-nextest
test-integration:
name: "Test: integration tests"
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Run tests
uses: actions-rs/cargo@v1.0.3
with:
command: nextest
args: run --workspace
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
clippy:
name: Cargo clippy
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true
- name: Run tests
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --all-targets --package integration-tests
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
test-ui:
name: "Test: UI tests"
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
wasm_tests:
name: Test wasm
runs-on: ubuntu-latest
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
steps:
- uses: actions/checkout@v3.1.0
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Run tests
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --all-targets --package ui-tests
- name: Install firefox
uses: browser-actions/setup-firefox@latest
tests-other:
name: "Test: other (mainly unit) tests"
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install chrome
uses: browser-actions/setup-chrome@latest
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Cargo test
uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --all-targets --workspace --exclude ui-tests --exclude integration-tests
clippy:
name: Cargo clippy
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Install Rust stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy
override: true
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Run clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D warnings
wasm_tests:
name: Test wasm
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.1.0
- name: Install wasm-pack
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- name: Install firefox
uses: browser-actions/setup-firefox@latest
- name: Install chrome
uses: browser-actions/setup-chrome@latest
- name: Rust Cache
uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1
- name: Download Substrate
run: |
curl $SUBSTRATE_URL --output substrate --location
chmod +x substrate
./substrate --version
mkdir -p ~/.local/bin
mv substrate ~/.local/bin
- name: Run WASM tests
run: |
substrate --dev --tmp > /dev/null 2>&1 &
wasm-pack test --headless --firefox
wasm-pack test --headless --chrome
pkill substrate
working-directory: testing/wasm-tests
- name: Run WASM tests
run: |
substrate --dev --tmp > /dev/null 2>&1 &
wasm-pack test --headless --firefox
wasm-pack test --headless --chrome
pkill substrate
working-directory: testing/wasm-tests
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -23,7 +23,7 @@
//! use frame_metadata::RuntimeMetadataPrefixed;
//! use subxt_codegen::{CratePath, DerivesRegistry, TypeSubstitutes};
//!
//! let encoded = fs::read("../artifacts/polkadot_metadata.scale").unwrap();
//! let encoded = fs::read("../artifacts/polkadot_metadata_full.scale").unwrap();
//!
//! // Runtime metadata obtained from a node.
//! let metadata = <RuntimeMetadataPrefixed as Decode>::decode(&mut &*encoded).unwrap();
+1 -1
View File
@@ -1,7 +1,7 @@
use futures::StreamExt;
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -1,6 +1,6 @@
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -1,6 +1,6 @@
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -2,7 +2,7 @@ use sp_keyring::AccountKeyring;
use subxt::dynamic::Value;
use subxt::{config::PolkadotConfig, OnlineClient};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -2,7 +2,7 @@ use subxt::ext::codec::Compact;
use subxt::ext::frame_metadata::RuntimeMetadataPrefixed;
use subxt::{OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -1,7 +1,7 @@
use sp_keyring::AccountKeyring;
use subxt::{config::PolkadotConfig, OnlineClient};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -25,7 +25,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 3. Metadata (I'll load it from the downloaded metadata, but you can use
// `subxt metadata > file.scale` to download it):
let metadata = {
let bytes = std::fs::read("./artifacts/polkadot_metadata.scale").unwrap();
let bytes = std::fs::read("./artifacts/polkadot_metadata_small.scale").unwrap();
let metadata = RuntimeMetadataPrefixed::decode(&mut &*bytes).unwrap();
Metadata::try_from(metadata).unwrap()
};
+1 -1
View File
@@ -2,7 +2,7 @@ use sp_keyring::AccountKeyring;
use subxt::{OnlineClient, PolkadotConfig};
// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -2
View File
@@ -1,7 +1,6 @@
use subxt::{OnlineClient, PolkadotConfig};
// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -2,7 +2,7 @@ use sp_keyring::AccountKeyring;
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -6,7 +6,7 @@ use subxt::{
};
// Generate an interface that we can use from the node's metadata.
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -2,7 +2,7 @@ use sp_keyring::AccountKeyring;
use subxt::config::polkadot::{Era, PlainTip, PolkadotExtrinsicParamsBuilder as Params};
use subxt::{tx::PairSigner, OnlineClient, PolkadotConfig};
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
pub mod polkadot {}
#[tokio::main]
+1 -1
View File
@@ -13,7 +13,7 @@ use subxt_metadata::{
};
fn load_metadata() -> RuntimeMetadataV15 {
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata.scale"))
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata_full.scale"))
.expect("Cannot read metadata blob");
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut &*bytes).expect("Cannot decode scale metadata");
+1 -1
View File
@@ -256,7 +256,7 @@ mod tests {
use std::{fs, path::Path};
fn load_metadata() -> RuntimeMetadataV15 {
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata.scale"))
let bytes = fs::read(Path::new("../artifacts/polkadot_metadata_full.scale"))
.expect("Cannot read metadata blob");
let meta: RuntimeMetadataPrefixed =
Decode::decode(&mut &*bytes).expect("Cannot decode scale metadata");
+21
View File
@@ -0,0 +1,21 @@
# # Generates the 3 metadata files in `/artifacts` and the polkadot.rs file for integration tests
#
# This script is to be run from the root of the repository: `scripts/artifacts.sh`
#
# It expects a local polkadot node to be running a JSON-RPC HTTP server at 127.0.0.1:9933
# A local polkadot node can be run via:
# ```
# git clone https://github.com/paritytech/polkadot.git
# cd polkadot
# cargo build --release
# ./target/release/polkadot --dev --tmp
# ```
# get the full metadata
cargo run --bin subxt metadata --version unstable > artifacts/polkadot_metadata_full.scale
# use it to generate polkadot.rs
cargo run --bin subxt codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/codegen/polkadot.rs
# generate a metadata file that only contains the pallets Balances, Staking, System and Multisig
cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "Balances,Staking,System,Multisig" > artifacts/polkadot_metadata_small.scale
# generate a metadata file that only contains no pallets
cargo run --bin subxt metadata --file artifacts/polkadot_metadata_full.scale --pallets "" > artifacts/polkadot_metadata_tiny.scale
+1 -1
View File
@@ -14,7 +14,7 @@
//! Using this macro looks something like:
//!
//! ```rust,no_run
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_tiny.scale")]
//! pub mod polkadot {}
//! ```
//!
+1 -1
View File
@@ -18,7 +18,7 @@
//! ```rust,no_run
//! use sp_keyring::AccountKeyring;
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
//! pub mod polkadot {}
//!
//! let constant_query = polkadot::constants().system().block_length();
+1 -1
View File
@@ -24,7 +24,7 @@
//! ```rust,no_run
//! use sp_keyring::AccountKeyring;
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
//! pub mod polkadot {}
//!
//! let runtime_call = polkadot::apis().metadata().metadata_versions();
+2 -2
View File
@@ -18,7 +18,7 @@
//! ```rust,no_run
//! use sp_keyring::AccountKeyring;
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
//! pub mod polkadot {}
//!
//! let account = AccountKeyring::Alice.to_account_id().into();
@@ -45,7 +45,7 @@
//! ```rust,no_run
//! use sp_keyring::AccountKeyring;
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
//! pub mod polkadot {}
//!
//! // A static query capable of iterating over accounts:
+1 -1
View File
@@ -26,7 +26,7 @@
//! We can use the statically generated interface to build transaction payloads:
//!
//! ```rust,no_run
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_small.scale")]
//! pub mod polkadot {}
//!
//! let remark = "Hello there".as_bytes().to_vec();
+9 -9
View File
@@ -109,7 +109,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// )]
/// mod polkadot {}
/// ```
@@ -130,7 +130,7 @@ pub mod ext {
/// # pub mod path { pub mod to { pub use subxt; } }
/// # fn main() {}
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// crate = "crate::path::to::subxt"
/// )]
/// mod polkadot {}
@@ -146,7 +146,7 @@ pub mod ext {
///
/// ```rust
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// substitute_type(path = "sp_arithmetic::per_things::Perbill", with = "crate::Foo")
/// )]
/// mod polkadot {}
@@ -184,7 +184,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// substitute_type(
/// path = "sp_runtime::multiaddress::MultiAddress<A, B>",
/// with = "::subxt::utils::Static<::sp_runtime::MultiAddress<A, B>>"
@@ -204,7 +204,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// derive_for_all_types = "Eq, PartialEq"
/// )]
/// mod polkadot {}
@@ -220,7 +220,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// derive_for_all_types = "Eq, PartialEq",
/// derive_for_type(path = "frame_support::PalletId", derive = "Ord, PartialOrd"),
/// derive_for_type(path = "sp_runtime::ModuleError", derive = "Hash"),
@@ -248,7 +248,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// generate_docs
/// )]
/// mod polkadot {}
@@ -261,7 +261,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// runtime_types_only
/// )]
/// mod polkadot {}
@@ -273,7 +273,7 @@ pub mod ext {
///
/// ```rust,no_run
/// #[subxt::subxt(
/// runtime_metadata_path = "../artifacts/polkadot_metadata.scale",
/// runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale",
/// runtime_types_only,
/// no_default_derives,
/// derive_for_all_types="codec::Encode, codec::Decode"
+1 -1
View File
@@ -25,7 +25,7 @@
//! # async fn main() {
//! use subxt::{ PolkadotConfig, OnlineClient, storage::StorageKey };
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
//! pub mod polkadot {}
//!
//! let api = OnlineClient::<PolkadotConfig>::new().await.unwrap();
+1 -1
View File
@@ -16,7 +16,7 @@
//! # async fn main() {
//! use subxt::{ PolkadotConfig, OnlineClient, storage::StorageKey };
//!
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
//! #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
//! pub mod polkadot {}
//!
//! let api = OnlineClient::<PolkadotConfig>::new().await.unwrap();
+2 -2
View File
@@ -62,7 +62,7 @@ where
/// ```no_run
/// use subxt::{ PolkadotConfig, OnlineClient };
///
/// #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
/// #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
/// pub mod polkadot {}
///
/// # #[tokio::main]
@@ -172,7 +172,7 @@ where
/// ```no_run
/// use subxt::{ PolkadotConfig, OnlineClient };
///
/// #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata.scale")]
/// #[subxt::subxt(runtime_metadata_path = "../artifacts/polkadot_metadata_full.scale")]
/// pub mod polkadot {}
///
/// # #[tokio::main]
+1 -1
View File
@@ -8,7 +8,7 @@
/// Generate by running this at the root of the repository:
///
/// ```
/// cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata.scale | rustfmt > testing/integration-tests/src/codegen/polkadot.rs
/// cargo run --bin subxt -- codegen --file artifacts/polkadot_metadata_full.scale | rustfmt > testing/integration-tests/src/codegen/polkadot.rs
/// ```
#[rustfmt::skip]
#[allow(clippy::all)]
File diff suppressed because it is too large Load Diff
@@ -20,7 +20,7 @@ pub struct Second<T, U>(T, U);
pub struct DoesntImplEncodeDecodeAsType(u16);
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Discarding both params:
@@ -30,7 +30,7 @@ pub struct DoesntImplEncodeDecodeAsType(u16);
pub mod node_runtime {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Discarding second param:
@@ -40,7 +40,7 @@ pub mod node_runtime {}
pub mod node_runtime2 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Discarding first param:
@@ -50,7 +50,7 @@ pub mod node_runtime2 {}
pub mod node_runtime3 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Swapping params:
@@ -60,7 +60,7 @@ pub mod node_runtime3 {}
pub mod node_runtime4 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress",
// Ignore input params and just use concrete types on output:
@@ -70,7 +70,7 @@ pub mod node_runtime4 {}
pub mod node_runtime5 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// We can put a static type in, too:
@@ -80,7 +80,7 @@ pub mod node_runtime5 {}
pub mod node_runtime6 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Check that things can be wrapped in our Static type:
@@ -90,7 +90,7 @@ pub mod node_runtime6 {}
pub mod node_runtime7 {}
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_small.scale",
substitute_type(
path = "sp_runtime::multiaddress::MultiAddress<A, B>",
// Recursive type param substitution should work too (swapping out nested A and B):
@@ -1,4 +1,4 @@
#[subxt::subxt(runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale")]
#[subxt::subxt(runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale")]
pub mod node_runtime {
pub struct SomeStruct;
pub enum SomeEnum {
@@ -1,5 +1,5 @@
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale",
substitute_type(
path = "sp_arithmetic::per_things::Perbill",
with = "sp_runtime::Perbill"
@@ -1,5 +1,5 @@
#[subxt::subxt(
runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale",
runtime_metadata_url = "wss://rpc.polkadot.io:443"
)]
pub mod node_runtime {}
@@ -2,7 +2,7 @@ error: Only one of 'runtime_metadata_path' or 'runtime_metadata_url' can be prov
--> src/incorrect/url_and_path_provided.rs:1:1
|
1 | / #[subxt::subxt(
2 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata.scale",
2 | | runtime_metadata_path = "../../../../artifacts/polkadot_metadata_tiny.scale",
3 | | runtime_metadata_url = "wss://rpc.polkadot.io:443"
4 | | )]
| |__^
+2 -1
View File
@@ -23,7 +23,8 @@ use crate::utils::{MetadataTestRunner, PalletMetadataTestRunner};
#[test]
fn ui_tests() {
let mut m = MetadataTestRunner::default();
let mut p = PalletMetadataTestRunner::new();
// specify pallets we want to test the metadata for (None => all pallets, but specifying only Some(..) speeds up test)
let mut p = PalletMetadataTestRunner::new(Some(&["Babe", "Claims", "Grandpa", "Balances"]));
let t = trybuild::TestCases::new();
t.pass("src/correct/*.rs");
@@ -8,15 +8,17 @@ use std::io::Read;
use subxt_metadata::{metadata_v14_to_latest, retain_metadata_pallets};
static TEST_DIR_PREFIX: &str = "subxt_generated_pallets_ui_tests_";
static METADATA_FILE: &str = "../../artifacts/polkadot_metadata.scale";
static METADATA_FILE: &str = "../../artifacts/polkadot_metadata_full.scale";
pub struct PalletMetadataTestRunner {
metadata: RuntimeMetadataV15,
index: usize,
pallet_names: Option<Vec<String>>,
}
impl PalletMetadataTestRunner {
pub fn new() -> PalletMetadataTestRunner {
/// if pallet_names is Some(..) only the provided pallets will be tested.
pub fn new(pallet_names: Option<&[&str]>) -> PalletMetadataTestRunner {
let mut file =
std::fs::File::open(METADATA_FILE).expect("Cannot open metadata.scale artifact");
@@ -32,8 +34,12 @@ impl PalletMetadataTestRunner {
frame_metadata::RuntimeMetadata::V15(v15) => v15,
_ => panic!("Unsupported metadata version {:?}", meta.1),
};
PalletMetadataTestRunner { metadata, index: 0 }
let pallet_names = pallet_names.map(|v| v.iter().map(|e| e.to_string()).collect());
PalletMetadataTestRunner {
metadata,
index: 0,
pallet_names,
}
}
pub fn path_to_next_ui_test(&mut self) -> Option<String> {
@@ -41,10 +47,15 @@ impl PalletMetadataTestRunner {
return None
};
let test_name = &pallet.name;
// Increment test index to avoid overlaps.
let index = self.index;
self.index += 1;
// if a pallet filter is set (pallet_names is Some), return the next pallet if this pallet is not in the filter.
if let Some(name_filter) = self.pallet_names.as_ref() {
if !name_filter.contains(test_name) {
return self.path_to_next_ui_test();
}
}
// Build custom metadata containing only this pallet.
let mut metadata = self.metadata.clone();
@@ -92,9 +103,17 @@ impl PalletMetadataTestRunner {
impl Drop for PalletMetadataTestRunner {
fn drop(&mut self) {
for i in 0..self.index {
let mut tmp_dir = std::env::temp_dir();
tmp_dir.push(format!("{TEST_DIR_PREFIX}{i}"));
std::fs::remove_dir_all(tmp_dir).expect("cannot cleanup temp files");
if let Some(pallet) = self.metadata.pallets.get(self.index) {
if let Some(name_filter) = self.pallet_names.as_ref() {
if !name_filter.contains(&pallet.name) {
continue;
}
}
let mut tmp_dir = std::env::temp_dir();
tmp_dir.push(format!("{TEST_DIR_PREFIX}{i}"));
std::fs::remove_dir_all(tmp_dir).expect("cannot cleanup temp files");
};
}
}
}