github.com/codingfuture/orig-energi3@v0.8.4/swarm/storage/feed/lookup/epoch_test.go (about)

     1  // Copyright 2018 The Energi Core Authors
     2  // Copyright 2018 The go-ethereum Authors
     3  // This file is part of the Energi Core library.
     4  //
     5  // The Energi Core library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The Energi Core library 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 Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package lookup_test
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/ethereum/go-ethereum/swarm/storage/feed/lookup"
    24  )
    25  
    26  func TestMarshallers(t *testing.T) {
    27  
    28  	for i := uint64(1); i < lookup.MaxTime; i *= 3 {
    29  		e := lookup.Epoch{
    30  			Time:  i,
    31  			Level: uint8(i % 20),
    32  		}
    33  		b, err := e.MarshalBinary()
    34  		if err != nil {
    35  			t.Fatal(err)
    36  		}
    37  		var e2 lookup.Epoch
    38  		if err := e2.UnmarshalBinary(b); err != nil {
    39  			t.Fatal(err)
    40  		}
    41  		if e != e2 {
    42  			t.Fatal("Expected unmarshalled epoch to be equal to marshalled onet.Fatal(err)")
    43  		}
    44  	}
    45  
    46  }
    47  
    48  func TestAfter(t *testing.T) {
    49  	a := lookup.Epoch{
    50  		Time:  5,
    51  		Level: 3,
    52  	}
    53  	b := lookup.Epoch{
    54  		Time:  6,
    55  		Level: 3,
    56  	}
    57  	c := lookup.Epoch{
    58  		Time:  6,
    59  		Level: 4,
    60  	}
    61  
    62  	if !b.After(a) {
    63  		t.Fatal("Expected 'after' to be true, got false")
    64  	}
    65  
    66  	if b.After(b) {
    67  		t.Fatal("Expected 'after' to be false when both epochs are identical, got true")
    68  	}
    69  
    70  	if !b.After(c) {
    71  		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")
    72  	}
    73  
    74  }