Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Fix breaking on getcurrentvotes due to vote weights (#116)
Browse files Browse the repository at this point in the history
* Add parse raw votes unit test

* Add failing test case

* Ignore extra fields in raw votes
  • Loading branch information
nmarley authored Apr 6, 2023
1 parent 8c0ff54 commit ad5daa2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dashlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ def did_we_vote(output):
def parse_raw_votes(raw_votes):
votes = []
for v in list(raw_votes.values()):
(outpoint, ntime, outcome, signal) = v.split(":")
(outpoint, ntime, outcome, signal, *_) = v.split(":")

signal = signal.lower()
outcome = outcome.lower()

Expand Down
50 changes: 50 additions & 0 deletions test/unit/test_dashy_things.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,53 @@ def test_blocks_to_seconds():
314.4
).quantize(precision)
assert int(dashlib.blocks_to_seconds(16616)) == 2612035


def test_parse_raw_votes():
import dashlib
from decimal import Decimal

expected = [
{
"mn_collateral_outpoint": "24668e26fea429b81e7d6e2f94ceaa4e3aefb0cbb23514c288d13c9199115007-0",
"signal": "delete",
"outcome": "yes",
"ntime": "1679654925",
},
{
"mn_collateral_outpoint": "4cf1a990965c98feff7e583685b5c90bc0ddcaa594d39d1deed462f51b849e07-1",
"signal": "funding",
"outcome": "no",
"ntime": "1679654927",
},
{
"mn_collateral_outpoint": "8a0275f11c71d73cf6e0162dc4f86aa66b33c5a5d8bb2fcdff5a716b44684407-1",
"signal": "funding",
"outcome": "yes",
"ntime": "1679654979",
},
]

sample_raw_votes = {
"4891b066619b4e2fa216dc50b389a17177466a0b2e8b60a08b16e36e517e85fc": "24668e26fea429b81e7d6e2f94ceaa4e3aefb0cbb23514c288d13c9199115007-0:1679654925:yes:delete",
"66dc0496fb953fb9fa0c52195faf0205c5f9559d8e57d3883f46527591bcf7ff": "4cf1a990965c98feff7e583685b5c90bc0ddcaa594d39d1deed462f51b849e07-1:1679654927:no:funding",
"292bf38f9afe4e7d0ebe630ec9fdf5d364d8440862d2d3b7d935a9c207166f4d": "8a0275f11c71d73cf6e0162dc4f86aa66b33c5a5d8bb2fcdff5a716b44684407-1:1679654979:yes:funding",
}

votes = dashlib.parse_raw_votes(sample_raw_votes)
# sort vote dicts to ensure ordering is the same as the expected output
# below
votes = sorted(votes, key=lambda x: x["mn_collateral_outpoint"])
assert votes == expected

sample_raw_votes_weights = {
"4891b066619b4e2fa216dc50b389a17177466a0b2e8b60a08b16e36e517e85fc": "24668e26fea429b81e7d6e2f94ceaa4e3aefb0cbb23514c288d13c9199115007-0:1679654925:yes:delete:1",
"66dc0496fb953fb9fa0c52195faf0205c5f9559d8e57d3883f46527591bcf7ff": "4cf1a990965c98feff7e583685b5c90bc0ddcaa594d39d1deed462f51b849e07-1:1679654927:no:funding:4",
"292bf38f9afe4e7d0ebe630ec9fdf5d364d8440862d2d3b7d935a9c207166f4d": "8a0275f11c71d73cf6e0162dc4f86aa66b33c5a5d8bb2fcdff5a716b44684407-1:1679654979:yes:funding:1",
}

votes = dashlib.parse_raw_votes(sample_raw_votes_weights)
# sort vote dicts to ensure ordering is the same as the expected output
# below
votes = sorted(votes, key=lambda x: x["mn_collateral_outpoint"])
assert votes == expected

0 comments on commit ad5daa2

Please sign in to comment.