Skip to content

Commit

Permalink
refactor: streamline GenesisBuilder RawGenesisTransaction `Genesi…
Browse files Browse the repository at this point in the history
…sBlock` flow (#5191)

Signed-off-by: Shunkichi Sato <49983831+s8sato@users.noreply.github.com>
  • Loading branch information
s8sato authored Oct 25, 2024
1 parent 84c117a commit aa4d60b
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 235 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions crates/iroha_core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,9 @@ mod tests {
use iroha_data_model::{
account::Account,
domain::{Domain, DomainId},
executor::Executor,
isi::Log,
peer::PeerId,
transaction::{TransactionBuilder, WasmSmartContract},
transaction::TransactionBuilder,
ChainId, Level,
};
use iroha_genesis::GenesisBuilder;
Expand Down Expand Up @@ -1111,16 +1110,11 @@ mod tests {
live_query_store,
);

let executor = {
let executor_blob = std::fs::read("../../defaults/executor.wasm").unwrap();
Executor::new(WasmSmartContract::from_compiled(executor_blob))
};
let genesis = GenesisBuilder::default().build_and_sign(
chain_id.clone(),
executor,
topology.as_ref().to_owned(),
&genesis_key_pair,
);
let executor_path = PathBuf::from("../../defaults/executor.wasm").into();
let genesis = GenesisBuilder::new(chain_id.clone(), executor_path)
.set_topology(topology.as_ref().to_owned())
.build_and_sign(&genesis_key_pair)
.expect("genesis block should be built");

{
let mut state_block = state.block(genesis.0.header());
Expand Down
9 changes: 9 additions & 0 deletions crates/iroha_data_model/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ impl Default for SmartContractParameters {
}
}

impl FromIterator<Parameter> for Parameters {
fn from_iter<T: IntoIterator<Item = Parameter>>(iter: T) -> Self {
iter.into_iter().fold(Parameters::default(), |mut acc, x| {
acc.set_parameter(x);
acc
})
}
}

impl Parameters {
/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = Parameter> + '_ {
Expand Down
2 changes: 2 additions & 0 deletions crates/iroha_genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ parity-scale-codec = { workspace = true }
[dev-dependencies]
iroha_crypto = { workspace = true, features = ["rand"] }
iroha_test_samples = { workspace = true }

tempfile = { workspace = true }
Loading

0 comments on commit aa4d60b

Please sign in to comment.