Skip to content

Commit

Permalink
update accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad committed Oct 9, 2023
1 parent 367585e commit 18e2268
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
39 changes: 38 additions & 1 deletion module-system/module-implementations/sov-accounts/src/genesis.rs
Original file line number Diff line number Diff line change
@@ -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<C: Context> {
/// Public keys to initialize the rollup.
pub pub_keys: Vec<C::PublicKey>,
}

impl<C: sov_modules_api::Context> Accounts<C> {
pub(crate) fn init_module(
&self,
Expand Down Expand Up @@ -51,3 +59,32 @@ impl<C: sov_modules_api::Context> Accounts<C> {
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::<DefaultContext> {
pub_keys: vec![pub_key.clone()],
};

let data = r#"
{
"pub_keys":["1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf"]
}"#;

let parsed_config: AccountConfig<DefaultContext> = serde_json::from_str(data).unwrap();
assert_eq!(parsed_config, config);
}
}
9 changes: 1 addition & 8 deletions module-system/module-implementations/sov-accounts/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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")]
Expand All @@ -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<C: Context> {
/// Public keys to initialize the rollup.
pub pub_keys: Vec<C::PublicKey>,
}

impl<C: Context> FromIterator<C::PublicKey> for AccountConfig<C> {
fn from_iter<T: IntoIterator<Item = C::PublicKey>>(iter: T) -> Self {
Expand Down
23 changes: 0 additions & 23 deletions module-system/module-implementations/sov-accounts/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
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;

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::<DefaultContext> {
pub_keys: vec![pub_key.clone()],
};

let data = r#"
{
"pub_keys":["1cd4e2d9d5943e6f3d12589d31feee6bb6c11e7b8cd996a393623e207da72cbf"]
}"#;

let parsed_config: AccountConfig<DefaultContext> = serde_json::from_str(data).unwrap();
assert_eq!(parsed_config, config);
}

#[test]
fn test_config_account() {
let priv_key = DefaultPrivateKey::generate();
Expand Down

0 comments on commit 18e2268

Please sign in to comment.