-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: chain and reserve state endpoints (#324)
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { safeAxios } from '../../utils/safeAxios' | ||
import { ChainState, ReserveState } from '../../types' | ||
|
||
const RESERVE_STATE_ENDPOINT = '/reservestate' | ||
const CHAIN_STATE_ENDPOINT = '/chainstate' | ||
|
||
/** | ||
* Get state of reserve | ||
* | ||
* @param url Bee debug URL | ||
*/ | ||
export async function getReserveState(url: string): Promise<ReserveState> { | ||
const response = await safeAxios<ReserveState>({ | ||
method: 'get', | ||
url: `${url}${RESERVE_STATE_ENDPOINT}`, | ||
responseType: 'json', | ||
}) | ||
|
||
return response.data | ||
} | ||
|
||
/** | ||
* Get state of reserve | ||
* | ||
* @param url Bee debug URL | ||
*/ | ||
export async function getChainState(url: string): Promise<ChainState> { | ||
const response = await safeAxios<ChainState>({ | ||
method: 'get', | ||
url: `${url}${CHAIN_STATE_ENDPOINT}`, | ||
responseType: 'json', | ||
forceBigInt: true, | ||
}) | ||
|
||
return response.data | ||
} |
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,34 @@ | ||
import { beeDebugUrl, commonMatchers } from '../../../utils' | ||
import * as states from '../../../../src/modules/debug/states' | ||
|
||
const BEE_DEBUG_URL = beeDebugUrl() | ||
commonMatchers() | ||
|
||
describe('modules/states', () => { | ||
describe('chainstate', () => { | ||
it('should fetch the chainstate', async () => { | ||
const state = await states.getChainState(BEE_DEBUG_URL) | ||
|
||
expect(state).toHaveProperty('block') | ||
expect(state).toHaveProperty('totalAmount') | ||
expect(state).toHaveProperty('currentPrice') | ||
expect(state.block).toBeType('bigint') | ||
expect(state.totalAmount).toBeType('bigint') | ||
expect(state.currentPrice).toBeType('bigint') | ||
}) | ||
}) | ||
describe('ReserveState', () => { | ||
it('should fetch the reserve state', async () => { | ||
const state = await states.getReserveState(BEE_DEBUG_URL) | ||
|
||
expect(state).toHaveProperty('radius') | ||
expect(state).toHaveProperty('available') | ||
expect(state).toHaveProperty('outer') | ||
expect(state).toHaveProperty('inner') | ||
expect(state.radius).toBeType('number') | ||
expect(state.available).toBeType('number') | ||
expect(state.outer).toBeType('number') | ||
expect(state.inner).toBeType('number') | ||
}) | ||
}) | ||
}) |