From af7274774c63a074deb6ab1f8587b12b26daeec8 Mon Sep 17 00:00:00 2001 From: Sammy Date: Thu, 9 Jan 2025 13:45:33 -0500 Subject: [PATCH] fix test --- ampd/src/handlers/evm_verify_msg.rs | 2 +- ampd/src/handlers/evm_verify_verifier_set.rs | 2 +- ampd/src/handlers/mvx_verify_msg.rs | 2 +- ampd/src/handlers/mvx_verify_verifier_set.rs | 2 +- ampd/src/handlers/stellar_verify_msg.rs | 2 +- .../handlers/stellar_verify_verifier_set.rs | 2 +- ampd/src/handlers/sui_verify_msg.rs | 2 +- ampd/src/handlers/sui_verify_verifier_set.rs | 2 +- contracts/voting-verifier/src/contract.rs | 7 +- .../voting-verifier/src/contract/execute.rs | 60 ++++++------- contracts/voting-verifier/src/events.rs | 86 +++++++++---------- .../testdata/events_should_not_change.golden | 26 +++--- packages/axelar-wasm-std-derive/src/lib.rs | 17 ++-- 13 files changed, 104 insertions(+), 108 deletions(-) diff --git a/ampd/src/handlers/evm_verify_msg.rs b/ampd/src/handlers/evm_verify_msg.rs index 563f6d3e5..fc4d15677 100644 --- a/ampd/src/handlers/evm_verify_msg.rs +++ b/ampd/src/handlers/evm_verify_msg.rs @@ -248,7 +248,7 @@ mod tests { fn poll_started_event( participants: Vec, expires_at: u64, - ) -> voting_verifier::events::EmptyEvent { + ) -> voting_verifier::events::Event { let msg_ids = [ HexTxHashAndEventIndex::new(Hash::random(), 0u64), HexTxHashAndEventIndex::new(Hash::random(), 1u64), diff --git a/ampd/src/handlers/evm_verify_verifier_set.rs b/ampd/src/handlers/evm_verify_verifier_set.rs index 95e02e429..814aeb5a2 100644 --- a/ampd/src/handlers/evm_verify_verifier_set.rs +++ b/ampd/src/handlers/evm_verify_verifier_set.rs @@ -272,7 +272,7 @@ mod tests { fn poll_started_event( participants: Vec, expires_at: u64, - ) -> voting_verifier::events::EmptyEvent { + ) -> voting_verifier::events::Event { let msg_id = HexTxHashAndEventIndex::new(Hash::random(), 100u64); voting_verifier::events::Event::VerifierSetPollStarted { diff --git a/ampd/src/handlers/mvx_verify_msg.rs b/ampd/src/handlers/mvx_verify_msg.rs index ef824a440..efe2d3c2d 100644 --- a/ampd/src/handlers/mvx_verify_msg.rs +++ b/ampd/src/handlers/mvx_verify_msg.rs @@ -299,7 +299,7 @@ mod tests { assert_eq!(handler.handle(&event).await.unwrap(), vec![]); } - fn poll_started_event(participants: Vec) -> voting_verifier::events::EmptyEvent { + fn poll_started_event(participants: Vec) -> voting_verifier::events::Event { voting_verifier::events::Event::MessagesPollStarted { poll_id: "100".parse().unwrap(), source_chain: "multiversx".parse().unwrap(), diff --git a/ampd/src/handlers/mvx_verify_verifier_set.rs b/ampd/src/handlers/mvx_verify_verifier_set.rs index 5abaa12e0..80c2c54a6 100644 --- a/ampd/src/handlers/mvx_verify_verifier_set.rs +++ b/ampd/src/handlers/mvx_verify_verifier_set.rs @@ -307,7 +307,7 @@ mod tests { fn verifier_set_poll_started_event( participants: Vec, 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(), diff --git a/ampd/src/handlers/stellar_verify_msg.rs b/ampd/src/handlers/stellar_verify_msg.rs index ba74bf0b7..a09d83d27 100644 --- a/ampd/src/handlers/stellar_verify_msg.rs +++ b/ampd/src/handlers/stellar_verify_msg.rs @@ -300,7 +300,7 @@ mod tests { fn poll_started_event( participants: Vec, 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(), diff --git a/ampd/src/handlers/stellar_verify_verifier_set.rs b/ampd/src/handlers/stellar_verify_verifier_set.rs index 0669e5c4d..b95de7389 100644 --- a/ampd/src/handlers/stellar_verify_verifier_set.rs +++ b/ampd/src/handlers/stellar_verify_verifier_set.rs @@ -281,7 +281,7 @@ mod tests { fn poll_started_event( participants: Vec, expires_at: u64, - ) -> voting_verifier::events::EmptyEvent { + ) -> voting_verifier::events::Event { let msg_id = HexTxHashAndEventIndex::new(Hash::random(), 0u64); voting_verifier::events::Event::VerifierSetPollStarted { diff --git a/ampd/src/handlers/sui_verify_msg.rs b/ampd/src/handlers/sui_verify_msg.rs index e384682d9..6c8eab2b1 100644 --- a/ampd/src/handlers/sui_verify_msg.rs +++ b/ampd/src/handlers/sui_verify_msg.rs @@ -327,7 +327,7 @@ mod tests { fn poll_started_event( participants: Vec, expires_at: u64, - ) -> voting_verifier::events::EmptyEvent { + ) -> voting_verifier::events::Event { let msg_id = Base58TxDigestAndEventIndex::new(TransactionDigest::random(), 0u64); voting_verifier::events::Event::MessagesPollStarted { diff --git a/ampd/src/handlers/sui_verify_verifier_set.rs b/ampd/src/handlers/sui_verify_verifier_set.rs index 4d9f4b30f..fe78d9312 100644 --- a/ampd/src/handlers/sui_verify_verifier_set.rs +++ b/ampd/src/handlers/sui_verify_verifier_set.rs @@ -223,7 +223,7 @@ mod tests { fn verifier_set_poll_started_event( participants: Vec, expires_at: u64, - ) -> voting_verifier::events::EmptyEvent { + ) -> voting_verifier::events::Event { let msg_id = Base58TxDigestAndEventIndex::new(TransactionDigest::random(), 0u64); voting_verifier::events::Event::VerifierSetPollStarted { diff --git a/contracts/voting-verifier/src/contract.rs b/contracts/voting-verifier/src/contract.rs index 4317922b4..93d17e2ea 100644 --- a/contracts/voting-verifier/src/contract.rs +++ b/contracts/voting-verifier/src/contract.rs @@ -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}; @@ -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, @@ -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)] diff --git a/contracts/voting-verifier/src/contract/execute.rs b/contracts/voting-verifier/src/contract/execute.rs index c2bdcee81..a73f953f8 100644 --- a/contracts/voting-verifier/src/contract/execute.rs +++ b/contracts/voting-verifier/src/contract/execute.rs @@ -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, }; @@ -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( @@ -141,7 +140,7 @@ pub fn verify_messages( }) .collect::, _>>()?; - Ok(Response::new().add_event(EmptyEvent::MessagesPollStarted { + let event: Event = Event::MessagesPollStarted { messages, poll_id: id, source_chain: config.source_chain, @@ -149,7 +148,8 @@ pub fn verify_messages( confirmation_height: config.confirmation_height, expires_at, participants, - })) + }; + Ok(Response::new().add_event(event)) } fn poll_results(poll: &Poll) -> PollResults { @@ -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())) } @@ -301,13 +302,12 @@ pub fn end_poll(deps: DepsMut, env: Env, poll_id: PollId) -> Result Result { diff --git a/contracts/voting-verifier/src/events.rs b/contracts/voting-verifier/src/events.rs index adf7b4eff..bf560cbef 100644 --- a/contracts/voting-verifier/src/events.rs +++ b/contracts/voting-verifier/src/events.rs @@ -17,7 +17,7 @@ use serde::Serialize; use crate::error::ContractError; #[derive(Serialize, IntoEvent)] -pub enum Event +pub enum Event where T: Serialize, { @@ -68,8 +68,6 @@ where }, } -pub type EmptyEvent = Event; - #[cw_serde] pub struct VerifierSetConfirmation { #[deprecated(since = "1.1.0", note = "use message_id field instead")] @@ -208,7 +206,7 @@ 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; @@ -216,8 +214,7 @@ mod test { 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]; @@ -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(), @@ -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(>::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(), @@ -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![ @@ -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, diff --git a/contracts/voting-verifier/src/testdata/events_should_not_change.golden b/contracts/voting-verifier/src/testdata/events_should_not_change.golden index 2ecaacc3c..8eb97de63 100644 --- a/contracts/voting-verifier/src/testdata/events_should_not_change.golden +++ b/contracts/voting-verifier/src/testdata/events_should_not_change.golden @@ -2,16 +2,16 @@ "event_instantiated": { "attributes": [ { - "key": "service_name", - "value": "serviceName" + "key": "service_registry_contract", + "value": "\"cosmwasm19d2spdjdycg0tfu27n2zrkwvr25yxwykaxvxwkpnf7hqkka93j4sfp809w\"" }, { - "key": "service_registry_contract", - "value": "cosmwasm19d2spdjdycg0tfu27n2zrkwvr25yxwykaxvxwkpnf7hqkka93j4sfp809w" + "key": "service_name", + "value": "\"serviceName\"" }, { "key": "source_gateway_address", - "value": "sourceGatewayAddress" + "value": "\"sourceGatewayAddress\"" }, { "key": "voting_threshold", @@ -19,7 +19,7 @@ }, { "key": "block_expiry", - "value": "10" + "value": "\"10\"" }, { "key": "confirmation_height", @@ -27,11 +27,11 @@ }, { "key": "source_chain", - "value": "sourcechain" + "value": "\"sourcechain\"" }, { "key": "rewards_contract", - "value": "cosmwasm1wyhnds94w36ar6jlz4aaaz75cmypwmr0rqnc92nm5m79ejy04hnsx25urh" + "value": "\"cosmwasm1wyhnds94w36ar6jlz4aaaz75cmypwmr0rqnc92nm5m79ejy04hnsx25urh\"" }, { "key": "msg_id_format", @@ -56,11 +56,11 @@ }, { "key": "source_chain", - "value": "sourcechain" + "value": "\"sourcechain\"" }, { "key": "source_gateway_address", - "value": "sourceGatewayAddress" + "value": "\"sourceGatewayAddress\"" }, { "key": "confirmation_height", @@ -123,11 +123,11 @@ }, { "key": "source_chain", - "value": "sourcechain" + "value": "\"sourcechain\"" }, { "key": "source_gateway_address", - "value": "sourceGatewayAddress" + "value": "\"sourceGatewayAddress\"" }, { "key": "confirmation_height", @@ -152,7 +152,7 @@ }, { "key": "voter", - "value": "cosmwasm12ehr5qctpa78s2r2luz4lqyuzm955nxvj5msmptpatlf3qzj0xds4lvke5" + "value": "\"cosmwasm12ehr5qctpa78s2r2luz4lqyuzm955nxvj5msmptpatlf3qzj0xds4lvke5\"" }, { "key": "votes", diff --git a/packages/axelar-wasm-std-derive/src/lib.rs b/packages/axelar-wasm-std-derive/src/lib.rs index 7dfc7876b..c775ace4b 100644 --- a/packages/axelar-wasm-std-derive/src/lib.rs +++ b/packages/axelar-wasm-std-derive/src/lib.rs @@ -46,7 +46,7 @@ pub fn into_contract_error_derive(input: TokenStream) -> TokenStream { /// } /// /// #[derive(IntoEvent)] -/// enum SomeEvents where +/// enum SomeEvents where /// T: Serialize, /// U: Serialize /// { @@ -64,15 +64,17 @@ pub fn into_contract_error_derive(input: TokenStream) -> TokenStream { /// } /// } /// -/// let actual = Event::from(SomeEvents::SomeEmptyEvent::); +/// let actual: SomeEvents = SomeEvents::SomeEmptyEvent; +/// let actual: Event = actual.into(); /// let expected = Event::new("some_empty_event"); /// assert_eq!(actual, expected); /// -/// let actual = Event::from(SomeEvents::SomeOtherEmptyEvent:: {}); +/// let actual: SomeEvents = SomeEvents::SomeOtherEmptyEvent {}; +/// let actual: Event = actual.into(); /// let expected = Event::new("some_other_empty_event"); /// assert_eq!(actual, expected); /// -/// let actual = Event::from(SomeEvents::SomeEvent:: { +/// let actual: SomeEvents = SomeEvents::SomeEvent { /// some_uint: 42, /// some_string: "some string".to_string(), /// some_bool: true, @@ -82,7 +84,8 @@ pub fn into_contract_error_derive(input: TokenStream) -> TokenStream { /// some_vec: vec!["a".to_string(), "b".to_string()], /// some_map: [("a".to_string(), "b".to_string()), ("c".to_string(), "d".to_string()), ("e".to_string(), "f".to_string())].into_iter().collect(), /// }, -/// }); +/// }; +/// let actual: Event = actual.into(); /// let expected = Event::new("some_event") /// .add_attribute("some_uint", "42") /// .add_attribute("some_string", "\"some string\"") @@ -90,10 +93,10 @@ pub fn into_contract_error_derive(input: TokenStream) -> TokenStream { /// .add_attribute("some_object", "{\"some_option\":\"some option\",\"some_other_option\":null,\"some_vec\":[\"a\",\"b\"],\"some_map\":{\"a\":\"b\",\"c\":\"d\",\"e\":\"f\"}}"); /// assert_eq!(actual, expected); /// -/// let actual = Event::from(SomeEvents::SomeGenericsEvent:: { +/// let actual: Event = SomeEvents::SomeGenericsEvent { /// some_generics: "some generics".to_string(), /// some_other_generics: 42, -/// }); +/// }.into(); /// let expected = Event::new("some_generics_event") /// .add_attribute("some_generics", "\"some generics\"") /// .add_attribute("some_other_generics", "42");