Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sammy committed Jan 9, 2025
1 parent 6f3c4e8 commit af72747
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 108 deletions.
2 changes: 1 addition & 1 deletion ampd/src/handlers/evm_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ mod tests {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
let msg_ids = [
HexTxHashAndEventIndex::new(Hash::random(), 0u64),
HexTxHashAndEventIndex::new(Hash::random(), 1u64),
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/evm_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ mod tests {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
let msg_id = HexTxHashAndEventIndex::new(Hash::random(), 100u64);

voting_verifier::events::Event::VerifierSetPollStarted {
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/mvx_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ mod tests {
assert_eq!(handler.handle(&event).await.unwrap(), vec![]);
}

fn poll_started_event(participants: Vec<TMAddress>) -> voting_verifier::events::EmptyEvent {
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(),
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/mvx_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mod tests {
fn verifier_set_poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
voting_verifier::events::Event::VerifierSetPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "multiversx".parse().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/stellar_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ mod tests {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
voting_verifier::events::Event::MessagesPollStarted {
poll_id: "100".parse().unwrap(),
source_chain: "stellar".parse().unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/stellar_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ mod tests {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
let msg_id = HexTxHashAndEventIndex::new(Hash::random(), 0u64);

voting_verifier::events::Event::VerifierSetPollStarted {
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/sui_verify_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ mod tests {
fn poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
let msg_id = Base58TxDigestAndEventIndex::new(TransactionDigest::random(), 0u64);

voting_verifier::events::Event::MessagesPollStarted {
Expand Down
2 changes: 1 addition & 1 deletion ampd/src/handlers/sui_verify_verifier_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
fn verifier_set_poll_started_event(
participants: Vec<TMAddress>,
expires_at: u64,
) -> voting_verifier::events::EmptyEvent {
) -> voting_verifier::events::Event {
let msg_id = Base58TxDigestAndEventIndex::new(TransactionDigest::random(), 0u64);

voting_verifier::events::Event::VerifierSetPollStarted {
Expand Down
7 changes: 4 additions & 3 deletions contracts/voting-verifier/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Empty, Env, MessageInf
use error_stack::ResultExt;

use crate::error::ContractError;
use crate::events::EmptyEvent;
use crate::events::Event;
use crate::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use crate::state::{Config, CONFIG};

Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn instantiate(
};
CONFIG.save(deps.storage, &config)?;

Ok(Response::new().add_event(EmptyEvent::Instantiated {
let event: Event = Event::Instantiated {
service_registry_contract: config.service_registry_contract,
service_name: config.service_name,
source_gateway_address: config.source_gateway_address,
Expand All @@ -61,7 +61,8 @@ pub fn instantiate(
rewards_contract: config.rewards_contract,
msg_id_format: config.msg_id_format,
address_format: config.address_format,
}))
};
Ok(Response::new().add_event(event))
}

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
60 changes: 30 additions & 30 deletions contracts/voting-verifier/src/contract/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use service_registry::WeightedVerifier;

use crate::contract::query::{message_status, verifier_set_status};
use crate::error::ContractError;
use crate::events::{EmptyEvent, Event, TxEventConfirmation, VerifierSetConfirmation};
use crate::events::{Event, TxEventConfirmation, VerifierSetConfirmation};
use crate::state::{
self, poll_messages, poll_verifier_sets, Poll, PollContent, CONFIG, POLLS, POLL_ID, VOTES,
};
Expand Down Expand Up @@ -64,21 +64,20 @@ pub fn verify_verifier_set(
)
.change_context(ContractError::StorageError)?;

Ok(
Response::new().add_event(EmptyEvent::VerifierSetPollStarted {
verifier_set: VerifierSetConfirmation::new(
message_id,
config.msg_id_format,
new_verifier_set,
)?,
poll_id,
source_chain: config.source_chain,
source_gateway_address: config.source_gateway_address,
confirmation_height: config.confirmation_height,
expires_at,
participants,
}),
)
let event: Event = Event::VerifierSetPollStarted {
verifier_set: VerifierSetConfirmation::new(
message_id,
config.msg_id_format,
new_verifier_set,
)?,
poll_id,
source_chain: config.source_chain,
source_gateway_address: config.source_gateway_address,
confirmation_height: config.confirmation_height,
expires_at,
participants,
};
Ok(Response::new().add_event(event))
}

pub fn verify_messages(
Expand Down Expand Up @@ -141,15 +140,16 @@ pub fn verify_messages(
})
.collect::<Result<Vec<TxEventConfirmation>, _>>()?;

Ok(Response::new().add_event(EmptyEvent::MessagesPollStarted {
let event: Event = Event::MessagesPollStarted {
messages,
poll_id: id,
source_chain: config.source_chain,
source_gateway_address: config.source_gateway_address,
confirmation_height: config.confirmation_height,
expires_at,
participants,
}))
};
Ok(Response::new().add_event(event))
}

fn poll_results(poll: &Poll) -> PollResults {
Expand Down Expand Up @@ -249,12 +249,13 @@ pub fn vote(
.save(deps.storage, (poll_id, info.sender.to_string()), &votes)
.change_context(ContractError::StorageError)?;

let event: Event = Event::Voted {
poll_id,
voter: info.sender,
votes,
};
Ok(Response::new()
.add_event(EmptyEvent::Voted {
poll_id,
voter: info.sender,
votes,
})
.add_event(event)
.add_events(quorum_events.into_iter().flatten()))
}

Expand Down Expand Up @@ -301,13 +302,12 @@ pub fn end_poll(deps: DepsMut, env: Env, poll_id: PollId) -> Result<Response, Co
funds: vec![],
});

Ok(Response::new()
.add_messages(rewards_msgs)
.add_event(EmptyEvent::PollEnded {
poll_id: poll_result.poll_id,
results: poll_result.results.0.clone(),
source_chain: config.source_chain,
}))
let event: Event = Event::PollEnded {
poll_id: poll_result.poll_id,
results: poll_result.results.0.clone(),
source_chain: config.source_chain.clone(),
};
Ok(Response::new().add_messages(rewards_msgs).add_event(event))
}

fn take_snapshot(deps: Deps, chain: &ChainName) -> Result<snapshot::Snapshot, ContractError> {
Expand Down
86 changes: 39 additions & 47 deletions contracts/voting-verifier/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use serde::Serialize;
use crate::error::ContractError;

#[derive(Serialize, IntoEvent)]
pub enum Event<T>
pub enum Event<T = Empty>
where
T: Serialize,
{
Expand Down Expand Up @@ -68,8 +68,6 @@ where
},
}

pub type EmptyEvent = Event<Empty>;

#[cw_serde]
pub struct VerifierSetConfirmation {
#[deprecated(since = "1.1.0", note = "use message_id field instead")]
Expand Down Expand Up @@ -208,16 +206,15 @@ mod test {
use axelar_wasm_std::voting::Vote;
use axelar_wasm_std::{nonempty, Threshold, VerificationStatus};
use cosmwasm_std::testing::MockApi;
use cosmwasm_std::{Attribute, Uint128};
use cosmwasm_std::Uint128;
use multisig::key::KeyType;
use multisig::test::common::{build_verifier_set, ecdsa_test_data};
use multisig::verifier_set::VerifierSet;
use router_api::{CrossChainId, Message};
use serde_json::json;

use super::{TxEventConfirmation, VerifierSetConfirmation};
use crate::events::{PollEnded, PollMetadata, PollStarted, QuorumReached, Voted};
use crate::state::Config;
use crate::events::Event;

fn random_32_bytes() -> [u8; 32] {
let mut bytes = [0; 32];
Expand Down Expand Up @@ -401,9 +398,9 @@ mod test {
fn events_should_not_change() {
let api = MockApi::default();

let config = Config {
service_name: "serviceName".try_into().unwrap(),
let event: Event = Event::Instantiated {
service_registry_contract: api.addr_make("serviceRegistry_contract"),
service_name: "serviceName".try_into().unwrap(),
source_gateway_address: "sourceGatewayAddress".try_into().unwrap(),
voting_threshold: Threshold::try_from((2, 3)).unwrap().try_into().unwrap(),
block_expiry: 10u64.try_into().unwrap(),
Expand All @@ -413,10 +410,9 @@ mod test {
msg_id_format: MessageIdFormat::HexTxHashAndEventIndex,
address_format: AddressFormat::Eip55,
};
let event_instantiated =
cosmwasm_std::Event::new("instantiated").add_attributes(<Vec<Attribute>>::from(config));
let event_instantiated: cosmwasm_std::Event = event.into();

let event_messages_poll_started: cosmwasm_std::Event = PollStarted::Messages {
let event: Event = Event::MessagesPollStarted {
messages: vec![
TxEventConfirmation {
tx_id: "txId1".try_into().unwrap(),
Expand All @@ -437,58 +433,54 @@ mod test {
payload_hash: [1; 32],
},
],
metadata: PollMetadata {
poll_id: 1.into(),
source_chain: "sourceChain".try_into().unwrap(),
source_gateway_address: "sourceGatewayAddress".try_into().unwrap(),
confirmation_height: 1,
expires_at: 1,
participants: vec![
api.addr_make("participant1"),
api.addr_make("participant2"),
api.addr_make("participant3"),
],
},
}
.into();
poll_id: 1.into(),
source_chain: "sourceChain".try_into().unwrap(),
source_gateway_address: "sourceGatewayAddress".try_into().unwrap(),
confirmation_height: 1,
expires_at: 1,
participants: vec![
api.addr_make("participant1"),
api.addr_make("participant2"),
api.addr_make("participant3"),
],
};
let event_messages_poll_started: cosmwasm_std::Event = event.into();

let event_verifier_set_poll_started: cosmwasm_std::Event = PollStarted::VerifierSet {
let event: Event = Event::VerifierSetPollStarted {
verifier_set: VerifierSetConfirmation {
tx_id: "txId".try_into().unwrap(),
event_index: 1,
message_id: "messageId".try_into().unwrap(),
verifier_set: build_verifier_set(KeyType::Ecdsa, &ecdsa_test_data::signers()),
},
metadata: PollMetadata {
poll_id: 2.into(),
source_chain: "sourceChain".try_into().unwrap(),
source_gateway_address: "sourceGatewayAddress".try_into().unwrap(),
confirmation_height: 1,
expires_at: 1,
participants: vec![
api.addr_make("participant4"),
api.addr_make("participant5"),
api.addr_make("participant6"),
],
},
}
.into();
poll_id: 2.into(),
source_chain: "sourceChain".try_into().unwrap(),
source_gateway_address: "sourceGatewayAddress".try_into().unwrap(),
confirmation_height: 1,
expires_at: 1,
participants: vec![
api.addr_make("participant4"),
api.addr_make("participant5"),
api.addr_make("participant6"),
],
};
let event_verifier_set_poll_started: cosmwasm_std::Event = event.into();

let event_quorum_reached: cosmwasm_std::Event = QuorumReached {
let event_quorum_reached: cosmwasm_std::Event = Event::QuorumReached {
content: "content".to_string(),
status: VerificationStatus::NotFoundOnSourceChain,
poll_id: 1.into(),
}
.into();

let event_voted: cosmwasm_std::Event = Voted {
let event: Event = Event::Voted {
poll_id: 1.into(),
voter: api.addr_make("voter"),
votes: vec![Vote::SucceededOnChain, Vote::FailedOnChain, Vote::NotFound],
}
.into();
};
let event_voted: cosmwasm_std::Event = event.into();

let event_poll_ended: cosmwasm_std::Event = PollEnded {
let event: Event = Event::PollEnded {
poll_id: 1.into(),
source_chain: "sourceChain".try_into().unwrap(),
results: vec![
Expand All @@ -497,8 +489,8 @@ mod test {
Some(Vote::NotFound),
None,
],
}
.into();
};
let event_poll_ended: cosmwasm_std::Event = event.into();

goldie::assert_json!(json!({
"event_instantiated": event_instantiated,
Expand Down
Loading

0 comments on commit af72747

Please sign in to comment.