Skip to content

Commit 1e1c9db

Browse files
slapec93Gergely Békési
andauthored
feat: add minimumValidityBlocks to chainstate response (#1194)
* feat: add minimumValidityBlocks to chainstate response * test: cover with spec --------- Co-authored-by: Gergely Békési <gergely.bekesi@ethswarm.org>
1 parent 17354e4 commit 1e1c9db

6 files changed

Lines changed: 32 additions & 7 deletions

File tree

package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
"debug": "^4.4.1",
7070
"isomorphic-ws": "^4.0.1",
7171
"semver": "^7.3.5",
72-
"ws": "^8.20.1"
72+
"ws": "^8.20.1",
73+
"zod": "^4.4.3"
7374
},
7475
"devDependencies": {
7576
"@babel/cli": "^7.19.3",

src/modules/debug/states.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Types } from 'cafe-utility'
22
import { BeeRequestOptions, ChainState, ReserveState, WalletBalance } from '../../types'
3+
import { GetChainStateResponse } from '../../types/schema'
34
import { http } from '../../utils/http'
45
import { BZZ, DAI } from '../../utils/tokens'
56
import { asNumberString } from '../../utils/type'
@@ -44,13 +45,14 @@ export async function getChainState(requestOptions: BeeRequestOptions): Promise<
4445
responseType: 'json',
4546
})
4647

47-
const body = Types.asObject(response.data, { name: 'response.data' })
48+
const body = GetChainStateResponse.parse(response.data)
4849

4950
return {
50-
block: Types.asNumber(body.block, { name: 'block' }),
51-
chainTip: Types.asNumber(body.chainTip, { name: 'chainTip' }),
52-
totalAmount: asNumberString(body.totalAmount, { name: 'totalAmount' }),
53-
currentPrice: normalizeCurrentPrice(Types.asNumber(body.currentPrice, { name: 'currentPrice' })),
51+
block: body.block,
52+
chainTip: body.chainTip,
53+
totalAmount: body.totalAmount,
54+
currentPrice: normalizeCurrentPrice(body.currentPrice),
55+
minimumValidityBlocks: body.minimumValidityBlocks,
5456
}
5557
}
5658

src/types/debug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ export interface ChainState {
264264
block: number
265265
totalAmount: NumberString
266266
currentPrice: number
267+
minimumValidityBlocks?: number
267268
}
268269

269270
export interface WalletBalance {

src/types/schema.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { z } from 'zod'
2+
import { asNumberString } from '../utils/type'
3+
4+
export const GetChainStateResponse = z.object({
5+
chainTip: z.number(),
6+
block: z.number(),
7+
totalAmount: z.string().transform(s => asNumberString(s, { name: 'totalAmount' })),
8+
currentPrice: z.string().transform(Number),
9+
minimumValidityBlocks: z.number().optional(),
10+
})

test/integration/status.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ test('GET chain state', async () => {
3131
expect(chainState.block).toBeGreaterThan(300)
3232
expect(parseInt(chainState.totalAmount)).not.toBeNaN()
3333
expect(chainState.currentPrice).toBe(24000)
34+
expect(chainState.minimumValidityBlocks).toBeGreaterThan(0)
3435
})
3536

3637
test('GET redistribution state', async () => {

0 commit comments

Comments
 (0)