Skip to content

Commit c4a3ca6

Browse files
authored
fix(runtime poc) (#65)
1 parent 09da858 commit c4a3ca6

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ polkavm-derive = { path = "vendor/polkavm/crates/polkavm-derive", default-featur
4646

4747
# polkadot-sdk
4848
sp-api = { path = "vendor/polkadot-sdk/substrate/primitives/api", default-features = false }
49+
sp-core = { path = "vendor/polkadot-sdk/substrate/primitives/core", default-features = false }
4950
frame = { package = "polkadot-sdk-frame", path = "vendor/polkadot-sdk/substrate/frame", default-features = false }
5051
pallet-balances = { path = "vendor/polkadot-sdk/substrate/frame/balances", default-features = false }
5152
pallet-assets = { path = "vendor/polkadot-sdk/substrate/frame/assets", default-features = false }
@@ -69,6 +70,7 @@ scale-info = { version = "2.11.3", default-features = false, features = [
6970
"derive",
7071
] }
7172
tracing = { version = "0.1.40", default-features = false }
73+
hex = { version = "0.4" }
7274

7375
# std
7476
clap = { version = "4.5.4", features = ["derive"] }

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ Available PoC guest programs:
2222
- `guest-total-supply`: get the total supply of an asset
2323
- `guest-sum-balance-percent`: sum the balances of multiple accounts and calculate the percentage of the total supply
2424

25+
### RuntimeAPI PoC
26+
27+
1. Use chopsticks to start a local chain with the RuntimeAPI enabled: `make run`
28+
2. Build guest programs: `make guests`
29+
3. Run test runner to display hex-encoded `args` in tracing logs: `cargo run -p pvq-test-runner -- --program output/<guest-program>`
30+
4. Upload `program` and `args` in PJS UI.
31+
2532
### XCM Integration PoC
2633

2734
The test case of XCM integration is located in `vendor/polkadot-sdk/polkadot/xcm/xcm-simulator/example/src/tests.rs`

poc/runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ std = [
5454
"pvq-primitives/std",
5555
"pvq-extension-core/std",
5656
"pvq-extension-fungibles/std",
57+
"pvq-runtime-api/std",
5758
]

pvq-test-runner/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ tracing = { workspace = true, features = ["std"] }
1313
tracing-subscriber = { workspace = true }
1414
parity-scale-codec = { workspace = true, features = ["std"] }
1515
scale-info = { workspace = true, features = ["std"] }
16+
sp-core = { workspace = true, features = ["std"] }
1617

1718
pvq-executor = { workspace = true, features = ["std"] }
1819
pvq-extension = { workspace = true, features = ["std"] }
@@ -21,3 +22,5 @@ pvq-extension-fungibles = { workspace = true, features = ["std"] }
2122
pvq-primitives = { workspace = true, features = ["std"] }
2223

2324
polkavm = { workspace = true, features = ["std"] }
25+
26+
hex = { workspace = true, features = ["std"] }

pvq-test-runner/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use parity_scale_codec::Encode;
22
use pvq_extension::{extensions_impl, ExtensionsExecutor, InvokeSource};
3+
use sp_core::crypto::{AccountId32, Ss58Codec};
34

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

5556
if program_path.contains("sum-balance") {
56-
input_data.extend_from_slice(&0u32.encode());
57-
input_data.extend_from_slice(&vec![[0u8; 32], [1u8; 32]].encode());
57+
input_data.extend_from_slice(&21u32.encode());
58+
59+
let alice_account: [u8; 32] =
60+
AccountId32::from_ss58check("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
61+
.expect("Failed to decode Alice's address")
62+
.into();
63+
input_data.extend_from_slice(&vec![alice_account].encode());
5864
} else if program_path.contains("total-supply") {
59-
input_data.extend_from_slice(&0u32.encode());
65+
input_data.extend_from_slice(&21u32.encode());
6066
} else if program_path.contains("transparent-call") {
6167
input_data.extend_from_slice(&4071833530116166512u64.encode());
68+
let alice_account = AccountId32::from_ss58check("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY")
69+
.expect("Failed to decode Alice's address");
6270
input_data.extend_from_slice(
6371
&ExtensionFungiblesFunctions::balance {
64-
asset: 0,
65-
who: [1u8; 32],
72+
asset: 21u32,
73+
who: alice_account.into(),
6674
}
6775
.encode(),
6876
);
6977
}
70-
78+
tracing::info!("Input data (hex): {}", hex::encode(&input_data));
7179
input_data
7280
}
7381

0 commit comments

Comments
 (0)