forked from iov-one/weave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore_test.go
57 lines (49 loc) · 1.59 KB
/
store_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
package app
import (
"context"
"testing"
"github.com/iov-one/weave"
"github.com/iov-one/weave/store/iavl"
"github.com/iov-one/weave/weavetest/assert"
abci "github.com/tendermint/tendermint/abci/types"
)
func TestAddValChange(t *testing.T) {
pubKey := weave.PubKey{
Type: "test",
Data: []byte("someKey"),
}
pubKey2 := weave.PubKey{
Type: "test",
Data: []byte("someKey2"),
}
app := NewStoreApp("dummy", iavl.MockCommitStore(), weave.NewQueryRouter(), context.Background())
t.Run("Diff is equal to output with one update", func(t *testing.T) {
diff := []weave.ValidatorUpdate{
{PubKey: pubKey, Power: 10},
}
app.AddValChange(diff)
res := app.EndBlock(abci.RequestEndBlock{})
assert.Equal(t, weave.ValidatorUpdatesFromABCI(res.ValidatorUpdates).ValidatorUpdates, diff)
})
t.Run("Only produce last update to multiple validators", func(t *testing.T) {
diff := []weave.ValidatorUpdate{
{PubKey: pubKey, Power: 10},
{PubKey: pubKey2, Power: 15},
{PubKey: pubKey, Power: 1},
{PubKey: pubKey2, Power: 2},
}
app.AddValChange(diff)
res := app.EndBlock(abci.RequestEndBlock{})
assert.Equal(t, weave.ValidatorUpdatesFromABCI(res.ValidatorUpdates).ValidatorUpdates, diff[2:])
})
t.Run("A call with an empty diff does nothing", func(t *testing.T) {
diff := []weave.ValidatorUpdate{
{PubKey: pubKey, Power: 10},
{PubKey: pubKey2, Power: 15},
}
app.AddValChange(diff)
app.AddValChange(make([]weave.ValidatorUpdate, 0))
res := app.EndBlock(abci.RequestEndBlock{})
assert.Equal(t, diff, weave.ValidatorUpdatesFromABCI(res.ValidatorUpdates).ValidatorUpdates)
})
}