Skip to content

Commit

Permalink
wip: add call-id test
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Dec 9, 2024
1 parent 2651f70 commit 39065c2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion blueprints/incredible-squaring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn xsquare(x: u64, context: MyContext) -> Result<u64, gadget_sdk::Error> {
),
)]
pub fn test_call_id(context: MyContext, call_id: u64) -> Result<u64, gadget_sdk::Error> {
gadget_sdk::error!("{:?}, {}", context.call_id, call_id);
gadget_sdk::error!("JOB CALL ID: {:?}, {}", context.call_id, call_id);
if context.call_id.unwrap() != call_id {
return Err(gadget_sdk::Error::Other(String::from("Call ID mismatch!")));
}
Expand Down
10 changes: 10 additions & 0 deletions blueprints/incredible-squaring/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ async fn main() {
)
.await?;

let test_call_id = blueprint::TestCallIdEventHandler::new(
&env,
blueprint::MyContext {
config: env.clone(),
call_id: None,
},
)
.await?;

info!(
"Starting the event watcher for {} ...",
x_square.signer.account_id()
Expand All @@ -25,6 +34,7 @@ async fn main() {
let tangle_config = TangleConfig::default();
BlueprintRunner::new(tangle_config, env)
.job(x_square)
.job(test_call_id)
.run()
.await?;

Expand Down
4 changes: 2 additions & 2 deletions blueprints/incredible-squaring/tests/call_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use blueprint_test_utils::{InputValue, OutputValue};
#[gadget_sdk::tokio::test(crate = "::gadget_sdk::tokio")]
async fn call_id_valid() {
const ITERATIONS: u8 = 5;
static CALL_ID: AtomicU64 = AtomicU64::new(1);
static CALL_ID: AtomicU64 = AtomicU64::new(0);

setup_log();

Expand All @@ -23,7 +23,7 @@ async fn call_id_valid() {
.await
.execute_with_async(|client, handles, blueprint| async move {
let keypair = handles[0].sr25519_id().clone();
let selected_service = &dbg!(&blueprint.services)[0];
let selected_service = &blueprint.services[0];
let service_id = selected_service.id;

for _ in 0..ITERATIONS {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/event_listener/tangle/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn services_pre_processor<C: TangleClientContext, E: EventMatcher<Outp

crate::info!("Pre-processing event for sid/bid = {service_id}/{job_id} ...");

crate::error!("{job_id}, {service_id}, {event_service_id}, {event_job_id}");
crate::error!("job ID: {job_id}, service ID: {service_id}, Event service ID: {event_service_id}, Event job ID: {event_job_id}");
if event_job_id == job_id && event_service_id == service_id {
crate::info!("Found actionable event for sid/bid = {event_service_id}/{event_job_id} ...");
// Set the call ID that way the user can access it in the job function
Expand Down

0 comments on commit 39065c2

Please sign in to comment.