-
Notifications
You must be signed in to change notification settings - Fork 6
/
state_cached_test.go
48 lines (37 loc) · 1.55 KB
/
state_cached_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
package state_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/hyperledger-labs/cckit/state/testdata"
testcc "github.com/hyperledger-labs/cckit/testing"
expectcc "github.com/hyperledger-labs/cckit/testing/expect"
)
const (
StateCachedChaincode = `state_cached`
)
var _ = Describe(`State caching`, func() {
//Create chaincode mocks
stateCachedCC := testcc.NewMockStub(StateCachedChaincode, testdata.NewStateCachedCC())
It("Read after write returns non empty entry", func() {
resp := expectcc.PayloadIs(stateCachedCC.Invoke(testdata.TxStateCachedReadAfterWrite), &testdata.Value{})
Expect(resp).To(Equal(testdata.KeyValue(testdata.Keys[0])))
})
It("Read after delete returns empty entry", func() {
resp := stateCachedCC.Invoke(testdata.TxStateCachedReadAfterDelete)
Expect(resp.Payload).To(Equal([]byte{}))
})
It("List after write returns list", func() {
resp := expectcc.PayloadIs(
stateCachedCC.Invoke(testdata.TxStateCachedListAfterWrite), &[]testdata.Value{}).([]testdata.Value)
// all key exists
Expect(resp).To(Equal([]testdata.Value{
testdata.KeyValue(testdata.Keys[0]), testdata.KeyValue(testdata.Keys[1]), testdata.KeyValue(testdata.Keys[2])}))
})
It("List after delete returns list without deleted item", func() {
resp := expectcc.PayloadIs(
stateCachedCC.Invoke(testdata.TxStateCachedListAfterDelete), &[]testdata.Value{}).([]testdata.Value)
// first key is deleted
Expect(resp).To(Equal([]testdata.Value{
testdata.KeyValue(testdata.Keys[1]), testdata.KeyValue(testdata.Keys[2])}))
})
})