-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(blueprint-metadata): add nested struct and enum tests
- Loading branch information
1 parent
1a755db
commit aec01bd
Showing
3 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::convert::Infallible; | ||
use blueprint_sdk::event_listeners::tangle::events::TangleEventListener; | ||
use blueprint_sdk::event_listeners::tangle::services::{services_post_processor, services_pre_processor}; | ||
use blueprint_sdk::macros::contexts::{ServicesContext, TangleClientContext}; | ||
use blueprint_sdk::macros::ext::tangle::tangle_subxt::tangle_testnet_runtime::api::services::events::JobCalled; | ||
use blueprint_sdk::config::GadgetConfiguration; | ||
|
||
#[derive(Clone, TangleClientContext, ServicesContext)] | ||
pub struct MyContext { | ||
#[config] | ||
pub env: GadgetConfiguration, | ||
#[call_id] | ||
pub call_id: Option<u64>, | ||
} | ||
|
||
#[derive(PartialEq)] | ||
pub enum Status { | ||
Failed, | ||
Success, | ||
} | ||
|
||
#[blueprint_sdk::job( | ||
id = 0, | ||
params(status), | ||
event_listener( | ||
listener = TangleEventListener<MyContext, JobCalled>, | ||
pre_processor = services_pre_processor, | ||
post_processor = services_post_processor, | ||
), | ||
)] | ||
pub fn check_status(status: Status, _context: MyContext) -> Result<bool, Infallible> { | ||
Ok(status == Status::Success) | ||
} |
47 changes: 47 additions & 0 deletions
47
crates/blueprint/metadata/tests/assets/job_primitive_nested_struct_param.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::convert::Infallible; | ||
use blueprint_sdk::event_listeners::tangle::events::TangleEventListener; | ||
use blueprint_sdk::event_listeners::tangle::services::{services_post_processor, services_pre_processor}; | ||
use blueprint_sdk::macros::contexts::{ServicesContext, TangleClientContext}; | ||
use blueprint_sdk::macros::ext::tangle::tangle_subxt::tangle_testnet_runtime::api::services::events::JobCalled; | ||
use blueprint_sdk::config::GadgetConfiguration; | ||
|
||
#[derive(Clone, TangleClientContext, ServicesContext)] | ||
pub struct MyContext { | ||
#[config] | ||
pub env: GadgetConfiguration, | ||
#[call_id] | ||
pub call_id: Option<u64>, | ||
} | ||
|
||
pub struct SomeParam { | ||
pub a: u8, | ||
pub nested: SomeNestedParam, | ||
} | ||
|
||
pub struct SomeNestedParam { | ||
pub b: u16, | ||
pub c: u32, | ||
pub d: u64, | ||
pub e: u128, | ||
pub f: i8, | ||
pub g: i16, | ||
pub h: i32, | ||
pub i: i64, | ||
pub j: i128, | ||
pub k: f32, | ||
pub l: f64, | ||
pub m: bool, | ||
} | ||
|
||
#[blueprint_sdk::job( | ||
id = 0, | ||
params(x), | ||
event_listener( | ||
listener = TangleEventListener<MyContext, JobCalled>, | ||
pre_processor = services_pre_processor, | ||
post_processor = services_post_processor, | ||
), | ||
)] | ||
pub fn xsquare(x: SomeParam, _context: MyContext) -> Result<u64, Infallible> { | ||
Ok(x.nested.d.saturating_pow(2)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters