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

Making Full Node Handle batch RPC Requests #46

Merged
merged 4 commits into from
Mar 20, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
test updates
  • Loading branch information
willmeister committed Mar 19, 2020

Verified

This commit was signed with the committer’s verified signature. The key has expired.
willmeister Will Meister
commit 4d58c8ab193e9fe562752f9e652fefd030cd01a8
158 changes: 105 additions & 53 deletions packages/rollup-full-node/test/app/fullnode-rpc-server.spec.ts
Original file line number Diff line number Diff line change
@@ -53,6 +53,31 @@ const request = async (
})
}

const getBadPayloads = () => {
return [
{
jsonrpc: '2.0',
method: defaultSupportedMethods[0],
},
{
id: '1',
jsonrpc: '2.0',
method: defaultSupportedMethods[0],
},
{
id: 1,
method: defaultSupportedMethods[0],
},
{
id: 1,
jsonrpc: 2.0,
method: defaultSupportedMethods[0],
},
{ id: 1, jsonrpc: '2.0' },
{ id: 1, jsonrpc: '2.0', method: unsupportedMethod },
]
}

const host = '0.0.0.0'
const port = 9999

@@ -77,75 +102,102 @@ describe('FullnodeHandler RPC Server', () => {
}
})

it('should work for valid requests & methods', async () => {
const results: AxiosResponse[] = await Promise.all(
Array.from(defaultSupportedMethods).map((x) =>
request(client, { id: 1, jsonrpc: '2.0', method: x })
describe('single requests', () => {
it('should work for valid requests & methods', async () => {
const results: AxiosResponse[] = await Promise.all(
Array.from(defaultSupportedMethods).map((x) =>
request(client, { id: 1, jsonrpc: '2.0', method: x })
)
)
)

results.forEach((r) => {
r.status.should.equal(200)
results.forEach((r) => {
r.status.should.equal(200)

r.data.should.haveOwnProperty('id')
r.data['id'].should.equal(1)
r.data.should.haveOwnProperty('id')
r.data['id'].should.equal(1)

r.data.should.haveOwnProperty('jsonrpc')
r.data['jsonrpc'].should.equal('2.0')
r.data.should.haveOwnProperty('jsonrpc')
r.data['jsonrpc'].should.equal('2.0')

r.data.should.haveOwnProperty('result')
r.data['result'].should.equal(dummyResponse)
r.data.should.haveOwnProperty('result')
r.data['result'].should.equal(dummyResponse)
})
})
})

it('fails on bad format or method', async () => {
const results: AxiosResponse[] = await Promise.all([
request(client, { jsonrpc: '2.0', method: defaultSupportedMethods[0] }),
request(client, {
id: '1',
jsonrpc: '2.0',
method: defaultSupportedMethods[0],
}),
request(client, { id: 1, method: defaultSupportedMethods[0] }),
request(client, {
id: 1,
jsonrpc: 2.0,
method: defaultSupportedMethods[0],
}),
request(client, { id: 1, jsonrpc: '2.0' }),
request(client, { id: 1, jsonrpc: '2.0', method: unsupportedMethod }),
])
it('fails on bad format or method', async () => {
const results: AxiosResponse[] = await Promise.all(
getBadPayloads().map((x) => request(client, x))
)
results.forEach((r) => {
r.status.should.equal(200)

results.forEach((r) => {
r.status.should.equal(200)
r.data.should.haveOwnProperty('id')
r.data.should.haveOwnProperty('jsonrpc')
r.data.should.haveOwnProperty('error')

r.data.should.haveOwnProperty('id')
r.data.should.haveOwnProperty('jsonrpc')
r.data.should.haveOwnProperty('error')
r.data['jsonrpc'].should.equal('2.0')
})
})

r.data['jsonrpc'].should.equal('2.0')
it('reverts properly', async () => {
const result: AxiosResponse = await request(client, {
id: 1,
jsonrpc: '2.0',
method: revertMethod,
})

result.status.should.equal(200)

result.data.should.haveOwnProperty('id')
result.data.should.haveOwnProperty('jsonrpc')
result.data.should.haveOwnProperty('error')
result.data['error'].should.haveOwnProperty('message')
result.data['error'].should.haveOwnProperty('code')
result.data['error']['message'].should.equal(
JSONRPC_ERRORS.REVERT_ERROR.message
)
result.data['error']['code'].should.equal(
JSONRPC_ERRORS.REVERT_ERROR.code
)

result.data['jsonrpc'].should.equal('2.0')
})
})

it('reverts properly', async () => {
const result: AxiosResponse = await request(client, {
id: 1,
jsonrpc: '2.0',
method: revertMethod,
describe('batch requests', () => {
it('should work for valid requests & methods', async () => {
const batchRequest = Array.from(
defaultSupportedMethods
).map((method, id) => ({ jsonrpc: '2.0', id, method }))
const result: AxiosResponse = await request(client, batchRequest)

result.status.should.equal(200)
const results = result.data

results.forEach((r, id) => {
r.should.haveOwnProperty('id')
r['id'].should.equal(id)

r.should.haveOwnProperty('jsonrpc')
r['jsonrpc'].should.equal('2.0')

r.should.haveOwnProperty('result')
r['result'].should.equal(dummyResponse)
})
})
it('should fail on bad format or for valid requests & methods', async () => {
const result: AxiosResponse = await request(client, getBadPayloads())

result.status.should.equal(200)
result.status.should.equal(200)
const results = result.data

result.data.should.haveOwnProperty('id')
result.data.should.haveOwnProperty('jsonrpc')
result.data.should.haveOwnProperty('error')
result.data['error'].should.haveOwnProperty('message')
result.data['error'].should.haveOwnProperty('code')
result.data['error']['message'].should.equal(
JSONRPC_ERRORS.REVERT_ERROR.message
)
result.data['error']['code'].should.equal(JSONRPC_ERRORS.REVERT_ERROR.code)
results.forEach((r) => {
r.should.haveOwnProperty('id')
r.should.haveOwnProperty('jsonrpc')
r.should.haveOwnProperty('error')

result.data['jsonrpc'].should.equal('2.0')
r['jsonrpc'].should.equal('2.0')
})
})
})
})