mirror of
https://github.com/fluencelabs/gitbook-docs
synced 2025-06-15 07:51:34 +00:00
GitBook: [2.0.0] 23 pages modified
This commit is contained in:
committed by
gitbook-bot
parent
c0684f0b16
commit
36bf9e20c4
@ -2,7 +2,7 @@
|
||||
|
||||
In the previous example, we used a local, browser-native service to facilitate the string generation and communication with another browser. The real power of the Fluence solution, however, is that services can be hosted on one or more nodes, easily reused and composed into decentralized applications with Aqua.
|
||||
|
||||
### Creating A Wasm Module
|
||||
### Creating A WebAssembly Module
|
||||
|
||||
In this section, we develop a simple `HelloWorld` service and host it on a peer-to-peer node of the Fluence testnet. In your VSCode IDE, change to the `2-hosted-services` directory and open the `src/main.rs` file:
|
||||
|
||||
@ -56,13 +56,13 @@ mod tests {
|
||||
use marine_rs_sdk_test::marine_test;
|
||||
|
||||
#[marine_test(config_path = "../configs/Config.toml", modules_dir = "../artifacts")]
|
||||
fn non_empty_string() {
|
||||
fn non_empty_string(hello_world: marine_test_env::hello_world::ModuleInterface) {
|
||||
let actual = hello_world.hello("SuperNode".to_string());
|
||||
assert_eq!(actual.msg, "Hello from: \nSuperNode".to_string());
|
||||
}
|
||||
|
||||
#[marine_test(config_path = "../configs/Config.toml", modules_dir = "../artifacts")]
|
||||
fn empty_string() {
|
||||
fn empty_string(hello_world: marine_test_env::hello_world::ModuleInterface) {
|
||||
let actual = hello_world.hello("".to_string());
|
||||
assert_eq!(actual.msg, "Hello from: \n");
|
||||
}
|
||||
@ -71,7 +71,7 @@ mod tests {
|
||||
```
|
||||
|
||||
|
||||
To run our tests, we can use the familiar[`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html) . However, we don't really care all that much about our native Rust functions being tested but want to test our WebAssembly functions. This is where the extra code in the test module comes into play. In short., we are running `cargo test` against the exposed interfaces of the `hello_world.wasm` module and in order to do that, we need the `marine_test` macro and provide it with both the modules directory, i.e., the `artifacts` directory, and the location of the `Config.toml` file. Note that the `Config.toml` file specifies the module metadata and optional module linking data. Moreover, we need to call our Wasm functions from the module namespace, i.e. `hello_world.hello` instead of the standard `hello` -- see lines 13 and 19 above.
|
||||
To run our tests, we can use the familiar[`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html) . However, we don't really care all that much about our native Rust functions being tested but want to test our WebAssembly functions. This is where the extra code in the test module comes into play. In short., we are running `cargo test` against the exposed interfaces of the `hello_world.wasm` module and in order to do that, we need the `marine_test` macro and provide it with both the modules directory, i.e., the `artifacts` directory, and the location of the `Config.toml` file. Note that the `Config.toml` file specifies the module metadata and optional module linking data. Moreover, we need to call our Wasm functions from the module namespace, i.e. `hello_world.hello` instead of the standard `hello` -- see lines 13 and 19 above, which we specify as an argument in the test function signature \(lines 11 and 17, respectively\).
|
||||
|
||||
From the VSCode terminal, we now run our tests with the`cargo +nightly test --release` command. Please note that if `nightly` is your default, you don't need it in your `cargo test` command.
|
||||
|
||||
@ -115,7 +115,7 @@ result: Object({"msg": String("Hello from: \nFluence"), "reply": String("Hello b
|
||||
|
||||
We can explore the available interfaces with the `i` command and see that the interfaces we marked with the `marine` macro in our Rust code above are indeed exposed and available for consumption. Using the `call` command, still in the REPL, we can access any available function in the module namespace, e.g., `call hello_word hello [<string arg>]`. You can exit the REPL with the `ctrl-c` command.
|
||||
|
||||
### Exporting Wasm Interfaces To Aqua
|
||||
### Exporting WebAssembly Interfaces To Aqua
|
||||
|
||||
In anticipation of future needs, note that `marine` allows us to export the Wasm interfaces ready for use in Aqua. In your VSCode terminal, navigate to the \`\` directory
|
||||
|
||||
|
Reference in New Issue
Block a user