diff --git a/Cargo.lock b/Cargo.lock index 4e4e103cd..6eae2a27b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7106,6 +7106,7 @@ dependencies = [ "serde_json", "sov-modules-api", "sov-state", + "sov-value-setter", "tempfile", "thiserror", ] diff --git a/examples/demo-stf/src/genesis_config.rs b/examples/demo-stf/src/genesis_config.rs index 083612202..9a07fb33a 100644 --- a/examples/demo-stf/src/genesis_config.rs +++ b/examples/demo-stf/src/genesis_config.rs @@ -1,3 +1,4 @@ +use anyhow::Context as AnyhowContext; #[cfg(feature = "experimental")] use reth_primitives::Bytes; use sov_chain_state::ChainStateConfig; @@ -5,7 +6,7 @@ use sov_cli::wallet_state::PrivateKeyAndAddress; #[cfg(feature = "experimental")] use sov_evm::{AccountData, EvmConfig, SpecId}; pub use sov_modules_api::default_context::DefaultContext; -use sov_modules_api::{Context, PrivateKey, PublicKey}; +use sov_modules_api::Context; use sov_rollup_interface::da::DaSpec; pub use sov_state::config::Config as StorageConfig; use sov_value_setter::ValueSetterConfig; @@ -38,19 +39,18 @@ pub fn get_genesis_config( initial_sequencer_balance, token_deployer.address.clone(), sequencer_da_address, - &token_deployer.private_key, #[cfg(feature = "experimental")] evm_genesis_addresses, ) + .expect("Unable to read genesis configuration") } fn create_genesis_config( initial_sequencer_balance: u64, sequencer_address: C::Address, sequencer_da_address: Vec, - value_setter_admin_private_key: &C::PrivateKey, #[cfg(feature = "experimental")] evm_genesis_addresses: Vec, -) -> GenesisConfig { +) -> anyhow::Result> { // This will be read from a file: #872 let token_config: sov_bank::TokenConfig = sov_bank::TokenConfig { token_name: DEMO_TOKEN_NAME.to_owned(), @@ -81,10 +81,13 @@ fn create_genesis_config( is_preferred_sequencer: true, }; - // This will be read from a file: #872 - let value_setter_config = ValueSetterConfig { - admin: value_setter_admin_private_key.pub_key().to_address(), - }; + // This path will be injected as a parameter: #872 + let value_setter_genesis_path = "../test-data/genesis/value_setter.json"; + let value_setter_data = std::fs::read_to_string(value_setter_genesis_path) + .with_context(|| format!("Failed to read genesis from {}", value_setter_genesis_path))?; + + let value_setter_config: ValueSetterConfig = serde_json::from_str(&value_setter_data) + .with_context(|| format!("Failed to parse genesis from {}", value_setter_genesis_path))?; // This will be read from a file: #872 let chain_state_config = ChainStateConfig { @@ -93,7 +96,7 @@ fn create_genesis_config( current_time: Default::default(), }; - GenesisConfig::new( + Ok(GenesisConfig::new( bank_config, sequencer_registry_config, (), @@ -102,7 +105,7 @@ fn create_genesis_config( sov_accounts::AccountConfig { pub_keys: vec![] }, #[cfg(feature = "experimental")] get_evm_config(evm_genesis_addresses), - ) + )) } // TODO: #840 diff --git a/examples/test-data/genesis/value_setter.json b/examples/test-data/genesis/value_setter.json new file mode 100644 index 000000000..35c01dd23 --- /dev/null +++ b/examples/test-data/genesis/value_setter.json @@ -0,0 +1,3 @@ +{ + "admin":"sov1l6n2cku82yfqld30lanm2nfw43n2auc8clw7r5u5m6s7p8jrm4zqrr8r94" +} \ No newline at end of file diff --git a/module-system/module-implementations/examples/sov-value-setter/Cargo.toml b/module-system/module-implementations/examples/sov-value-setter/Cargo.toml index 3926cb558..392fbcf4a 100644 --- a/module-system/module-implementations/examples/sov-value-setter/Cargo.toml +++ b/module-system/module-implementations/examples/sov-value-setter/Cargo.toml @@ -12,7 +12,9 @@ readme = "README.md" resolver = "2" publish = false + [dev-dependencies] +sov-value-setter = { path = ".", features = ["native"] } tempfile = { workspace = true } [dependencies] diff --git a/module-system/module-implementations/examples/sov-value-setter/src/lib.rs b/module-system/module-implementations/examples/sov-value-setter/src/lib.rs index 63b3ec422..a49519240 100644 --- a/module-system/module-implementations/examples/sov-value-setter/src/lib.rs +++ b/module-system/module-implementations/examples/sov-value-setter/src/lib.rs @@ -15,6 +15,10 @@ pub use query::*; use sov_modules_api::{Error, ModuleInfo, WorkingSet}; /// Initial configuration for sov-value-setter module. +#[cfg_attr( + feature = "native", + derive(serde::Serialize, serde::Deserialize, Debug, PartialEq) +)] pub struct ValueSetterConfig { /// Admin of the module. pub admin: C::Address, diff --git a/module-system/module-implementations/examples/sov-value-setter/src/tests.rs b/module-system/module-implementations/examples/sov-value-setter/src/tests.rs index 4981f8369..01e107f40 100644 --- a/module-system/module-implementations/examples/sov-value-setter/src/tests.rs +++ b/module-system/module-implementations/examples/sov-value-setter/src/tests.rs @@ -5,6 +5,20 @@ use sov_state::{ProverStorage, ZkStorage}; use super::ValueSetter; use crate::{call, query, ValueSetterConfig}; +#[test] +fn test_config_serialization() { + let admin = Address::from([1; 32]); + let config = ValueSetterConfig:: { admin }; + + let data = r#" + { + "admin":"sov1qyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqszqgpqyqs259tk3" + }"#; + + let parsed_config: ValueSetterConfig = serde_json::from_str(data).unwrap(); + assert_eq!(parsed_config, config); +} + #[test] fn test_value_setter() { let tmpdir = tempfile::tempdir().unwrap();