Skip to content

Commit

Permalink
fix(deps): update fluence-spell to v0.6.0 (#1958)
Browse files Browse the repository at this point in the history
* fix(deps): update fluence-spell to v0.6.0

* fix(spell-service-api): fix compilation

* fix(spell-service-api): fix compilation

* fix(tests): fix some spell tests

* fix(tests): fix all spell tests

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: folex <0xdxdy@gmail.com>
  • Loading branch information
renovate[bot] and folex committed Dec 20, 2023
1 parent 1063eae commit 5bc6495
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 36 deletions.
35 changes: 24 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion crates/connected-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}");
Expand Down
41 changes: 25 additions & 16 deletions crates/nox-tests/tests/spells.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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") [])
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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])
)
)"#,
Expand Down Expand Up @@ -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])
)
)"#,
Expand Down
12 changes: 6 additions & 6 deletions crates/spell-service-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<UnitValue>(params, function)?;
Expand All @@ -117,11 +117,11 @@ impl SpellServiceApi {

pub fn get_script(&self, params: CallParams) -> Result<String, CallError> {
let function = Function {
name: "get_script_source_from_file",
name: "get_script",
args: vec![],
};
let script_value = self.call::<ScriptValue>(params, function)?;
Ok(script_value.source_code)
Ok(script_value.value)
}
pub fn set_trigger_config(
&self,
Expand Down Expand Up @@ -161,7 +161,7 @@ impl SpellServiceApi {
args: vec![json!(key)],
};
let result = self.call::<StringValue>(params, function)?;
Ok((!result.absent).then_some(result.str))
Ok((!result.absent).then_some(result.value))
}

pub fn set_string(
Expand All @@ -185,7 +185,7 @@ impl SpellServiceApi {
args: vec![json!("counter")],
};
let result = self.call::<U32Value>(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)
Expand Down Expand Up @@ -462,7 +462,7 @@ mod tests {
let result = api.call::<StringValue>(params, function);
assert!(result.is_ok(), "must be able to add get_string");
let trigger_event_read: Result<serde_json::Value, _> =
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"
Expand Down

0 comments on commit 5bc6495

Please sign in to comment.