diff --git a/Cargo.lock b/Cargo.lock index 7d249ba5..3ec3a04e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,13 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +[[package]] +name = "call_parameters" +version = "0.1.0" +dependencies = [ + "fluence", +] + [[package]] name = "cc" version = "1.0.59" @@ -1283,11 +1290,12 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d7559a8a40d0f97e1edea3220f698f78b1c5ab67532e49f68fde3910323b722" +checksum = "c60c0dfe32c10b43a144bad8fc83538c52f58302c92300ea7ec7bf7b38d5a7b9" dependencies = [ "adler", + "autocfg", ] [[package]] @@ -1387,15 +1395,14 @@ dependencies = [ [[package]] name = "nix" -version = "0.17.0" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" +checksum = "83450fe6a6142ddd95fb064b746083fc4ef1705fe81f64a64e1d4b39f54a1055" dependencies = [ "bitflags", "cc", "cfg-if", "libc", - "void", ] [[package]] @@ -1815,16 +1822,16 @@ checksum = "ccb57833f46c9d679d68f383e81b9a74b82aa8d6f8a9c9aaae7fc29476bc3274" [[package]] name = "rustyline" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3358c21cbbc1a751892528db4e1de4b7a2b6a73f001e215aaba97d712cfa9777" +checksum = "6f0d5e7b0219a3eadd5439498525d4765c59b7c993ef0c12244865cd2d988413" dependencies = [ "cfg-if", "dirs-next", "libc", "log", "memchr", - "nix 0.17.0", + "nix 0.18.0", "scopeguard", "skim", "unicode-segmentation", @@ -1911,9 +1918,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5" +checksum = "96fe57af81d28386a513cbc6858332abc6117cfdb5999647c6444b8f43a370a5" dependencies = [ "serde_derive", ] @@ -1939,9 +1946,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48" +checksum = "f630a6370fd8e457873b4bd2ffdae75408bc291ba72be773772a4c2a065d9ae8" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index a2856ee7..9d21061a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,10 @@ members = [ "examples/records/effector", "examples/records/pure", "examples/records/test-record", - "examples/site-storage/wasm/site-storage", - "examples/site-storage/wasm/curl", - "examples/site-storage/wasm/local_storage", + "examples/site-storage/site-storage", + "examples/site-storage/curl", + "examples/site-storage/local_storage", + "examples/call_parameters", "fluence-app-service", "fluence-faas", "tools/cli", diff --git a/examples/call_parameters/Cargo.toml b/examples/call_parameters/Cargo.toml new file mode 100644 index 00000000..bd20c31b --- /dev/null +++ b/examples/call_parameters/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "call_parameters" +version = "0.1.0" +authors = ["Fluence Labs"] +edition = "2018" + +[[bin]] +name = "call_parameters" +path = "src/main.rs" + +[dependencies] +fluence = { git = "https://github.com/fluencelabs/rust-sdk" } diff --git a/examples/greeting/Config_cp.toml b/examples/call_parameters/Config.toml similarity index 75% rename from examples/greeting/Config_cp.toml rename to examples/call_parameters/Config.toml index d7e63a9d..2e3a9120 100644 --- a/examples/greeting/Config_cp.toml +++ b/examples/call_parameters/Config.toml @@ -1,6 +1,6 @@ modules_dir = "artifacts/" [[module]] - name = "greeting_cp" + name = "call_parameters" mem_pages_count = 1 logger_enabled = false diff --git a/examples/call_parameters/artifacts/call_parameters.wasm b/examples/call_parameters/artifacts/call_parameters.wasm new file mode 100755 index 00000000..0ae04027 Binary files /dev/null and b/examples/call_parameters/artifacts/call_parameters.wasm differ diff --git a/examples/call_parameters/build.sh b/examples/call_parameters/build.sh new file mode 100755 index 00000000..e53d222e --- /dev/null +++ b/examples/call_parameters/build.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +cargo update +fce build --release + +rm -f artifacts/* +cp ../../target/wasm32-wasi/release/call_parameters.wasm artifacts/ diff --git a/examples/greeting/src/main_cp.rs b/examples/call_parameters/src/main.rs similarity index 78% rename from examples/greeting/src/main_cp.rs rename to examples/call_parameters/src/main.rs index c1d88820..e194281c 100644 --- a/examples/greeting/src/main_cp.rs +++ b/examples/call_parameters/src/main.rs @@ -14,11 +14,13 @@ * limitations under the License. */ +use fluence::fce; + pub fn main() {} -#[fluence::fce] +#[fce] #[cfg(target_arch = "wasm32")] -pub fn greeting() -> String { - let name = fluence::get_call_parameters().user_name; - format!("Hi, {}", name) +pub fn call_parameters() -> String { + let cp = fluence::get_call_parameters(); + format!("{}\n{}\n{}", cp.call_id, cp.user_name, cp.application_id) } diff --git a/examples/greeting/Cargo.toml b/examples/greeting/Cargo.toml index a7ef7303..8f7b7b3c 100644 --- a/examples/greeting/Cargo.toml +++ b/examples/greeting/Cargo.toml @@ -8,9 +8,5 @@ edition = "2018" name = "greeting" path = "src/main.rs" -[[bin]] -name = "greeting_cp" -path = "src/main_cp.rs" - [dependencies] fluence = { git = "https://github.com/fluencelabs/rust-sdk" } diff --git a/examples/site-storage/Config.toml b/examples/site-storage/Config.toml index ed6c15b2..fb152493 100644 --- a/examples/site-storage/Config.toml +++ b/examples/site-storage/Config.toml @@ -1,13 +1,13 @@ -modules_dir = "wasm/artifacts/modules/" +modules_dir = "artifacts/" [[module]] name = "local_storage" logger_enabled = true [module.wasi] - preopened_files = ["./../sites"] + preopened_files = ["./sites"] # this is where files will be stored - mapped_dirs = { "sites" = "./../sites" } + mapped_dirs = { "sites" = "./sites" } [[module]] name = "curl" diff --git a/examples/site-storage/artifacts/curl.wasm b/examples/site-storage/artifacts/curl.wasm new file mode 100755 index 00000000..77e90765 Binary files /dev/null and b/examples/site-storage/artifacts/curl.wasm differ diff --git a/examples/site-storage/artifacts/local_storage.wasm b/examples/site-storage/artifacts/local_storage.wasm new file mode 100755 index 00000000..55c63318 Binary files /dev/null and b/examples/site-storage/artifacts/local_storage.wasm differ diff --git a/examples/site-storage/wasm/artifacts/modules/site-storage.wasm b/examples/site-storage/artifacts/site-storage.wasm similarity index 58% rename from examples/site-storage/wasm/artifacts/modules/site-storage.wasm rename to examples/site-storage/artifacts/site-storage.wasm index b954f04f..73522e00 100755 Binary files a/examples/site-storage/wasm/artifacts/modules/site-storage.wasm and b/examples/site-storage/artifacts/site-storage.wasm differ diff --git a/examples/site-storage/build.sh b/examples/site-storage/build.sh index 81ecf1d2..200f13f6 100755 --- a/examples/site-storage/build.sh +++ b/examples/site-storage/build.sh @@ -1,7 +1,7 @@ #!/bin/sh # This script builds all subprojects and puts all created Wasm modules in one dir -cd wasm/site-storage +cd site-storage cargo update fce build --release cd ../curl @@ -12,7 +12,7 @@ cargo update fce build --release cd .. -rm artifacts/modules/* -cp ../../../target/wasm32-wasi/release/curl.wasm artifacts/modules -cp ../../../target/wasm32-wasi/release/local_storage.wasm artifacts/modules -cp ../../../target/wasm32-wasi/release/site-storage.wasm artifacts/modules +rm -f artifacts/* +cp ../../target/wasm32-wasi/release/curl.wasm artifacts/ +cp ../../target/wasm32-wasi/release/local_storage.wasm artifacts/ +cp ../../target/wasm32-wasi/release/site-storage.wasm artifacts/ diff --git a/examples/site-storage/wasm/curl/Cargo.toml b/examples/site-storage/curl/Cargo.toml similarity index 100% rename from examples/site-storage/wasm/curl/Cargo.toml rename to examples/site-storage/curl/Cargo.toml diff --git a/examples/site-storage/wasm/curl/src/main.rs b/examples/site-storage/curl/src/main.rs similarity index 100% rename from examples/site-storage/wasm/curl/src/main.rs rename to examples/site-storage/curl/src/main.rs diff --git a/examples/site-storage/wasm/local_storage/Cargo.toml b/examples/site-storage/local_storage/Cargo.toml similarity index 100% rename from examples/site-storage/wasm/local_storage/Cargo.toml rename to examples/site-storage/local_storage/Cargo.toml diff --git a/examples/site-storage/wasm/local_storage/src/main.rs b/examples/site-storage/local_storage/src/main.rs similarity index 100% rename from examples/site-storage/wasm/local_storage/src/main.rs rename to examples/site-storage/local_storage/src/main.rs diff --git a/examples/site-storage/wasm/site-storage/Cargo.toml b/examples/site-storage/site-storage/Cargo.toml similarity index 100% rename from examples/site-storage/wasm/site-storage/Cargo.toml rename to examples/site-storage/site-storage/Cargo.toml diff --git a/examples/site-storage/wasm/site-storage/src/main.rs b/examples/site-storage/site-storage/src/main.rs similarity index 100% rename from examples/site-storage/wasm/site-storage/src/main.rs rename to examples/site-storage/site-storage/src/main.rs diff --git a/fluence-faas/tests/call_parameters.rs b/fluence-faas/tests/call_parameters.rs new file mode 100644 index 00000000..38ef14d5 --- /dev/null +++ b/fluence-faas/tests/call_parameters.rs @@ -0,0 +1,60 @@ +/* + * Copyright 2020 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use fluence_faas::FluenceFaaS; +use fluence_faas::IValue; + +#[test] +pub fn call_parameters() { + let call_parameters_config_path = "../examples/call_parameters/Config.toml"; + + let call_parameters_config_raw = std::fs::read(call_parameters_config_path) + .expect("../examples/call_parameters/Config.toml should presence"); + + let mut call_parameters_config: fluence_faas::RawModulesConfig = + toml::from_slice(&call_parameters_config_raw) + .expect("call_parameters config should be well-formed"); + call_parameters_config.modules_dir = + Some(String::from("../examples/call_parameters/artifacts")); + + let mut faas = FluenceFaaS::with_raw_config(call_parameters_config) + .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); + + let call_id = "0x1337"; + let user_name = "root"; + let application_id = "0x31337"; + + let result = faas + .call( + "call_parameters", + "call_parameters", + &[], + fluence_sdk_main::CallParameters { + call_id: call_id.to_string(), + user_name: user_name.to_string(), + application_id: application_id.to_string(), + }, + ) + .unwrap_or_else(|e| panic!("can't invoke call_parameters: {:?}", e)); + + assert_eq!( + result, + vec![IValue::String(format!( + "{}\n{}\n{}", + call_id, user_name, application_id + ))] + ); +} diff --git a/fluence-faas/tests/greeting.rs b/fluence-faas/tests/greeting.rs index 9bcbeff8..89cb2aa4 100644 --- a/fluence-faas/tests/greeting.rs +++ b/fluence-faas/tests/greeting.rs @@ -29,7 +29,7 @@ pub fn greeting() { greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts")); let mut faas = FluenceFaaS::with_raw_config(greeting_config) - .unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); + .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); let result1 = faas .call( @@ -65,7 +65,7 @@ pub fn get_interfaces() { greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts")); let faas = FluenceFaaS::with_raw_config(greeting_config) - .unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); + .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); let interface = faas.get_interface(); @@ -83,33 +83,3 @@ pub fn get_interfaces() { assert_eq!(interface, fluence_faas::FaaSInterface { modules }); } - -#[test] -pub fn call_parameters() { - let greeting_config_path = "../examples/greeting/Config_cp.toml"; - - let greeting_config_raw = std::fs::read(greeting_config_path) - .expect("../examples/greeting/Config_cp.toml should presence"); - - let mut greeting_config: fluence_faas::RawModulesConfig = - toml::from_slice(&greeting_config_raw).expect("greeting config should be well-formed"); - greeting_config.modules_dir = Some(String::from("../examples/greeting/artifacts")); - - let mut faas = FluenceFaaS::with_raw_config(greeting_config) - .unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); - - let result = faas - .call( - "greeting_cp", - "greeting", - &[], - fluence_sdk_main::CallParameters { - call_id: "0x1337".to_string(), - user_name: "root".to_string(), - application_id: "0x31337".to_string(), - }, - ) - .unwrap_or_else(|e| panic!("can't invoke greeting_cp: {:?}", e)); - - assert_eq!(result, vec![IValue::String(String::from("Hi, root"))]); -} diff --git a/fluence-faas/tests/records.rs b/fluence-faas/tests/records.rs index 0d81c03b..a483ce04 100644 --- a/fluence-faas/tests/records.rs +++ b/fluence-faas/tests/records.rs @@ -26,11 +26,11 @@ pub fn records() { .expect("../examples/records/Config.toml should presence"); let mut records_config: fluence_faas::RawModulesConfig = - toml::from_slice(&records_config_raw).expect("greeting config should be well-formed"); + toml::from_slice(&records_config_raw).expect("records config should be well-formed"); records_config.modules_dir = Some(String::from("../examples/records/artifacts/wasm_modules/")); let mut faas = FluenceFaaS::with_raw_config(records_config) - .unwrap_or_else(|e| panic!("can't crate Fluence FaaS instance: {:?}", e)); + .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {:?}", e)); let result = faas .call("pure", "invoke", &[], <_>::default())