Skip to content

Commit

Permalink
update executor test
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjiao committed Jan 19, 2025
1 parent 5025139 commit df4325a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
30 changes: 30 additions & 0 deletions executor/tests/executor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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(())
}
12 changes: 9 additions & 3 deletions state/statedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -140,6 +144,7 @@ impl AccountStateObject {
}

pub fn set(&self, data_path: DataPath, value: Vec<u8>) {
let human_str = format!("{}", data_path);
match data_path {
DataPath::Code(module_name) => {
if self.code_tree.lock().is_none() {
Expand All @@ -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);
}
}
Expand All @@ -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(())
}
Expand Down

0 comments on commit df4325a

Please sign in to comment.