diff --git a/Cargo.lock b/Cargo.lock index 4f51ce1bde..813b21d5f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10617,6 +10617,7 @@ dependencies = [ "starcoin-transaction-builder", "starcoin-types", "starcoin-vm-runtime", + "starcoin-vm-runtime-types", "starcoin-vm-types", "stdlib", "stest", diff --git a/executor/Cargo.toml b/executor/Cargo.toml index 58ef99ad84..d71da166b2 100644 --- a/executor/Cargo.toml +++ b/executor/Cargo.toml @@ -27,6 +27,7 @@ starcoin-transaction-builder = { workspace = true } starcoin-state-tree = { workspace = true } starcoin-statedb = { workspace = true } starcoin-vm-runtime = { workspace = true } +starcoin-vm-runtime-types = { workspace = true } stdlib = { workspace = true } stest = { workspace = true } tempfile = { workspace = true } diff --git a/executor/tests/executor_test.rs b/executor/tests/executor_test.rs index cbb07528ae..44fc1e22de 100644 --- a/executor/tests/executor_test.rs +++ b/executor/tests/executor_test.rs @@ -36,8 +36,11 @@ use test_helper::executor::{ use starcoin_state_api::StateReaderExt; use starcoin_types::account::Account; use starcoin_types::account_config::G_STC_TOKEN_CODE; +use starcoin_vm_runtime::data_cache::AsMoveResolver; +use starcoin_vm_runtime::move_vm_ext::ResourceGroupResolver; use starcoin_vm_runtime::starcoin_vm::{chunk_block_transactions, StarcoinVM}; use starcoin_vm_types::account_config::core_code_address; +use starcoin_vm_types::language_storage::StructTag; use starcoin_vm_types::state_store::state_key::StateKey; use starcoin_vm_types::state_store::state_value::StateValue; use test_helper::executor::{ @@ -1134,3 +1137,30 @@ fn test_chunk_block_transactions() -> Result<()> { Ok(()) } + +#[test] +fn test_genesis_writeset_for_object() -> Result<()> { + starcoin_logger::init_for_test(); + + let (chain_statedb, _network) = prepare_genesis(); + let state_key = StateKey::resource_group( + &genesis_address(), + &StructTag { + address: genesis_address(), + module: Identifier::new("object").unwrap(), + name: Identifier::new("ObjectGroup").unwrap(), + type_args: vec![], + }, + ); + let object_core_tag = StructTag { + address: genesis_address(), + module: Identifier::new("object").unwrap(), + name: Identifier::new("ObjectCore").unwrap(), + type_args: vec![], + }; + let resource_group_adapter = chain_statedb.as_move_resolver(); + assert!(resource_group_adapter + .resource_exists_in_group(&state_key, &object_core_tag) + .unwrap()); + Ok(()) +} diff --git a/state/statedb/src/lib.rs b/state/statedb/src/lib.rs index 11fa6c3d78..47a0fab320 100644 --- a/state/statedb/src/lib.rs +++ b/state/statedb/src/lib.rs @@ -112,8 +112,12 @@ impl AccountStateObject { .transpose()? .flatten()), DataPath::Resource(struct_tag) => self.resource_tree.lock().get(struct_tag), - DataPath::ResourceGroup(_) => { - bail!("resource_group_tree not support get"); + DataPath::ResourceGroup(struct_tag) => { + eprintln!( + "redirect getting resource_group_tree to resource_tree {}", + data_path + ); + self.resource_tree.lock().get(struct_tag) } } } @@ -140,6 +144,7 @@ impl AccountStateObject { } pub fn set(&self, data_path: DataPath, value: Vec) { + let human_str = format!("{}", data_path); match data_path { DataPath::Code(module_name) => { if self.code_tree.lock().is_none() { @@ -156,7 +161,7 @@ impl AccountStateObject { self.resource_tree.lock().put(struct_tag, value); } DataPath::ResourceGroup(struct_tag) => { - eprintln!("treat resource_group as resource"); + eprintln!("redirect setting resource_group to resource {}", human_str); self.resource_tree.lock().put(struct_tag, value); } } @@ -169,6 +174,7 @@ impl AccountStateObject { let struct_tag = data_path .as_struct_tag() .expect("DataPath must been struct tag at here."); + eprintln!("remove resource {}", struct_tag); self.resource_tree.lock().remove(struct_tag); Ok(()) }