def test_message_dump(self): # Test dump for message msg = Message({'__SIGNATURE__': "Test", "__NONCE__": 1000.3}) expectedDump = {'__SIGNATURE__': "Test", "__NONCE__": 1000.3, "__TYPE__": "/gossip.Message/MessageBase", "PublicKey": None} self.assertEqual(msg.dump(), expectedDump)
def test_message_dump(self): # Test dump for message msg = Message({'__SIGNATURE__': "Test", "__NONCE__": 1000.3}) expectedDump = { '__SIGNATURE__': "Test", "__NONCE__": 1000.3, "__TYPE__": "/gossip.Message/MessageBase" } self.assertEquals(msg.dump(), expectedDump)
def test_message_len(self): # Test the overriden len function # First case is when the msg has no data, creates data msg = Message({'__SIGNATURE__': "Test"}) length = len(dict2cbor(msg.dump())) self.assertIsNone(msg._data) self.assertEqual(len(msg), length) # The second case is when the msg does have data msg2 = Message({"__SIGNATURE__": "Test"}) msg2._data = "test data" self.assertEqual(len(msg2), len("test data"))
def test_message_len(self): # Test the overriden len function # First case is when the msg has no data, creates data msg = Message({'__SIGNATURE__': "Test"}) length = len(dict2cbor(msg.dump())) self.assertIsNone(msg._data) self.assertEquals(len(msg), length) # The second case is when the msg does have data msg2 = Message({"__SIGNATURE__": "Test"}) msg2._data = "test data" self.assertEquals(len(msg2), len("test data"))
def test_unpack_message(self): # Make sure that the message can be unpacked after serliazation msg = Message({'__SIGNATURE__': "Test"}) cbor = dict2cbor(msg.dump()) msgdict = unpack_message_data(cbor) self.assertEqual(msg.dump(), msgdict)
def test_unpack_message(self): # Make sure that the message can be unpacked after serliazation msg = Message({'__SIGNATURE__': "Test"}) cbor = dict2cbor(msg.dump()) msgdict = unpack_message_data(cbor) self.assertEquals(msg.dump(), msgdict)