@@ -15,8 +15,10 @@ import (
1515 "github.com/stretchr/testify/require"
1616
1717 "github.com/hyperledger/fabric-x-committer/api/protoblocktx"
18+ "github.com/hyperledger/fabric-x-committer/api/protonotify"
1819 "github.com/hyperledger/fabric-x-committer/api/protoqueryservice"
1920 "github.com/hyperledger/fabric-x-committer/integration/runner"
21+ "github.com/hyperledger/fabric-x-committer/utils/test"
2022)
2123
2224func TestQueryService (t * testing.T ) {
@@ -33,8 +35,9 @@ func TestQueryService(t *testing.T) {
3335 ctx , cancel := context .WithTimeout (t .Context (), time .Minute * 5 )
3436 t .Cleanup (cancel )
3537
36- c .MakeAndSendTransactionsToOrderer (t , [][]* protoblocktx.TxNamespace {{
37- {
38+ t .Log ("Insert TXs" )
39+ txIDs := c .MakeAndSendTransactionsToOrderer (t , [][]* protoblocktx.TxNamespace {
40+ {{
3841 NsId : "1" ,
3942 NsVersion : 0 ,
4043 BlindWrites : []* protoblocktx.Write {
@@ -47,8 +50,8 @@ func TestQueryService(t *testing.T) {
4750 Value : []byte ("v2" ),
4851 },
4952 },
50- },
51- {
53+ }} ,
54+ {{
5255 NsId : "2" ,
5356 NsVersion : 0 ,
5457 BlindWrites : []* protoblocktx.Write {
@@ -61,72 +64,97 @@ func TestQueryService(t *testing.T) {
6164 Value : []byte ("v4" ),
6265 },
6366 },
67+ }},
68+ }, []protoblocktx.Status {protoblocktx .Status_COMMITTED , protoblocktx .Status_COMMITTED })
69+ require .Len (t , txIDs , 2 )
70+
71+ t .Log ("Query TXs status" )
72+ status , err := c .QueryServiceClient .GetTransactionStatus (ctx , & protoqueryservice.TxStatusQuery {
73+ TxIds : txIDs ,
74+ })
75+ require .NoError (t , err )
76+ require .Len (t , status .Statuses , len (txIDs ))
77+ test .RequireProtoElementsMatch (t , []* protonotify.TxStatusEvent {
78+ {
79+ TxId : txIDs [0 ],
80+ StatusWithHeight : & protoblocktx.StatusWithHeight {
81+ Code : protoblocktx .Status_COMMITTED ,
82+ TxNumber : uint32 (0 ),
83+ BlockNumber : uint64 (2 ),
84+ },
6485 },
65- }}, []protoblocktx.Status {protoblocktx .Status_COMMITTED })
86+ {
87+ TxId : txIDs [1 ],
88+ StatusWithHeight : & protoblocktx.StatusWithHeight {
89+ Code : protoblocktx .Status_COMMITTED ,
90+ TxNumber : uint32 (1 ),
91+ BlockNumber : uint64 (2 ),
92+ },
93+ },
94+ }, status .Statuses )
6695
67- t .Run ("Query-GetRows-Both-Namespaces" , func (t * testing.T ) {
68- ret , err := c .QueryServiceClient .GetRows (
69- ctx ,
70- & protoqueryservice.Query {
71- Namespaces : []* protoqueryservice.QueryNamespace {
72- {
73- NsId : "1" ,
74- Keys : [][]byte {
75- []byte ("k1" ), []byte ("k2" ),
76- },
96+ t .Log ("Query Rows" )
97+ ret , err := c .QueryServiceClient .GetRows (
98+ ctx ,
99+ & protoqueryservice.Query {
100+ Namespaces : []* protoqueryservice.QueryNamespace {
101+ {
102+ NsId : "1" ,
103+ Keys : [][]byte {
104+ []byte ("k1" ), []byte ("k2" ),
77105 },
78- {
79- NsId : "2" ,
80- Keys : [][] byte {
81- [] byte ( "k3" ), []byte ( "k4" ),
82- } ,
106+ },
107+ {
108+ NsId : "2" ,
109+ Keys : [] []byte {
110+ [] byte ( "k3" ), [] byte ( "k4" ) ,
83111 },
84112 },
85113 },
86- )
87- require .NoError (t , err )
114+ },
115+ )
116+ require .NoError (t , err )
88117
89- testItemsVersion := uint64 (0 )
118+ testItemsVersion := uint64 (0 )
90119
91- requiredItems := []* protoqueryservice.RowsNamespace {
92- {
93- NsId : "1" ,
94- Rows : []* protoqueryservice.Row {
95- {
96- Key : []byte ("k1" ),
97- Value : []byte ("v1" ),
98- Version : testItemsVersion ,
99- },
100- {
101- Key : []byte ("k2" ),
102- Value : []byte ("v2" ),
103- Version : testItemsVersion ,
104- },
120+ requiredItems := []* protoqueryservice.RowsNamespace {
121+ {
122+ NsId : "1" ,
123+ Rows : []* protoqueryservice.Row {
124+ {
125+ Key : []byte ("k1" ),
126+ Value : []byte ("v1" ),
127+ Version : testItemsVersion ,
128+ },
129+ {
130+ Key : []byte ("k2" ),
131+ Value : []byte ("v2" ),
132+ Version : testItemsVersion ,
105133 },
106134 },
107- {
108- NsId : "2" ,
109- Rows : [] * protoqueryservice. Row {
110- {
111- Key : [] byte ( "k3" ),
112- Value : []byte ("v3 " ),
113- Version : testItemsVersion ,
114- } ,
115- {
116- Key : [] byte ( "k4" ),
117- Value : []byte ("v4 " ),
118- Version : testItemsVersion ,
119- } ,
135+ },
136+ {
137+ NsId : "2" ,
138+ Rows : [] * protoqueryservice. Row {
139+ {
140+ Key : []byte ("k3 " ),
141+ Value : [] byte ( "v3" ) ,
142+ Version : testItemsVersion ,
143+ },
144+ {
145+ Key : []byte ("k4 " ),
146+ Value : [] byte ( "v4" ) ,
147+ Version : testItemsVersion ,
120148 },
121149 },
122- }
150+ },
151+ }
123152
124- requireQueryResults (
125- t ,
126- requiredItems ,
127- ret .Namespaces ,
128- )
129- })
153+ requireQueryResults (
154+ t ,
155+ requiredItems ,
156+ ret .Namespaces ,
157+ )
130158}
131159
132160// requireQueryResults requires that the items retrieved by the Query service
0 commit comments