Skip to content

Commit

Permalink
Remove attitudes.DOWNVOTE As suggested by TAs
Browse files Browse the repository at this point in the history
  • Loading branch information
Emojigit committed Dec 25, 2023
1 parent 2e03baf commit 9472893
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
2 changes: 0 additions & 2 deletions bchosttrust/attitudes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from collections import defaultdict

UPVOTE = 0
DOWNVOTE = 1

WEIGHTS = defaultdict(lambda: 0)
WEIGHTS[UPVOTE] = 1
WEIGHTS[DOWNVOTE] = -1
27 changes: 17 additions & 10 deletions tests/analysis_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ def setUp(self):
# Not caring about satisfying PoW here
self.block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
self.block2 = BCHTBlock(1, self.block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
self.block3 = BCHTBlock(1, self.block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.org", attitudes.UPVOTE),
))

self.db.put(self.block1)
Expand All @@ -49,22 +47,31 @@ def testGetVotes(self):

self.assertDictEqual(votes, {
"www.example.com": {
attitudes.UPVOTE: 3
attitudes.UPVOTE: 2
},
"www.example.net": {
attitudes.UPVOTE: 1,
attitudes.DOWNVOTE: 2
}
attitudes.UPVOTE: 1
},
"www.example.org": {
attitudes.UPVOTE: 1
},
})

def testRating(self):
ratings = search.get_website_rating(self.db, self.block3.hash)

self.assertDictEqual(ratings, {
"www.example.com": 3,
"www.example.net": -1 # (-1) + 1 + (-1)
"www.example.com": 2,
"www.example.net": 1,
"www.example.org": 1
})

def testSpecificRating(self):
specific_rating = search.get_specific_website_rating(
self.db, self.block3.hash, "www.example.com")

self.assertEqual(specific_rating, 2)


if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions tests/analysis_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ def setUp(self):
# Not caring about satisfying PoW here
self.block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
self.block2 = BCHTBlock(1, self.block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
self.block3 = BCHTBlock(1, self.block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

self.db.put(self.block1)
Expand Down
4 changes: 2 additions & 2 deletions tests/consensus_limitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BCHTConsensusTestCase(unittest.TestCase):
def test_success(self):
block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

self.assertTrue(limitations.validate_block_limitations(block1))
Expand All @@ -34,7 +34,7 @@ def test_failed_empty(self):
def test_failed_duplicate(self):
block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.com", attitudes.DOWNVOTE)
BCHTEntry("www.example.com", attitudes.UPVOTE)
))

self.assertFalse(limitations.validate_block_limitations(block1))
Expand Down
10 changes: 5 additions & 5 deletions tests/import_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def setUp(self):
self.blocks = []
self.blocks.append(BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
)))
self.blocks.append(BCHTBlock(1, self.blocks[0].hash, 1, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
)))
self.blocks.append(BCHTBlock(1, self.blocks[0].hash, 2, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
)))

for block in self.blocks:
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_import_block_build_on(self):
# We build a block on top of blocks[1]
new_block, _ = attempt(1, self.blocks[1].hash, 5, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

# By definition of attempt, we are now getting a block
Expand All @@ -97,7 +97,7 @@ def test_import_block_fork(self):

new_block, _ = attempt(1, self.blocks[0].hash, 5, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

# By definition of attempt, we are now getting a block
Expand Down
11 changes: 5 additions & 6 deletions tests/storage_dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def testIteration(self):

block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block2 = BCHTBlock(1, block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block3 = BCHTBlock(1, block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

backend.put(block1)
Expand All @@ -93,23 +93,22 @@ def testIterationDict(self):

block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block2 = BCHTBlock(1, block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block3 = BCHTBlock(1, block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

backend.put(block1)
backend.put(block2)
backend.put(block3)

dict_blocks = {key: value for key,
value in backend.iter_blocks_with_key()}
dict_blocks = dict(backend.iter_blocks_with_key())

for block in (block1, block2, block3):
self.assertTrue(block.hash in dict_blocks)
Expand Down
11 changes: 5 additions & 6 deletions tests/storage_leveldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def testIteration(self):

block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block2 = BCHTBlock(1, block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block3 = BCHTBlock(1, block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

backend.put(block1)
Expand All @@ -113,23 +113,22 @@ def testIterationDict(self):

block1 = BCHTBlock(1, b"\x00" * 32, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block2 = BCHTBlock(1, block1.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.UPVOTE)
))
block3 = BCHTBlock(1, block2.hash, 0, 4, (
BCHTEntry("www.example.com", attitudes.UPVOTE),
BCHTEntry("www.example.net", attitudes.DOWNVOTE)
BCHTEntry("www.example.net", attitudes.UPVOTE)
))

backend.put(block1)
backend.put(block2)
backend.put(block3)

dict_blocks = {key: value for key,
value in backend.iter_blocks_with_key()}
dict_blocks = dict(backend.iter_blocks_with_key())

for block in (block1, block2, block3):
self.assertTrue(block.hash in dict_blocks)
Expand Down

0 comments on commit 9472893

Please sign in to comment.