Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(minor-voting-verifier): integrate the voting-verifier with the into-event macro #743

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

34 changes: 18 additions & 16 deletions ampd/src/handlers/evm_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mod tests {
use router_api::ChainName;
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, TxEventConfirmation};
use voting_verifier::events::TxEventConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand All @@ -245,26 +245,28 @@ mod tests {
use crate::types::TMAddress;
use crate::PREFIX;

fn poll_started_event(participants: Vec<TMAddress>, expires_at: u64) -> PollStarted {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::Event {
let msg_ids = [
HexTxHashAndEventIndex::new(H256::repeat_byte(1), 0u64),
HexTxHashAndEventIndex::new(H256::repeat_byte(2), 1u64),
HexTxHashAndEventIndex::new(H256::repeat_byte(3), 10u64),
];
PollStarted::Messages {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},

voting_verifier::events::Event::MessagesPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
#[allow(deprecated)] // TODO: The below events use the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
messages: vec![
TxEventConfirmation {
Expand Down
34 changes: 18 additions & 16 deletions ampd/src/handlers/evm_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod tests {
use router_api::ChainName;
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, VerifierSetConfirmation};
use voting_verifier::events::VerifierSetConfirmation;

use crate::event_processor::EventHandler;
use crate::evm::finalizer::Finalization;
Expand Down Expand Up @@ -268,29 +268,31 @@ mod tests {
assert_eq!(handler.handle(&event).await.unwrap(), vec![]);
}

fn poll_started_event(participants: Vec<TMAddress>, expires_at: u64) -> PollStarted {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::Event {
let msg_id = HexTxHashAndEventIndex::new(H256::repeat_byte(1), 100u64);
PollStarted::VerifierSet {

voting_verifier::events::Event::VerifierSetPollStarted {
#[allow(deprecated)] // TODO: The below event uses the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
verifier_set: VerifierSetConfirmation {
tx_id: msg_id.tx_hash_as_hex(),
event_index: u32::try_from(msg_id.event_index).unwrap(),
message_id: msg_id.to_string().parse().unwrap(),
verifier_set: build_verifier_set(KeyType::Ecdsa, &ecdsa_test_data::signers()),
},
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},
poll_id: "100".parse().unwrap(),
source_chain: "ethereum".parse().unwrap(),
source_gateway_address: "0x4f4495243837681061c4743b74eedf548d5686a5"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
}
}
}
32 changes: 15 additions & 17 deletions ampd/src/handlers/mvx_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod tests {
use hex::ToHex;
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, TxEventConfirmation};
use voting_verifier::events::TxEventConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -299,22 +299,20 @@ mod tests {
assert_eq!(handler.handle(&event).await.unwrap(), vec![]);
}

fn poll_started_event(participants: Vec<TMAddress>) -> PollStarted {
PollStarted::Messages {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "multiversx".parse().unwrap(),
source_gateway_address:
"erd1qqqqqqqqqqqqqpgqsvzyz88e8v8j6x3wquatxuztnxjwnw92kkls6rdtzx"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at: 100,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},
fn poll_started_event(participants: Vec<TMAddress>) -> voting_verifier::events::Event {
voting_verifier::events::Event::MessagesPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "multiversx".parse().unwrap(),
source_gateway_address:
"erd1qqqqqqqqqqqqqpgqsvzyz88e8v8j6x3wquatxuztnxjwnw92kkls6rdtzx"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at: 100,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
#[allow(deprecated)] // TODO: The below event uses the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
messages: vec![TxEventConfirmation {
tx_id: "dfaf64de66510723f2efbacd7ead3c4f8c856aed1afc2cb30254552aeda47312"
Expand Down
32 changes: 15 additions & 17 deletions ampd/src/handlers/mvx_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ mod tests {
use multisig::test::common::{build_verifier_set, ed25519_test_data};
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, VerifierSetConfirmation};
use voting_verifier::events::VerifierSetConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -309,22 +309,20 @@ mod tests {
fn verifier_set_poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> PollStarted {
PollStarted::VerifierSet {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "multiversx".parse().unwrap(),
source_gateway_address:
"erd1qqqqqqqqqqqqqpgqsvzyz88e8v8j6x3wquatxuztnxjwnw92kkls6rdtzx"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},
) -> voting_verifier::events::Event {
voting_verifier::events::Event::VerifierSetPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "multiversx".parse().unwrap(),
source_gateway_address:
"erd1qqqqqqqqqqqqqpgqsvzyz88e8v8j6x3wquatxuztnxjwnw92kkls6rdtzx"
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
#[allow(deprecated)] // TODO: The below event uses the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
verifier_set: VerifierSetConfirmation {
tx_id: "dfaf64de66510723f2efbacd7ead3c4f8c856aed1afc2cb30254552aeda47312"
Expand Down
35 changes: 18 additions & 17 deletions ampd/src/handlers/stellar_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod tests {
use stellar_xdr::curr::ScAddress;
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, TxEventConfirmation};
use voting_verifier::events::TxEventConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -299,22 +299,23 @@ mod tests {
assert!(MsgExecuteContract::from_any(actual.first().unwrap()).is_ok());
}

fn poll_started_event(participants: Vec<TMAddress>, expires_at: u64) -> PollStarted {
PollStarted::Messages {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "stellar".parse().unwrap(),
source_gateway_address: ScAddress::Contract(stellar_xdr::curr::Hash::from([1; 32]))
.to_string()
.try_into()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::Event {
voting_verifier::events::Event::MessagesPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "stellar".parse().unwrap(),
source_gateway_address: ScAddress::Contract(stellar_xdr::curr::Hash::from([1; 32]))
.to_string()
.try_into()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
messages: (0..2)
.map(|i| {
let msg_id = HexTxHashAndEventIndex::new([3; 32], i as u64);
Expand Down
36 changes: 19 additions & 17 deletions ampd/src/handlers/stellar_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ mod tests {
use stellar_xdr::curr::ScAddress;
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, VerifierSetConfirmation};
use voting_verifier::events::VerifierSetConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -279,23 +279,25 @@ mod tests {
assert!(MsgExecuteContract::from_any(actual.first().unwrap()).is_ok());
}

fn poll_started_event(participants: Vec<TMAddress>, expires_at: u64) -> PollStarted {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::Event {
let msg_id = HexTxHashAndEventIndex::new([1; 32], 0u64);
PollStarted::VerifierSet {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "stellar".parse().unwrap(),
source_gateway_address: ScAddress::Contract(stellar_xdr::curr::Hash::from([2; 32]))
.to_string()
.try_into()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},

voting_verifier::events::Event::VerifierSetPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "stellar".parse().unwrap(),
source_gateway_address: ScAddress::Contract(stellar_xdr::curr::Hash::from([2; 32]))
.to_string()
.try_into()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
#[allow(deprecated)] // TODO: The below event uses the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
verifier_set: VerifierSetConfirmation {
tx_id: msg_id.tx_hash_as_hex(),
Expand Down
38 changes: 20 additions & 18 deletions ampd/src/handlers/sui_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod tests {
use sui_types::base_types::{SuiAddress, SUI_ADDRESS_LENGTH};
use tokio::sync::watch;
use tokio::test as async_test;
use voting_verifier::events::{PollMetadata, PollStarted, TxEventConfirmation};
use voting_verifier::events::TxEventConfirmation;

use super::PollStartedEvent;
use crate::event_processor::EventHandler;
Expand Down Expand Up @@ -327,24 +327,26 @@ mod tests {
assert_eq!(handler.handle(&event).await.unwrap(), vec![]);
}

fn poll_started_event(participants: Vec<TMAddress>, expires_at: u64) -> PollStarted {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::Event {
let msg_id = Base58TxDigestAndEventIndex::new([1; 32], 0u64);
PollStarted::Messages {
metadata: PollMetadata {
poll_id: "100".parse().unwrap(),
source_chain: "sui".parse().unwrap(),
source_gateway_address: SuiAddress::from_bytes([3; SUI_ADDRESS_LENGTH])
.unwrap()
.to_string()
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
},

voting_verifier::events::Event::MessagesPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "sui".parse().unwrap(),
source_gateway_address: SuiAddress::from_bytes([3; SUI_ADDRESS_LENGTH])
.unwrap()
.to_string()
.parse()
.unwrap(),
confirmation_height: 15,
expires_at,
participants: participants
.into_iter()
.map(|addr| cosmwasm_std::Addr::unchecked(addr.to_string()))
.collect(),
#[allow(deprecated)] // TODO: The below event uses the deprecated tx_id and event_index fields. Remove this attribute when those fields are removed
messages: vec![TxEventConfirmation {
tx_id: msg_id.tx_digest_as_base58(),
Expand Down
Loading
Loading