Skip to content

Commit

Permalink
fix request constructor test
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottyPoi committed Aug 27, 2024
1 parent 56f7ff8 commit 9a3d707
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/util/test/requests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@ import { bytesToBigInt, randomBytes } from '../src/bytes.js'
import {
CLRequestFactory,
CLRequestType,
createConsolidationRequest,
createDepositRequest,
createWithdrawalRequest,
} from '../src/request.js'

import type {
CLRequest,
ConsolidationRequest,
DepositRequest,
WithdrawalRequest,
} from '../src/request.js'

import type { CLRequest } from '../src/request.js'

describe('Requests', () => {
const testCases = [
const testCases: [
string,
any,
CLRequestType,
(...args: any) => ConsolidationRequest | DepositRequest | WithdrawalRequest,
][] = [
[
'DepositRequest',
{
Expand All @@ -23,7 +33,7 @@ describe('Requests', () => {
index: bytesToBigInt(randomBytes(8)),
},
CLRequestType.Deposit,
DepositRequest,
createDepositRequest,
],
[
'WithdrawalRequest',
Expand All @@ -33,7 +43,7 @@ describe('Requests', () => {
amount: bytesToBigInt(randomBytes(8)),
},
CLRequestType.Withdrawal,
WithdrawalRequest,
createWithdrawalRequest,
],
[
'ConsolidationRequest',
Expand All @@ -43,14 +53,12 @@ describe('Requests', () => {
targetPubkey: randomBytes(48),
},
CLRequestType.Consolidation,
ConsolidationRequest,
createConsolidationRequest,
],
]
for (const [requestName, requestData, requestType, RequestInstanceType] of testCases) {
for (const [requestName, requestData, requestType, requestInstanceConstructor] of testCases) {
it(`${requestName}`, () => {
const requestObject = RequestInstanceType.fromRequestData(
requestData,
) as CLRequest<CLRequestType>
const requestObject = requestInstanceConstructor(requestData) as CLRequest<CLRequestType>
const requestJSON = requestObject.toJSON()
const serialized = requestObject.serialize()
assert.equal(serialized[0], requestType)
Expand Down

0 comments on commit 9a3d707

Please sign in to comment.