Skip to content

Commit

Permalink
Merge branch 'tiago/duped-eth-tally-votes' (#1860)
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Aug 31, 2023
2 parents 80f08b4 + 827cfbe commit 8a131b5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/bug-fixes/1860-duped-eth-tally-votes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Log proper duped validator votes on Ethereum tallies
([\#1860](https://github.com/anoma/namada/pull/1860))
24 changes: 22 additions & 2 deletions ethereum_bridge/src/protocol/transactions/votes/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ impl NewVotes {
let mut inner = self.inner;
let mut removed = HashSet::default();
for voter in voters {
inner.remove(voter);
removed.insert(voter);
if inner.remove(voter).is_some() {
removed.insert(voter);
}
}
(Self { inner }, removed)
}
Expand Down Expand Up @@ -313,6 +314,25 @@ mod tests {
Ok(())
}

#[test]
fn test_vote_info_remove_non_dupe() -> Result<()> {
let validator = address::testing::established_address_1();
let new_validator = address::testing::established_address_2();
let vote_height = BlockHeight(100);
let voting_power = FractionalVotingPower::ONE_THIRD;
let vote = (validator.clone(), vote_height);
let votes = Votes::from([vote.clone()]);
let voting_powers = HashMap::from([(vote, voting_power)]);
let vote_info = NewVotes::new(votes, &voting_powers)?;

let (vote_info, removed) =
vote_info.without_voters(vec![&new_validator]);

assert!(removed.is_empty());
assert_eq!(vote_info.voters(), BTreeSet::from([validator]));
Ok(())
}

#[test]
fn test_apply_duplicate_votes() -> Result<()> {
let mut wl_storage = TestWlStorage::default();
Expand Down

0 comments on commit 8a131b5

Please sign in to comment.