@@ -27,7 +27,7 @@ import { Registry } from 'prom-client';
2727import sinon from 'sinon' ;
2828import cache from 'js-cache' ;
2929dotenv . config ( { path : path . resolve ( __dirname , '../test.env' ) } ) ;
30- import { RelayImpl , MirrorNodeClientError } from '@hashgraph/json-rpc-relay' ;
30+ import { RelayImpl } from '@hashgraph/json-rpc-relay' ;
3131import { predefined } from '../../src/lib/errors/JsonRpcError' ;
3232import { EthImpl } from '../../src/lib/eth' ;
3333import { MirrorNodeClient } from '../../src/lib/clients/mirrorNodeClient' ;
@@ -417,7 +417,7 @@ describe('Eth calls using MirrorNode', async function () {
417417 "contract_id" : "0.0.1052" ,
418418 "created_timestamp" : "1659622477.294172233" ,
419419 "deleted" : false ,
420- "evm_address" : contractAddress1 ,
420+ "evm_address" : null ,
421421 "expiration_timestamp" : null ,
422422 "file_id" : "0.0.1051" ,
423423 "max_automatic_token_associations" : 0 ,
@@ -805,7 +805,7 @@ describe('Eth calls using MirrorNode', async function () {
805805 try {
806806 await ethImpl . getBlockByHash ( blockHash , false ) ;
807807 } catch ( e ) {
808- console . log ( e ) ;
808+
809809 expect ( e . code ) . to . equal ( - 32603 ) ;
810810 expect ( e . name ) . to . equal ( 'Internal error' ) ;
811811 }
@@ -931,7 +931,6 @@ describe('Eth calls using MirrorNode', async function () {
931931 try {
932932 await ethImpl . getTransactionByBlockNumberAndIndex ( EthImpl . numberTo0x ( defaultBlock . number ) , EthImpl . numberTo0x ( defaultBlock . count ) ) ;
933933 } catch ( e ) {
934- console . log ( e ) ;
935934 expect ( e . code ) . to . equal ( - 32603 ) ;
936935 expect ( e . name ) . to . equal ( 'Internal error' ) ;
937936 }
@@ -1036,7 +1035,6 @@ describe('Eth calls using MirrorNode', async function () {
10361035 try {
10371036 await ethImpl . getTransactionByBlockHashAndIndex ( defaultBlock . hash , EthImpl . numberTo0x ( defaultBlock . count ) ) ;
10381037 } catch ( e ) {
1039- console . log ( e ) ;
10401038 expect ( e . code ) . to . equal ( - 32603 ) ;
10411039 expect ( e . name ) . to . equal ( 'Internal error' ) ;
10421040 }
@@ -1454,13 +1452,58 @@ describe('Eth calls using MirrorNode', async function () {
14541452 } ) ;
14551453
14561454 it ( 'no filters' , async function ( ) {
1455+ const filteredLogs = {
1456+ logs : [
1457+ defaultLogs . logs [ 0 ] ,
1458+ { ...defaultLogs . logs [ 1 ] , address : "0x0000000000000000000000000000000002131952" } ,
1459+ { ...defaultLogs . logs [ 2 ] , address : "0x0000000000000000000000000000000002131953" } ,
1460+ { ...defaultLogs . logs [ 3 ] , address : "0x0000000000000000000000000000000002131954" }
1461+ ]
1462+ } ;
14571463 mock . onGet ( "blocks?limit=1&order=desc" ) . reply ( 200 , { blocks : [ defaultBlock ] } ) ;
1458- mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , defaultLogs ) ;
1464+ mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1465+ filteredLogs . logs . forEach ( ( log , index ) => {
1466+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , { ...defaultContract , contract_id : `0.0.105${ index } ` } ) ;
1467+ } ) ;
1468+
1469+ const result = await ethImpl . getLogs ( null , null , null , null , null ) ;
1470+ expect ( result ) . to . exist ;
1471+
1472+ expect ( result . length ) . to . eq ( 4 ) ;
1473+ expectLogData ( result [ 0 ] , filteredLogs . logs [ 0 ] , defaultDetailedContractResults ) ;
1474+ expectLogData ( result [ 1 ] , filteredLogs . logs [ 1 ] , defaultDetailedContractResults ) ;
1475+ expectLogData ( result [ 2 ] , filteredLogs . logs [ 2 ] , defaultDetailedContractResults2 ) ;
1476+ expectLogData ( result [ 3 ] , filteredLogs . logs [ 3 ] , defaultDetailedContractResults3 ) ;
1477+ } ) ;
1478+
1479+ it ( 'Should return evm address if contract has one' , async function ( ) {
1480+ const filteredLogs = {
1481+ logs : [ defaultLogs . logs [ 0 ] ]
1482+ } ;
1483+
1484+ mock . onGet ( "blocks?limit=1&order=desc" ) . reply ( 200 , { blocks : [ defaultBlock ] } ) ;
1485+ mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1486+ mock . onGet ( `contracts/${ filteredLogs . logs [ 0 ] . address } ` ) . reply ( 200 , { ...defaultContract , evm_address : defaultEvmAddress } ) ;
14591487
14601488 const result = await ethImpl . getLogs ( null , null , null , null , null ) ;
14611489 expect ( result ) . to . exist ;
14621490
1491+ expect ( result . length ) . to . eq ( 1 ) ;
1492+ expect ( result [ 0 ] . address ) . to . eq ( defaultEvmAddress ) ;
1493+ } ) ;
1494+
1495+ it ( 'Should cache contracts/contractIdOrAddress request' , async function ( ) {
1496+ mock . onGet ( "blocks?limit=1&order=desc" ) . reply ( 200 , { blocks : [ defaultBlock ] } ) ;
1497+ mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , defaultLogs ) ;
1498+ mock . onGet ( `contracts/${ defaultLogs . logs [ 0 ] . address } ` ) . replyOnce ( 200 , defaultContract ) ; // This mock will fire only once, if the request is not cached, the test will fail with no mock error
1499+
1500+ const result = await ethImpl . getLogs ( null , null , null , null , null ) ;
1501+
1502+ expect ( cache . keys ( ) . includes ( 'getLogEvmAddress.0x0000000000000000000000000000000002131951' ) ) . to . be . true ;
1503+
1504+ expect ( result ) . to . exist ;
14631505 expect ( result . length ) . to . eq ( 4 ) ;
1506+
14641507 expectLogData1 ( result [ 0 ] ) ;
14651508 expectLogData2 ( result [ 1 ] ) ;
14661509 expectLogData3 ( result [ 2 ] ) ;
@@ -1473,6 +1516,9 @@ describe('Eth calls using MirrorNode', async function () {
14731516 } ;
14741517 mock . onGet ( "blocks?limit=1&order=desc" ) . reply ( 200 , { blocks : [ defaultBlock ] } ) ;
14751518 mock . onGet ( `contracts/${ contractAddress1 } /results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1519+ for ( const log of filteredLogs . logs ) {
1520+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1521+ }
14761522
14771523 const result = await ethImpl . getLogs ( null , null , null , contractAddress1 , null ) ;
14781524
@@ -1491,6 +1537,9 @@ describe('Eth calls using MirrorNode', async function () {
14911537
14921538 mock . onGet ( `blocks/${ blockHash } ` ) . reply ( 200 , defaultBlock ) ;
14931539 mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1540+ for ( const log of filteredLogs . logs ) {
1541+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1542+ }
14941543
14951544 const result = await ethImpl . getLogs ( blockHash , null , null , null , null ) ;
14961545
@@ -1515,6 +1564,9 @@ describe('Eth calls using MirrorNode', async function () {
15151564 mock . onGet ( 'blocks/5' ) . reply ( 200 , defaultBlock ) ;
15161565 mock . onGet ( 'blocks/16' ) . reply ( 200 , toBlock ) ;
15171566 mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ toBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1567+ for ( const log of filteredLogs . logs ) {
1568+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1569+ }
15181570
15191571 const result = await ethImpl . getLogs ( null , '0x5' , '0x10' , null , null ) ;
15201572
@@ -1526,6 +1578,7 @@ describe('Eth calls using MirrorNode', async function () {
15261578 it ( 'with non-existing fromBlock filter' , async function ( ) {
15271579 mock . onGet ( 'blocks/5' ) . reply ( 200 , defaultBlock ) ;
15281580 mock . onGet ( 'blocks/16' ) . reply ( 404 , { "_status" : { "messages" : [ { "message" : "Not found" } ] } } ) ;
1581+
15291582 const result = await ethImpl . getLogs ( null , '0x10' , '0x5' , null , null ) ;
15301583
15311584 expect ( result ) . to . exist ;
@@ -1540,6 +1593,8 @@ describe('Eth calls using MirrorNode', async function () {
15401593 mock . onGet ( 'blocks/5' ) . reply ( 200 , defaultBlock ) ;
15411594 mock . onGet ( 'blocks/16' ) . reply ( 404 , { "_status" : { "messages" : [ { "message" : "Not found" } ] } } ) ;
15421595 mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ` ) . reply ( 200 , filteredLogs ) ;
1596+ mock . onGet ( `contracts/${ filteredLogs . logs [ 0 ] . address } ` ) . reply ( 200 , defaultContract ) ;
1597+
15431598 const result = await ethImpl . getLogs ( null , '0x5' , '0x10' , null , null ) ;
15441599
15451600 expect ( result ) . to . exist ;
@@ -1571,6 +1626,9 @@ describe('Eth calls using MirrorNode', async function () {
15711626
15721627 mock . onGet ( 'blocks?limit=1&order=desc' ) . reply ( 200 , { blocks : [ defaultBlock ] } ) ;
15731628 mock . onGet ( `contracts/results/logs?timestamp=gte:${ defaultBlock . timestamp . from } ×tamp=lte:${ defaultBlock . timestamp . to } ` ) . reply ( 200 , filteredLogs ) ;
1629+ for ( const log of filteredLogs . logs ) {
1630+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1631+ }
15741632
15751633 const result = await ethImpl . getLogs ( null , null , 'latest' , null , null ) ;
15761634
@@ -1610,6 +1668,9 @@ describe('Eth calls using MirrorNode', async function () {
16101668 `&topic0=${ defaultLogTopics [ 0 ] } &topic1=${ defaultLogTopics [ 1 ] } ` +
16111669 `&topic2=${ defaultLogTopics [ 2 ] } &topic3=${ defaultLogTopics [ 3 ] } `
16121670 ) . reply ( 200 , filteredLogs ) ;
1671+ for ( const log of filteredLogs . logs ) {
1672+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1673+ }
16131674
16141675 const result = await ethImpl . getLogs ( null , null , null , null , defaultLogTopics ) ;
16151676
@@ -1632,6 +1693,9 @@ describe('Eth calls using MirrorNode', async function () {
16321693 `&topic0=${ defaultLogTopics [ 0 ] } &topic1=${ defaultLogTopics [ 1 ] } ` +
16331694 `&topic2=${ defaultLogTopics [ 2 ] } &topic3=${ defaultLogTopics [ 3 ] } `
16341695 ) . reply ( 200 , filteredLogs ) ;
1696+ for ( const log of filteredLogs . logs ) {
1697+ mock . onGet ( `contracts/${ log . address } ` ) . reply ( 200 , defaultContract ) ;
1698+ }
16351699
16361700 const result = await ethImpl . getLogs ( null , '0x5' , '0x10' , null , defaultLogTopics ) ;
16371701
0 commit comments