@@ -4,7 +4,13 @@ import { grpc } from '@improbable-eng/grpc-web';
44import { waitFor } from '@testing-library/react' ;
55import Big from 'big.js' ;
66import { BalanceMode } from 'util/constants' ;
7- import { lndChannelEvent , lndListChannels } from 'util/tests/sampleData' ;
7+ import {
8+ lndChannel ,
9+ lndChannelEvent ,
10+ lndGetChanInfo ,
11+ lndGetNodeInfo ,
12+ lndListChannels ,
13+ } from 'util/tests/sampleData' ;
814import { createStore , Store } from 'store' ;
915import Channel from 'store/models/channel' ;
1016import ChannelStore from 'store/stores/channelStore' ;
@@ -120,6 +126,72 @@ describe('ChannelStore', () => {
120126 expect ( + store . totalOutbound ) . toBe ( outbound ) ;
121127 } ) ;
122128
129+ it ( 'should fetch aliases for channels' , async ( ) => {
130+ await store . fetchChannels ( ) ;
131+ const channel = store . channels . get ( lndChannel . chanId ) as Channel ;
132+ expect ( channel . alias ) . toBeUndefined ( ) ;
133+ // the alias is fetched from the API and should be updated after a few ticks
134+ await waitFor ( ( ) => {
135+ expect ( channel . alias ) . toBe ( lndGetNodeInfo . node . alias ) ;
136+ } ) ;
137+ } ) ;
138+
139+ it ( 'should use cached aliases for channels' , async ( ) => {
140+ const cache = {
141+ expires : Date . now ( ) + 60 * 1000 ,
142+ data : {
143+ [ lndGetNodeInfo . node . pubKey ] : lndGetNodeInfo . node . alias ,
144+ } ,
145+ } ;
146+ jest
147+ . spyOn ( window . sessionStorage . __proto__ , 'getItem' )
148+ . mockReturnValue ( JSON . stringify ( cache ) ) ;
149+
150+ const channel = new Channel ( rootStore , lndChannel ) ;
151+ store . channels = observable . map ( {
152+ [ channel . chanId ] : channel ,
153+ } ) ;
154+
155+ await store . fetchAliases ( ) ;
156+ expect ( channel . alias ) . toBe ( lndGetNodeInfo . node . alias ) ;
157+ expect ( grpcMock . unary ) . not . toBeCalled ( ) ;
158+ } ) ;
159+
160+ it ( 'should fetch fee rates for channels' , async ( ) => {
161+ await store . fetchChannels ( ) ;
162+ const channel = store . channels . get ( lndChannel . chanId ) as Channel ;
163+ expect ( channel . remoteFeeRate ) . toBe ( 0 ) ;
164+ // the alias is fetched from the API and should be updated after a few ticks
165+ await waitFor ( ( ) => {
166+ const rate = + Big ( lndGetChanInfo . node1Policy . feeRateMilliMsat )
167+ . div ( 1000000 )
168+ . mul ( 100 ) ;
169+ expect ( channel . remoteFeeRate ) . toBe ( rate ) ;
170+ } ) ;
171+ } ) ;
172+
173+ it ( 'should use cached fee rates for channels' , async ( ) => {
174+ const rate = + Big ( lndGetChanInfo . node1Policy . feeRateMilliMsat ) . div ( 1000000 ) . mul ( 100 ) ;
175+ const cache = {
176+ expires : Date . now ( ) + 60 * 1000 ,
177+ data : {
178+ [ lndGetChanInfo . channelId ] : rate ,
179+ } ,
180+ } ;
181+ jest
182+ . spyOn ( window . sessionStorage . __proto__ , 'getItem' )
183+ . mockReturnValue ( JSON . stringify ( cache ) ) ;
184+
185+ const channel = new Channel ( rootStore , lndChannel ) ;
186+ store . channels = observable . map ( {
187+ [ channel . chanId ] : channel ,
188+ } ) ;
189+
190+ await store . fetchFeeRates ( ) ;
191+ expect ( channel . remoteFeeRate ) . toBe ( rate ) ;
192+ expect ( grpcMock . unary ) . not . toBeCalled ( ) ;
193+ } ) ;
194+
123195 describe ( 'onChannelEvent' , ( ) => {
124196 const {
125197 OPEN_CHANNEL ,
0 commit comments