Skip to content

fix(runtime poc) #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ polkavm-derive = { path = "vendor/polkavm/crates/polkavm-derive", default-featur

# polkadot-sdk
sp-api = { path = "vendor/polkadot-sdk/substrate/primitives/api", default-features = false }
sp-core = { path = "vendor/polkadot-sdk/substrate/primitives/core", default-features = false }
frame = { package = "polkadot-sdk-frame", path = "vendor/polkadot-sdk/substrate/frame", default-features = false }
pallet-balances = { path = "vendor/polkadot-sdk/substrate/frame/balances", default-features = false }
pallet-assets = { path = "vendor/polkadot-sdk/substrate/frame/assets", default-features = false }
Expand All @@ -69,6 +70,7 @@ scale-info = { version = "2.11.3", default-features = false, features = [
"derive",
] }
tracing = { version = "0.1.40", default-features = false }
hex = { version = "0.4" }

# std
clap = { version = "4.5.4", features = ["derive"] }
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ Available PoC guest programs:
- `guest-total-supply`: get the total supply of an asset
- `guest-sum-balance-percent`: sum the balances of multiple accounts and calculate the percentage of the total supply

### RuntimeAPI PoC

1. Use chopsticks to start a local chain with the RuntimeAPI enabled: `make run`
2. Build guest programs: `make guests`
3. Run test runner to display hex-encoded `args` in tracing logs: `cargo run -p pvq-test-runner -- --program output/<guest-program>`
4. Upload `program` and `args` in PJS UI.

### XCM Integration PoC

The test case of XCM integration is located in `vendor/polkadot-sdk/polkadot/xcm/xcm-simulator/example/src/tests.rs`
Expand Down
1 change: 1 addition & 0 deletions poc/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ std = [
"pvq-primitives/std",
"pvq-extension-core/std",
"pvq-extension-fungibles/std",
"pvq-runtime-api/std",
]
3 changes: 3 additions & 0 deletions pvq-test-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tracing = { workspace = true, features = ["std"] }
tracing-subscriber = { workspace = true }
parity-scale-codec = { workspace = true, features = ["std"] }
scale-info = { workspace = true, features = ["std"] }
sp-core = { workspace = true, features = ["std"] }

pvq-executor = { workspace = true, features = ["std"] }
pvq-extension = { workspace = true, features = ["std"] }
Expand All @@ -21,3 +22,5 @@ pvq-extension-fungibles = { workspace = true, features = ["std"] }
pvq-primitives = { workspace = true, features = ["std"] }

polkavm = { workspace = true, features = ["std"] }

hex = { workspace = true, features = ["std"] }
20 changes: 14 additions & 6 deletions pvq-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use parity_scale_codec::Encode;
use pvq_extension::{extensions_impl, ExtensionsExecutor, InvokeSource};
use sp_core::crypto::{AccountId32, Ss58Codec};

#[derive(Encode)]
#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -53,21 +54,28 @@ impl TestRunner {
let mut input_data = Vec::new();

if program_path.contains("sum-balance") {
input_data.extend_from_slice(&0u32.encode());
input_data.extend_from_slice(&vec![[0u8; 32], [1u8; 32]].encode());
input_data.extend_from_slice(&21u32.encode());

let alice_account: [u8; 32] =
AccountId32::from_ss58check("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
.expect("Failed to decode Alice's address")
.into();
input_data.extend_from_slice(&vec![alice_account].encode());
} else if program_path.contains("total-supply") {
input_data.extend_from_slice(&0u32.encode());
input_data.extend_from_slice(&21u32.encode());
} else if program_path.contains("transparent-call") {
input_data.extend_from_slice(&4071833530116166512u64.encode());
let alice_account = AccountId32::from_ss58check("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
.expect("Failed to decode Alice's address");
input_data.extend_from_slice(
&ExtensionFungiblesFunctions::balance {
asset: 0,
who: [1u8; 32],
asset: 21u32,
who: alice_account.into(),
}
.encode(),
);
}

tracing::info!("Input data (hex): {}", hex::encode(&input_data));
input_data
}

Expand Down
Loading