diff --git a/solar_crypto/transactions/builder/vote.py b/solar_crypto/transactions/builder/vote.py index 573c20b..3703cd9 100644 --- a/solar_crypto/transactions/builder/vote.py +++ b/solar_crypto/transactions/builder/vote.py @@ -72,13 +72,13 @@ def set_votes( def validate(votes): - if sum(votes.values()) > 100: - raise SolarInvalidTransaction("Total vote weight must not be greater than 100.") - for value in votes.values(): if not valid_precision(value): raise SolarInvalidTransaction("Only two decimal places are allowed.") + if Decimal(sum(votes.values())) != Decimal("100"): + raise SolarInvalidTransaction("Total vote weight must equal 100.") + def valid_precision(value, max_precision=2): if isinstance(value, Decimal): diff --git a/tests/transactions/builder/test_vote.py b/tests/transactions/builder/test_vote.py index 33b04bc..60ffb34 100644 --- a/tests/transactions/builder/test_vote.py +++ b/tests/transactions/builder/test_vote.py @@ -13,7 +13,7 @@ def test_vote_transaction_input_error(): - vote = {"deadlock": 50.3333} + vote = {"fun": 50.67, "deadlock": 50.3333} transaction = Vote() with pytest.raises(SolarInvalidTransaction) as e: @@ -43,13 +43,17 @@ def test_vote_transaction_multiple_votes(vote): transaction.verify() # if no exception is raised, it means the transaction is valid -def test_vote_transaction_greater_than_100(): +@pytest.mark.parametrize("vote", [ + {"fun": 50, "deadlock": 55}, + {"fun": 50}, +]) +def test_vote_transaction_must_equal_100(vote): vote = {"fun": 50, "deadlock": 55} transaction = Vote() with pytest.raises(SolarInvalidTransaction) as e: transaction.set_votes(vote) - assert str(e.value) == "Total vote weight must not be greater than 100." + assert str(e.value) == "Total vote weight must equal 100." def test_vote_transaction_using_empty_list():