@@ -199,4 +199,79 @@ describe('MoneyAccountService', () => {
199199 ) ;
200200 } ) ;
201201 } ) ;
202+
203+ describe ( 'getMoneyAccount' , ( ) => {
204+ it ( 'returns the money keyring metadata if one exists' , async ( ) => {
205+ const { service, mocks } = setup ( ) ;
206+ const MOCK_MONEY_METADATA = { id : 'existing-money-keyring-id' , name : '' } ;
207+
208+ mocks . withKeyring . mockImplementation ( async ( selector , operation ) => {
209+ if ( 'type' in selector && selector . type === KeyringTypes . money ) {
210+ return operation ( {
211+ keyring : { } ,
212+ metadata : MOCK_MONEY_METADATA ,
213+ } ) ;
214+ }
215+ return operation ( {
216+ keyring : {
217+ type : 'HD Key Tree' ,
218+ mnemonic : MOCK_MNEMONIC ,
219+ } as unknown as HdKeyring ,
220+ metadata : { id : MOCK_ENTROPY_SOURCE , name : '' } ,
221+ } ) ;
222+ } ) ;
223+
224+ const result = await service . getMoneyAccount ( ) ;
225+
226+ expect ( result ) . toStrictEqual ( MOCK_MONEY_METADATA ) ;
227+ } ) ;
228+
229+ it ( 'returns null if no money account exists' , async ( ) => {
230+ const { service } = setup ( ) ;
231+
232+ const result = await service . getMoneyAccount ( ) ;
233+
234+ expect ( result ) . toBeNull ( ) ;
235+ } ) ;
236+
237+ it ( 'is callable via the messenger' , async ( ) => {
238+ const { rootMessenger, mocks } = setup ( ) ;
239+ const MOCK_MONEY_METADATA = { id : 'existing-money-keyring-id' , name : '' } ;
240+
241+ mocks . withKeyring . mockImplementation ( async ( selector , operation ) => {
242+ if ( 'type' in selector && selector . type === KeyringTypes . money ) {
243+ return operation ( {
244+ keyring : { } ,
245+ metadata : MOCK_MONEY_METADATA ,
246+ } ) ;
247+ }
248+ return operation ( {
249+ keyring : {
250+ type : 'HD Key Tree' ,
251+ mnemonic : MOCK_MNEMONIC ,
252+ } as unknown as HdKeyring ,
253+ metadata : { id : MOCK_ENTROPY_SOURCE , name : '' } ,
254+ } ) ;
255+ } ) ;
256+
257+ const result = await rootMessenger . call (
258+ 'MoneyAccountService:getMoneyAccount' ,
259+ ) ;
260+
261+ expect ( result ) . toStrictEqual ( MOCK_MONEY_METADATA ) ;
262+ } ) ;
263+
264+ it ( 're-throws errors other than KeyringNotFound' , async ( ) => {
265+ const { service, mocks } = setup ( ) ;
266+ const unexpectedError = new KeyringControllerError ( 'Unexpected error' ) ;
267+
268+ mocks . withKeyring . mockImplementation ( async ( selector ) => {
269+ if ( 'type' in selector && selector . type === KeyringTypes . money ) {
270+ throw unexpectedError ;
271+ }
272+ } ) ;
273+
274+ await expect ( service . getMoneyAccount ( ) ) . rejects . toThrow ( unexpectedError ) ;
275+ } ) ;
276+ } ) ;
202277} ) ;
0 commit comments