@@ -8,13 +8,18 @@ import { of } from 'rxjs';
88import stakingOpportunityResponse from '~/test/mocks/shadeStaking/stakingOpportunityResponse.json' ;
99import { stakingOpportunityResponseParsed } from '~/test/mocks/shadeStaking/response' ;
1010import {
11+ batchQueryShadeStakingOpportunity ,
12+ batchQueryShadeStakingOpportunity$ ,
1113 parseStakingOpportunity ,
1214 queryShadeStakingOpportunity ,
1315 queryShadeStakingOpportunity$ ,
1416} from '~/contracts/services/shadeStaking' ;
1517import { StakingInfoServiceResponse } from '~/types/contracts/shadeStaking/index' ;
18+ import { batchStakingInfoUnparsed } from '~/test/mocks/shadeStaking/batchStakingInfoUnparsed' ;
19+ import { batchStakingInfoParsed } from '~/test/mocks/shadeStaking/batchStakingInfoParsed' ;
1620
1721const sendSecretClientContractQuery$ = vi . hoisted ( ( ) => vi . fn ( ) ) ;
22+ const batchQuery$ = vi . hoisted ( ( ) => vi . fn ( ) ) ;
1823
1924beforeAll ( ( ) => {
2025 vi . mock ( '~/contracts/definitions/shadeStaking' , ( ) => ( {
@@ -28,6 +33,10 @@ beforeAll(() => {
2833 vi . mock ( '~/client/services/clientServices' , ( ) => ( {
2934 sendSecretClientContractQuery$,
3035 } ) ) ;
36+
37+ vi . mock ( '~/contracts/services/batchQuery' , ( ) => ( {
38+ batchQuery$,
39+ } ) ) ;
3140} ) ;
3241
3342test ( 'it can parse the shade staking info' , ( ) => {
@@ -76,3 +85,60 @@ test('it can call the query shade staking info service', async () => {
7685
7786 expect ( output2 ) . toStrictEqual ( stakingOpportunityResponseParsed ) ;
7887} ) ;
88+
89+ test ( 'it can call the batch shade staking info query service' , async ( ) => {
90+ const input = {
91+ queryRouterContractAddress : 'CONTRACT_ADDRESS' ,
92+ queryRouterCodeHash : 'CODE_HASH' ,
93+ lcdEndpoint : 'LCD_ENDPOINT' ,
94+ chainId : 'CHAIN_ID' ,
95+ stakingContracts : [ {
96+ address : 'STAKING_ADDRESS' ,
97+ codeHash : 'STAKING_CODE_HASH' ,
98+ } ] ,
99+ } ;
100+ // observables function
101+ batchQuery$ . mockReturnValueOnce ( of ( batchStakingInfoUnparsed ) ) ;
102+ let output ;
103+ batchQueryShadeStakingOpportunity$ ( input ) . subscribe ( {
104+ next : ( response ) => {
105+ output = response ;
106+ } ,
107+ } ) ;
108+
109+ expect ( batchQuery$ ) . toHaveBeenCalledWith ( {
110+ contractAddress : input . queryRouterContractAddress ,
111+ codeHash : input . queryRouterCodeHash ,
112+ lcdEndpoint : input . lcdEndpoint ,
113+ chainId : input . chainId ,
114+ queries : [ {
115+ id : input . stakingContracts [ 0 ] . address ,
116+ contract : {
117+ address : input . stakingContracts [ 0 ] . address ,
118+ codeHash : input . stakingContracts [ 0 ] . codeHash ,
119+ } ,
120+ queryMsg : 'STAKING_INFO_MSG' ,
121+ } ] ,
122+ } ) ;
123+
124+ expect ( output ) . toStrictEqual ( batchStakingInfoParsed ) ;
125+
126+ // async/await function
127+ batchQuery$ . mockReturnValueOnce ( of ( batchStakingInfoUnparsed ) ) ;
128+ const response = await batchQueryShadeStakingOpportunity ( input ) ;
129+ expect ( batchQuery$ ) . toHaveBeenCalledWith ( {
130+ contractAddress : input . queryRouterContractAddress ,
131+ codeHash : input . queryRouterCodeHash ,
132+ lcdEndpoint : input . lcdEndpoint ,
133+ chainId : input . chainId ,
134+ queries : [ {
135+ id : input . stakingContracts [ 0 ] . address ,
136+ contract : {
137+ address : input . stakingContracts [ 0 ] . address ,
138+ codeHash : input . stakingContracts [ 0 ] . codeHash ,
139+ } ,
140+ queryMsg : 'STAKING_INFO_MSG' ,
141+ } ] ,
142+ } ) ;
143+ expect ( response ) . toStrictEqual ( batchStakingInfoParsed ) ;
144+ } ) ;
0 commit comments