mirror of
https://github.com/fluencelabs/aquavm
synced 2025-04-24 23:02:16 +00:00
New crate air_interpreter_sede introduces a flexible serialization and deserialization infrastructure. Low level API: the Format trait and related. It includes simple and universal mechanisms for serializing any possible (e.g. implementing the Serde traits) value. High level API: Representation trait and related. It allows declaring representation types that can serialize and deserialize only certain types (for example, InterpreterDataRepr can serialize only the InterpreterData, but deserialize InterpreterData and Versions` types), producing newtype values as serialization results. The serialized representation of CallResults now contains byte arrays, not strings, because the new infrastructure serializes to byte arrays only. Also, the basic support for multicodecs is added.
71 lines
2.6 KiB
Rust
71 lines
2.6 KiB
Rust
/*
|
|
* Copyright 2022 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 air::min_supported_version;
|
|
use air::PreparationError;
|
|
use air_interpreter_interface::INTERPRETER_SUCCESS;
|
|
use air_test_utils::prelude::*;
|
|
|
|
#[test]
|
|
fn minimal_version_check() {
|
|
let mut vm = create_avm(echo_call_service(), "");
|
|
let script = "(null)";
|
|
|
|
let actual_version = semver::Version::new(0, 31, 1);
|
|
let current_data = InterpreterData::new(actual_version.clone());
|
|
let current_data = current_data.serialize().expect("default serializer shouldn't fail");
|
|
let result = call_vm!(vm, <_>::default(), script, "", current_data);
|
|
|
|
let expected_error = PreparationError::UnsupportedInterpreterVersion {
|
|
actual_version,
|
|
required_version: min_supported_version().clone(),
|
|
};
|
|
|
|
assert!(check_error(&result, expected_error));
|
|
}
|
|
|
|
#[test]
|
|
fn publish_version_check() {
|
|
let mut vm = create_avm(echo_call_service(), "");
|
|
let script = "(null)";
|
|
|
|
let actual_version =
|
|
semver::Version::parse("1.0.1-feat-VM-173-add-interpreter-version-in-data-a2d575b-205-1.0").unwrap();
|
|
let current_data = InterpreterData::new(actual_version);
|
|
let current_data = current_data.serialize().expect("default serializer shouldn't fail");
|
|
let result = call_vm!(vm, <_>::default(), script, "", current_data);
|
|
|
|
assert_eq!(result.ret_code, INTERPRETER_SUCCESS, "{:?}", result.error_message);
|
|
}
|
|
|
|
#[test]
|
|
fn publish_unsupported_version_check() {
|
|
let mut vm = create_avm(echo_call_service(), "");
|
|
|
|
let actual_version =
|
|
semver::Version::parse("0.31.1-feat-VM-173-add-interpreter-version-in-data-a2d575b-205-1.0").unwrap();
|
|
let current_data = InterpreterData::new(actual_version.clone());
|
|
let current_data = current_data.serialize().expect("default serializer shouldn't fail");
|
|
let result = call_vm!(vm, <_>::default(), "", "", current_data);
|
|
|
|
let expected_error = PreparationError::UnsupportedInterpreterVersion {
|
|
actual_version,
|
|
required_version: min_supported_version().clone(),
|
|
};
|
|
|
|
assert!(check_error(&result, expected_error));
|
|
}
|