Skip to content

Commit

Permalink
fix: return empty array if payload of batch request is an empty array
Browse files Browse the repository at this point in the history
Short circuit batch request with an empty array if request payload
is an empty array
  • Loading branch information
Keith-CY committed Jun 6, 2023
1 parent 5a462ca commit dc67253
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/ckb-sdk-rpc/__tests__/ckb-rpc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,11 @@ describe('Test with mock', () => {
},
])
})

it('should return empty array as response if request is an empty array', async () => {
const emptyBatch = rpc.createBatchRequest([])
expect(await emptyBatch.exec()).toEqual([])
})
})
})

Expand Down
4 changes: 4 additions & 0 deletions packages/ckb-sdk-rpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class CKBRPC extends Base {
}
})

if (!payload.length) {
return []
}

const batchRes = await axios({
method: 'POST',
headers: { 'content-type': 'application/json' },
Expand Down

0 comments on commit dc67253

Please sign in to comment.