diff --git a/Cargo.lock b/Cargo.lock index 9335385916..b7e61ca3a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1639,7 +1639,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2222e93a91a282fb033c64f39b0e8a118f15afbc63bed1f0acb76f2b76bd80ef" dependencies = [ "built 0.7.1", - "fluence-spell-dtos", + "fluence-spell-dtos 0.5.32", "maplit", "serde_json", ] @@ -2151,11 +2151,11 @@ dependencies = [ [[package]] name = "fluence-spell-distro" -version = "0.5.32" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38bb3c7c024ba98047785c1e304e8cdb6abf6b7656b082b0ad8fc8d4fab052f" +checksum = "3c4432e1ce493689cf93e4a112ad3970a5b2fd982a89efc0ee33a9f089663b78" dependencies = [ - "built 0.6.1", + "built 0.7.1", "maplit", ] @@ -2172,6 +2172,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fluence-spell-dtos" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bf9c61ee22595ff957be32faa0444758e9b61009eab25cd9596503ba78a1ec0" +dependencies = [ + "eyre", + "marine-rs-sdk", + "marine-sqlite-connector", + "serde", + "thiserror", +] + [[package]] name = "fnv" version = "1.0.7" @@ -4371,9 +4384,9 @@ dependencies = [ [[package]] name = "marine-sqlite-connector" -version = "0.9.1" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92552a0cc893d708ac324f45e687dae9ac9e1333b06ecc7e2c3d81abaf6b2d7d" +checksum = "41e6a51c5a4480dfee082aff7253656ee10aa669631fa9922967f41a70049550" dependencies = [ "bytesize", "marine-rs-sdk", @@ -4856,7 +4869,7 @@ dependencies = [ "fluence-app-service", "fluence-keypair", "fluence-libp2p", - "fluence-spell-dtos", + "fluence-spell-dtos 0.6.0", "fs-utils", "fstrings", "futures", @@ -6796,7 +6809,7 @@ dependencies = [ "eyre", "fluence-keypair", "fluence-libp2p", - "fluence-spell-dtos", + "fluence-spell-dtos 0.6.0", "fstrings", "futures", "kademlia", @@ -6833,7 +6846,7 @@ dependencies = [ "derivative", "eyre", "fluence-libp2p", - "fluence-spell-dtos", + "fluence-spell-dtos 0.6.0", "fstrings", "futures", "libp2p", @@ -6863,7 +6876,7 @@ dependencies = [ "config-utils", "fluence-app-service", "fluence-libp2p", - "fluence-spell-dtos", + "fluence-spell-dtos 0.6.0", "key-manager", "libp2p-identity", "maplit", @@ -7058,7 +7071,7 @@ dependencies = [ "decider-distro", "eyre", "fluence-app-service", - "fluence-spell-dtos", + "fluence-spell-dtos 0.6.0", "libp2p", "log", "maplit", diff --git a/Cargo.toml b/Cargo.toml index 0686c63f3c..42a5ee103b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -92,8 +92,8 @@ health = { path = "crates/health" } subnet-resolver = { path = "crates/subnet-resolver" } # spell -fluence-spell-dtos = "=0.5.32" -fluence-spell-distro = "=0.5.32" +fluence-spell-dtos = "=0.6.0" +fluence-spell-distro = "=0.6.0" # marine fluence-app-service = { version = "0.29.0" } diff --git a/crates/connected-client/src/client.rs b/crates/connected-client/src/client.rs index 655e8e6710..5710fff787 100644 --- a/crates/connected-client/src/client.rs +++ b/crates/connected-client/src/client.rs @@ -180,7 +180,6 @@ impl Client { // Messages that were received from relay node Some(from_relay) = swarm.next() => { - log::debug!("Swarm message received {:?}", from_relay); match Self::receive_from_node(from_relay, &client_outlet).await { Err(err) => { let err_msg = format!("{err:?}"); diff --git a/crates/nox-tests/tests/spells.rs b/crates/nox-tests/tests/spells.rs index 550fee0f79..245502534b 100644 --- a/crates/nox-tests/tests/spells.rs +++ b/crates/nox-tests/tests/spells.rs @@ -29,6 +29,7 @@ use connected_client::ConnectedClient; use created_swarm::system_services_config::{DeciderConfig, SystemServicesConfig}; use created_swarm::{make_swarms, make_swarms_with_cfg}; use fluence_spell_dtos::trigger_config::{ClockConfig, TriggerConfig}; +use log_utils::enable_logs; use service_modules::load_module; use spell_event_bus::api::{TriggerInfo, TriggerInfoAqua, MAX_PERIOD_SEC}; use test_utils::{create_service, create_service_worker}; @@ -170,10 +171,10 @@ async fn spell_simple_test() { (call %init_peer_id% ("getDataSrv" "spell_id") [] spell_id) (seq (seq - (call %init_peer_id% (spell_id "get_script_source_from_file") [] script) + (call %init_peer_id% (spell_id "get_script") [] script) (call %init_peer_id% (spell_id "get_u32") ["counter"] counter) ) - (call "{}" ("return" "") [script.$.source_code counter]) + (call "{}" ("return" "") [script.$.value counter]) ) )"#, client.peer_id @@ -185,7 +186,7 @@ async fn spell_simple_test() { let response = client.receive_args().await.wrap_err("receive").unwrap(); let result = response[0].as_str().unwrap().to_string(); assert!(response[1]["success"].as_bool().unwrap()); - let counter = response[1]["num"].as_u64().unwrap(); + let counter = response[1]["value"].as_u64().unwrap(); assert_eq!(result, script); assert_ne!(counter, 0); @@ -306,7 +307,7 @@ async fn spell_return_test() { (seq (seq (call %init_peer_id% (spell_id "get_string") ["key"] value_raw) - (call %init_peer_id% ("json" "parse") [value_raw.$.str] value) + (call %init_peer_id% ("json" "parse") [value_raw.$.value] value) ) (xor (call %init_peer_id% ("callbackSrv" "response") []) @@ -401,7 +402,7 @@ async fn spell_run_oneshot() { .unwrap(); if response[0]["success"].as_bool().unwrap() { - let counter = response[0]["num"].as_u64().unwrap(); + let counter = response[0]["value"].as_u64().unwrap(); assert_eq!(counter, 1); } } @@ -446,8 +447,13 @@ async fn spell_install_ok_empty_config() { .await .unwrap(); - if response[0]["success"].as_bool().unwrap() { - let counter = response[0]["num"].as_u64().unwrap(); + if response[0]["success"] + .as_bool() + .expect(&format!("{:?}", response)) + { + let counter = response[0]["value"] + .as_u64() + .expect(&format!("{:?}", response)); assert_eq!(counter, 0); } // 2. Connect and disconnect a client to the same node. The spell should not be executed @@ -476,7 +482,7 @@ async fn spell_install_ok_empty_config() { .await .unwrap(); if response[0]["success"].as_bool().unwrap() { - let counter = response[0]["num"].as_u64().unwrap(); + let counter = response[0]["value"].as_u64().unwrap(); assert_eq!(counter, 0); } @@ -665,7 +671,8 @@ async fn spell_store_trigger_config() { .unwrap(); if response[0]["success"].as_bool().unwrap() { - let result_config = serde_json::from_value(response[0]["config"].clone()).unwrap(); + let result_config = serde_json::from_value(response[0]["config"].clone()) + .expect(&format!("{:?}", response)); assert_eq!(config, result_config); } } @@ -865,6 +872,8 @@ async fn spell_remove_service_as_spell() { #[tokio::test] async fn spell_call_by_alias() { + enable_logs(); + let swarms = make_swarms(1).await; let mut client = ConnectedClient::connect_to(swarms[0].multiaddr.clone()) @@ -882,13 +891,13 @@ async fn spell_call_by_alias() { (call %init_peer_id% ("alias" "get_u32") ["counter"] counter) ) - (call "{}" ("return" "") [counter.$.num]) + (call "{}" ("return" "") [counter.$.value]) ) )"#, client.peer_id ); - let config = make_clock_config(2, 1, 0); + let config = make_clock_config(100, 1, 0); create_spell(&mut client, &script, config, json!({}), None).await; if let [JValue::Number(counter)] = client @@ -1153,10 +1162,10 @@ async fn spell_set_u32() { assert_eq!(absent["absent"], json!(true)); assert_eq!(one["absent"], json!(false)); - assert_eq!(one["num"], json!(1)); + assert_eq!(one["value"], json!(1)); assert_eq!(two["absent"], json!(false)); - assert_eq!(two["num"], json!(2)); + assert_eq!(two["value"], json!(2)); } #[tokio::test] @@ -1998,7 +2007,7 @@ async fn spell_call_by_default_alias() { ) ) ) - (call "{}" ("return" "") [counter1.$.num spell_id1 error1 counter2.$.num spell_id2 error2]) + (call "{}" ("return" "") [counter1.$.value spell_id1 error1 counter2.$.value spell_id2 error2]) )"#, client.peer_id ); @@ -2154,7 +2163,7 @@ async fn test_decider_api_endpoint_rewrite() { r#"(seq (call relay ("decider" "get_string") ["chain"] chain_info_str) (seq - (call relay ("json" "parse") [chain_info_str.$.str] chain_info) + (call relay ("json" "parse") [chain_info_str.$.value] chain_info) (call client ("return" "") [chain_info.$.api_endpoint]) ) )"#, @@ -2212,7 +2221,7 @@ async fn test_decider_api_endpoint_rewrite() { r#"(seq (call relay ("decider" "get_string") ["chain"] chain_info_str) (seq - (call relay ("json" "parse") [chain_info_str.$.str] chain_info) + (call relay ("json" "parse") [chain_info_str.$.value] chain_info) (call client ("return" "") [chain_info.$.api_endpoint]) ) )"#, diff --git a/crates/spell-service-api/src/lib.rs b/crates/spell-service-api/src/lib.rs index 1cfe4d0bcb..29b924b724 100644 --- a/crates/spell-service-api/src/lib.rs +++ b/crates/spell-service-api/src/lib.rs @@ -108,7 +108,7 @@ impl SpellServiceApi { pub fn set_script(&self, params: CallParams, script: String) -> Result<(), CallError> { let function = Function { - name: "set_script_source_to_file", + name: "set_script", args: vec![json!(script)], }; let _ = self.call::(params, function)?; @@ -117,11 +117,11 @@ impl SpellServiceApi { pub fn get_script(&self, params: CallParams) -> Result { let function = Function { - name: "get_script_source_from_file", + name: "get_script", args: vec![], }; let script_value = self.call::(params, function)?; - Ok(script_value.source_code) + Ok(script_value.value) } pub fn set_trigger_config( &self, @@ -161,7 +161,7 @@ impl SpellServiceApi { args: vec![json!(key)], }; let result = self.call::(params, function)?; - Ok((!result.absent).then_some(result.str)) + Ok((!result.absent).then_some(result.value)) } pub fn set_string( @@ -185,7 +185,7 @@ impl SpellServiceApi { args: vec![json!("counter")], }; let result = self.call::(params, function)?; - Ok((!result.absent).then_some(result.num)) + Ok((!result.absent).then_some(result.value)) } /// Update the counter (how many times the spell was run) @@ -462,7 +462,7 @@ mod tests { let result = api.call::(params, function); assert!(result.is_ok(), "must be able to add get_string"); let trigger_event_read: Result = - serde_json::from_str(&result.unwrap().str); + serde_json::from_str(&result.unwrap().value); assert!( trigger_event_read.is_ok(), "read trigger event must be parsable"