-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a function to retrieve current network information (#14)
- Loading branch information
Showing
16 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/sdk/src/core/__tests__/methods/get-network.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { mockWalletProvider } from '../../__mocks__/mock-wallet-provider'; | ||
import { getNetwork } from '../../methods'; | ||
import { WalletResponseSuccessType } from '../../types'; | ||
import { GetNetworkResponse } from '../../types/methods'; | ||
import { makeResponseMessage } from '../../utils'; | ||
|
||
describe('getNetwork', () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should call getNetwork and return the response', async () => { | ||
const mockResponse: GetNetworkResponse = makeResponseMessage(WalletResponseSuccessType.GET_NETWORK_SUCCESS, { | ||
chainId: 'chainId', | ||
networkName: 'networkName', | ||
addressPrefix: 'g', | ||
rpcUrl: 'rpcUrl', | ||
indexerUrl: null, | ||
}); | ||
|
||
mockWalletProvider.getNetwork.mockResolvedValue(mockResponse); | ||
|
||
const response = await getNetwork(mockWalletProvider); | ||
|
||
expect(mockWalletProvider.getNetwork).toHaveBeenCalled(); | ||
expect(response).toEqual(mockResponse); | ||
}); | ||
|
||
it('should handle errors when getNetwork fails', async () => { | ||
const mockError = new Error('Failed to get network'); | ||
mockWalletProvider.getNetwork.mockRejectedValue(mockError); | ||
|
||
await expect(getNetwork(mockWalletProvider)).rejects.toThrow('Failed to get network'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { WalletProvider } from '../providers'; | ||
import { GetNetworkResponse } from '../types/methods'; | ||
|
||
export const getNetwork = (walletProvider: WalletProvider): Promise<GetNetworkResponse> => { | ||
return walletProvider.getNetwork(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './account.types'; | ||
export * from './config.types'; | ||
export * from './network.types'; | ||
export * from './transaction.types'; | ||
export * from './wallet.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { NetworkInfo } from '../network.types'; | ||
import { WalletResponse } from '../wallet.types'; | ||
|
||
export type GetNetworkResponse = WalletResponse<NetworkInfo>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export type NetworkInfo = { | ||
chainId: string; | ||
networkName: string; | ||
addressPrefix: string; | ||
rpcUrl: string; | ||
indexerUrl: string | null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './adena-wallet'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters