You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.2 KiB

  1. package p2p
  2. import "testing"
  3. import "encoding/hex"
  4. func Test_Levin_Header_Deserialisation(t *testing.T) {
  5. // this structure has been manually pulled from wireshark stream
  6. raw_data := "0121010101010101e20000000000000001e9030000000000000100000001000000"
  7. raw_data_blob, _ := hex.DecodeString(raw_data)
  8. _ = raw_data_blob
  9. var lheader Levin_Header
  10. err := lheader.DeSerialize(raw_data_blob)
  11. if err != nil {
  12. t.Error("DeSerialize Levin header Failed\n")
  13. return
  14. }
  15. // now serialize once again
  16. serialised, _ := lheader.Serialize()
  17. if raw_data != hex.EncodeToString(serialised) {
  18. t.Error("Serialize Levin_Header Failed")
  19. }
  20. }
  21. func Test_Levin_Data_Header(t *testing.T) {
  22. // this structure has been manually pulled from wireshark stream
  23. raw_data := "01110101010102010100"
  24. raw_data_blob, _ := hex.DecodeString(raw_data)
  25. _ = raw_data_blob
  26. var lheader Levin_Data_Header
  27. err := lheader.DeSerialize(raw_data_blob)
  28. if err != nil {
  29. t.Error("DeSerialize Levin Data header Failed\n")
  30. return
  31. }
  32. // now serialize once again
  33. serialised, _ := lheader.Serialize()
  34. if raw_data != hex.EncodeToString(serialised) {
  35. t.Errorf("Serialize Levin_Data_Header Failed \n%s correct value \n%s Our value", raw_data, hex.EncodeToString(serialised))
  36. }
  37. }