Skip to content

Commit 51c7965

Browse files
committed
Add E2E tests for validating max addresses on related JSON-RPC endpoints
1 parent 675a659 commit 51c7965

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

tests/web3js/eth_filter_endpoints_test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,47 @@ describe('eth_newFilter', async () => {
5454
assert.equal(response.body.error.message, 'invalid argument 0: exceed max topics')
5555
})
5656

57+
it('should validate max number of addresses', async () => {
58+
let latestBlockNumber = await web3.eth.getBlockNumber()
59+
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
60+
61+
let addresses = []
62+
for (let i = 0; i <= 1000; i++) {
63+
addresses.push(
64+
'0x0000000071727de22e5e9d8baf0edac6f37da032'
65+
)
66+
}
67+
68+
let blockRangeFilter = {
69+
fromBlock: web3.utils.numberToHex(latestBlock.number),
70+
toBlock: web3.utils.numberToHex(latestBlock.number),
71+
address: addresses,
72+
topics: []
73+
}
74+
75+
let response = await helpers.callRPCMethod('eth_newFilter', [blockRangeFilter])
76+
assert.equal(response.status, 200)
77+
assert.isDefined(response.body.error)
78+
assert.equal(response.body.error.message, 'invalid argument 0: exceed max addresses')
79+
80+
let blockHashFilter = {
81+
blockHash: latestBlock.hash,
82+
address: addresses,
83+
topics: []
84+
}
85+
86+
response = await helpers.callRPCMethod('eth_newFilter', [blockHashFilter])
87+
assert.equal(response.status, 200)
88+
assert.isDefined(response.body.error)
89+
assert.equal(response.body.error.message, 'invalid argument 0: exceed max addresses')
90+
})
91+
5792
it('should validate max number of sub-topics', async () => {
5893
let latestBlockNumber = await web3.eth.getBlockNumber()
5994
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
6095

6196
let subTopics = []
62-
for (i = 0; i <= 1000; i++) {
97+
for (let i = 0; i <= 1000; i++) {
6398
subTopics.push(
6499
'0x76efea95e5da1fa661f235b2921ae1d89b99e457ec73fb88e34a1d150f95c64b'
65100
)

tests/web3js/eth_logs_filtering_test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,47 @@ it('validates max number of allowed topics', async () => {
231231
assert.equal(response.body.error.message, 'invalid argument 0: exceed max topics')
232232
})
233233

234+
it('validates max number of allowed addresses', async () => {
235+
let latestBlockNumber = await web3.eth.getBlockNumber()
236+
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
237+
238+
let addresses = []
239+
for (let i = 0; i <= 1000; i++) {
240+
addresses.push(
241+
'0x0000000071727de22e5e9d8baf0edac6f37da032'
242+
)
243+
}
244+
245+
let blockRangeFilter = {
246+
fromBlock: web3.utils.numberToHex(latestBlock.number),
247+
toBlock: web3.utils.numberToHex(latestBlock.number),
248+
address: addresses,
249+
topics: []
250+
}
251+
252+
let response = await helpers.callRPCMethod('eth_getLogs', [blockRangeFilter])
253+
assert.equal(response.status, 200)
254+
assert.isDefined(response.body.error)
255+
assert.equal(response.body.error.message, 'invalid argument 0: exceed max addresses')
256+
257+
let blockHashFilter = {
258+
blockHash: latestBlock.hash,
259+
address: addresses,
260+
topics: []
261+
}
262+
263+
response = await helpers.callRPCMethod('eth_getLogs', [blockHashFilter])
264+
assert.equal(response.status, 200)
265+
assert.isDefined(response.body.error)
266+
assert.equal(response.body.error.message, 'invalid argument 0: exceed max addresses')
267+
})
268+
234269
it('validates max number of allowed sub-topics', async () => {
235270
let latestBlockNumber = await web3.eth.getBlockNumber()
236271
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
237272

238273
let subTopics = []
239-
for (i = 0; i <= 1000; i++) {
274+
for (let i = 0; i <= 1000; i++) {
240275
subTopics.push(
241276
'0x76efea95e5da1fa661f235b2921ae1d89b99e457ec73fb88e34a1d150f95c64b'
242277
)

tests/web3js/eth_streaming_filters_test.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,62 @@ it('should validate max number of topics', async () => {
228228
ws.currentProvider.disconnect()
229229
})
230230

231+
it('should validate max number of addresses', async () => {
232+
let latestBlockNumber = await web3.eth.getBlockNumber()
233+
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
234+
235+
let addresses = []
236+
for (let i = 0; i <= 1000; i++) {
237+
addresses.push(
238+
'0x0000000071727de22e5e9d8baf0edac6f37da032'
239+
)
240+
}
241+
242+
let blockRangeFilter = {
243+
fromBlock: web3.utils.numberToHex(latestBlock.number),
244+
toBlock: web3.utils.numberToHex(latestBlock.number),
245+
address: addresses,
246+
topics: []
247+
}
248+
249+
let ws = new Web3('ws://127.0.0.1:8545')
250+
251+
try {
252+
await ws.eth.subscribe('logs', blockRangeFilter)
253+
assert.fail('should have received response error')
254+
} catch (err) {
255+
assert.equal(
256+
err.innerError.message,
257+
'invalid argument 1: exceed max addresses'
258+
)
259+
}
260+
261+
let blockHashFilter = {
262+
blockHash: latestBlock.hash,
263+
address: addresses,
264+
topics: []
265+
}
266+
267+
try {
268+
await ws.eth.subscribe('logs', blockHashFilter)
269+
assert.fail('should have received response error')
270+
} catch (err) {
271+
assert.equal(
272+
err.innerError.message,
273+
'invalid argument 1: exceed max addresses'
274+
)
275+
}
276+
277+
ws.currentProvider.disconnect()
278+
})
279+
280+
231281
it('should validate max number of sub-topics', async () => {
232282
let latestBlockNumber = await web3.eth.getBlockNumber()
233283
let latestBlock = await web3.eth.getBlock(latestBlockNumber)
234284

235285
let subTopics = []
236-
for (i = 0; i <= 1000; i++) {
286+
for (let i = 0; i <= 1000; i++) {
237287
subTopics.push(
238288
'0x76efea95e5da1fa661f235b2921ae1d89b99e457ec73fb88e34a1d150f95c64b'
239289
)

0 commit comments

Comments
 (0)