Skip to content

Commit

Permalink
fix starcoin-aggregator test mod errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Nov 13, 2024
1 parent 19ee5d3 commit 8362d98
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 31 deletions.
64 changes: 37 additions & 27 deletions vm/starcoin-aggregator/src/tests/identifier_mappings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,40 @@ use move_core_types::value::{
MoveTypeLayout,
MoveTypeLayout::{Address, Bool, Struct, Vector, U128, U64, U8},
};
use move_vm_types::delayed_values::delayed_field_id::DelayedFieldID;
use move_vm_types::delayed_values::derived_string_snapshot::bytes_to_string;
use move_vm_types::delayed_values::delayed_field_id::TryFromMoveValue;
use move_vm_types::delayed_values::delayed_field_id::{DelayedFieldID, TryIntoMoveValue};
use move_vm_types::delayed_values::derived_string_snapshot::bytes_and_width_to_derived_string_struct;
use move_vm_types::values::Value;
use once_cell::sync::Lazy;
use test_case::test_case;
use DelayedFieldValue as A;
use IdentifierMappingKind as K;

static STRING: Lazy<MoveTypeLayout> = Lazy::new(|| Struct(Runtime(vec![Vector(Box::new(U8))])));
static DERIVED_STRING: Lazy<MoveTypeLayout> = Lazy::new(|| {
Struct(Runtime(vec![
// String value
Struct(Runtime(vec![Vector(Box::new(U8))])),
// Vec<u8> padding
Vector(Box::new(U8)),
]))
});

#[test_case(&U64)]
#[test_case(&U128)]
#[test_case(&*STRING)]
fn test_aggregator_id_roundtrip_ok(layout: &MoveTypeLayout) {
let value = assert_ok!(DelayedFieldID::new(100).try_into_move_value(layout));
let id = assert_ok!(DelayedFieldID::try_from_move_value(layout, value, &()));
assert_eq!(id, DelayedFieldID::new(100));
#[test_case(&U64, 8)]
#[test_case(&U128, 16)]
#[test_case(&*DERIVED_STRING, 20)]
fn test_aggregator_id_roundtrip_ok(layout: &MoveTypeLayout, width: u32) {
let input = DelayedFieldID::new_with_width(100, width);
let value = assert_ok!(input.try_into_move_value(layout));
let (id, _) = assert_ok!(DelayedFieldID::try_from_move_value(layout, value, &()));
assert_eq!(id, input);
}

#[test_case(&U8)]
#[test_case(&Bool)]
#[test_case(&Address)]
#[test_case(&Vector(Box::new(U8)))]
fn test_aggregator_id_to_value_err(layout: &MoveTypeLayout) {
assert_err!(DelayedFieldID::new(100).try_into_move_value(layout));
assert_err!(DelayedFieldID::new_with_width(100, 8).try_into_move_value(layout));
}

#[test_case(&U64, Value::u8(1))]
Expand All @@ -44,37 +53,38 @@ fn test_aggregator_id_from_value_err(layout: &MoveTypeLayout, value: Value) {
assert_err!(DelayedFieldID::try_from_move_value(layout, value, &()));
}

#[test_case(A::Aggregator(10), &U64, K::Aggregator)]
#[test_case(A::Aggregator(10), &U128, K::Aggregator)]
#[test_case(A::Snapshot(10), &U64, K::Snapshot)]
#[test_case(A::Snapshot(10), &U128, K::Snapshot)]
#[test_case(A::Derived(vec![0, 1]), &*STRING, K::Snapshot)]
#[test_case(A::Aggregator(10), &U64, K::Aggregator, 8)]
#[test_case(A::Aggregator(10), &U128, K::Aggregator, 16)]
#[test_case(A::Snapshot(10), &U64, K::Snapshot, 8)]
#[test_case(A::Snapshot(10), &U128, K::Snapshot, 16)]
#[test_case(A::Derived(vec![0, 1]), &*DERIVED_STRING, K::DerivedString, 20)]
fn test_aggregator_value_roundtrip_ok(
aggregator_value: DelayedFieldValue,
layout: &MoveTypeLayout,
kind: IdentifierMappingKind,
width: u32,
) {
let value = assert_ok!(aggregator_value.clone().try_into_move_value(layout));
let a = assert_ok!(DelayedFieldValue::try_from_move_value(layout, value, &kind));
let value = assert_ok!(aggregator_value.clone().try_into_move_value(layout, width));
let (a, _) = assert_ok!(DelayedFieldValue::try_from_move_value(layout, value, &kind));
assert_eq!(a, aggregator_value);
}

#[test_case(&U8)]
#[test_case(&Bool)]
#[test_case(&Address)]
#[test_case(&Vector(Box::new(U8)))]
fn test_aggregator_value_to_value_err(layout: &MoveTypeLayout) {
assert_err!(DelayedFieldValue::Aggregator(0).try_into_move_value(layout));
assert_err!(DelayedFieldValue::Snapshot(1).try_into_move_value(layout));
assert_err!(DelayedFieldValue::Derived(vec![3]).try_into_move_value(layout));
#[test_case(&U8, 1)]
#[test_case(&Bool, 1)]
#[test_case(&Address, 20)]
#[test_case(&Vector(Box::new(U8)), 5)]
fn test_aggregator_value_to_value_err(layout: &MoveTypeLayout, width: u32) {
assert_err!(DelayedFieldValue::Aggregator(0).try_into_move_value(layout, width));
assert_err!(DelayedFieldValue::Snapshot(1).try_into_move_value(layout, width));
assert_err!(DelayedFieldValue::Derived(vec![3]).try_into_move_value(layout, width));
}

#[test_case(&U64, Value::u8(1), K::Aggregator)]
#[test_case(&U8, Value::u8(1), K::Aggregator)]
#[test_case(&U8, Value::u8(1), K::Snapshot)]
#[test_case(&Bool, Value::u8(1), K::Snapshot)]
#[test_case(&Vector(Box::new(U8)), Value::vector_u8(vec![0, 1]), K::Snapshot)]
#[test_case(&*STRING, bytes_to_string(vec![1,2]), K::Aggregator)]
#[test_case(&*DERIVED_STRING, bytes_and_width_to_derived_string_struct(vec![1,2], 20).unwrap(), K::Aggregator)]
fn test_aggregator_value_from_value_err(
layout: &MoveTypeLayout,
value: Value,
Expand Down
2 changes: 0 additions & 2 deletions vm/types/src/account_config/resources/account.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::account_config::genesis_address;
use crate::{account_config::constants::ACCOUNT_MODULE_NAME, event::EventHandle};
use move_core_types::account_address::AccountAddress;
use move_core_types::language_storage::{StructTag, CORE_CODE_ADDRESS};
use move_core_types::{
ident_str,
identifier::IdentStr,
Expand Down
5 changes: 3 additions & 2 deletions vm/vm-runtime/src/move_vm_ext/write_op_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,20 @@ impl<'r> WriteOpConverter<'r> {

#[cfg(test)]
mod tests {
use std::collections::BTreeMap;
use super::*;
use crate::{
data_cache::tests::as_resolver_with_group_size_kind,
move_vm_ext::resolver::ResourceGroupResolver,
};
use aptos_types::{
use starcoin_vm_types::{
account_address::AccountAddress,
state_store::{
errors::StateviewError, state_storage_usage::StateStorageUsage,
state_value::StateValue, TStateView,
},
};
use aptos_vm_types::resource_group_adapter::{group_size_as_sum, GroupSizeKind};
use starcoin_vm_types::resource_group_adapter::{group_size_as_sum, GroupSizeKind};
use claims::{assert_none, assert_some_eq};
use move_core_types::{
identifier::Identifier,
Expand Down

0 comments on commit 8362d98

Please sign in to comment.