@@ -1103,6 +1103,79 @@ describe('Stub', () => {
11031103 } ) ;
11041104 } ) ;
11051105
1106+ describe ( 'getMultipleStates' , ( ) => {
1107+ let stub ;
1108+
1109+ beforeEach ( ( ) => {
1110+ stub = new Stub ( {
1111+ handleGetState : sinon . stub ( ) . resolves ( Buffer . from ( 'value' ) )
1112+ } , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
1113+ } ) ;
1114+
1115+ it ( 'should throw an error if keys is not an array' , async ( ) => {
1116+ await expect ( stub . getMultipleStates ( 'not-an-array' ) ) . to . be . rejectedWith ( / k e y s m u s t b e a n a r r a y o f s t r i n g s / ) ;
1117+ } ) ;
1118+
1119+ it ( 'should call getState for each key and return the results' , async ( ) => {
1120+ sandbox . stub ( stub , 'getState' ) . callsFake ( async ( key ) => {
1121+ if ( key === 'key1' ) {
1122+ return Buffer . from ( 'value1' ) ;
1123+ } else if ( key === 'key2' ) {
1124+ return Buffer . from ( 'value2' ) ;
1125+ }
1126+ } ) ;
1127+
1128+ const results = await stub . getMultipleStates ( [ 'key1' , 'key2' ] ) ;
1129+ expect ( results ) . to . deep . equal ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] ) ;
1130+ sinon . assert . calledTwice ( stub . getState ) ;
1131+ } ) ;
1132+ } ) ;
1133+
1134+ describe ( 'getMultiplePrivateData' , ( ) => {
1135+ let stub ;
1136+
1137+ beforeEach ( ( ) => {
1138+ stub = new Stub ( {
1139+ handleGetState : sinon . stub ( ) . resolves ( Buffer . from ( 'value' ) )
1140+ } , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
1141+ } ) ;
1142+
1143+ it ( 'should throw an error if collection is missing' , async ( ) => {
1144+ await expect ( stub . getMultiplePrivateData ( null , [ 'key1' ] ) ) . to . be . rejectedWith ( / c o l l e c t i o n m u s t b e a v a l i d s t r i n g / ) ;
1145+ } ) ;
1146+
1147+ it ( 'should throw an error if keys is not an array' , async ( ) => {
1148+ await expect ( stub . getMultiplePrivateData ( 'collection' , 'not-an-array' ) ) . to . be . rejectedWith ( / k e y s m u s t b e a n a r r a y o f s t r i n g s / ) ;
1149+ } ) ;
1150+
1151+ it ( 'should call getPrivateData for each key and return the results' , async ( ) => {
1152+ sandbox . stub ( stub , 'getPrivateData' ) . callsFake ( async ( collection , key ) => {
1153+ if ( key === 'key1' ) {
1154+ return Buffer . from ( 'value1' ) ;
1155+ } else if ( key === 'key2' ) {
1156+ return Buffer . from ( 'value2' ) ;
1157+ }
1158+ } ) ;
1159+
1160+ const results = await stub . getMultiplePrivateData ( 'collection' , [ 'key1' , 'key2' ] ) ;
1161+ expect ( results ) . to . deep . equal ( [ Buffer . from ( 'value1' ) , Buffer . from ( 'value2' ) ] ) ;
1162+ sinon . assert . calledTwice ( stub . getPrivateData ) ;
1163+ } ) ;
1164+ } ) ;
1165+
1166+ describe ( 'Write Batching Fallbacks' , ( ) => {
1167+ it ( 'should execute startWriteBatch as a no-op' , ( ) => {
1168+ const stub = new Stub ( 'dummyClient' , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
1169+ stub . startWriteBatch ( ) ;
1170+ } ) ;
1171+
1172+ it ( 'should execute finishWriteBatch as a no-op' , async ( ) => {
1173+ const stub = new Stub ( 'dummyClient' , 'dummyChannelId' , 'dummyTxid' , chaincodeInput ) ;
1174+ await stub . finishWriteBatch ( ) ;
1175+ } ) ;
1176+ } ) ;
1177+
1178+
11061179 describe ( 'getPrivateDataHash' , ( ) => {
11071180 let handleGetPrivateDataHashStub ;
11081181 let stub ;
0 commit comments