From 18e2268f8c9d08a796d725625f2b670258846943 Mon Sep 17 00:00:00 2001 From: bkolad Date: Mon, 9 Oct 2023 13:55:25 +0200 Subject: [PATCH] update accounts --- .../sov-accounts/src/genesis.rs | 39 ++++++++++++++++++- .../sov-accounts/src/lib.rs | 9 +---- .../sov-accounts/src/tests.rs | 23 ----------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/module-system/module-implementations/sov-accounts/src/genesis.rs b/module-system/module-implementations/sov-accounts/src/genesis.rs index ffee617ea..2666d6a95 100644 --- a/module-system/module-implementations/sov-accounts/src/genesis.rs +++ b/module-system/module-implementations/sov-accounts/src/genesis.rs @@ -1,8 +1,16 @@ use anyhow::{bail, Result}; -use sov_modules_api::{PublicKey, WorkingSet}; +use sov_modules_api::{Context, PublicKey, WorkingSet}; use crate::{Account, Accounts}; +/// Initial configuration for sov-accounts module. +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[serde(bound = "C::PublicKey: serde::Serialize + serde::de::DeserializeOwned")] +pub struct AccountConfig { + /// Public keys to initialize the rollup. + pub pub_keys: Vec, +} + impl Accounts { pub(crate) fn init_module( &self, @@ -51,3 +59,32 @@ impl Accounts { Ok(()) } } + +#[cfg(test)] +mod tests { + use std::str::FromStr; + + use sov_modules_api::{default_context::DefaultContext, default_signature::DefaultPublicKey}; + + use super::*; + + #[test] + fn test_config_serialization() { + let pub_key = &DefaultPublicKey::from_str( + "1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf", + ) + .unwrap(); + + let config = AccountConfig:: { + pub_keys: vec![pub_key.clone()], + }; + + let data = r#" + { + "pub_keys":["1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf"] + }"#; + + let parsed_config: AccountConfig = serde_json::from_str(data).unwrap(); + assert_eq!(parsed_config, config); + } +} diff --git a/module-system/module-implementations/sov-accounts/src/lib.rs b/module-system/module-implementations/sov-accounts/src/lib.rs index 922fce9f4..830024122 100644 --- a/module-system/module-implementations/sov-accounts/src/lib.rs +++ b/module-system/module-implementations/sov-accounts/src/lib.rs @@ -1,9 +1,9 @@ #![deny(missing_docs)] #![doc = include_str!("../README.md")] mod hooks; - mod call; mod genesis; +pub use genesis::*; #[cfg(feature = "native")] mod query; #[cfg(feature = "native")] @@ -14,13 +14,6 @@ mod tests; pub use call::{CallMessage, UPDATE_ACCOUNT_MSG}; use sov_modules_api::{Context, Error, ModuleInfo, WorkingSet}; -/// Initial configuration for sov-accounts module. -#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[serde(bound = "C::PublicKey: serde::Serialize + serde::de::DeserializeOwned")] -pub struct AccountConfig { - /// Public keys to initialize the rollup. - pub pub_keys: Vec, -} impl FromIterator for AccountConfig { fn from_iter>(iter: T) -> Self { diff --git a/module-system/module-implementations/sov-accounts/src/tests.rs b/module-system/module-implementations/sov-accounts/src/tests.rs index 573168530..a1821894c 100644 --- a/module-system/module-implementations/sov-accounts/src/tests.rs +++ b/module-system/module-implementations/sov-accounts/src/tests.rs @@ -1,8 +1,5 @@ -use std::str::FromStr; - use sov_modules_api::default_context::DefaultContext; use sov_modules_api::default_signature::private_key::DefaultPrivateKey; -use sov_modules_api::default_signature::DefaultPublicKey; use sov_modules_api::{AddressBech32, Context, Module, PrivateKey, PublicKey, Spec, WorkingSet}; use sov_state::ProverStorage; @@ -10,26 +7,6 @@ use crate::query::{self, Response}; use crate::{call, AccountConfig, Accounts}; type C = DefaultContext; -#[test] -fn test_config_serialization() { - let pub_key = &DefaultPublicKey::from_str( - "1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf", - ) - .unwrap(); - - let config = AccountConfig:: { - pub_keys: vec![pub_key.clone()], - }; - - let data = r#" - { - "pub_keys":["1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf"] - }"#; - - let parsed_config: AccountConfig = serde_json::from_str(data).unwrap(); - assert_eq!(parsed_config, config); -} - #[test] fn test_config_account() { let priv_key = DefaultPrivateKey::generate();