github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/swarm/storage/feed/lookup/epoch_test.go (about) 1 2 //<developer> 3 // <name>linapex 曹一峰</name> 4 // <email>linapex@163.com</email> 5 // <wx>superexc</wx> 6 // <qqgroup>128148617</qqgroup> 7 // <url>https://jsq.ink</url> 8 // <role>pku engineer</role> 9 // <date>2019-03-16 19:16:44</date> 10 //</624450119139332096> 11 12 package lookup_test 13 14 import ( 15 "testing" 16 17 "github.com/ethereum/go-ethereum/swarm/storage/feed/lookup" 18 ) 19 20 func TestMarshallers(t *testing.T) { 21 22 for i := uint64(1); i < lookup.MaxTime; i *= 3 { 23 e := lookup.Epoch{ 24 Time: i, 25 Level: uint8(i % 20), 26 } 27 b, err := e.MarshalBinary() 28 if err != nil { 29 t.Fatal(err) 30 } 31 var e2 lookup.Epoch 32 if err := e2.UnmarshalBinary(b); err != nil { 33 t.Fatal(err) 34 } 35 if e != e2 { 36 t.Fatal("Expected unmarshalled epoch to be equal to marshalled onet.Fatal(err)") 37 } 38 } 39 40 } 41 42 func TestAfter(t *testing.T) { 43 a := lookup.Epoch{ 44 Time: 5, 45 Level: 3, 46 } 47 b := lookup.Epoch{ 48 Time: 6, 49 Level: 3, 50 } 51 c := lookup.Epoch{ 52 Time: 6, 53 Level: 4, 54 } 55 56 if !b.After(a) { 57 t.Fatal("Expected 'after' to be true, got false") 58 } 59 60 if b.After(b) { 61 t.Fatal("Expected 'after' to be false when both epochs are identical, got true") 62 } 63 64 if !b.After(c) { 65 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") 66 } 67 68 } 69