-
Notifications
You must be signed in to change notification settings - Fork 573
A working subset of #1788 #1875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ed52b41
Add a test for base58 and use samples everywhere in test_addresses
g1itch a94ff1e
New test case for packets data, so far here are the tests for:
g1itch 8a5d90f
protocol: bytes everywhere in CreatePacket and assembleVersionMessage
g1itch 93c7cfb
test_base58: added tests for a single character, zero and invalid data
g1itch b3577a0
Return None from addresses.encodeBase58() for negative number
g1itch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
import unittest | ||
from binascii import unhexlify | ||
from struct import pack | ||
|
||
from pybitmessage import addresses, protocol | ||
|
||
from .samples import magic | ||
|
||
|
||
class TestSerialize(unittest.TestCase): | ||
"""Test serializing and deserializing packet data""" | ||
|
||
def test_varint(self): | ||
"""Test varint encoding and decoding""" | ||
data = addresses.encodeVarint(0) | ||
self.assertEqual(data, b'\x00') | ||
data = addresses.encodeVarint(42) | ||
self.assertEqual(data, b'*') | ||
data = addresses.encodeVarint(252) | ||
self.assertEqual(data, unhexlify('fc')) | ||
data = addresses.encodeVarint(253) | ||
self.assertEqual(data, unhexlify('fd00fd')) | ||
data = addresses.encodeVarint(100500) | ||
self.assertEqual(data, unhexlify('fe00018894')) | ||
data = addresses.encodeVarint(65535) | ||
self.assertEqual(data, unhexlify('fdffff')) | ||
data = addresses.encodeVarint(4294967295) | ||
self.assertEqual(data, unhexlify('feffffffff')) | ||
data = addresses.encodeVarint(4294967296) | ||
self.assertEqual(data, unhexlify('ff0000000100000000')) | ||
data = addresses.encodeVarint(18446744073709551615) | ||
self.assertEqual(data, unhexlify('ffffffffffffffffff')) | ||
|
||
with self.assertRaises(addresses.varintEncodeError): | ||
addresses.encodeVarint(18446744073709551616) | ||
|
||
value, length = addresses.decodeVarint(b'\xfeaddr') | ||
self.assertEqual(value, protocol.OBJECT_ADDR) | ||
self.assertEqual(length, 5) | ||
value, length = addresses.decodeVarint(b'\xfe\x00tor') | ||
self.assertEqual(value, protocol.OBJECT_ONIONPEER) | ||
self.assertEqual(length, 5) | ||
|
||
def test_packet(self): | ||
"""Check the packet created by protocol.CreatePacket()""" | ||
head = unhexlify(b'%x' % magic) | ||
self.assertEqual( | ||
protocol.CreatePacket(b'ping')[:len(head)], head) | ||
|
||
def test_encodehost(self): | ||
"""Check the result of protocol.encodeHost()""" | ||
self.assertEqual( | ||
protocol.encodeHost('127.0.0.1'), | ||
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF' | ||
+ pack('>L', 2130706433)) | ||
self.assertEqual( | ||
protocol.encodeHost('191.168.1.1'), | ||
unhexlify('00000000000000000000ffffbfa80101')) | ||
self.assertEqual( | ||
protocol.encodeHost('1.1.1.1'), | ||
unhexlify('00000000000000000000ffff01010101')) | ||
self.assertEqual( | ||
protocol.encodeHost('0102:0304:0506:0708:090A:0B0C:0D0E:0F10'), | ||
unhexlify('0102030405060708090a0b0c0d0e0f10')) | ||
self.assertEqual( | ||
protocol.encodeHost('quzwelsuziwqgpt2.onion'), | ||
unhexlify('fd87d87eeb438533622e54ca2d033e7a')) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.