Skip to content
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

feat(call-parachain): add remark action #387

Merged
merged 4 commits into from
Dec 17, 2024
Merged
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
90 changes: 47 additions & 43 deletions crates/pop-parachains/src/call/metadata/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,19 @@ pub enum Action {
props(Pallet = "Assets")
)]
MintAsset,
/// Create an NFT collection.
/// Create a NFT collection.
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved
#[strum(
serialize = "create_nft",
message = "create",
detailed_message = "Create an NFT collection",
detailed_message = "Create a NFT collection",
props(Pallet = "Nfts")
)]
CreateCollection,
/// Mint an NFT.
/// Mint a NFT.
#[strum(
serialize = "mint_nft",
message = "mint",
detailed_message = "Mint an NFT",
detailed_message = "Mint a NFT",
props(Pallet = "Nfts")
)]
MintNFT,
Expand Down Expand Up @@ -83,6 +83,14 @@ pub enum Action {
props(Pallet = "Registrar")
)]
Register,
/// Make a remark.
#[strum(
serialize = "remark",
message = "remark_with_event",
detailed_message = "Make a remark",
props(Pallet = "System")
)]
Remark,
}

impl Action {
Expand Down Expand Up @@ -119,7 +127,7 @@ pub fn supported_actions(pallets: &[Pallet]) -> Vec<Action> {

#[cfg(test)]
mod tests {
use super::*;
use super::{Action::*, *};
use crate::{call::tests::POP_NETWORK_TESTNET_URL, parse_chain_metadata, set_up_client};
use anyhow::Result;
use std::collections::HashMap;
Expand All @@ -129,14 +137,15 @@ mod tests {
#[test]
fn action_descriptions_are_correct() {
let descriptions = HashMap::from([
(Action::CreateAsset, "Create an asset"),
(Action::MintAsset, "Mint an asset"),
(Action::CreateCollection, "Create an NFT collection"),
(Action::MintNFT, "Mint an NFT"),
(Action::PurchaseOnDemandCoretime, "Purchase on-demand coretime"),
(Action::Transfer, "Transfer balance"),
(Action::Register, "Register a parachain ID with genesis state and code"),
(Action::Reserve, "Reserve a parachain ID"),
(CreateAsset, "Create an asset"),
(MintAsset, "Mint an asset"),
(CreateCollection, "Create a NFT collection"),
(MintNFT, "Mint a NFT"),
(PurchaseOnDemandCoretime, "Purchase on-demand coretime"),
(Transfer, "Transfer balance"),
(Register, "Register a parachain ID with genesis state and code"),
(Reserve, "Reserve a parachain ID"),
(Remark, "Make a remark"),
]);

for action in Action::VARIANTS.iter() {
Expand All @@ -147,14 +156,15 @@ mod tests {
#[test]
fn pallet_names_are_correct() {
let pallets = HashMap::from([
(Action::CreateAsset, "Assets"),
(Action::MintAsset, "Assets"),
(Action::CreateCollection, "Nfts"),
(Action::MintNFT, "Nfts"),
(Action::PurchaseOnDemandCoretime, "OnDemand"),
(Action::Transfer, "Balances"),
(Action::Register, "Registrar"),
(Action::Reserve, "Registrar"),
(CreateAsset, "Assets"),
(MintAsset, "Assets"),
(CreateCollection, "Nfts"),
(MintNFT, "Nfts"),
(PurchaseOnDemandCoretime, "OnDemand"),
(Transfer, "Balances"),
(Register, "Registrar"),
(Reserve, "Registrar"),
(Remark, "System"),
]);

for action in Action::VARIANTS.iter() {
Expand All @@ -165,14 +175,15 @@ mod tests {
#[test]
fn function_names_are_correct() {
let pallets = HashMap::from([
(Action::CreateAsset, "create"),
(Action::MintAsset, "mint"),
(Action::CreateCollection, "create"),
(Action::MintNFT, "mint"),
(Action::PurchaseOnDemandCoretime, "place_order_allow_death"),
(Action::Transfer, "transfer_allow_death"),
(Action::Register, "register"),
(Action::Reserve, "reserve"),
(CreateAsset, "create"),
(MintAsset, "mint"),
(CreateCollection, "create"),
(MintNFT, "mint"),
(PurchaseOnDemandCoretime, "place_order_allow_death"),
(Transfer, "transfer_allow_death"),
(Register, "register"),
(Reserve, "reserve"),
(Remark, "remark_with_event"),
]);

for action in Action::VARIANTS.iter() {
Expand All @@ -185,23 +196,16 @@ mod tests {
// Test Pop Parachain.
let mut client: subxt::OnlineClient<subxt::SubstrateConfig> =
set_up_client(POP_NETWORK_TESTNET_URL).await?;
let mut actions = supported_actions(&parse_chain_metadata(&client)?);
assert_eq!(actions.len(), 5);
assert_eq!(actions[0], Action::Transfer);
assert_eq!(actions[1], Action::CreateAsset);
assert_eq!(actions[2], Action::MintAsset);
assert_eq!(actions[3], Action::CreateCollection);
assert_eq!(actions[4], Action::MintNFT);
let actions = supported_actions(&parse_chain_metadata(&client)?);
assert_eq!(
actions,
vec![Transfer, CreateAsset, MintAsset, CreateCollection, MintNFT, Remark]
);

// Test Polkadot Relay Chain.
client = set_up_client(POLKADOT_NETWORK_URL).await?;
actions = supported_actions(&parse_chain_metadata(&client)?);
assert_eq!(actions.len(), 4);
assert_eq!(actions[0], Action::Transfer);
assert_eq!(actions[1], Action::PurchaseOnDemandCoretime);
assert_eq!(actions[2], Action::Reserve);
assert_eq!(actions[3], Action::Register);

let actions = supported_actions(&parse_chain_metadata(&client)?);
assert_eq!(actions, vec![Transfer, PurchaseOnDemandCoretime, Reserve, Register, Remark]);
Ok(())
}
}
Loading