aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/mru/lookup/epoch_test.go
blob: 62cf5523d8066a53e0c904a6e851e19846106ac0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lookup_test

import (
    "testing"

    "github.com/ethereum/go-ethereum/swarm/storage/mru/lookup"
)

func TestMarshallers(t *testing.T) {

    for i := uint64(1); i < lookup.MaxTime; i *= 3 {
        e := lookup.Epoch{
            Time:  i,
            Level: uint8(i % 20),
        }
        b, err := e.MarshalBinary()
        if err != nil {
            t.Fatal(err)
        }
        var e2 lookup.Epoch
        if err := e2.UnmarshalBinary(b); err != nil {
            t.Fatal(err)
        }
        if e != e2 {
            t.Fatal("Expected unmarshalled epoch to be equal to marshalled onet.Fatal(err)")
        }
    }

}

func TestAfter(t *testing.T) {
    a := lookup.Epoch{
        Time:  5,
        Level: 3,
    }
    b := lookup.Epoch{
        Time:  6,
        Level: 3,
    }
    c := lookup.Epoch{
        Time:  6,
        Level: 4,
    }

    if !b.After(a) {
        t.Fatal("Expected 'after' to be true, got false")
    }

    if b.After(b) {
        t.Fatal("Expected 'after' to be false when both epochs are identical, got true")
    }

    if !b.After(c) {
        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")
    }

}