Skip to content

Commit

Permalink
[explorer/rest]: add more unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLaw committed Nov 3, 2023
1 parent 95061d8 commit 6ef5c35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
6 changes: 4 additions & 2 deletions explorer/rest/tests/facade/test_NemRestFacade.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
'signature': (
'2ABDD19AD3EFAB0413B42772A586FAA19DEDB16D35F665F90D598046A2132C4A'
'D1E71001545CEAA44E63C04345591E7AADBFD330AF82A0D8A1DA5643E791FF0F'
)
),
'size': 936
}

EXPECTED_BLOCK_2 = {
Expand All @@ -34,7 +35,8 @@
'signature': (
'1B81379847241E45DA86B27911E5C9A9192EC04F644D98019657D32838B49C14'
'3EAA4815A3028B80F9AFFDBF0B94CD620F7A925E02783DDA67B8627B69DDF70E'
)
),
'size': 752
}

# endregion
Expand Down
8 changes: 6 additions & 2 deletions explorer/rest/tests/model/test_Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def _create_default_block_view(override=None):
(
'919AE66A34119B49812B335827B357F86884AB08B628029FD6E8DB3572FAEB4F'
'323A7BF9488C76EF8FAA5B513036BBCCE2D949BA3E41086D95A54C0007403C0B'
)
),
356
)

if override:
Expand All @@ -42,6 +43,7 @@ def test_can_create_block_view(self):
'323A7BF9488C76EF8FAA5B513036BBCCE2D949BA3E41086D95A54C0007403C0B',
block_view.signature
)
self.assertEqual(356, block_view.size)

def test_can_convert_to_simple_dict(self):
# Arrange:
Expand All @@ -62,7 +64,8 @@ def test_can_convert_to_simple_dict(self):
'signature': (
'919AE66A34119B49812B335827B357F86884AB08B628029FD6E8DB3572FAEB4F'
'323A7BF9488C76EF8FAA5B513036BBCCE2D949BA3E41086D95A54C0007403C0B'
)
),
'size': 356
}, block_view_dict)

def test_eq_is_supported(self):
Expand All @@ -81,3 +84,4 @@ def test_eq_is_supported(self):
self.assertNotEqual(block_view, self._create_default_block_view(('block_hash', 'random hash')))
self.assertNotEqual(block_view, self._create_default_block_view(('signer', 'random signer')))
self.assertNotEqual(block_view, self._create_default_block_view(('signature', 'random signature')))
self.assertNotEqual(block_view, self._create_default_block_view(('size', 'random size')))
31 changes: 24 additions & 7 deletions explorer/rest/tests/test/DatabaseTestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@

from rest.db.NemDatabase import NemDatabase

Block = namedtuple('Block', ['height', 'timestamp', 'total_fees', 'total_transactions', 'difficulty', 'block_hash', 'signer', 'signature'])
Block = namedtuple(
'Block',
[
'height',
'timestamp',
'total_fees',
'total_transactions',
'difficulty',
'block_hash',
'signer',
'signature',
'size'
]
)
DatabaseConfig = namedtuple('DatabaseConfig', ['database', 'user', 'password', 'host', 'port'])

# region test data
Expand All @@ -18,7 +31,8 @@
'438CF6375DAB5A0D32F9B7BF151D4539E00A590F7C022D5572C7D41815A24BE4',
'8D07F90FB4BBE7715FA327C926770166A11BE2E494A970605F2E12557F66C9B9',
'2ABDD19AD3EFAB0413B42772A586FAA19DEDB16D35F665F90D598046A2132C4A'
'D1E71001545CEAA44E63C04345591E7AADBFD330AF82A0D8A1DA5643E791FF0F'),
'D1E71001545CEAA44E63C04345591E7AADBFD330AF82A0D8A1DA5643E791FF0F',
936),
Block(
2,
'2015-03-29 20:34:19',
Expand All @@ -28,7 +42,8 @@
'1DD9D4D7B6AF603D29C082F9AA4E123F07D18154DDBCD7DDC6702491B854C5E4',
'F9BD190DD0C364261F5C8A74870CC7F7374E631352293C62ECC437657E5DE2CD',
'1B81379847241E45DA86B27911E5C9A9192EC04F644D98019657D32838B49C14'
'3EAA4815A3028B80F9AFFDBF0B94CD620F7A925E02783DDA67B8627B69DDF70E')
'3EAA4815A3028B80F9AFFDBF0B94CD620F7A925E02783DDA67B8627B69DDF70E',
752),
]

# endregion
Expand All @@ -50,16 +65,17 @@ def initialize_database(db_config):
difficulty bigInt NOT NULL,
hash bytea NOT NULL,
signer bytea NOT NULL,
signature bytea NOT NULL
signature bytea NOT NULL,
size bigint DEFAULT 0
)
''')

# Insert data
for block in BLOCKS:
cursor.execute(
'''
INSERT INTO blocks (height, timestamp, total_fees, total_transactions, difficulty, hash, signer, signature)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
INSERT INTO blocks (height, timestamp, total_fees, total_transactions, difficulty, hash, signer, signature, size)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)
''', (
block.height,
block.timestamp,
Expand All @@ -68,7 +84,8 @@ def initialize_database(db_config):
block.difficulty,
unhexlify(block.block_hash),
unhexlify(block.signer),
unhexlify(block.signature)
unhexlify(block.signature),
block.size
)
)

Expand Down

0 comments on commit 6ef5c35

Please sign in to comment.