chore: update readme (#51)

* add developer notes

* update readme

* update

* update

* remove merge artifacts

* pr fixes
This commit is contained in:
Mike Voronov 2023-02-21 21:11:18 +03:00 committed by GitHub
parent 02d6775a69
commit 4cfe82ac93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 2 deletions

13
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,13 @@
## Contribute Code
You are welcome to contribute to Fluence!
Things you need to know:
1. You need to **agree to the [Contributor License Agreement](https://gist.github.com/fluencelabs-org/3f4cbb3cc14c1c0fb9ad99d8f7316ed7) (CLA)**. This is a common practice in all major Open Source projects. At the current moment, we are unable to accept contributions made on behalf of a company. Only individual contributions will be accepted.
2. **Not all proposed contributions can be accepted**. Some features may, e.g., just fit a third-party add-on better. The contribution must fit the overall direction of Fluence and really improve it. The more effort you invest, the better you should clarify in advance whether the contribution fits: the best way would be to just open an issue to discuss the contribution you plan to make.
### Contributor License Agreement
When you contribute, you have to be aware that your contribution is covered by **[Apache License 2.0](./LICENSE)**, but might relicensed under few other software licenses mentioned in the **Contributor License Agreement**. In particular, you need to agree to the Contributor License Agreement. If you agree to its content, you simply have to click on the link posted by the CLA assistant as a comment to the pull request. Click it to check the CLA, then accept it on the following screen if you agree to it. The CLA assistant will save this decision for upcoming contributions and will notify you if there is any change to the CLA in the meantime.

View File

@ -1,4 +1,69 @@
# Marine Test Rust SDK
[![crates.io version](https://img.shields.io/crates/v/marine-rs-sdk-test?color=green)](https://crates.io/crates/marine-rs-sdk-test)
## Marine Test Rust SDK
This SDK is intended to test application built with [Marine Rust SDK](https://github.com/fluencelabs/marine-rs-sdk). More information about usage and some internals could found in [docs](https://fluence.dev/docs/marine-book/marine-rust-sdk/).
This SDK aims to help developers targeting [Marine](https://github.com/fluencelabs/marine) to test their Wasm modules and services because `cargo test` can't run such modules, but it's necessary for testing. To avoid that limitation, the sdk introduces the `#[marine_test]` macro that does much of the heavy lifting to allow developers to use `cargo test` as intended. That is, the `#[marine_test]` macro generates the necessary code to call Marine, one instance per test function, based on the Wasm module and associated configuration file so that the actual test function is run against the Wasm module, not the native code.
## Usage
The core component of the sdk is the `#[marine_test]` macro that can wrap a test function, providing an experience similar to "vanilla" Rust. A wrapped function should receive a special object representing a module interface, let's see an example:
```rust
use marine_rs_sdk::marine;
pub fn main() {}
#[marine]
pub fn greeting(name: String) -> String {
format!("Hi, {}", name)
}
#[cfg(test)]
mod tests {
use marine_rs_sdk_test::marine_test;
#[marine_test(config_path = "../Config.toml", modules_dir = "../artifacts")]
fn test(greeting: marine_test_env::greeting::ModuleInterface) {
let actual = greeting.greeting("John".to_string());
assert_eq!(actual, "Hi, John");
}
}
```
This example shows a simple [module](https://fluence.dev/docs/marine-book/quick-start/develop-a-single-module-service) with one export function `greeting` and a test. The test function is wrapped with `#[marine_test]` macro with the specified path to the config file (`Config.toml`), and the directory containing the Wasm module we obtained after compiling our project with the [marine CLI](https://fluence.dev/docs/marine-book/marine-tooling-reference/marine-cli) build command. This macro generates all the necessary glue code to instantiate Marine instance under the hood and call the greeting module loaded into it.
After we have our Wasm module and tests in place, we can proceed with `cargo test`.
In a setup without the Marine test suite, the `greeting` function will be compiled to native and then test natively, comparingly with the suite it will be compiled to Wasm, loaded into Marine, and only then called as a Wasm module.
More details can be found in [this chapter](https://fluence.dev/docs/marine-book/marine-rust-sdk/testing-and-debugging/) of the Marine book.
## Documentation
- [Marine Book](https://fluence.dev/docs/marine-book/introduction)
- [Marine Examples](https://github.com/fluencelabs/examples/tree/main/marine-examples)
- [Quickstart](https://fluence.dev/docs/marine-book/quick-start/)
## Repository structure
- **[crates](./crates)**
- [macro-build-rs-generator](./crates/macro-build-rs-generator) - generator of `build.rs` file intended to provide IDE support for generated glue code
- [marine-test-macro-impl](./crates/marine-test-macro-impl) - actual implementation of the `#[marine_test]` macro
- [marine-test-macro](./crates/marine-test-macro) - proc-macro crate for the `#[marine_test]` macro
- **[src](./src)** - reexports all necessary things intended to use by end user
## Support
Please, [file an issue](https://github.com/fluencelabs/marine-rs-sdk-test/issues) if you find a bug. You can also contact us at [Discord](https://discord.com/invite/5qSnPZKh7u) or [Telegram](https://t.me/fluence_project). We will do our best to resolve the issue ASAP.
## Contributing
Any interested person is welcome to contribute to the project. Please, make sure you read and follow some basic [rules](./CONTRIBUTING.md).
## License
All software code is copyright (c) Fluence Labs, Inc. under the [Apache-2.0](./LICENSE) license.