@@ -29,6 +29,7 @@ import {AccountBalanceQuery, ContractFunctionParameters} from '@hashgraph/sdk';
2929// local resources
3030import parentContractJson from '../contracts/Parent.json' ;
3131import basicContractJson from '../contracts/Basic.json' ;
32+ import logsContractJson from '../contracts/Logs.json' ;
3233import { predefined } from '../../../relay/src/lib/errors' ;
3334
3435describe ( 'RPC Server Acceptance Tests' , function ( ) {
@@ -96,6 +97,137 @@ describe('RPC Server Acceptance Tests', function () {
9697 mirrorSecondaryAccount = ( await mirrorNode . get ( `accounts?account.id=${ accounts [ 1 ] . accountId } ` ) ) . accounts [ 0 ] ;
9798 } ) ;
9899
100+ describe ( 'eth_getLogs' , ( ) => {
101+
102+ let log0Block , log4Block , contractAddress ;
103+
104+ it ( 'should deploy a contract' , async ( ) => {
105+ const logsContract = await servicesNode . deployContract ( logsContractJson ) ;
106+ const mirrorNodeResp = await mirrorNode . get ( `/contracts/${ logsContract . contractId } ` ) ;
107+ expect ( mirrorNodeResp ) . to . have . property ( 'evm_address' ) ;
108+ expect ( mirrorNodeResp . env_address ) . to . not . be . null ;
109+ contractAddress = mirrorNodeResp . evm_address ;
110+
111+ const params = new ContractFunctionParameters ( ) . addUint256 ( 1 ) ;
112+ const log0 = await accounts [ 1 ] . client . executeContractCall ( logsContract . contractId , 'log0' , params ) ;
113+ await accounts [ 1 ] . client . executeContractCall ( logsContract . contractId , 'log1' , params ) ;
114+
115+ params . addUint256 ( 1 ) ;
116+ await accounts [ 1 ] . client . executeContractCall ( logsContract . contractId , 'log2' , params ) ;
117+
118+ params . addUint256 ( 1 ) ;
119+ await accounts [ 1 ] . client . executeContractCall ( logsContract . contractId , 'log3' , params ) ;
120+
121+ params . addUint256 ( 1 ) ;
122+ const log4 = await accounts [ 1 ] . client . executeContractCall ( logsContract . contractId , 'log4' , params ) ;
123+
124+ await new Promise ( r => setTimeout ( r , 5000 ) ) ;
125+
126+ const logs = await relay . call ( 'eth_getLogs' , [ { } ] ) ;
127+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
128+ const txIndexLogIndexMapping : any [ ] = [ ] ;
129+ for ( let i in logs ) {
130+ expect ( logs [ i ] ) . to . have . property ( 'address' ) ;
131+ expect ( logs [ i ] ) . to . have . property ( 'logIndex' ) ;
132+
133+ const key = `${ logs [ i ] . transactionHash } ---${ logs [ i ] . logIndex } ` ;
134+ txIndexLogIndexMapping . push ( key ) ;
135+ }
136+ const uniqueTxIndexLogIndexMapping = txIndexLogIndexMapping . filter ( ( value , index , self ) =>
137+ self . indexOf ( value ) === index
138+ ) ;
139+ expect ( txIndexLogIndexMapping . length ) . to . equal ( uniqueTxIndexLogIndexMapping . length ) ;
140+
141+ log0Block = await relay . call ( 'eth_getTransactionByHash' , [ log0 . contractExecutedTransactionId ] ) ;
142+ expect ( log0Block ) . to . have . property ( 'blockNumber' ) ;
143+
144+ log4Block = await relay . call ( 'eth_getTransactionByHash' , [ log4 . contractExecutedTransactionId ] ) ;
145+ expect ( log4Block ) . to . have . property ( 'blockNumber' ) ;
146+ } ) ;
147+
148+ it ( 'should be able to use `fromBlock` param' , async ( ) => {
149+ const logs = await relay . call ( 'eth_getLogs' , [ {
150+ 'fromBlock' : log4Block . blockNumber
151+ } ] ) ;
152+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
153+
154+ const log4BlockInt = parseInt ( log4Block . blockNumber ) ;
155+ for ( let i in logs ) {
156+ expect ( logs [ i ] . blockNumber ) . to . be . greaterThanOrEqual ( log4BlockInt ) ;
157+ }
158+ } ) ;
159+
160+ it ( 'should be able to use `toBlock` param' , async ( ) => {
161+ const logs = await relay . call ( 'eth_getLogs' , [ {
162+ 'toBlock' : log0Block . blockNumber
163+ } ] ) ;
164+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
165+
166+ const log0BlockInt = parseInt ( log0Block . blockNumber ) ;
167+ for ( let i in logs ) {
168+ expect ( logs [ i ] . blockNumber ) . to . be . lessThanOrEqual ( log0BlockInt ) ;
169+ }
170+ } ) ;
171+
172+ it ( 'should be able to use range of `fromBlock` and `toBlock` params' , async ( ) => {
173+ const logs = await relay . call ( 'eth_getLogs' , [ {
174+ 'fromBlock' : log0Block . blockNumber ,
175+ 'toBlock' : log4Block . blockNumber
176+ } ] ) ;
177+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
178+
179+ const log0BlockInt = parseInt ( log0Block . blockNumber ) ;
180+ const log4BlockInt = parseInt ( log4Block . blockNumber ) ;
181+ for ( let i in logs ) {
182+ expect ( logs [ i ] . blockNumber ) . to . be . greaterThanOrEqual ( log0BlockInt ) ;
183+ expect ( logs [ i ] . blockNumber ) . to . be . lessThanOrEqual ( log4BlockInt ) ;
184+ }
185+ } ) ;
186+
187+ it ( 'should be able to use `address` param' , async ( ) => {
188+ const logs = await relay . call ( 'eth_getLogs' , [ {
189+ 'address' : contractAddress
190+ } ] ) ;
191+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
192+
193+ for ( let i in logs ) {
194+ expect ( logs [ i ] . address ) . to . equal ( contractAddress ) ;
195+ }
196+ } ) ;
197+
198+ it ( 'should be able to use `blockHash` param' , async ( ) => {
199+ const logs = await relay . call ( 'eth_getLogs' , [ {
200+ 'blockHash' : log0Block . blockHash
201+ } ] ) ;
202+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
203+
204+ for ( let i in logs ) {
205+ expect ( logs [ i ] . blockHash ) . to . equal ( log0Block . blockHash ) ;
206+ }
207+ } ) ;
208+
209+ it ( 'should be able to use `topics` param' , async ( ) => {
210+ const logs = await relay . call ( 'eth_getLogs' , [ {
211+ 'fromBlock' : log0Block . blockNumber ,
212+ 'toBlock' : log4Block . blockNumber ,
213+ } ] ) ;
214+ expect ( logs . length ) . to . be . greaterThan ( 0 ) ;
215+ const topic = logs [ 0 ] . topics [ 0 ] ;
216+
217+ const logsWithTopic = await relay . call ( 'eth_getLogs' , [ {
218+ 'fromBlock' : log0Block . blockNumber ,
219+ 'toBlock' : log4Block . blockNumber ,
220+ 'topics' : [ logs [ 0 ] . topics [ 0 ] ]
221+ } ] ) ;
222+ expect ( logsWithTopic . length ) . to . be . greaterThan ( 0 ) ;
223+
224+ for ( let i in logsWithTopic ) {
225+ expect ( logsWithTopic [ i ] . topics . length ) . to . be . greaterThan ( 0 ) ;
226+ expect ( logsWithTopic [ i ] . topics [ 0 ] ) . to . be . equal ( topic ) ;
227+ }
228+ } ) ;
229+ } ) ;
230+
99231 describe ( 'Block related RPC calls' , ( ) => {
100232
101233 let mirrorBlock ;
@@ -820,7 +952,7 @@ describe('RPC Server Acceptance Tests', function () {
820952 describe ( 'Gas Price related RPC endpoints' , ( ) => {
821953 let lastBlockBeforeUpdate ;
822954 let lastBlockAfterUpdate ;
823-
955+
824956 before ( async ( ) => {
825957 await servicesNode . updateFileContent ( FEE_SCHEDULE_FILE_ID , FEE_SCHEDULE_FILE_CONTENT_DEFAULT ) ;
826958 await servicesNode . updateFileContent ( EXCHANGE_RATE_FILE_ID , EXCHANGE_RATE_FILE_CONTENT_DEFAULT ) ;
@@ -857,7 +989,7 @@ describe('RPC Server Acceptance Tests', function () {
857989 await relay . call ( 'eth_feeHistory' , [ '0x1' , newestBlockNumberHex , null ] ) ;
858990 } catch ( error ) {
859991 Assertions . jsonRpcError ( error , predefined . REQUEST_BEYOND_HEAD_BLOCK ( newestBlockNumber , latestBlock . number ) ) ;
860- }
992+ }
861993 } ) ;
862994
863995 it ( 'should call eth_feeHistory with zero block count' , async function ( ) {
0 commit comments