varint_differential.rs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2024 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. extern crate darkfi_serial;
  19. extern crate bitcoin;
  20. use honggfuzz::fuzz;
  21. use darkfi_serial::VarInt;
  22. use bitcoin::VarInt as BTCVarInt;
  23. // use bitcoin::consensus::serialize;
  24. // use bitcoin::psbt::serialize;
  25. // use darkfi_serial::{serialize, deserialize};
  26. fn main() {
  27. loop {
  28. fuzz!(|data: u64 | {
  29. let dark_vi = VarInt(data.clone());
  30. let btc_vi = BTCVarInt(data.clone());
  31. assert_eq!(
  32. dark_vi.length(),
  33. btc_vi.len(),
  34. );
  35. let dark_ser = darkfi_serial::serialize(&dark_vi);
  36. let btc_ser = bitcoin::consensus::serialize(&btc_vi);
  37. assert_eq!(dark_ser, btc_ser);
  38. let dark_des: VarInt = darkfi_serial::deserialize(&dark_ser).unwrap();
  39. let btc_des: BTCVarInt = bitcoin::consensus::deserialize(&btc_ser).unwrap();
  40. assert_eq!(
  41. dark_des.length(),
  42. btc_des.len(),
  43. );
  44. // assert_eq!(
  45. // darkfi_serial::decode(&dark_ser).unwrap(),
  46. // bitcoin::consensus::decode(&btc_ser).unwrap(),
  47. // );
  48. });
  49. }
  50. }