Skip to content

Commit

Permalink
Make event more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed May 30, 2023
1 parent 84f79fa commit efb068b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

.idea
**/.DS_Store

.vscode

# The cache for docker container dependency
.cargo
Expand Down
4 changes: 2 additions & 2 deletions pallets/dkg-proposals/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ benchmarks! {
}
}: _(RawOrigin::Signed(caller.clone()), nonce.into(), chain_id, resource_id, proposal.clone())
verify {
assert_last_event::<T>(Event::VoteFor{ chain_id, proposal_nonce: nonce.into(), who: caller, kind: proposal.kind()}.into());
assert_last_event::<T>(Event::VoteFor{ src_chain_id: chain_id, proposal_nonce: nonce.into(), who: caller, kind: proposal.kind()}.into());
}

reject_proposal {
Expand All @@ -169,7 +169,7 @@ benchmarks! {
}
}: _(RawOrigin::Signed(caller.clone()), nonce.into(), chain_id, resource_id, proposal.clone())
verify {
assert_last_event::<T>(Event::VoteAgainst{ chain_id, proposal_nonce: nonce.into(), who: caller,kind: proposal.kind()}.into());
assert_last_event::<T>(Event::VoteAgainst{ src_chain_id: chain_id, proposal_nonce: nonce.into(), who: caller,kind: proposal.kind()}.into());
}

eval_vote_state {
Expand Down
26 changes: 15 additions & 11 deletions pallets/dkg-proposals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,37 +303,41 @@ pub mod pallet {
/// Vote submitted in favour of proposal
VoteFor {
kind: ProposalKind,
chain_id: TypedChainId,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
who: T::AccountId,
},
/// Vot submitted against proposal
VoteAgainst {
kind: ProposalKind,
chain_id: TypedChainId,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
who: T::AccountId,
},
/// Voting successful for a proposal
ProposalApproved {
kind: ProposalKind,
chain_id: TypedChainId,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
},
/// Voting rejected a proposal
ProposalRejected {
kind: ProposalKind,
chain_id: TypedChainId,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
},
/// Execution of call succeeded
ProposalSucceeded {
kind: ProposalKind,
chain_id: TypedChainId,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
},
/// Execution of call failed
ProposalFailed { kind: ProposalKind, chain_id: TypedChainId, proposal_nonce: ProposalNonce },
ProposalFailed {
kind: ProposalKind,
src_chain_id: TypedChainId,
proposal_nonce: ProposalNonce,
},
/// Proposers have been reset
AuthorityProposersReset { proposers: Vec<T::AccountId> },
}
Expand Down Expand Up @@ -707,15 +711,15 @@ impl<T: Config> Pallet<T> {
if in_favour {
votes.votes_for.try_push(who.clone()).map_err(|_| Error::<T>::OutOfBounds)?;
Self::deposit_event(Event::VoteFor {
chain_id: src_chain_id,
src_chain_id,
proposal_nonce: nonce,
kind: prop.kind(),
who,
});
} else {
votes.votes_against.try_push(who.clone()).map_err(|_| Error::<T>::OutOfBounds)?;
Self::deposit_event(Event::VoteAgainst {
chain_id: src_chain_id,
src_chain_id,
proposal_nonce: nonce,
kind: prop.kind(),
who,
Expand Down Expand Up @@ -783,7 +787,7 @@ impl<T: Config> Pallet<T> {
prop: &ProposalOf<T>,
) -> DispatchResultWithPostInfo {
Self::deposit_event(Event::ProposalApproved {
chain_id: src_chain_id,
src_chain_id,
proposal_nonce: nonce,
kind: prop.kind(),
});
Expand All @@ -792,7 +796,7 @@ impl<T: Config> Pallet<T> {
dkg_runtime_primitives::ProposalAction::Sign(0),
)?;
Self::deposit_event(Event::ProposalSucceeded {
chain_id: src_chain_id,
src_chain_id,
proposal_nonce: nonce,
kind: prop.kind(),
});
Expand All @@ -806,7 +810,7 @@ impl<T: Config> Pallet<T> {
prop: &ProposalOf<T>,
) -> DispatchResultWithPostInfo {
Self::deposit_event(Event::ProposalRejected {
chain_id: src_chain_id,
src_chain_id,
proposal_nonce: nonce,
kind: prop.kind(),
});
Expand Down
26 changes: 13 additions & 13 deletions pallets/dkg-proposals/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,25 +325,25 @@ fn create_successful_proposal() {

assert_events(vec![
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteFor {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_A),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteAgainst {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_B),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteFor {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_C),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::ProposalApproved {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
kind: proposal.kind(),
proposal_nonce: prop_id,
}),
Expand All @@ -353,7 +353,7 @@ fn create_successful_proposal() {
data: proposal.data().clone(),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::ProposalSucceeded {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
}),
Expand Down Expand Up @@ -431,25 +431,25 @@ fn create_unsucessful_proposal() {
assert_eq!(Balances::free_balance(mock_pub_key(PROPOSER_B)), 0);
assert_events(vec![
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteFor {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_A),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteAgainst {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
kind: proposal.kind(),
proposal_nonce: prop_id,
who: mock_pub_key(PROPOSER_B),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteAgainst {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
kind: proposal.kind(),
proposal_nonce: prop_id,
who: mock_pub_key(PROPOSER_C),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::ProposalRejected {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
}),
Expand Down Expand Up @@ -509,7 +509,7 @@ fn execute_after_threshold_change() {
assert_eq!(Balances::free_balance(mock_pub_key(PROPOSER_B)), 0);
assert_events(vec![
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteFor {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_A),
Expand All @@ -518,7 +518,7 @@ fn execute_after_threshold_change() {
new_threshold: 1,
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::ProposalApproved {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
}),
Expand All @@ -528,7 +528,7 @@ fn execute_after_threshold_change() {
data: proposal.data().clone(),
}),
RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::ProposalSucceeded {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
}),
Expand Down Expand Up @@ -619,7 +619,7 @@ fn proposal_expires() {
assert_eq!(prop, expected);

assert_events(vec![RuntimeEvent::DKGProposals(pallet_dkg_proposals::Event::VoteFor {
chain_id: typed_chain_id,
src_chain_id: typed_chain_id,
proposal_nonce: prop_id,
kind: proposal.kind(),
who: mock_pub_key(PROPOSER_A),
Expand Down

0 comments on commit efb068b

Please sign in to comment.