This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
api_test.go
58 lines (48 loc) · 1.79 KB
/
api_test.go
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
58
package debianupdate
import (
"testing"
"github.com/dedis/paper_chainiac/skipchain"
"github.com/stretchr/testify/require"
"gopkg.in/dedis/onet.v1"
"gopkg.in/dedis/onet.v1/log"
)
func TestClient_LatestUpdates(t *testing.T) {
local := onet.NewLocalTest()
defer local.CloseAll()
_, roster, s := local.MakeHELS(5, debianUpdateService)
service := s.(*DebianUpdate)
cpr, err := service.CreateRepository(nil,
&CreateRepository{roster, chain1.blocks[0].release, 2, 10})
log.ErrFatal(err)
sc := cpr.(*CreateRepositoryRet).RepositoryChain
upr, err := service.UpdateRepository(nil,
&UpdateRepository{sc, chain1.blocks[1].release})
log.ErrFatal(err)
sc2 := upr.(*UpdateRepositoryRet).RepositoryChain
client := NewClient(roster)
lbret, err := client.LatestUpdates([]skipchain.SkipBlockID{sc.Data.Hash})
log.ErrFatal(err)
require.Equal(t, 1, len(lbret.Updates))
require.Equal(t, sc2.Data.Hash, lbret.Updates[0][1].Hash)
cpr, err = service.CreateRepository(nil,
&CreateRepository{roster, chain2.blocks[0].release, 2, 10})
log.ErrFatal(err)
sc3 := cpr.(*CreateRepositoryRet).RepositoryChain
upr, err = service.UpdateRepository(nil,
&UpdateRepository{sc3, chain2.blocks[1].release})
log.ErrFatal(err)
sc4 := upr.(*UpdateRepositoryRet).RepositoryChain
lbret, err = client.LatestUpdates([]skipchain.SkipBlockID{sc.Data.Hash,
sc3.Data.Hash})
log.ErrFatal(err)
require.Equal(t, 2, len(lbret.Updates))
require.Equal(t, 2, len(lbret.Updates[0]))
require.Equal(t, 2, len(lbret.Updates[1]))
require.Equal(t, sc2.Data.Hash, lbret.Updates[0][1].Hash)
require.Equal(t, sc4.Data.Hash, lbret.Updates[1][1].Hash)
lbret, err = client.LatestUpdates([]skipchain.SkipBlockID{sc2.Data.Hash,
sc3.Data.Hash})
log.ErrFatal(err)
require.Equal(t, 1, len(lbret.Updates))
require.Equal(t, 2, len(lbret.Updates[0]))
}