[tor-commits] [stem/master] Test VersionsCell.pack

atagar at torproject.org atagar at torproject.org
Sun Jan 21 02:04:04 UTC 2018


commit ae90fd8ed263f6ebfd9390df85e35ad75a6e32dc
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Jan 10 10:25:20 2018 -0800

    Test VersionsCell.pack
---
 stem/client/cell.py      | 2 +-
 test/unit/client/cell.py | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/stem/client/cell.py b/stem/client/cell.py
index 9a6e6788..e3fb6a71 100644
--- a/stem/client/cell.py
+++ b/stem/client/cell.py
@@ -184,7 +184,7 @@ class VersionsCell(Cell):
     # since VERSION cells avoid most version dependent attributes.
 
     payload = b''.join([struct.pack(Pack.SHORT, v) for v in versions])
-    return cls._pack('VERSIONS', 3, payload)
+    return cls._pack(3, payload)
 
 
 class NetinfoCell(Cell):
diff --git a/test/unit/client/cell.py b/test/unit/client/cell.py
index 188fd773..c8161a7e 100644
--- a/test/unit/client/cell.py
+++ b/test/unit/client/cell.py
@@ -4,7 +4,7 @@ Unit tests for the stem.client.cell.
 
 import unittest
 
-from stem.client.cell import Cell
+from stem.client.cell import Cell, VersionsCell
 
 
 class TestCell(unittest.TestCase):
@@ -29,3 +29,8 @@ class TestCell(unittest.TestCase):
     self.assertRaises(ValueError, Cell.by_value, 'NOPE')
     self.assertRaises(ValueError, Cell.by_value, 85)
     self.assertRaises(ValueError, Cell.by_value, None)
+
+  def test_versions_pack(self):
+    self.assertEqual('\x00\x00\x07\x00\x00', VersionsCell.pack([]))
+    self.assertEqual('\x00\x00\x07\x00\x02\x00\x01', VersionsCell.pack([1]))
+    self.assertEqual('\x00\x00\x07\x00\x06\x00\x01\x00\x02\x00\x03', VersionsCell.pack([1, 2, 3]))





More information about the tor-commits mailing list