diff --git a/toolkit/partner-chains-cli/src/io.rs b/toolkit/partner-chains-cli/src/io.rs index 6b93931fd..7323a2e6b 100644 --- a/toolkit/partner-chains-cli/src/io.rs +++ b/toolkit/partner-chains-cli/src/io.rs @@ -4,6 +4,7 @@ use anyhow::{anyhow, Context}; use jsonrpsee::http_client::HttpClient; use partner_chains_cardano_offchain::d_param::UpsertDParam; use partner_chains_cardano_offchain::init_governance::InitGovernance; +use partner_chains_cardano_offchain::permissioned_candidates::UpsertPermissionedCandidates; use partner_chains_cardano_offchain::scripts_data::GetScriptsData; use sp_core::offchain::Timestamp; use std::path::PathBuf; @@ -16,7 +17,7 @@ use tempfile::{TempDir, TempPath}; pub trait IOContext { /// It should implement all the required traits for offchain operations - type Offchain: GetScriptsData + InitGovernance + UpsertDParam; + type Offchain: GetScriptsData + InitGovernance + UpsertDParam + UpsertPermissionedCandidates; fn run_command(&self, cmd: &str) -> anyhow::Result; fn print(&self, msg: &str); diff --git a/toolkit/partner-chains-cli/src/tests/mod.rs b/toolkit/partner-chains-cli/src/tests/mod.rs index 10e6ddf3a..b154b7600 100644 --- a/toolkit/partner-chains-cli/src/tests/mod.rs +++ b/toolkit/partner-chains-cli/src/tests/mod.rs @@ -4,6 +4,7 @@ use anyhow::anyhow; use ogmios_client::types::OgmiosTx; use partner_chains_cardano_offchain::d_param::UpsertDParam; use partner_chains_cardano_offchain::init_governance::InitGovernance; +use partner_chains_cardano_offchain::permissioned_candidates::UpsertPermissionedCandidates; use partner_chains_cardano_offchain::scripts_data::{GetScriptsData, ScriptsData}; use partner_chains_cardano_offchain::OffchainError; use pretty_assertions::assert_eq; @@ -256,6 +257,10 @@ pub struct OffchainMock { Result, >, pub upsert_d_param: HashMap<(UtxoId, DParameter, [u8; 32]), Result, String>>, + pub upsert_permissioned_candidates: HashMap< + (UtxoId, Vec, [u8; 32]), + Result, String>, + >, } impl OffchainMock { @@ -295,6 +300,23 @@ impl OffchainMock { ) -> Self { Self { upsert_d_param: [((genesis_utxo, d_param, payment_key.0), result)].into(), ..self } } + + pub(crate) fn with_upsert_permissioned_candidates( + self, + genesis_utxo: UtxoId, + candidates: &[sidechain_domain::PermissionedCandidateData], + payment_key: MainchainPrivateKey, + result: Result, String>, + ) -> Self { + Self { + upsert_permissioned_candidates: [( + (genesis_utxo, candidates.to_vec(), payment_key.0), + result, + )] + .into(), + ..self + } + } } impl GetScriptsData for OffchainMock { @@ -338,6 +360,23 @@ impl UpsertDParam for OffchainMock { } } +impl UpsertPermissionedCandidates for OffchainMock { + async fn upsert_permissioned_candidates( + &self, + genesis_utxo: UtxoId, + candidates: &[sidechain_domain::PermissionedCandidateData], + payment_signing_key: [u8; 32], + ) -> anyhow::Result> { + self.upsert_permissioned_candidates + .get(&(genesis_utxo, candidates.to_vec(), payment_signing_key)) + .cloned() + .unwrap_or_else(|| { + Err(format!("No mock for upsert_permissioned_candidates({genesis_utxo:?}, {candidates:?}, {payment_signing_key:?})\n defined mocks:{:?}", self.upsert_permissioned_candidates)) + }) + .map_err(|err| anyhow!("{err}")) + } +} + impl Drop for MockIOContext { fn drop(&mut self) { if std::thread::panicking() { diff --git a/toolkit/primitives/domain/src/lib.rs b/toolkit/primitives/domain/src/lib.rs index 5063b3cac..effceaf31 100644 --- a/toolkit/primitives/domain/src/lib.rs +++ b/toolkit/primitives/domain/src/lib.rs @@ -294,7 +294,7 @@ impl ScEpochNumber { } } -#[derive(Clone, PartialEq, Eq, Encode, Decode, ToDatum, TypeInfo, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Encode, Decode, ToDatum, TypeInfo, PartialOrd, Ord, Hash)] #[byte_string(debug, hex_serialize, hex_deserialize, as_ref)] pub struct SidechainPublicKey(pub Vec); @@ -586,7 +586,7 @@ impl SidechainPublicKeysSorted { } } -#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, PartialOrd, Ord, Hash)] #[byte_string(debug, hex_serialize, hex_deserialize)] pub struct AuraPublicKey(pub Vec); impl AuraPublicKey { @@ -595,7 +595,7 @@ impl AuraPublicKey { } } -#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, PartialOrd, Ord)] +#[derive(Clone, PartialEq, Eq, Encode, Decode, TypeInfo, PartialOrd, Ord, Hash)] #[byte_string(debug, hex_serialize, hex_deserialize)] pub struct GrandpaPublicKey(pub Vec); impl GrandpaPublicKey { @@ -617,7 +617,7 @@ impl DParameter { } } -#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, TypeInfo, PartialOrd, Ord)] +#[derive(Debug, Clone, PartialEq, Eq, Decode, Encode, TypeInfo, PartialOrd, Ord, Hash)] pub struct PermissionedCandidateData { pub sidechain_public_key: SidechainPublicKey, pub aura_public_key: AuraPublicKey,