-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: tidy up test network code & docs
Signed-off-by: 0x009922 <[email protected]>
- Loading branch information
Showing
11 changed files
with
428 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//! Sample configuration builders | ||
use std::path::Path; | ||
|
||
use iroha_config::base::toml::WriteExt; | ||
use iroha_data_model::{ | ||
asset::AssetDefinitionId, | ||
isi::{Grant, Instruction}, | ||
peer::PeerId, | ||
ChainId, | ||
}; | ||
use iroha_executor_data_model::permission::{ | ||
asset::{CanBurnAssetWithDefinition, CanMintAssetWithDefinition}, | ||
domain::CanUnregisterDomain, | ||
executor::CanUpgradeExecutor, | ||
peer::CanUnregisterAnyPeer, | ||
role::CanUnregisterAnyRole, | ||
}; | ||
use iroha_genesis::{GenesisBlock, RawGenesisTransaction}; | ||
use iroha_primitives::unique_vec::UniqueVec; | ||
use iroha_test_samples::{ALICE_ID, SAMPLE_GENESIS_ACCOUNT_KEYPAIR}; | ||
use toml::Table; | ||
|
||
pub fn chain_id() -> ChainId { | ||
ChainId::from("00000000-0000-0000-0000-000000000000") | ||
} | ||
|
||
pub fn base_iroha_config() -> Table { | ||
Table::new() | ||
.write("chain", chain_id()) | ||
.write( | ||
["genesis", "public_key"], | ||
SAMPLE_GENESIS_ACCOUNT_KEYPAIR.public_key(), | ||
) | ||
// There is no need in persistence in tests. | ||
.write(["snapshot", "mode"], "disabled") | ||
.write(["kura", "store_dir"], "./storage") | ||
.write(["network", "block_gossip_size"], 1) | ||
.write(["logger", "level"], "DEBUG") | ||
} | ||
|
||
pub fn genesis<T: Instruction>( | ||
extra_isi: impl IntoIterator<Item = T>, | ||
topology: UniqueVec<PeerId>, | ||
) -> GenesisBlock { | ||
// TODO: Fix this somehow. Probably we need to make `kagami` a library (#3253). | ||
let mut genesis = RawGenesisTransaction::from_path( | ||
Path::new(env!("CARGO_MANIFEST_DIR")).join("../../defaults/genesis.json"), | ||
) | ||
.expect("Failed to deserialize genesis block from file"); | ||
|
||
let rose_definition_id = "rose#wonderland".parse::<AssetDefinitionId>().unwrap(); | ||
|
||
let grant_mint_rose_permission = Grant::account_permission( | ||
CanMintAssetWithDefinition { | ||
asset_definition: rose_definition_id.clone(), | ||
}, | ||
ALICE_ID.clone(), | ||
); | ||
let grant_burn_rose_permission = Grant::account_permission( | ||
CanBurnAssetWithDefinition { | ||
asset_definition: rose_definition_id, | ||
}, | ||
ALICE_ID.clone(), | ||
); | ||
let grant_unregister_any_peer_permission = | ||
Grant::account_permission(CanUnregisterAnyPeer, ALICE_ID.clone()); | ||
let grant_unregister_any_role_permission = | ||
Grant::account_permission(CanUnregisterAnyRole, ALICE_ID.clone()); | ||
let grant_unregister_wonderland_domain = Grant::account_permission( | ||
CanUnregisterDomain { | ||
domain: "wonderland".parse().unwrap(), | ||
}, | ||
ALICE_ID.clone(), | ||
); | ||
let grant_upgrade_executor_permission = | ||
Grant::account_permission(CanUpgradeExecutor, ALICE_ID.clone()); | ||
for isi in [ | ||
grant_mint_rose_permission, | ||
grant_burn_rose_permission, | ||
grant_unregister_any_peer_permission, | ||
grant_unregister_any_role_permission, | ||
grant_unregister_wonderland_domain, | ||
grant_upgrade_executor_permission, | ||
] { | ||
genesis.append_instruction(isi); | ||
} | ||
|
||
for isi in extra_isi.into_iter() { | ||
genesis.append_instruction(isi); | ||
} | ||
|
||
let genesis_key_pair = SAMPLE_GENESIS_ACCOUNT_KEYPAIR.clone(); | ||
genesis | ||
.with_topology(topology.into()) | ||
.build_and_sign(&genesis_key_pair) | ||
.expect("genesis should load fine") | ||
} |
Oops, something went wrong.