epoch_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package lookup_test
  2. import (
  3. "testing"
  4. "github.com/ethereum/go-ethereum/swarm/storage/feeds/lookup"
  5. )
  6. func TestMarshallers(t *testing.T) {
  7. for i := uint64(1); i < lookup.MaxTime; i *= 3 {
  8. e := lookup.Epoch{
  9. Time: i,
  10. Level: uint8(i % 20),
  11. }
  12. b, err := e.MarshalBinary()
  13. if err != nil {
  14. t.Fatal(err)
  15. }
  16. var e2 lookup.Epoch
  17. if err := e2.UnmarshalBinary(b); err != nil {
  18. t.Fatal(err)
  19. }
  20. if e != e2 {
  21. t.Fatal("Expected unmarshalled epoch to be equal to marshalled onet.Fatal(err)")
  22. }
  23. }
  24. }
  25. func TestAfter(t *testing.T) {
  26. a := lookup.Epoch{
  27. Time: 5,
  28. Level: 3,
  29. }
  30. b := lookup.Epoch{
  31. Time: 6,
  32. Level: 3,
  33. }
  34. c := lookup.Epoch{
  35. Time: 6,
  36. Level: 4,
  37. }
  38. if !b.After(a) {
  39. t.Fatal("Expected 'after' to be true, got false")
  40. }
  41. if b.After(b) {
  42. t.Fatal("Expected 'after' to be false when both epochs are identical, got true")
  43. }
  44. if !b.After(c) {
  45. t.Fatal("Expected 'after' to be true when both epochs have the same time but the level is lower in the first one, but got false")
  46. }
  47. }