Skip to content

Commit

Permalink
Read chain_state genesis from a file (#973)
Browse files Browse the repository at this point in the history
* chain state config

* remove nft config

* Add unit test

* fix imports

* fix lint
  • Loading branch information
bkolad authored Oct 2, 2023
1 parent 86d1f00 commit baebd03
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
12 changes: 5 additions & 7 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use sov_cli::wallet_state::PrivateKeyAndAddress;
use sov_evm::{AccountData, EvmConfig, SpecId};
pub use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::Context;
use sov_nft_module::NonFungibleTokenConfig;
use sov_rollup_interface::da::DaSpec;
pub use sov_state::config::Config as StorageConfig;
use sov_value_setter::ValueSetterConfig;
Expand Down Expand Up @@ -80,13 +81,10 @@ fn create_genesis_config<C: Context, Da: DaSpec>(
let accounts_genesis_path = "../test-data/genesis/accounts.json";
let accounts_config: AccountConfig<C> = read_json_file(accounts_genesis_path)?;

let nft_config = sov_nft_module::NonFungibleTokenConfig {};
// This will be read from a file: #872
let chain_state_config = ChainStateConfig {
// TODO: Put actual value
initial_slot_height: 0,
current_time: Default::default(),
};
let nft_config: NonFungibleTokenConfig = NonFungibleTokenConfig {};

let chain_state_path = "../test-data/genesis/chain_state.json";
let chain_state_config: ChainStateConfig = read_json_file(chain_state_path)?;

Ok(GenesisConfig::new(
bank_config,
Expand Down
7 changes: 7 additions & 0 deletions examples/test-data/genesis/chain_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"initial_slot_height":0,
"current_time":{
"secs":0,
"nanos":0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

/// Contains the call methods used by the module
pub mod call;
#[cfg(test)]
mod tests;

/// Genesis state configuration
pub mod genesis;
Expand Down Expand Up @@ -147,7 +149,7 @@ pub struct ChainState<C: sov_modules_api::Context, Da: sov_modules_api::DaSpec>
}

/// Initial configuration of the chain state
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct ChainStateConfig {
/// Initial slot height
pub initial_slot_height: TransitionHeight,
Expand Down
24 changes: 24 additions & 0 deletions module-system/module-implementations/sov-chain-state/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use sov_rollup_interface::da::{NanoSeconds, Time};

use crate::ChainStateConfig;

#[test]
fn test_config_serialization() {
let time = Time::new(2, NanoSeconds::new(3).unwrap());
let config = ChainStateConfig {
initial_slot_height: 1,
current_time: time,
};

let data = r#"
{
"initial_slot_height":1,
"current_time":{
"secs":2,
"nanos":3
}
}"#;

let parsed_config: ChainStateConfig = serde_json::from_str(data).unwrap();
assert_eq!(config, parsed_config)
}

0 comments on commit baebd03

Please sign in to comment.