Skip to content

Commit

Permalink
fix genesis, sdk-builder test mod errors (#4280)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg authored Nov 12, 2024
1 parent ad77731 commit 68b4d83
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion account/src/account_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ pub fn test_wallet_account() -> Result<()> {
address: CORE_CODE_ADDRESS,
module: Identifier::from(IdentStr::new("Account")?),
name: Identifier::from(IdentStr::new("Account")?),
type_params: vec![],
type_args: vec![],
};
let access_path = AccessPath::resource_access_path(address, struct_tag);
println!("access path is {:?}", access_path);
Expand Down
6 changes: 4 additions & 2 deletions contrib-contracts/src/starcoin_merkle_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use starcoin_types::identifier::Identifier;
use starcoin_types::language_storage::ModuleId;
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::account_config::association_address;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::transaction::{EntryFunction, Package, TransactionPayload};
use starcoin_vm_types::value::MoveValue;
use test_helper::executor::{
Expand All @@ -15,8 +16,9 @@ use test_helper::executor::{
#[stest::test]
fn test_starcoin_merkle() -> Result<()> {
let (chain_state, net) = prepare_genesis();
let state_key = StateKey::resource(&association_address(), &account_struct_tag())?;
let ap = AccessPath::resource_access_path(association_address(), account_struct_tag());
let state_with_proof = chain_state.get_with_proof(&ap)?;
let state_with_proof = chain_state.get_with_proof(&state_key)?;
state_with_proof.proof.verify(
chain_state.state_root(),
ap,
Expand Down Expand Up @@ -66,7 +68,7 @@ fn test_starcoin_merkle() -> Result<()> {
// let state_root = chain_state.state_root();
let _expected_root = MoveValue::vector_u8(state_root.to_vec());

let ap = AccessPath::resource_access_path(association_address(), account_struct_tag());
let ap = StateKey::resource(&association_address(), &account_struct_tag())?;
let state_with_proof = old_chain_state.get_with_proof(&ap)?;
let account_address = MoveValue::vector_u8(association_address().to_vec());
let account_state_hash = MoveValue::vector_u8(
Expand Down
32 changes: 16 additions & 16 deletions genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,29 +466,29 @@ mod tests {
"chain id in Move resource should equals ChainNetwork's chain_id."
);
let genesis_account_resource =
account_state_reader.get_account_resource(&genesis_address())?;
account_state_reader.get_account_resource(&genesis_address());
assert!(
genesis_account_resource.is_some(),
genesis_account_resource.is_ok(),
"genesis account must exist in genesis state."
);

let genesis_balance = account_state_reader.get_balance(&genesis_address())?;
let genesis_balance = account_state_reader.get_balance(&genesis_address());
assert!(
genesis_balance.is_some(),
genesis_balance.is_ok(),
"genesis account balance must exist in genesis state."
);

let association_account_resource =
account_state_reader.get_account_resource(&association_address())?;
account_state_reader.get_account_resource(&association_address());
assert!(
association_account_resource.is_some(),
association_account_resource.is_ok(),
"association account must exist in genesis state."
);

let association_balance = account_state_reader.get_balance(&association_address())?;
let association_balance = account_state_reader.get_balance(&association_address());

assert!(
association_balance.is_some(),
association_balance.is_ok(),
"association account balance must exist in genesis state."
);

Expand All @@ -500,7 +500,7 @@ mod tests {
// assert_eq!(vm_config.as_ref().unwrap(), &net.genesis_config().vm_config);

let vm_publish_option =
account_state_reader.get_on_chain_config::<TransactionPublishOption>()?;
account_state_reader.get_on_chain_config::<TransactionPublishOption>();
assert!(
vm_publish_option.is_some(),
"vm_publish_option on_chain_config should exist."
Expand All @@ -510,7 +510,7 @@ mod tests {
&net.genesis_config().publishing_option
);

let consensus_config = account_state_reader.get_on_chain_config::<ConsensusConfig>()?;
let consensus_config = account_state_reader.get_on_chain_config::<ConsensusConfig>();
assert!(
consensus_config.is_some(),
"ConsensusConfig on_chain_config should exist."
Expand All @@ -527,17 +527,17 @@ mod tests {
// "DaoConfig on_chain_config should exist."
// );

let version = account_state_reader.get_on_chain_config::<Version>()?;
let version = account_state_reader.get_on_chain_config::<Version>();
assert!(version.is_some(), "Version on_chain_config should exist.");
assert_eq!(
version.as_ref().unwrap().major,
net.genesis_config().stdlib_version.version()
);

let module_upgrade_strategy =
account_state_reader.get_resource::<ModuleUpgradeStrategy>(genesis_address())?;
account_state_reader.get_resource::<ModuleUpgradeStrategy>(genesis_address());
assert!(
module_upgrade_strategy.is_some(),
module_upgrade_strategy.is_ok(),
"ModuleUpgradeStrategy should exist."
);
assert!(
Expand Down Expand Up @@ -581,8 +581,8 @@ mod tests {
block_accumulator.append(&[HashValue::random()])?;
block_accumulator.flush()?;

let epoch = account_state_reader.get_resource::<Epoch>(genesis_address())?;
assert!(epoch.is_some(), "Epoch resource should exist.");
let epoch = account_state_reader.get_resource::<Epoch>(genesis_address());
assert!(epoch.is_ok(), "Epoch resource should exist.");

// test_gas_schedule_in_genesis(net, &state_db)?;

Expand All @@ -604,7 +604,7 @@ mod tests {
);
let account_state_reader = AccountStateReader::new(state_db);
let genesis_gas_schedule =
account_state_reader.get_on_chain_config::<GasSchedule>()?;
account_state_reader.get_on_chain_config::<GasSchedule>();
assert!(
genesis_gas_schedule.is_some(),
"GasSchedule config should exist."
Expand Down
4 changes: 2 additions & 2 deletions state/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ mod tests {
registry.put_shared(config).await?;
registry.put_shared(storage).await?;
let service_ref = registry.register::<ChainStateService>().await?;
let account_state = service_ref.get_account_state(genesis_address()).await?;
assert!(account_state.is_some());
let account_state = service_ref.get_account_state(genesis_address()).await;
assert!(account_state.is_ok());
Ok(())
}
}
2 changes: 1 addition & 1 deletion vm/starcoin-sdk-builder/tests/generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde_generate as serdegen;
use serde_generate::SourceInstaller as _;
use serde_reflection::Registry;
use starcoin_sdk_builder as buildgen;
use starcoin_types::transaction::EntryABI;
use starcoin_vm_types::transaction::EntryABI;
use std::{io::Write, process::Command};
use tempfile::tempdir;

Expand Down
2 changes: 2 additions & 0 deletions vm/stdlib/tests/generated_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use move_compiler::construct_pre_compiled_lib;
use move_compiler::shared::PackagePaths;
use starcoin_move_compiler::starcoin_framework_named_addresses;
use std::collections::BTreeSet;
use std::path::PathBuf;
use std::process::Command;
use stdlib::stdlib_files;
Expand Down Expand Up @@ -58,6 +59,7 @@ fn test_stdlib_pre_compiled() {
}],
None,
move_compiler::Flags::empty(),
&BTreeSet::new(),
)
.unwrap();
assert!(program_res.is_ok());
Expand Down
2 changes: 2 additions & 0 deletions vm/types/src/account_config/resources/account.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 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

0 comments on commit 68b4d83

Please sign in to comment.