mirror of
https://github.com/fluencelabs/marine-rs-sdk-test
synced 2024-12-04 15:20:18 +00:00
commit
4a59f8343f
@ -15,6 +15,7 @@ all-features = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-wit = { path = "../wit", version = "=0.5.0" }
|
||||
|
@ -14,6 +14,7 @@ all-features = true
|
||||
|
||||
[lib]
|
||||
proc-macro = true
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-test-macro-impl = { path = "../fce-test-macro-impl", version = "=0.5.0" }
|
||||
|
@ -16,6 +16,7 @@ all-features = true
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["rlib"]
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "../fce-macro", version = "=0.5.0" }
|
||||
|
@ -123,7 +123,7 @@ impl ParsedType {
|
||||
}
|
||||
_ if !type_segment.arguments.is_empty() => Err(Error::new(
|
||||
type_segment.span(),
|
||||
"type with lifetimes or generics aren't allowed".to_string(),
|
||||
"types with lifetimes or generics aren't allowed".to_string(),
|
||||
)),
|
||||
_ => Ok(ParsedType::Record(
|
||||
(&type_segment.ident).into_token_stream().to_string(),
|
||||
|
@ -16,6 +16,7 @@ all-features = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-test-macro = { path = "../crates/fce-test-macro", version = "=0.5.0" }
|
||||
|
@ -16,11 +16,15 @@ all-features = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
doctest = false
|
||||
|
||||
[dependencies]
|
||||
fluence-sdk-macro = { path = "../crates/fce-macro", version = "=0.5.0" }
|
||||
fluence-sdk-main = { path = "../crates/main", version = "=0.5.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
trybuild = "1.0"
|
||||
|
||||
[features]
|
||||
# Print some internal logs by log_utf8_string
|
||||
debug = ["fluence-sdk-main/debug"]
|
||||
|
67
fluence/tests/export_functions/arrays.rs
Normal file
67
fluence/tests/export_functions/arrays.rs
Normal file
@ -0,0 +1,67 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub fn byte_type( __arg: Vec<u8>) -> Vec<u8> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn inner_arrays_1(_arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[derive(Default)]
|
||||
pub struct TestRecord {
|
||||
pub field_0: i32,
|
||||
pub field_1: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn inner_arrays_2(_arg: Vec<Vec<Vec<Vec<TestRecord>>>>) -> Vec<Vec<Vec<Vec<TestRecord>>>> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn string_type(_arg: Vec<String>) -> Vec<String> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f32_type(_arg: Vec<f32>) -> Vec<f32> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f64_type(_arg: Vec<f64>) -> Vec<f64> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u32_type(_arg: Vec<u32>) -> Vec<u32> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u64_type(_arg: Vec<u64>) -> Vec<u64> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i32_type(_arg: Vec<i32>) -> Vec<i32> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i64_type(_arg: Vec<i64>) -> Vec<i64> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn empty_type() -> Vec<String> {
|
||||
unimplemented!()
|
||||
}
|
73
fluence/tests/export_functions/basic_types.rs
Normal file
73
fluence/tests/export_functions/basic_types.rs
Normal file
@ -0,0 +1,73 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub fn all_types(
|
||||
_arg_0: i8,
|
||||
_arg_1: i16,
|
||||
_arg_2: i32,
|
||||
_arg_3: i64,
|
||||
_arg_4: u8,
|
||||
_arg_5: u16,
|
||||
_arg_6: u32,
|
||||
_arg_7: u64,
|
||||
_arg_8: f32,
|
||||
_arg_9: f64,
|
||||
_arg_10: String,
|
||||
_arg_11: Vec<u8>,
|
||||
) -> Vec<u8> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn string_type(_arg: String) -> String {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn bytearray_type(_arg: Vec<u8>) -> Vec<u8> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn bool_type(_arg: bool) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f32_type(_arg: f32) -> f32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn f64_type(_arg: f64) -> f64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u32_type(_arg: u32) -> u32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn u64_type(_arg: u64) -> u64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i32_type(_arg: i32) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn i64_type(_arg: i64) -> i64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub fn empty_type() -> String {
|
||||
unimplemented!()
|
||||
}
|
24
fluence/tests/export_functions/improper_types.rs
Normal file
24
fluence/tests/export_functions/improper_types.rs
Normal file
@ -0,0 +1,24 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
fn test(_arg_1: Box<i32>) {}
|
||||
|
||||
#[fce]
|
||||
fn test2(_arg_1: std::rc::Rc<i32>) {}
|
||||
|
||||
#[fce]
|
||||
fn test3(_arg_1: std::collections::HashMap<i32, String>) {}
|
||||
|
||||
#[fce]
|
||||
fn test4(_arg_1: i32) -> (i32, i32) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
#[fce]
|
||||
fn test5(_arg_1: i32) -> Box<i32> {
|
||||
unimplemented!()
|
||||
}
|
29
fluence/tests/export_functions/improper_types.stderr
Normal file
29
fluence/tests/export_functions/improper_types.stderr
Normal file
@ -0,0 +1,29 @@
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/improper_types.rs:8:17
|
||||
|
|
||||
8 | fn test(_arg_1: Box<i32>) {}
|
||||
| ^^^^^^^^
|
||||
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/improper_types.rs:11:27
|
||||
|
|
||||
11 | fn test2(_arg_1: std::rc::Rc<i32>) {}
|
||||
| ^^^^^^^
|
||||
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/improper_types.rs:14:36
|
||||
|
|
||||
14 | fn test3(_arg_1: std::collections::HashMap<i32, String>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: Incorrect argument type - passing only by value is supported now
|
||||
--> $DIR/improper_types.rs:17:26
|
||||
|
|
||||
17 | fn test4(_arg_1: i32) -> (i32, i32) {
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/improper_types.rs:22:26
|
||||
|
|
||||
22 | fn test5(_arg_1: i32) -> Box<i32> {
|
||||
| ^^^^^^^^
|
40
fluence/tests/import_functions/arrays.rs
Normal file
40
fluence/tests/import_functions/arrays.rs
Normal file
@ -0,0 +1,40 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
#[derive(Default)]
|
||||
pub struct TestRecord {
|
||||
pub field_0: i32,
|
||||
pub field_1: Vec<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "arrays_passing_effector")]
|
||||
extern "C" {
|
||||
pub fn inner_arrays_1(arg: Vec<Vec<Vec<Vec<u8>>>>) -> Vec<Vec<Vec<Vec<u8>>>>;
|
||||
|
||||
pub fn inner_arrays_2(
|
||||
arg: Vec<Vec<Vec<Vec<TestRecord>>>>,
|
||||
) -> Vec<Vec<Vec<Vec<TestRecord>>>>;
|
||||
|
||||
pub fn string_type(arg: Vec<String>) -> Vec<String>;
|
||||
|
||||
pub fn byte_type(arg: Vec<u8>) -> Vec<u8>;
|
||||
|
||||
pub fn f32_type(arg: Vec<f32>) -> Vec<f32>;
|
||||
|
||||
pub fn f64_type(arg: Vec<f64>) -> Vec<f64>;
|
||||
|
||||
pub fn u32_type(arg: Vec<u32>) -> Vec<u32>;
|
||||
|
||||
pub fn u64_type(arg: Vec<u64>) -> Vec<u64>;
|
||||
|
||||
pub fn i32_type(arg: Vec<i32>) -> Vec<i32>;
|
||||
|
||||
pub fn i64_type(arg: Vec<i64>) -> Vec<i64>;
|
||||
|
||||
pub fn empty_type() -> Vec<String>;
|
||||
}
|
40
fluence/tests/import_functions/basic_types.rs
Normal file
40
fluence/tests/import_functions/basic_types.rs
Normal file
@ -0,0 +1,40 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "arguments_passing_effector")]
|
||||
extern "C" {
|
||||
pub fn all_types(
|
||||
arg_0: i8,
|
||||
arg_1: i16,
|
||||
arg_2: i32,
|
||||
arg_3: i64,
|
||||
arg_4: u8,
|
||||
arg_5: u16,
|
||||
arg_6: u32,
|
||||
arg_7: u64,
|
||||
arg_8: f32,
|
||||
arg_9: f64,
|
||||
arg_10: String,
|
||||
arg_11: Vec<u8>,
|
||||
) -> Vec<u8>;
|
||||
|
||||
pub fn string_type(arg: String) -> String;
|
||||
pub fn bytearray_type(arg: Vec<u8>) -> Vec<u8>;
|
||||
|
||||
pub fn bool_type(arg: bool) -> bool;
|
||||
|
||||
pub fn f32_type(arg: f32) -> f32;
|
||||
pub fn f64_type(arg: f64) -> f64;
|
||||
|
||||
pub fn u32_type(arg: u32) -> u32;
|
||||
pub fn u64_type(arg: u64) -> u64;
|
||||
|
||||
pub fn i32_type(arg: i32) -> i32;
|
||||
pub fn i64_type(arg: i64) -> i64;
|
||||
|
||||
pub fn empty_type() -> String;
|
||||
}
|
24
fluence/tests/import_functions/improper_types.rs
Normal file
24
fluence/tests/import_functions/improper_types.rs
Normal file
@ -0,0 +1,24 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
pub fn main() {}
|
||||
|
||||
#[fce]
|
||||
#[link(wasm_import_module = "arguments_passing_effector")]
|
||||
extern "C" {
|
||||
#[fce]
|
||||
fn test(_arg_1: Box<i32>);
|
||||
|
||||
#[fce]
|
||||
fn test2(_arg_1: std::rc::Rc<i32>);
|
||||
|
||||
#[fce]
|
||||
fn test3(_arg_1: std::collections::HashMap<i32, String>);
|
||||
|
||||
#[fce]
|
||||
fn test4(_arg_1: i32) -> (i32, i32);
|
||||
|
||||
#[fce]
|
||||
fn test5(_arg_1: i32) -> Box<i32>;
|
||||
}
|
5
fluence/tests/import_functions/improper_types.stderr
Normal file
5
fluence/tests/import_functions/improper_types.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/improper_types.rs:11:21
|
||||
|
|
||||
11 | fn test(_arg_1: Box<i32>);
|
||||
| ^^^^^^^^
|
82
fluence/tests/records/basic_structs.rs
Normal file
82
fluence/tests/records/basic_structs.rs
Normal file
@ -0,0 +1,82 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
pub struct TestRecord {
|
||||
pub field_0: bool,
|
||||
pub field_1: i8,
|
||||
pub field_2: i16,
|
||||
pub field_3: i32,
|
||||
pub field_4: i64,
|
||||
pub field_5: u8,
|
||||
pub field_6: u16,
|
||||
pub field_7: u32,
|
||||
pub field_8: u64,
|
||||
pub field_9: f32,
|
||||
pub field_10: f64,
|
||||
pub field_11: String,
|
||||
pub field_12: Vec<u8>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct Tx {
|
||||
pub block_hash: String,
|
||||
pub block_number: String,
|
||||
pub from: String,
|
||||
pub gas: String,
|
||||
pub gas_price: String,
|
||||
pub hash: String,
|
||||
pub input: String,
|
||||
pub nonce: String,
|
||||
pub to: String,
|
||||
pub transaction_index: String,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[derive(Debug)]
|
||||
pub struct JsonRpcResult {
|
||||
pub json_rpc: String,
|
||||
pub result: String,
|
||||
pub error: String,
|
||||
pub id: u64,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
|
||||
pub struct User {
|
||||
pub peer_id: String,
|
||||
pub relay_id: String,
|
||||
pub signature: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct GetUsersServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub users: Vec<User>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct EmptyServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct ExistsServiceResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub is_exists: bool,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
pub struct AuthResult {
|
||||
pub ret_code: i32,
|
||||
pub err_msg: String,
|
||||
pub is_authenticated: bool,
|
||||
}
|
8
fluence/tests/records/empty_struct.rs
Normal file
8
fluence/tests/records/empty_struct.rs
Normal file
@ -0,0 +1,8 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
struct A {}
|
20
fluence/tests/records/struct_with_improper_types.rs
Normal file
20
fluence/tests/records/struct_with_improper_types.rs
Normal file
@ -0,0 +1,20 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
struct StructWithBox {
|
||||
pub a: Box<i32>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
struct StructWithRc {
|
||||
pub a: std::rc::Rc<i32>,
|
||||
}
|
||||
|
||||
#[fce]
|
||||
struct StructWithHashMap {
|
||||
pub a: std::collections::HashMap<i32, String>,
|
||||
}
|
17
fluence/tests/records/struct_with_improper_types.stderr
Normal file
17
fluence/tests/records/struct_with_improper_types.stderr
Normal file
@ -0,0 +1,17 @@
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/struct_with_improper_types.rs:9:12
|
||||
|
|
||||
9 | pub a: Box<i32>,
|
||||
| ^^^^^^^^
|
||||
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/struct_with_improper_types.rs:14:21
|
||||
|
|
||||
14 | pub a: std::rc::Rc<i32>,
|
||||
| ^^^^^^^
|
||||
|
||||
error: types with lifetimes or generics aren't allowed
|
||||
--> $DIR/struct_with_improper_types.rs:19:30
|
||||
|
|
||||
19 | pub a: std::collections::HashMap<i32, String>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
11
fluence/tests/records/struct_with_private_fields.rs
Normal file
11
fluence/tests/records/struct_with_private_fields.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![allow(improper_ctypes)]
|
||||
|
||||
use fluence::fce;
|
||||
|
||||
fn main() {}
|
||||
|
||||
#[fce]
|
||||
struct StructWithPrivateFields {
|
||||
a: i32,
|
||||
b: usize,
|
||||
}
|
5
fluence/tests/records/struct_with_private_fields.stderr
Normal file
5
fluence/tests/records/struct_with_private_fields.stderr
Normal file
@ -0,0 +1,5 @@
|
||||
error: #[fce] could be applied only to struct with all public fields
|
||||
--> $DIR/struct_with_private_fields.rs:9:5
|
||||
|
|
||||
9 | a: i32,
|
||||
| ^^^^^^
|
16
fluence/tests/test_runner.rs
Normal file
16
fluence/tests/test_runner.rs
Normal file
@ -0,0 +1,16 @@
|
||||
#[test]
|
||||
fn test() {
|
||||
let tests = trybuild::TestCases::new();
|
||||
tests.pass("tests/export_functions/arrays.rs");
|
||||
tests.pass("tests/export_functions/basic_types.rs");
|
||||
tests.compile_fail("tests/export_functions/improper_types.rs");
|
||||
|
||||
tests.pass("tests/import_functions/arrays.rs");
|
||||
tests.pass("tests/import_functions/basic_types.rs");
|
||||
tests.compile_fail("tests/import_functions/improper_types.rs");
|
||||
|
||||
tests.pass("tests/records/basic_structs.rs");
|
||||
tests.pass("tests/records/empty_struct.rs");
|
||||
tests.compile_fail("tests/records/struct_with_improper_types.rs");
|
||||
tests.compile_fail("tests/records/struct_with_private_fields.rs");
|
||||
}
|
Loading…
Reference in New Issue
Block a user