def test_read_var_int(self, prepareLogger): assert wire.readVarInt(ByteArray([0xFC]), wire.ProtocolVersion) == 0xFC with pytest.raises(DecredError): wire.readVarInt( ByteArray([0xFE, 0xFF, 0xFF, 0x0, 0x0]), wire.ProtocolVersion ) with pytest.raises(DecredError): wire.readVarInt(ByteArray([0xFD, 0xFC, 0x0]), wire.ProtocolVersion)
def test_write_var_int(self, prepareLogger): for val, bytes_ in self.data: from_val = wire.writeVarInt(wire.ProtocolVersion, val) from_bytes = ByteArray(bytes_) assert from_val == from_bytes val_from_bytes = wire.readVarInt(from_bytes, wire.ProtocolVersion) assert val_from_bytes == val with pytest.raises(DecredError): wire.writeVarInt(wire.ProtocolVersion, wire.MaxUint64 + 1)
def test_write_var_int(self): for val, bytes_ in self.data: from_val = wire.writeVarInt(wire.ProtocolVersion, val) from_bytes = ByteArray(bytes_) self.assertEqual(from_val, from_bytes) val_from_bytes = wire.readVarInt(from_bytes, wire.ProtocolVersion) self.assertEqual(val_from_bytes, val) self.assertRaises( DecredError, wire.writeVarInt, wire.ProtocolVersion, wire.MaxUint64 + 1 )
def test_read_var_int(self): self.assertEqual(wire.readVarInt(ByteArray([0xFC]), wire.ProtocolVersion), 0xFC) self.assertRaises( DecredError, wire.readVarInt, ByteArray([0xFE, 0xFF, 0xFF, 0x0, 0x0]), wire.ProtocolVersion, ) self.assertRaises( DecredError, wire.readVarInt, ByteArray([0xFD, 0xFC, 0x0]), wire.ProtocolVersion, )
def deserialize(b): """ Deserialize the filter. Args: b (ByteArray): The serialized filter. Returns: FilterV2: The filter. """ filterData = ByteArray(b) n = 0 if len(filterData) > 0: n = wire.readVarInt(filterData, 0) return FilterV2(n, filterData)