-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for eth_getFilterLogs endpoint
- Loading branch information
Showing
4 changed files
with
682 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const chai = require('chai') | ||
const chaiHttp = require('chai-http') | ||
const conf = require('./config') | ||
const helpers = require('./helpers') | ||
const web3 = conf.web3 | ||
chai.use(chaiHttp); | ||
|
||
it('create logs filter and call eth_getFilterLogs', async () => { | ||
// deploy contract | ||
let deployed = await helpers.deployContract('storage') | ||
let contractAddress = deployed.receipt.contractAddress | ||
|
||
// create logs filter on the address of the deployed contract | ||
let response = await callRPCMethod('eth_newFilter', [{ 'address': contractAddress }]) | ||
|
||
chai.assert.equal(200, response.status) | ||
chai.assert.isDefined(response.body['result']) | ||
let filterID = response.body['result'] | ||
|
||
// make contract function call that emits a log | ||
let res = await helpers.signAndSend({ | ||
from: conf.eoa.address, | ||
to: contractAddress, | ||
data: deployed.contract.methods.sum(15, 20).encodeABI(), | ||
gas: 1000000, | ||
gasPrice: 0 | ||
}) | ||
chai.assert.equal(res.receipt.status, conf.successStatus) | ||
|
||
// check the matching items from the logs filter | ||
response = await callRPCMethod('eth_getFilterLogs', [filterID]) | ||
|
||
chai.assert.equal(200, response.status) | ||
chai.assert.equal(1, response.body['result'].length) | ||
|
||
let logs = response.body['result'] | ||
chai.assert.equal(contractAddress.toLowerCase(), logs[0].address) | ||
chai.assert.lengthOf(logs[0].topics, 4) | ||
chai.assert.equal( | ||
'35', | ||
web3.eth.abi.decodeParameter("int256", logs[0].data) | ||
) | ||
|
||
// make contract function call that emits another log | ||
res = await helpers.signAndSend({ | ||
from: conf.eoa.address, | ||
to: contractAddress, | ||
data: deployed.contract.methods.sum(30, 20).encodeABI(), | ||
gas: 1000000, | ||
gasPrice: 0 | ||
}) | ||
|
||
chai.assert.equal(res.receipt.status, conf.successStatus) | ||
|
||
// check the matching items from the logs filter include both logs | ||
// from the above 2 contract function calls | ||
response = await callRPCMethod('eth_getFilterLogs', [filterID]) | ||
|
||
chai.assert.equal(200, response.status) | ||
chai.assert.equal(2, response.body['result'].length) | ||
logs = response.body['result'] | ||
console.log() | ||
|
||
chai.assert.equal(contractAddress.toLowerCase(), logs[1].address) | ||
chai.assert.lengthOf(logs[1].topics, 4) | ||
chai.assert.equal( | ||
'50', | ||
web3.eth.abi.decodeParameter("int256", logs[1].data) | ||
) | ||
|
||
}).timeout(10 * 1000) | ||
|
||
async function callRPCMethod(methodName, params) { | ||
return chai.request('http://127.0.0.1:8545') | ||
.post('/') | ||
.set('Content-Type', 'application/json') | ||
.set('Accept', 'application/json') | ||
.send({ | ||
'jsonrpc': '2.0', | ||
'method': methodName, | ||
'id': 1, | ||
'params': params | ||
}) | ||
} |
Oops, something went wrong.