Skip to content

Commit

Permalink
move InMemoryStorage to sui-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill committed Jul 8, 2022
1 parent d322947 commit 2d348e0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_core_types::{language_storage::ModuleId, resolver::ModuleResolver};
use std::collections::BTreeMap;
use sui_types::{
base_types::{ObjectID, ObjectRef, SequenceNumber},
error::SuiResult,
error::{SuiError, SuiResult},
object::Object,
storage::{BackingPackageStore, DeleteKind},
};
Expand All @@ -22,6 +23,38 @@ impl BackingPackageStore for InMemoryStorage {
}
}

impl BackingPackageStore for &mut InMemoryStorage {
fn get_package(&self, package_id: &ObjectID) -> SuiResult<Option<Object>> {
(**self).get_package(package_id)
}
}

impl ModuleResolver for InMemoryStorage {
type Error = SuiError;

fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
Ok(self
.get_package(&ObjectID::from(*module_id.address()))?
.and_then(|package| {
package
.data
.try_as_package()
.unwrap()
.serialized_module_map()
.get(module_id.name().as_str())
.cloned()
}))
}
}

impl ModuleResolver for &mut InMemoryStorage {
type Error = SuiError;

fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
(**self).get_module(module_id)
}
}

impl InMemoryStorage {
pub fn new(objects: Vec<Object>) -> Self {
let mut persistent = BTreeMap::new();
Expand All @@ -35,6 +68,14 @@ impl InMemoryStorage {
self.persistent.get(id)
}

pub fn get_objects(&self, objects: &[ObjectID]) -> Vec<Option<&Object>> {
let mut result = Vec::new();
for id in objects {
result.push(self.get_object(id));
}
result
}

pub fn insert_object(&mut self, object: Object) {
self.persistent.insert(object.id(), object);
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-adapter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
pub mod adapter;
pub mod bytecode_rewriter;
pub mod genesis;
pub mod in_memory_storage;
pub mod object_root_ancestor_map;
pub mod temporary_store;
1 change: 0 additions & 1 deletion crates/sui-transactional-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//! This module contains the transactional test runner instantiation for the Sui adapter
pub mod args;
pub mod in_memory_storage;
pub mod test_adapter;

use move_transactional_test_runner::framework::run_test_impl;
Expand Down
6 changes: 4 additions & 2 deletions crates/sui-transactional-test-runner/src/test_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! This module contains the transactional test runner instantiation for the Sui adapter
use crate::{args::*, in_memory_storage::InMemoryStorage};
use crate::args::*;
use anyhow::bail;
use bimap::btree::BiBTreeMap;
use move_binary_format::{file_format::CompiledScript, CompiledModule};
Expand Down Expand Up @@ -36,8 +36,10 @@ use std::{
path::Path,
sync::Arc,
};
use sui_adapter::in_memory_storage::InMemoryStorage;
use sui_adapter::temporary_store::TemporaryStore;
use sui_adapter::{adapter::new_move_vm, genesis};
use sui_core::{authority::TemporaryStore, execution_engine};
use sui_core::execution_engine;
use sui_framework::DEFAULT_FRAMEWORK_PATH;
use sui_types::{
base_types::{
Expand Down

0 comments on commit 2d348e0

Please sign in to comment.