Skip to content

Commit

Permalink
[fix] fix compile error; add custom serialization for tests
Browse files Browse the repository at this point in the history
Signed-off-by: VAmuzing <amuzik95@gmail.com>
  • Loading branch information
VAmuzing committed Apr 24, 2024
1 parent d15bda1 commit 190ee3d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 0 additions & 3 deletions cli/src/lib.rs
Expand Up @@ -670,13 +670,10 @@ mod tests {
fn config_to_toml_value(config: PartialUserConfig) -> Result<toml::Value> {
use iroha_crypto::ExposedPrivateKey;
let private_key = config.private_key.as_ref().unwrap().clone();
let genesis_private_key = config.genesis.private_key.as_ref().unwrap().clone();
let mut result = toml::Value::try_from(config)?;

// private key will be serialized as "[REDACTED PrivateKey]" so need to restore it
result["private_key"] = toml::Value::try_from(ExposedPrivateKey(private_key))?;
result["genesis"]["private_key"] =
toml::Value::try_from(ExposedPrivateKey(genesis_private_key))?;

Ok(result)
}
Expand Down
9 changes: 6 additions & 3 deletions core/src/sumeragi/main_loop.rs
Expand Up @@ -271,9 +271,12 @@ impl Sumeragi {
assert_eq!(state_view.latest_block_hash(), None);
}

let genesis_accepted_tx =
AcceptedTransaction::accept_genesis(genesis_network.into_transaction(), &self.chain_id)
.expect("Genesis invalid");
let genesis_accepted_tx = AcceptedTransaction::accept_genesis(
genesis_network.into_transaction(),
&self.chain_id,
genesis_public_key,
)
.expect("Genesis invalid");
let transactions = Vec::from([genesis_accepted_tx]);

let mut state_block = state.block();
Expand Down
12 changes: 11 additions & 1 deletion genesis/src/lib.rs
Expand Up @@ -58,13 +58,23 @@ pub enum GenesisSignatureParseError {
impl std::error::Error for GenesisSignatureParseError {}

/// [`SignedGenesisConfig`] contains data that is used for loading signed genesis from config.
#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode)]
pub struct GenesisSignature {
chain_id: ChainId,
creation_time: Duration,
signatures: SignaturesOf<TransactionPayload>,
}

impl Serialize for GenesisSignature {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
let hex_encoded_string = self.to_hex_string();
hex_encoded_string.serialize(serializer)
}
}

struct GenesisSignatureVisitor;

impl de::Visitor<'_> for GenesisSignatureVisitor {
Expand Down
6 changes: 3 additions & 3 deletions tools/kagami/src/genesis.rs
Expand Up @@ -272,6 +272,9 @@ fn generate_synthetic(
#[command(group = ArgGroup::new("private_key").required(true))]
#[command(group = ArgGroup::new("public_key").required(true))]
pub struct SignArgs {
/// Path to genesis json file
#[clap(long)]
genesis_file: PathBuf,
/// The algorithm of the provided keypair
#[clap(default_value_t, long, short)]
algorithm: crypto::AlgorithmArg,
Expand All @@ -293,9 +296,6 @@ pub struct SignArgs {
/// Unique id of blockchain
#[clap(long)]
chain_id: ChainId,
/// Path to genesis json file
#[clap(long, short)]
genesis_file: PathBuf,
/// Encode signed genesis block with SCALE (it is only supported with file output)
#[clap(long, short, default_value_t = false)]
binary: bool,
Expand Down

0 comments on commit 190ee3d

Please sign in to comment.