2020-08-23 22:00:38 +00:00
|
|
|
/*
|
2024-06-26 09:37:14 +00:00
|
|
|
* Marine WebAssembly runtime
|
2020-08-23 22:00:38 +00:00
|
|
|
*
|
2024-06-26 09:37:14 +00:00
|
|
|
* Copyright (C) 2024 Fluence DAO
|
2020-08-23 22:00:38 +00:00
|
|
|
*
|
2024-06-26 09:37:14 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation version 3 of the
|
|
|
|
* License.
|
2020-08-23 22:00:38 +00:00
|
|
|
*
|
2024-06-26 09:37:14 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-08-23 22:00:38 +00:00
|
|
|
*/
|
|
|
|
|
2022-06-09 14:00:19 +00:00
|
|
|
use marine_core::MarineCore;
|
2023-12-13 16:51:58 +00:00
|
|
|
use marine_core::MarineCoreConfig;
|
2022-06-09 14:00:19 +00:00
|
|
|
use marine_core::IValue;
|
2024-04-10 20:34:34 +00:00
|
|
|
use marine_wasm_backend_traits::WasmBackend;
|
|
|
|
use marine_wasmtime_backend::WasmtimeWasmBackend;
|
2020-08-23 22:00:38 +00:00
|
|
|
|
2024-04-10 20:34:34 +00:00
|
|
|
#[tokio::test]
|
|
|
|
pub async fn records() {
|
2020-09-15 22:14:15 +00:00
|
|
|
let effector_wasm_bytes = std::fs::read("../examples/records/artifacts/records_effector.wasm")
|
|
|
|
.expect("../examples/records/artifacts/records_effector.wasm should presence");
|
2020-08-23 22:00:38 +00:00
|
|
|
|
2020-09-15 22:14:15 +00:00
|
|
|
let pure_wasm_bytes = std::fs::read("../examples/records/artifacts/records_pure.wasm")
|
|
|
|
.expect("../examples/records/artifacts/records_pure.wasm should presence");
|
2020-08-23 22:00:38 +00:00
|
|
|
|
2024-04-10 20:34:34 +00:00
|
|
|
let backend = WasmtimeWasmBackend::new_async().unwrap();
|
|
|
|
let mut marine_core = MarineCore::new(MarineCoreConfig::new(backend, None)).unwrap();
|
|
|
|
let load_result = marine_core
|
|
|
|
.load_module("pure", &pure_wasm_bytes, <_>::default())
|
|
|
|
.await;
|
2020-08-23 22:00:38 +00:00
|
|
|
assert!(load_result.is_err());
|
|
|
|
|
2022-06-09 14:00:19 +00:00
|
|
|
marine_core
|
2021-05-10 09:51:22 +00:00
|
|
|
.load_module("records_effector", &effector_wasm_bytes, <_>::default())
|
2024-04-10 20:34:34 +00:00
|
|
|
.await
|
2021-05-10 09:51:22 +00:00
|
|
|
.unwrap_or_else(|e| panic!("can't load a module into Marine: {:?}", e));
|
2020-08-23 22:00:38 +00:00
|
|
|
|
2022-06-09 14:00:19 +00:00
|
|
|
marine_core
|
2021-05-10 09:51:22 +00:00
|
|
|
.load_module("records_pure", &pure_wasm_bytes, <_>::default())
|
2024-04-10 20:34:34 +00:00
|
|
|
.await
|
2021-05-10 09:51:22 +00:00
|
|
|
.unwrap_or_else(|e| panic!("can't load a module into Marine: {:?}", e));
|
2020-08-23 22:00:38 +00:00
|
|
|
|
2022-06-09 14:00:19 +00:00
|
|
|
let result = marine_core
|
2024-04-10 20:34:34 +00:00
|
|
|
.call_async("records_pure", "invoke", &[])
|
|
|
|
.await
|
2020-08-23 22:00:38 +00:00
|
|
|
.unwrap_or_else(|e| panic!("can't invoke pure: {:?}", e));
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
result,
|
|
|
|
vec![IValue::Record(
|
2021-05-10 09:51:22 +00:00
|
|
|
wasmer_it::NEVec::new(vec![
|
2021-04-26 11:02:26 +00:00
|
|
|
IValue::Boolean(true),
|
2020-08-23 22:00:38 +00:00
|
|
|
IValue::S8(1),
|
|
|
|
IValue::S16(2),
|
|
|
|
IValue::S32(3),
|
|
|
|
IValue::S64(4),
|
|
|
|
IValue::U8(5),
|
|
|
|
IValue::U16(6),
|
|
|
|
IValue::U32(7),
|
|
|
|
IValue::U64(8),
|
|
|
|
IValue::F32(9.0),
|
|
|
|
IValue::F64(10.0),
|
|
|
|
IValue::String(String::from("field_11")),
|
2021-04-26 11:02:26 +00:00
|
|
|
IValue::ByteArray(vec![0x13, 0x37])
|
2020-08-23 22:00:38 +00:00
|
|
|
])
|
|
|
|
.unwrap()
|
|
|
|
)]
|
|
|
|
);
|
|
|
|
}
|