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.

35 lines
705 B

  1. // nolint: gosec
  2. package addr
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. "math/rand"
  7. "github.com/tendermint/tendermint/p2p"
  8. "github.com/tendermint/tendermint/p2p/pex"
  9. )
  10. var addrBook = pex.NewAddrBook("./testdata/addrbook.json", true)
  11. func Fuzz(data []byte) int {
  12. addr := new(p2p.NetAddress)
  13. if err := json.Unmarshal(data, addr); err != nil {
  14. return -1
  15. }
  16. // Fuzz AddAddress.
  17. err := addrBook.AddAddress(addr, addr)
  18. if err != nil {
  19. return 0
  20. }
  21. // Also, make sure PickAddress always returns a non-nil address.
  22. bias := rand.Intn(100)
  23. if p := addrBook.PickAddress(bias); p == nil {
  24. panic(fmt.Sprintf("picked a nil address (bias: %d, addrBook size: %v)",
  25. bias, addrBook.Size()))
  26. }
  27. return 1
  28. }