Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return empty array if payload of batch request is an empty array #616

Merged
merged 1 commit into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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